directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pamarce...@apache.org
Subject svn commit: r556964 - in /directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor: model/io/ view/wizards/
Date Tue, 17 Jul 2007 16:38:08 GMT
Author: pamarcelot
Date: Tue Jul 17 09:38:06 2007
New Revision: 556964

URL: http://svn.apache.org/viewvc?view=rev&rev=556964
Log:
Added the loaded schemas in the exported schema projects file.
Modified the XML Importer/Exporter to be able to reuse the methods from the Project Importer/Exporter.

Modified:
    directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/model/io/ProjectsExporter.java
    directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/model/io/ProjectsImporter.java
    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/model/io/XMLSchemaFileImporter.java
    directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/wizards/ExportSchemasAsXmlWizard.java

Modified: directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/model/io/ProjectsExporter.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/model/io/ProjectsExporter.java?view=diff&rev=556964&r1=556963&r2=556964
==============================================================================
--- directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/model/io/ProjectsExporter.java
(original)
+++ directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/model/io/ProjectsExporter.java
Tue Jul 17 09:38:06 2007
@@ -28,6 +28,7 @@
 
 import org.apache.directory.studio.apacheds.schemaeditor.Activator;
 import org.apache.directory.studio.apacheds.schemaeditor.model.Project;
+import org.apache.directory.studio.apacheds.schemaeditor.model.Schema;
 import org.apache.directory.studio.apacheds.schemaeditor.model.Project.ProjectType;
 import org.dom4j.Branch;
 import org.dom4j.Document;
@@ -128,6 +129,9 @@
             {
                 element.addAttribute( TYPE_TAG, type.toString() );
             }
+
+            // Schemas
+            XMLSchemaFileExporter.addSchemas( project.getSchemaHandler().getSchemas().toArray(
new Schema[0] ), element );
         }
     }
 

Modified: directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/model/io/ProjectsImporter.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/model/io/ProjectsImporter.java?view=diff&rev=556964&r1=556963&r2=556964
==============================================================================
--- directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/model/io/ProjectsImporter.java
(original)
+++ directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/model/io/ProjectsImporter.java
Tue Jul 17 09:38:06 2007
@@ -25,6 +25,7 @@
 import java.util.List;
 
 import org.apache.directory.studio.apacheds.schemaeditor.model.Project;
+import org.apache.directory.studio.apacheds.schemaeditor.model.Schema;
 import org.apache.directory.studio.apacheds.schemaeditor.model.Project.ProjectType;
 import org.dom4j.Attribute;
 import org.dom4j.Document;
@@ -45,6 +46,7 @@
     private static final String PROJECT_TAG = "project";
     private static final String PROJECTS_TAG = "projects";
     private static final String NAME_TAG = "name";
+    private static final String SCHEMAS_TAG = "schemas";
     private static final String TYPE_TAG = "type";
 
 
@@ -160,6 +162,25 @@
             catch ( IllegalArgumentException e )
             {
                 throw new ProjectsImportException( "The parser was not able to convert the
type value of the project." );
+            }
+        }
+
+        // Schemas
+        Element schemasElement = element.element( SCHEMAS_TAG );
+        if ( schemasElement != null )
+        {
+            Schema[] schemas = null;
+            try
+            {
+                schemas = XMLSchemaFileImporter.readSchemas( schemasElement, path );
+            }
+            catch ( XMLSchemaFileImportException e )
+            {
+                throw new ProjectsImportException( "The parser was not able to convert the
schemas of the project." );
+            }
+            for ( Schema schema : schemas )
+            {
+                project.getSchemaHandler().addSchema( schema );
             }
         }
     }

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=556964&r1=556963&r2=556964
==============================================================================
--- 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
Tue Jul 17 09:38:06 2007
@@ -97,7 +97,7 @@
      * @return
      *      the corresponding source code representation
      */
