directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pamarce...@apache.org
Subject svn commit: r555305 - in /directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor: model/io/ view/wizards/
Date Wed, 11 Jul 2007 15:29:59 GMT
Author: pamarcelot
Date: Wed Jul 11 08:29:58 2007
New Revision: 555305

URL: http://svn.apache.org/viewvc?view=rev&rev=555305
Log:
Implemented the export of schemas in a single XML file.

Modified:
    directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/model/io/XMLSchemaFileExporter.java
    directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/ExportSchemasAsXmlWizard.java
    directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/ExportSchemasAsXmlWizardPage.java

Modified: directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/model/io/XMLSchemaFileExporter.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/model/io/XMLSchemaFileExporter.java?view=diff&rev=555305&r1=555304&r2=555305
==============================================================================
--- directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/model/io/XMLSchemaFileExporter.java
(original)
+++ directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/model/io/XMLSchemaFileExporter.java
Wed Jul 11 08:29:58 2007
@@ -36,6 +36,7 @@
 import org.apache.directory.studio.apacheds.schemaeditor.model.ObjectClassImpl;
 import org.apache.directory.studio.apacheds.schemaeditor.model.Schema;
 import org.apache.directory.studio.apacheds.schemaeditor.model.SyntaxImpl;
+import org.dom4j.Branch;
 import org.dom4j.Document;
 import org.dom4j.DocumentHelper;
 import org.dom4j.Element;
@@ -74,6 +75,7 @@
     private static final String OPTIONAL_TAG = "optional";
     private static final String ORDERING_TAG = "ordering";
     private static final String SCHEMA_TAG = "schema";
+    private static final String SCHEMAS_TAG = "schemas";
     private static final String SINGLE_VALUE_TAG = "singlevalue";
     private static final String SUBSTRING_TAG = "substring";
     private static final String SUPERIOR_TAG = "superior";
@@ -99,60 +101,105 @@
     {
         // Creating the Document and the 'root' Element
         Document document = DocumentHelper.createDocument();
-        Element element = document.addElement( SCHEMA_TAG );
 
-        // Name 
-        String name = schema.getName();
-        if ( ( name != null ) && ( !name.equals( "" ) ) )
-        {
-            element.addAttribute( NAME_TAG, name );
-        }
+        addSchema( schema, document );
+
+        return styleDocument( document ).asXML();
+    }
 
