directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pamarce...@apache.org
Subject svn commit: r605234 - in /directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor: model/io/OpenLdapSchemaFileImporter.java view/wizards/ImportSchemasFromOpenLdapWizard.java
Date Tue, 18 Dec 2007 15:29:27 GMT
Author: pamarcelot
Date: Tue Dec 18 07:29:26 2007
New Revision: 605234

URL: http://svn.apache.org/viewvc?rev=605234&view=rev
Log:
Fix for DIRSTUDIO-239 (No error message when importing a bad schema).

Modified:
    directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/io/OpenLdapSchemaFileImporter.java
    directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/ImportSchemasFromOpenLdapWizard.java

Modified: directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/io/OpenLdapSchemaFileImporter.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/io/OpenLdapSchemaFileImporter.java?rev=605234&r1=605233&r2=605234&view=diff
==============================================================================
--- directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/io/OpenLdapSchemaFileImporter.java
(original)
+++ directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/model/io/OpenLdapSchemaFileImporter.java
Tue Dec 18 07:29:26 2007
@@ -20,11 +20,14 @@
 package org.apache.directory.studio.schemaeditor.model.io;
 
 
+import java.io.ByteArrayInputStream;
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
 import java.text.ParseException;
 import java.util.List;
+import java.util.Scanner;
+import java.util.regex.MatchResult;
 
 import org.apache.directory.server.core.tools.schema.AttributeTypeLiteral;
 import org.apache.directory.server.core.tools.schema.ObjectClassLiteral;
@@ -77,7 +80,12 @@
         }
         catch ( ParseException e )
         {
-            throw new OpenLdapSchemaFileImportException( "The file '" + path + "' can not
be read correctly." );
+            ExceptionMessage exceptionMessage = parseExceptionMessage( e.getMessage() );
+            throw new OpenLdapSchemaFileImportException( "The file '"
+                + path
+                + "' can not be read correctly."
+                + ( exceptionMessage == null ? "" : "\nLine: " + exceptionMessage.lineNumber
+ ", Column: "
+                    + exceptionMessage.columnNumber + ", Cause: " + exceptionMessage.cause
) );
         }
 
         String schemaName = getNameFromPath( path );
@@ -175,5 +183,45 @@
         newOC.setMayNamesList( oc.getMay() );
 
         return newOC;
+    }
+
+
+    /**
+     * Parses the exception message and fills an {@link ExceptionMessage}.
+     *
+     * @param message
+     *      the exception message to parse
+     * @return
+     *      the corresponding {@link ExceptionMessage}, or <code>null</code>
+     */
+    private static ExceptionMessage parseExceptionMessage( String message )
+    {
+        Scanner scanner = new Scanner( new ByteArrayInputStream( message.getBytes() ) );
+        String foundString = scanner.findWithinHorizon( ".*line (\\d+):(\\d+): *([^\\n]*).*",
message.length() );
+        if ( foundString != null )
+        {
+            MatchResult result = scanner.match();
+            if ( result.groupCount() == 3 )
+            {
+                ExceptionMessage exceptionMessage = new ExceptionMessage();
+                exceptionMessage.lineNumber = result.group( 1 );
+                exceptionMessage.columnNumber = result.group( 2 );
+                exceptionMessage.cause = result.group( 3 );
+
+                scanner.close();
+                return exceptionMessage;
+            }
+
+        }
+
+        scanner.close();
+        return null;
+    }
+
+    private static class ExceptionMessage
+    {
+        String lineNumber;
+        String columnNumber;
+        String cause;
     }
 }

Modified: directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/ImportSchemasFromOpenLdapWizard.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/ImportSchemasFromOpenLdapWizard.java?rev=605234&r1=605233&r2=605234&view=diff
==============================================================================
--- directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/ImportSchemasFromOpenLdapWizard.java
(original)
+++ directory/studio/trunk/studio-schemaeditor/src/main/java/org/apache/directory/studio/schemaeditor/view/wizards/ImportSchemasFromOpenLdapWizard.java
Tue Dec 18 07:29:26 2007
@@ -88,7 +88,7 @@
 
         try
         {
-            getContainer().run( true, false, new IRunnableWithProgress()
+            getContainer().run( false, false, new IRunnableWithProgress()
             {
                 public void run( IProgressMonitor monitor )
                 {
@@ -99,27 +99,39 @@
                         monitor.subTask( schemaFile.getName() );
                         try
                         {
-                            Schema schema = OpenLdapSchemaFileImporter.getSchema( new FileInputStream(
schemaFile), schemaFile.getAbsolutePath() );
+                            Schema schema = OpenLdapSchemaFileImporter.getSchema( new FileInputStream(
schemaFile ),
+                                schemaFile.getAbsolutePath() );
                             schemaHandler.addSchema( schema );
                         }
                         catch ( OpenLdapSchemaFileImportException e )
                         {
-                            PluginUtils.logError( "An error occured when importing the schema
" + schemaFile.getName()
-                                + ".", e );
-                            ViewUtils.displayErrorMessageBox( "Error", "An error occured
when importing the schema "
-                                + schemaFile.getName() + "." );
+                            reportError( e, schemaFile );
                         }
                         catch ( FileNotFoundException e )
                         {
-                            PluginUtils.logError( "An error occured when importing the schema
" + schemaFile.getName()
-                                + ".", e );
-                            ViewUtils.displayErrorMessageBox( "Error", "An error occured
when importing the schema "
-                                + schemaFile.getName() + "." );
+                            reportError( e, schemaFile );
                         }
                         monitor.worked( 1 );
                     }
 
                     monitor.done();
+                }
+
+
+                /**
+                 * Reports the error raised.
+                 *
+                 * @param e
+                 *      the exception
+                 * @param schemaFile
+                 *      the schema file
+                 */
+                private void reportError( Exception e, File schemaFile )
+                {
+                    PluginUtils
+                        .logError( "An error occured when importing the schema " + schemaFile.getName()
+ ".", e );
+                    ViewUtils.displayErrorMessageBox( "Error", "An error occured when importing
the schema "
+                        + schemaFile.getName() + "." + "\n\n" + e.getMessage() );
                 }
             } );
         }



Mime
View raw message