-    public static String toSourceCode( Schema schema )
+    public static String toXml( Schema schema )
     {
         // Creating the Document
         Document document = DocumentHelper.createDocument();
@@ -118,27 +118,43 @@
      * @return
      *      the corresponding source code representation
      */
-    public static String toSourceCode( Schema[] schemas )
+    public static String toXml( Schema[] schemas )
     {
         // Creating the Document and the 'root' Element
         Document document = DocumentHelper.createDocument();
-        Element root = document.addElement( SCHEMAS_TAG );
+
+        addSchemas( schemas, document );
+
+        return styleDocument( document ).asXML();
+    }
+
+
+    /**
+     * Add the XML representation of the given schemas
+     * to the given branch.
+     *
+     * @param schemas
+     *      the schemas
+     * @param branch
+     *      the branch
+     */
+    public static void addSchemas( Schema[] schemas, Branch branch )
+    {
+        Element element = branch.addElement( SCHEMAS_TAG );
 
         if ( schemas != null )
         {
             for ( Schema schema : schemas )
             {
-                addSchema( schema, root );
+                addSchema( schema, element );
             }
         }
-
-        return styleDocument( document ).asXML();
     }
 
 
     /**
      * Add the XML representation of the given schema
-     * to the given branch
+     * to the given branch.
      *
      * @param schema
      *      the schema
@@ -164,7 +180,7 @@
                 Element attributeTypesNode = element.addElement( ATTRIBUTE_TYPES_TAG );
                 for ( AttributeTypeImpl at : ats )
                 {
-                    toSourceCode( at, attributeTypesNode );
+                    toXml( at, attributeTypesNode );
                 }
             }
 
@@ -175,7 +191,7 @@
                 Element objectClassesNode = element.addElement( OBJECT_CLASSES_TAG );
                 for ( ObjectClassImpl oc : ocs )
                 {
-                    toSourceCode( oc, objectClassesNode );
+                    toXml( oc, objectClassesNode );
                 }
             }
 
@@ -186,7 +202,7 @@
                 Element matchingRulesNode = element.addElement( MATCHING_RULES_TAG );
                 for ( MatchingRuleImpl mr : mrs )
                 {
-                    toSourceCode( mr, matchingRulesNode );
+                    toXml( mr, matchingRulesNode );
                 }
             }
 
@@ -197,7 +213,7 @@
                 Element syntaxesNode = element.addElement( SYNTAXES_TAG );
                 for ( SyntaxImpl syntax : syntaxes )
                 {
-                    toSourceCode( syntax, syntaxesNode );
+                    toXml( syntax, syntaxesNode );
                 }
             }
         }
@@ -212,7 +228,7 @@
      * @param root
      *      the root Element
      */
-    private static void toSourceCode( AttributeTypeImpl at, Element root )
+    private static void toXml( AttributeTypeImpl at, Element root )
     {
         Element atNode = root.addElement( ATTRIBUTE_TYPE_TAG );
 
@@ -340,7 +356,7 @@
      * @param root
      *      the root Element
      */
-    private static void toSourceCode( ObjectClassImpl oc, Element root )
+    private static void toXml( ObjectClassImpl oc, Element root )
     {
         Element ocNode = root.addElement( OBJECT_CLASS_TAG );
 
@@ -429,7 +445,7 @@
      * @param root
      *      the root Element
      */
-    private static void toSourceCode( MatchingRuleImpl mr, Element root )
+    private static void toXml( MatchingRuleImpl mr, Element root )
     {
         Element mrNode = root.addElement( MATCHING_RULE_TAG );
 
@@ -488,7 +504,7 @@
      * @return
      *      the corresponding source code representation
      */
-    private static void toSourceCode( SyntaxImpl syntax, Element root )
+    private static void toXml( SyntaxImpl syntax, Element root )
     {
         Element syntaxNode = root.addElement( SYNTAX_TAG );
 

Modified: directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/model/io/XMLSchemaFileImporter.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/model/io/XMLSchemaFileImporter.java?view=diff&rev=556964&r1=556963&r2=556964
==============================================================================
--- directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/model/io/XMLSchemaFileImporter.java
(original)
+++ directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/model/io/XMLSchemaFileImporter.java
Tue Jul 17 09:38:06 2007
@@ -96,8 +96,6 @@
      */
     public static Schema[] getSchemas( String path ) throws XMLSchemaFileImportException
     {
-        List<Schema> schemas = new ArrayList<Schema>();
-
         SAXReader reader = new SAXReader();
         Document document = null;
         try
@@ -114,16 +112,8 @@
         {
             throw new XMLSchemaFileImportException( "The file '" + path + "' does not seem
to be a valid Schema file." );
         }
-        
-        for ( Iterator<?> i = rootElement.elementIterator( SCHEMA_TAG ); i.hasNext();
)
-        {
-            Element schemaElement = ( Element ) i.next();
-            Schema schema = new SchemaImpl( null );
-            readSchema( schemaElement, schema, path );
-            schemas.add( schema );
-        }
-        
-        return schemas.toArray( new Schema[0] );
+
+        return readSchemas( rootElement, path );
     }
 
 
@@ -139,9 +129,6 @@
      */
     public static Schema getSchema( String path ) throws XMLSchemaFileImportException
     {
-        // Creating the schema with an empty name
-        Schema schema = new SchemaImpl( null );
-
         SAXReader reader = new SAXReader();
         Document document = null;
         try
@@ -154,14 +141,39 @@
         }
 
         Element rootElement = document.getRootElement();
-        if ( !rootElement.getName().equals( SCHEMA_TAG ) )
+
+        return readSchema( rootElement, path );
+    }
+
+
+    /**
+     * Reads schemas.
+     *
+     * @param element
+     *      the element
+     * @param path
+     *      the path of the file
+     * @throws XMLSchemaFileImportException
+     *      if an error occurs when importing the schema
+     * @return
+     *      the corresponding schemas
+     */
+    public static Schema[] readSchemas( Element element, String path ) throws XMLSchemaFileImportException
+    {
+        List<Schema> schemas = new ArrayList<Schema>();
+        
+        if ( !element.getName().equals( SCHEMAS_TAG ) )
         {
             throw new XMLSchemaFileImportException( "The file '" + path + "' does not seem
to be a valid Schema file." );
         }
 
-        readSchema( rootElement, schema, path );
+        for ( Iterator<?> i = element.elementIterator( SCHEMA_TAG ); i.hasNext(); )
+        {
+            Element schemaElement = ( Element ) i.next();
+            schemas.add( readSchema( schemaElement, path ) );
+        }
 
-        return schema;
+        return schemas.toArray( new Schema[0] );
     }
 
 
@@ -170,15 +182,18 @@
      *
      * @param element
      *      the element
-     * @param schema
-     *      the schema
      * @param path
      *      the path of the file
      * @throws XMLSchemaFileImportException
      *      if an error occurs when importing the schema
+     * @return
+     *      the corresponding schema
      */
-    private static void readSchema( Element element, Schema schema, String path ) throws
XMLSchemaFileImportException
+    public static Schema readSchema( Element element, String path ) throws XMLSchemaFileImportException
     {
+        // Creating the schema with an empty name
+        Schema schema = new SchemaImpl( null );
+
         // Name
         schema.setName( getSchemaName( element, path ) );
 
@@ -193,6 +208,8 @@
 
         // Syntaxes
         readSyntaxes( element, schema );
+
+        return schema;
     }
 
 

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=556964&r1=556963&r2=556964
==============================================================================
--- 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
Tue Jul 17 09:38:06 2007
@@ -86,7 +86,7 @@
                             {
                                 BufferedWriter buffWriter = new BufferedWriter( new FileWriter(
exportDirectory + "/"
                                     + schema.getName() + ".xml" ) );
-                                buffWriter.write( XMLSchemaFileExporter.toSourceCode( schema
) );
+                                buffWriter.write( XMLSchemaFileExporter.toXml( schema ) );
                                 buffWriter.close();
                             }
                             catch ( IOException e )
@@ -122,7 +122,7 @@
                         try
                         {
                             BufferedWriter buffWriter = new BufferedWriter( new FileWriter(
exportFile ) );
-                            buffWriter.write( XMLSchemaFileExporter.toSourceCode( selectedSchemas
) );
+                            buffWriter.write( XMLSchemaFileExporter.toXml( selectedSchemas
) );
                             buffWriter.close();
                         }
                         catch ( IOException e )



Mime
View raw message