-        // Attribute Types
-        List<AttributeTypeImpl> ats = schema.getAttributeTypes();
-        if ( ( ats != null ) && ( ats.size() >= 1 ) )
+
+    /**
+     * Converts the given schemas to their source code representation
+     * in one XML file format.
+     *
+     * @param schemas
+     *      the array of schemas to convert
+     * @return
+     *      the corresponding source code representation
+     */
+    public static String toSourceCode( Schema[] schemas )
+    {
+        // Creating the Document and the 'root' Element
+        Document document = DocumentHelper.createDocument();
+        Element root = document.addElement( SCHEMAS_TAG );
+
+        if ( schemas != null )
         {
-            Element attributeTypesNode = element.addElement( ATTRIBUTE_TYPES_TAG );
-            for ( AttributeTypeImpl at : ats )
+            for ( Schema schema : schemas )
             {
-                toSourceCode( at, attributeTypesNode );
+                addSchema( schema, root );
             }
         }
 
-        // Object Classes
-        List<ObjectClassImpl> ocs = schema.getObjectClasses();
-        if ( ( ocs != null ) && ( ocs.size() >= 1 ) )
+        return styleDocument( document ).asXML();
+    }
+
+
+    /**
+     * Add the XML representation of the given schema
+     * to the given branch
+     *
+     * @param schema
+     *      the schema
+     * @param branch
+     *      the branch
+     */
+    public static void addSchema( Schema schema, Branch branch )
+    {
+        Element element = branch.addElement( SCHEMA_TAG );
+        if ( schema != null )
         {
-            Element objectClassesNode = element.addElement( OBJECT_CLASSES_TAG );
-            for ( ObjectClassImpl oc : ocs )
+            // Name 
+            String name = schema.getName();
+            if ( ( name != null ) && ( !name.equals( "" ) ) )
             {
-                toSourceCode( oc, objectClassesNode );
+                element.addAttribute( NAME_TAG, name );
             }
-        }
 
-        // Matching Rules
-        List<MatchingRuleImpl> mrs = schema.getMatchingRules();
-        if ( ( mrs != null ) && ( mrs.size() >= 1 ) )
-        {
-            Element matchingRulesNode = element.addElement( MATCHING_RULES_TAG );
-            for ( MatchingRuleImpl mr : mrs )
+            // Attribute Types
+            List<AttributeTypeImpl> ats = schema.getAttributeTypes();
+            if ( ( ats != null ) && ( ats.size() >= 1 ) )
             {
-                toSourceCode( mr, matchingRulesNode );
+                Element attributeTypesNode = element.addElement( ATTRIBUTE_TYPES_TAG );
+                for ( AttributeTypeImpl at : ats )
+                {
+                    toSourceCode( at, attributeTypesNode );
+                }
             }
-        }
 
-        // Syntaxes
-        List<SyntaxImpl> syntaxes = schema.getSyntaxes();
-        if ( ( syntaxes != null ) && ( syntaxes.size() >= 1 ) )
-        {
-            Element syntaxesNode = element.addElement( SYNTAXES_TAG );
-            for ( SyntaxImpl syntax : syntaxes )
+            // Object Classes
+            List<ObjectClassImpl> ocs = schema.getObjectClasses();
+            if ( ( ocs != null ) && ( ocs.size() >= 1 ) )
             {
-                toSourceCode( syntax, syntaxesNode );
+                Element objectClassesNode = element.addElement( OBJECT_CLASSES_TAG );
+                for ( ObjectClassImpl oc : ocs )
+                {
+                    toSourceCode( oc, objectClassesNode );
+                }
             }
-        }
 
-        return styleDocument( document ).asXML();
+            // Matching Rules
+            List<MatchingRuleImpl> mrs = schema.getMatchingRules();
+            if ( ( mrs != null ) && ( mrs.size() >= 1 ) )
+            {
+                Element matchingRulesNode = element.addElement( MATCHING_RULES_TAG );
+                for ( MatchingRuleImpl mr : mrs )
+                {
+                    toSourceCode( mr, matchingRulesNode );
+                }
+            }
+
+            // Syntaxes
+            List<SyntaxImpl> syntaxes = schema.getSyntaxes();
+            if ( ( syntaxes != null ) && ( syntaxes.size() >= 1 ) )
+            {
+                Element syntaxesNode = element.addElement( SYNTAXES_TAG );
+                for ( SyntaxImpl syntax : syntaxes )
+                {
+                    toSourceCode( syntax, syntaxesNode );
+                }
+            }
+        }
     }
 
 
@@ -318,7 +365,7 @@
         String description = oc.getDescription();
         if ( ( description != null ) && ( !description.equals( "" ) ) )
         {
-            ocNode.addElement( DESCRIPTION_TAG ).setText(  description );
+            ocNode.addElement( DESCRIPTION_TAG ).setText( description );
         }
 
         // Superiors
@@ -328,7 +375,7 @@
             Element superiorsNode = ocNode.addElement( SUPERIORS_TAG );
             for ( String superior : superiors )
             {
-                superiorsNode.addElement( SUPERIOR_TAG ).setText(  superior );
+                superiorsNode.addElement( SUPERIOR_TAG ).setText( superior );
             }
         }
 
@@ -336,7 +383,7 @@
         ObjectClassTypeEnum type = oc.getType();
         if ( type != null )
         {
-            ocNode.addElement( TYPE_TAG ).setText(  type.toString() );
+            ocNode.addElement( TYPE_TAG ).setText( type.toString() );
         }
 
         // Obsolete
@@ -356,7 +403,7 @@
             Element mandatoryNode = ocNode.addElement( MANDATORY_TAG );
             for ( String mandatoryAT : mandatoryATs )
             {
-                mandatoryNode.addElement( ATTRIBUTE_TYPE_TAG ).setText(  mandatoryAT );
+                mandatoryNode.addElement( ATTRIBUTE_TYPE_TAG ).setText( mandatoryAT );
             }
         }
 
@@ -367,7 +414,7 @@
             Element optionalNode = ocNode.addElement( OPTIONAL_TAG );
             for ( String optionalAT : optionalATs )
             {
-                optionalNode.addElement( ATTRIBUTE_TYPE_TAG ).setText(  optionalAT );
+                optionalNode.addElement( ATTRIBUTE_TYPE_TAG ).setText( optionalAT );
             }
         }
     }
@@ -399,7 +446,7 @@
             Element aliasesNode = mrNode.addElement( ALIASES_TAG );
             for ( String alias : aliases )
             {
-                aliasesNode.addElement( ALIAS_TAG ).setText(  alias );
+                aliasesNode.addElement( ALIAS_TAG ).setText( alias );
             }
         }
 
@@ -407,7 +454,7 @@
         String description = mr.getDescription();
         if ( ( description != null ) && ( !description.equals( "" ) ) )
         {
-            mrNode.addElement( DESCRIPTION_TAG ).setText(  description );
+            mrNode.addElement( DESCRIPTION_TAG ).setText( description );
         }
 
         // Obsolete
@@ -424,7 +471,7 @@
         String syntaxOid = mr.getSyntaxOid();
         if ( ( syntaxOid != null ) && ( !syntaxOid.equals( "" ) ) )
         {
-            mrNode.addElement( SYNTAX_OID_TAG ).setText(  syntaxOid );
+            mrNode.addElement( SYNTAX_OID_TAG ).setText( syntaxOid );
         }
     }
 
@@ -458,7 +505,7 @@
             Element aliasesNode = syntaxNode.addElement( ALIASES_TAG );
             for ( String alias : aliases )
             {
-                aliasesNode.addElement( ALIAS_TAG ).setText(  alias );
+                aliasesNode.addElement( ALIAS_TAG ).setText( alias );
             }
         }
 
@@ -466,7 +513,7 @@
         String description = syntax.getDescription();
         if ( ( description != null ) && ( !description.equals( "" ) ) )
         {
-            syntaxNode.addElement( DESCRIPTION_TAG ).setText(  description );
+            syntaxNode.addElement( DESCRIPTION_TAG ).setText( description );
         }
 
         // Obsolete

Modified: directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/ExportSchemasAsXmlWizard.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/ExportSchemasAsXmlWizard.java?view=diff&rev=555305&r1=555304&r2=555305
==============================================================================
--- directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/ExportSchemasAsXmlWizard.java
(original)
+++ directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/ExportSchemasAsXmlWizard.java
Wed Jul 11 08:29:58 2007
@@ -111,7 +111,38 @@
         }
         else if ( exportType == ExportSchemasAsXmlWizardPage.EXPORT_SINGLE_FILE )
         {
-
+            final String exportFile = page.getExportFile();
+            try
+            {
+                getContainer().run( true, true, new IRunnableWithProgress()
+                {
+                    public void run( IProgressMonitor monitor )
+                    {
+                        monitor.beginTask( "Exporting schemas ", 1 );
+                        try
+                        {
+                            BufferedWriter buffWriter = new BufferedWriter( new FileWriter(
exportFile ) );
+                            buffWriter.write( XMLSchemaFileExporter.toSourceCode( selectedSchemas
) );
+                            buffWriter.close();
+                        }
+                        catch ( IOException e )
+                        {
+                            // TODO Auto-generated catch block
+                            e.printStackTrace();
+                        }
+                        monitor.worked( 1 );
+                        monitor.done();
+                    }
+                } );
+            }
+            catch ( InvocationTargetException e )
+            {
+                // Nothing to do (it will never occur)
+            }
+            catch ( InterruptedException e )
+            {
+                // Nothing to do.
+            }
         }
 
         return true;

Modified: directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/ExportSchemasAsXmlWizardPage.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/ExportSchemasAsXmlWizardPage.java?view=diff&rev=555305&r1=555304&r2=555305
==============================================================================
--- directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/ExportSchemasAsXmlWizardPage.java
(original)
+++ directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/ExportSchemasAsXmlWizardPage.java
Wed Jul 11 08:29:58 2007
@@ -347,7 +347,7 @@
      */
     private void chooseExportFile()
     {
-        FileDialog dialog = new FileDialog( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell()
);
+        FileDialog dialog = new FileDialog( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
SWT.SAVE );
         dialog.setText( "Select File" );
         dialog.setFilterExtensions( new String[]
             { "*.xml", "*" } );



Mime
View raw message