directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pamarce...@apache.org
Subject svn commit: r554698 - in /directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor: ./ model/openldapfile/ view/editors/attributetype/ view/editors/objectclass/ view/editors/schema/
Date Mon, 09 Jul 2007 16:39:04 GMT
Author: pamarcelot
Date: Mon Jul  9 09:39:01 2007
New Revision: 554698

URL: http://svn.apache.org/viewvc?view=rev&rev=554698
Log:
Added a SchemaExporter class for OpenLDAP Schema Files.
Moved some conversion methods to this class.

Added:
    directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/model/openldapfile/SchemaExporter.java
Modified:
    directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/PluginUtils.java
    directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/editors/attributetype/AttributeTypeEditorSourceCodePage.java
    directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/editors/objectclass/ObjectClassEditorSourceCodePage.java
    directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/editors/schema/SchemaEditorSourceCodePage.java

Modified: directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/PluginUtils.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/PluginUtils.java?view=diff&rev=554698&r1=554697&r2=554698
==============================================================================
--- directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/PluginUtils.java
(original)
+++ directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/PluginUtils.java
Mon Jul  9 09:39:01 2007
@@ -101,256 +101,4 @@
 
         return clone;
     }
-
-
-    /**
-     * Converts the given attribute type to its source code representation
-     * in OpenLDAP Schema file format.
-     *
-     * @param at
-     *      the attribute type to convert
-     * @return
-     *      the corresponding source code representation
-     */
-    public static String toSourceCode( AttributeTypeImpl at )
-    {
-        StringBuffer sb = new StringBuffer();
-
-        // Opening the definition and OID
-        sb.append( "attributetype ( " + at.getOid() + " \n" ); //$NON-NLS-1$ //$NON-NLS-2$
-
-        // NAME(S)
-        String[] names = at.getNames();
-        sb.append( "\tNAME " ); //$NON-NLS-1$
-        if ( names.length > 1 )
-        {
-            sb.append( "( " ); //$NON-NLS-1$
-            for ( String name : names )
-            {
-                sb.append( "'" + name + "' " ); //$NON-NLS-1$ //$NON-NLS-2$
-            }
-            sb.append( ") \n" ); //$NON-NLS-1$
-        }
-        else
-        {
-            sb.append( "'" + names[0] + "' \n" ); //$NON-NLS-1$ //$NON-NLS-2$
-        }
-
-        // DESC
-        if ( ( at.getDescription() != null ) && ( !at.getDescription().equals( ""
) ) ) //$NON-NLS-1$
-        {
-            sb.append( "\tDESC '" + at.getDescription() + "' \n" ); //$NON-NLS-1$ //$NON-NLS-2$
-        }
-
-        // OBSOLETE
-        if ( at.isObsolete() )
-        {
-            sb.append( "\tOBSOLETE \n" ); //$NON-NLS-1$
-        }
-
-        // SUP
-        if ( ( at.getSuperiorName() != null ) && ( !at.getSuperiorName().equals(
"" ) ) ) //$NON-NLS-1$
-        {
-            sb.append( "\tSUP " + at.getSuperiorName() + " \n" ); //$NON-NLS-1$ //$NON-NLS-2$
-        }
-
-        // EQUALITY
-        if ( ( at.getEqualityName() != null ) && ( !at.getEqualityName().equals(
"" ) ) ) //$NON-NLS-1$
-        {
-            sb.append( "\tEQUALITY " + at.getEqualityName() + " \n" ); //$NON-NLS-1$ //$NON-NLS-2$
-        }
-
-        // ORDERING
-        if ( ( at.getOrderingName() != null ) && ( !at.getOrderingName().equals(
"" ) ) ) //$NON-NLS-1$
-        {
-            sb.append( "\tORDERING " + at.getOrderingName() + " \n" ); //$NON-NLS-1$ //$NON-NLS-2$
-        }
-
-        // SUBSTR
-        if ( ( at.getSubstrName() != null ) && ( !at.getSubstrName().equals( "" )
) ) //$NON-NLS-1$
-        {
-            sb.append( "\tSUBSTR " + at.getSubstrName() + " \n" ); //$NON-NLS-1$ //$NON-NLS-2$
-        }
-
-        // SYNTAX
-        if ( ( at.getSyntaxOid() != null ) && ( !at.getSyntaxOid().equals( "" ) )
) //$NON-NLS-1$
-        {
-            sb.append( "\tSYNTAX " + at.getSyntaxOid() ); //$NON-NLS-1$
-            if ( at.getLength() > 0 )
-            {
-                sb.append( "{" + at.getLength() + "}" ); //$NON-NLS-1$ //$NON-NLS-2$
-            }
-            sb.append( " \n" ); //$NON-NLS-1$
-        }
-
-        // SINGLE-VALUE
-        if ( at.isSingleValue() )
-        {
-            sb.append( "\tSINGLE-VALUE \n" ); //$NON-NLS-1$
-        }
-
-        // COLLECTIVE
-        if ( at.isCollective() )
-        {
-            sb.append( "\tCOLLECTIVE \n" ); //$NON-NLS-1$
-        }
-
-        // NO-USER-MODIFICATION
-        if ( !at.isCanUserModify() )
-        {
-            sb.append( "\tNO-USER-MODIFICATION \n" ); //$NON-NLS-1$
-        }
-
-        // USAGE
-        UsageEnum usage = at.getUsage();
-        if ( usage != null )
-        {
-            if ( usage == UsageEnum.DIRECTORY_OPERATION )
-            {
-                sb.append( "\tUSAGE directoryOperation \n" ); //$NON-NLS-1$
-            }
-            else if ( usage == UsageEnum.DISTRIBUTED_OPERATION )
-            {
-                sb.append( "\tUSAGE distributedOperation \n" ); //$NON-NLS-1$
-            }
-            else if ( usage == UsageEnum.DSA_OPERATION )
-            {
-                sb.append( "\tUSAGE dSAOperation \n" ); //$NON-NLS-1$
-            }
-            else if ( usage == UsageEnum.USER_APPLICATIONS )
-            {
-                // There's nothing to write, this is the default option
-            }
-        }
-
-        // Closing the definition
-        sb.append( " )\n" ); //$NON-NLS-1$
-
-        return sb.toString();
-    }
-
-
-    /**
-     * Converts the given object class to its source code representation
-     * in OpenLDAP Schema file format.
-     *
-     * @param at
-     *      the object class to convert
-     * @return
-     *      the corresponding source code representation
-     */
-    public static String toSourceCode( ObjectClassImpl oc )
-    {
-        StringBuffer sb = new StringBuffer();
-
-        // Opening the definition and OID
-        sb.append( "objectclass ( " + oc.getOid() + " \n" ); //$NON-NLS-1$ //$NON-NLS-2$
-
-        // NAME(S)
-        String[] names = oc.getNames();
-        sb.append( "\tNAME " ); //$NON-NLS-1$
-        if ( names.length > 1 )
-        {
-            sb.append( "( " ); //$NON-NLS-1$
-            for ( String name : names )
-            {
-                sb.append( "'" + name + "' " ); //$NON-NLS-1$ //$NON-NLS-2$
-            }
-            sb.append( ") \n" ); //$NON-NLS-1$
-        }
-        else
-        {
-            sb.append( "'" + names[0] + "' \n" ); //$NON-NLS-1$ //$NON-NLS-2$
-        }
-
-        // DESC
-        if ( ( oc.getDescription() != null ) && ( !oc.getDescription().equals( ""
) ) ) //$NON-NLS-1$
-        {
-            sb.append( "\tDESC '" + oc.getDescription() + "' \n" ); //$NON-NLS-1$ //$NON-NLS-2$
-        }
-
-        // OBSOLETE
-        if ( oc.isObsolete() )
-        {
-            sb.append( "\tOBSOLETE \n" ); //$NON-NLS-1$
-        }
-
-        // SUP
-        String[] superiors = oc.getSuperClassesNames();
-        if ( ( superiors != null ) && ( superiors.length != 0 ) )
-        {
-            if ( superiors.length > 1 )
-            {
-                sb.append( "\tSUP (" + superiors[0] ); //$NON-NLS-1$
-                for ( int i = 1; i < superiors.length; i++ )
-                {
-                    sb.append( " $ " + superiors[i] ); //$NON-NLS-1$
-                }
-                sb.append( ") \n" ); //$NON-NLS-1$
-            }
-            else
-            {
-                sb.append( "\tSUP " + superiors[0] + " \n" ); //$NON-NLS-1$ //$NON-NLS-2$
-            }
-        }
-
-        // CLASSTYPE
-        ObjectClassTypeEnum classtype = oc.getType();
-        if ( classtype == ObjectClassTypeEnum.ABSTRACT )
-        {
-            sb.append( "\tABSTRACT \n" ); //$NON-NLS-1$
-        }
-        else if ( classtype == ObjectClassTypeEnum.AUXILIARY )
-        {
-            sb.append( "\tAUXILIARY \n" ); //$NON-NLS-1$
-        }
-        else if ( classtype == ObjectClassTypeEnum.STRUCTURAL )
-        {
-            sb.append( "\tSTRUCTURAL \n" ); //$NON-NLS-1$
-        }
-
-        // MUST
-        String[] must = oc.getMustNamesList();
-        if ( ( must != null ) && ( must.length != 0 ) )
-        {
-            sb.append( "\tMUST " ); //$NON-NLS-1$
-            if ( must.length > 1 )
-            {
-                sb.append( "( " + must[0] + " " ); //$NON-NLS-1$ //$NON-NLS-2$
-                for ( int i = 1; i < must.length; i++ )
-                {
-                    sb.append( "$ " + must[i] + " " ); //$NON-NLS-1$ //$NON-NLS-2$
-                }
-                sb.append( ") \n" ); //$NON-NLS-1$
-            }
-            else if ( must.length == 1 )
-            {
-                sb.append( must[0] + " \n" ); //$NON-NLS-1$
-            }
-        }
-
-        // MAY
-        String[] may = oc.getMayNamesList();
-        if ( ( may != null ) && ( may.length != 0 ) )
-        {
-            sb.append( "\tMAY " ); //$NON-NLS-1$
-            if ( may.length > 1 )
-            {
-                sb.append( "( " + may[0] + " " ); //$NON-NLS-1$ //$NON-NLS-2$
-                for ( int i = 1; i < may.length; i++ )
-                {
-                    sb.append( "$ " + may[i] + " " ); //$NON-NLS-1$ //$NON-NLS-2$
-                }
-                sb.append( ") \n" ); //$NON-NLS-1$
-            }
-            else if ( may.length == 1 )
-            {
-                sb.append( may[0] + " \n" ); //$NON-NLS-1$
-            }
-        }
-        // Closing the definition
-        sb.append( " )\n" ); //$NON-NLS-1$
-
-        return sb.toString();
-    }
 }

Added: directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/model/openldapfile/SchemaExporter.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/model/openldapfile/SchemaExporter.java?view=auto&rev=554698
==============================================================================
--- directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/model/openldapfile/SchemaExporter.java
(added)
+++ directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/model/openldapfile/SchemaExporter.java
Mon Jul  9 09:39:01 2007
@@ -0,0 +1,317 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.studio.apacheds.schemaeditor.model.openldapfile;
+
+
+import org.apache.directory.shared.ldap.schema.ObjectClassTypeEnum;
+import org.apache.directory.shared.ldap.schema.UsageEnum;
+import org.apache.directory.studio.apacheds.schemaeditor.model.AttributeTypeImpl;
+import org.apache.directory.studio.apacheds.schemaeditor.model.ObjectClassImpl;
+import org.apache.directory.studio.apacheds.schemaeditor.model.Schema;
+
+
+/**
+ * This class is used to export a Schema file into the OpenLDAP Format.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class SchemaExporter
+{
+    /**
+     * Converts the given schema to its source code representation
+     * in OpenLDAP Schema file format.
+     *
+     * @param schema
+     *      the schema to convert
+     * @return
+     *      the corresponding source code representation
+     */
+    public static String toSourceCode( Schema schema )
+    {
+        StringBuffer sb = new StringBuffer();
+
+        for ( AttributeTypeImpl at : schema.getAttributeTypes() )
+        {
+            sb.append( toSourceCode( at ) );
+            sb.append( "\n" );
+        }
+
+        for ( ObjectClassImpl oc : schema.getObjectClasses() )
+        {
+            sb.append( toSourceCode( oc ) );
+            sb.append( "\n" );
+        }
+
+        return sb.toString();
+    }
+
+
+    /**
+     * Converts the given attribute type to its source code representation
+     * in OpenLDAP Schema file format.
+     *
+     * @param at
+     *      the attribute type to convert
+     * @return
+     *      the corresponding source code representation
+     */
+    public static String toSourceCode( AttributeTypeImpl at )
+    {
+        StringBuffer sb = new StringBuffer();
+
+        // Opening the definition and OID
+        sb.append( "attributetype ( " + at.getOid() + " \n" ); //$NON-NLS-1$ //$NON-NLS-2$
+
+        // NAME(S)
+        String[] names = at.getNames();
+        sb.append( "\tNAME " ); //$NON-NLS-1$
+        if ( names.length > 1 )
+        {
+            sb.append( "( " ); //$NON-NLS-1$
+            for ( String name : names )
+            {
+                sb.append( "'" + name + "' " ); //$NON-NLS-1$ //$NON-NLS-2$
+            }
+            sb.append( ") \n" ); //$NON-NLS-1$
+        }
+        else
+        {
+            sb.append( "'" + names[0] + "' \n" ); //$NON-NLS-1$ //$NON-NLS-2$
+        }
+
+        // DESC
+        if ( ( at.getDescription() != null ) && ( !at.getDescription().equals( ""
) ) ) //$NON-NLS-1$
+        {
+            sb.append( "\tDESC '" + at.getDescription() + "' \n" ); //$NON-NLS-1$ //$NON-NLS-2$
+        }
+
+        // OBSOLETE
+        if ( at.isObsolete() )
+        {
+            sb.append( "\tOBSOLETE \n" ); //$NON-NLS-1$
+        }
+
+        // SUP
+        if ( ( at.getSuperiorName() != null ) && ( !at.getSuperiorName().equals(
"" ) ) ) //$NON-NLS-1$
+        {
+            sb.append( "\tSUP " + at.getSuperiorName() + " \n" ); //$NON-NLS-1$ //$NON-NLS-2$
+        }
+
+        // EQUALITY
+        if ( ( at.getEqualityName() != null ) && ( !at.getEqualityName().equals(
"" ) ) ) //$NON-NLS-1$
+        {
+            sb.append( "\tEQUALITY " + at.getEqualityName() + " \n" ); //$NON-NLS-1$ //$NON-NLS-2$
+        }
+
+        // ORDERING
+        if ( ( at.getOrderingName() != null ) && ( !at.getOrderingName().equals(
"" ) ) ) //$NON-NLS-1$
+        {
+            sb.append( "\tORDERING " + at.getOrderingName() + " \n" ); //$NON-NLS-1$ //$NON-NLS-2$
+        }
+
+        // SUBSTR
+        if ( ( at.getSubstrName() != null ) && ( !at.getSubstrName().equals( "" )
) ) //$NON-NLS-1$
+        {
+            sb.append( "\tSUBSTR " + at.getSubstrName() + " \n" ); //$NON-NLS-1$ //$NON-NLS-2$
+        }
+
+        // SYNTAX
+        if ( ( at.getSyntaxOid() != null ) && ( !at.getSyntaxOid().equals( "" ) )
) //$NON-NLS-1$
+        {
+            sb.append( "\tSYNTAX " + at.getSyntaxOid() ); //$NON-NLS-1$
+            if ( at.getLength() > 0 )
+            {
+                sb.append( "{" + at.getLength() + "}" ); //$NON-NLS-1$ //$NON-NLS-2$
+            }
+            sb.append( " \n" ); //$NON-NLS-1$
+        }
+
+        // SINGLE-VALUE
+        if ( at.isSingleValue() )
+        {
+            sb.append( "\tSINGLE-VALUE \n" ); //$NON-NLS-1$
+        }
+
+        // COLLECTIVE
+        if ( at.isCollective() )
+        {
+            sb.append( "\tCOLLECTIVE \n" ); //$NON-NLS-1$
+        }
+
+        // NO-USER-MODIFICATION
+        if ( !at.isCanUserModify() )
+        {
+            sb.append( "\tNO-USER-MODIFICATION \n" ); //$NON-NLS-1$
+        }
+
+        // USAGE
+        UsageEnum usage = at.getUsage();
+        if ( usage != null )
+        {
+            if ( usage == UsageEnum.DIRECTORY_OPERATION )
+            {
+                sb.append( "\tUSAGE directoryOperation \n" ); //$NON-NLS-1$
+            }
+            else if ( usage == UsageEnum.DISTRIBUTED_OPERATION )
+            {
+                sb.append( "\tUSAGE distributedOperation \n" ); //$NON-NLS-1$
+            }
+            else if ( usage == UsageEnum.DSA_OPERATION )
+            {
+                sb.append( "\tUSAGE dSAOperation \n" ); //$NON-NLS-1$
+            }
+            else if ( usage == UsageEnum.USER_APPLICATIONS )
+            {
+                // There's nothing to write, this is the default option
+            }
+        }
+
+        // Closing the definition
+        sb.append( " )\n" ); //$NON-NLS-1$
+
+        return sb.toString();
+    }
+
+
+    /**
+     * Converts the given object class to its source code representation
+     * in OpenLDAP Schema file format.
+     *
+     * @param at
+     *      the object class to convert
+     * @return
+     *      the corresponding source code representation
+     */
+    public static String toSourceCode( ObjectClassImpl oc )
+    {
+        StringBuffer sb = new StringBuffer();
+
+        // Opening the definition and OID
+        sb.append( "objectclass ( " + oc.getOid() + " \n" ); //$NON-NLS-1$ //$NON-NLS-2$
+
+        // NAME(S)
+        String[] names = oc.getNames();
+        sb.append( "\tNAME " ); //$NON-NLS-1$
+        if ( names.length > 1 )
+        {
+            sb.append( "( " ); //$NON-NLS-1$
+            for ( String name : names )
+            {
+                sb.append( "'" + name + "' " ); //$NON-NLS-1$ //$NON-NLS-2$
+            }
+            sb.append( ") \n" ); //$NON-NLS-1$
+        }
+        else
+        {
+            sb.append( "'" + names[0] + "' \n" ); //$NON-NLS-1$ //$NON-NLS-2$
+        }
+
+        // DESC
+        if ( ( oc.getDescription() != null ) && ( !oc.getDescription().equals( ""
) ) ) //$NON-NLS-1$
+        {
+            sb.append( "\tDESC '" + oc.getDescription() + "' \n" ); //$NON-NLS-1$ //$NON-NLS-2$
+        }
+
+        // OBSOLETE
+        if ( oc.isObsolete() )
+        {
+            sb.append( "\tOBSOLETE \n" ); //$NON-NLS-1$
+        }
+
+        // SUP
+        String[] superiors = oc.getSuperClassesNames();
+        if ( ( superiors != null ) && ( superiors.length != 0 ) )
+        {
+            if ( superiors.length > 1 )
+            {
+                sb.append( "\tSUP (" + superiors[0] ); //$NON-NLS-1$
+                for ( int i = 1; i < superiors.length; i++ )
+                {
+                    sb.append( " $ " + superiors[i] ); //$NON-NLS-1$
+                }
+                sb.append( ") \n" ); //$NON-NLS-1$
+            }
+            else
+            {
+                sb.append( "\tSUP " + superiors[0] + " \n" ); //$NON-NLS-1$ //$NON-NLS-2$
+            }
+        }
+
+        // CLASSTYPE
+        ObjectClassTypeEnum classtype = oc.getType();
+        if ( classtype == ObjectClassTypeEnum.ABSTRACT )
+        {
+            sb.append( "\tABSTRACT \n" ); //$NON-NLS-1$
+        }
+        else if ( classtype == ObjectClassTypeEnum.AUXILIARY )
+        {
+            sb.append( "\tAUXILIARY \n" ); //$NON-NLS-1$
+        }
+        else if ( classtype == ObjectClassTypeEnum.STRUCTURAL )
+        {
+            sb.append( "\tSTRUCTURAL \n" ); //$NON-NLS-1$
+        }
+
+        // MUST
+        String[] must = oc.getMustNamesList();
+        if ( ( must != null ) && ( must.length != 0 ) )
+        {
+            sb.append( "\tMUST " ); //$NON-NLS-1$
+            if ( must.length > 1 )
+            {
+                sb.append( "( " + must[0] + " " ); //$NON-NLS-1$ //$NON-NLS-2$
+                for ( int i = 1; i < must.length; i++ )
+                {
+                    sb.append( "$ " + must[i] + " " ); //$NON-NLS-1$ //$NON-NLS-2$
+                }
+                sb.append( ") \n" ); //$NON-NLS-1$
+            }
+            else if ( must.length == 1 )
+            {
+                sb.append( must[0] + " \n" ); //$NON-NLS-1$
+            }
+        }
+
+        // MAY
+        String[] may = oc.getMayNamesList();
+        if ( ( may != null ) && ( may.length != 0 ) )
+        {
+            sb.append( "\tMAY " ); //$NON-NLS-1$
+            if ( may.length > 1 )
+            {
+                sb.append( "( " + may[0] + " " ); //$NON-NLS-1$ //$NON-NLS-2$
+                for ( int i = 1; i < may.length; i++ )
+                {
+                    sb.append( "$ " + may[i] + " " ); //$NON-NLS-1$ //$NON-NLS-2$
+                }
+                sb.append( ") \n" ); //$NON-NLS-1$
+            }
+            else if ( may.length == 1 )
+            {
+                sb.append( may[0] + " \n" ); //$NON-NLS-1$
+            }
+        }
+        // Closing the definition
+        sb.append( " )\n" ); //$NON-NLS-1$
+
+        return sb.toString();
+    }
+}

Modified: directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/editors/attributetype/AttributeTypeEditorSourceCodePage.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/editors/attributetype/AttributeTypeEditorSourceCodePage.java?view=diff&rev=554698&r1=554697&r2=554698
==============================================================================
--- directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/editors/attributetype/AttributeTypeEditorSourceCodePage.java
(original)
+++ directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/editors/attributetype/AttributeTypeEditorSourceCodePage.java
Mon Jul  9 09:39:01 2007
@@ -20,14 +20,15 @@
 
 package org.apache.directory.studio.apacheds.schemaeditor.view.editors.attributetype;
 
+
 import java.io.IOException;
 import java.text.ParseException;
 import java.util.List;
 
 import org.apache.directory.server.core.tools.schema.AttributeTypeLiteral;
 import org.apache.directory.server.core.tools.schema.OpenLdapSchemaParser;
-import org.apache.directory.studio.apacheds.schemaeditor.PluginUtils;
 import org.apache.directory.studio.apacheds.schemaeditor.model.AttributeTypeImpl;
+import org.apache.directory.studio.apacheds.schemaeditor.model.openldapfile.SchemaExporter;
 import org.apache.directory.studio.apacheds.schemaeditor.view.widget.SchemaSourceViewer;
 import org.eclipse.jface.resource.JFaceResources;
 import org.eclipse.jface.text.Document;
@@ -44,142 +45,162 @@
 import org.eclipse.ui.forms.widgets.FormToolkit;
 import org.eclipse.ui.forms.widgets.ScrolledForm;
 
+
 /**
  * This class is the Source Code Page of the Attribute Type Editor
  */
-public class AttributeTypeEditorSourceCodePage extends FormPage {
-	/** The page ID */
-	public static final String ID = AttributeTypeEditor.ID + "sourceCodePage"; //$NON-NLS-1$
-
-	/** The page title */
-	public static String TITLE = "Source Code";
-
-	/** The modified attribute type */
-	private AttributeTypeImpl modifiedAttributeType;
-
-	/** The Schema Source Viewer */
-	private SchemaSourceViewer schemaSourceViewer;
-
-	/** The flag to indicate if the user can leave the Source Code page */
-	private boolean canLeaveThePage = true;
-
-	/** The listener of the Schema Source Editor Widget */
-	private ModifyListener schemaSourceViewerListener = new ModifyListener() {
-		public void modifyText(ModifyEvent e) {
-			canLeaveThePage = true;
-			try {
-				((AttributeTypeEditor) getEditor()).setDirty(true);
-				OpenLdapSchemaParser parser = new OpenLdapSchemaParser();
-				parser.parse(schemaSourceViewer.getTextWidget().getText());
-				List attributeTypes = parser.getAttributeTypes();
-				if (attributeTypes.size() != 1) {
-					// Throw an exception and return
-				} else {
-					updateAttributeType((AttributeTypeLiteral) attributeTypes
-							.get(0));
-				}
-			} catch (IOException e1) {
-				canLeaveThePage = false;
-			} catch (ParseException exception) {
-				canLeaveThePage = false;
-			}
-		}
-	};
-
-	/**
-	 * Default constructor
-	 * 
-	 * @param editor
-	 *            the associated editor
-	 */
-	public AttributeTypeEditorSourceCodePage(FormEditor editor) {
-		super(editor, ID, TITLE);
-	}
-
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see org.eclipse.ui.forms.editor.FormPage#createFormContent(org.eclipse.ui.forms.IManagedForm)
-	 */
-	protected void createFormContent(IManagedForm managedForm) {
-		ScrolledForm form = managedForm.getForm();
-		FormToolkit toolkit = managedForm.getToolkit();
-		GridLayout layout = new GridLayout();
-		layout.marginWidth = 0;
-		layout.marginHeight = 0;
-		form.getBody().setLayout(layout);
-		toolkit.paintBordersFor(form.getBody());
-
-		modifiedAttributeType = ((AttributeTypeEditor) getEditor())
-				.getModifiedAttributeType();
-
-		// SOURCE CODE Field
-		schemaSourceViewer = new SchemaSourceViewer(form.getBody(), null, null,
-				false, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
-		GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
-		gd.heightHint = 10;
-		schemaSourceViewer.getTextWidget().setLayoutData(gd);
-
-		// set text font
-		Font font = JFaceResources.getFont(JFaceResources.TEXT_FONT);
-		schemaSourceViewer.getTextWidget().setFont(font);
-
-		IDocument document = new Document();
-		schemaSourceViewer.setDocument(document);
-
-		// Initialization from the "input" attribute type
-		fillInUiFields();
-
-		schemaSourceViewer.getTextWidget().addModifyListener(
-				schemaSourceViewerListener);
-	}
-
-	/**
-	 * Fills in the User Interface.
-	 */
-	private void fillInUiFields() {
-		// SOURCE CODE Field
-		schemaSourceViewer.getDocument().set(
-				PluginUtils.toSourceCode(modifiedAttributeType));
-	}
-
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see org.eclipse.ui.forms.editor.FormPage#canLeaveThePage()
-	 */
-	public boolean canLeaveThePage() {
-		return canLeaveThePage;
-	}
-
-	/**
-	 * Updates the Modified Attribute Type from the given Attribute Type
-	 * Literal.
-	 * 
-	 * @param atl
-	 *            the Attribute Type Literal
-	 */
-	private void updateAttributeType(AttributeTypeLiteral atl) {
-		modifiedAttributeType.setCanUserModify(!atl.isNoUserModification());
-		modifiedAttributeType.setCollective(atl.isCollective());
-		modifiedAttributeType.setDescription(atl.getDescription());
-		modifiedAttributeType.setEqualityName(atl.getEquality());
-		modifiedAttributeType.setLength(atl.getLength());
-		modifiedAttributeType.setNames(atl.getNames());
-		modifiedAttributeType.setObsolete(atl.isObsolete());
-		modifiedAttributeType.setOid(atl.getOid());
-		modifiedAttributeType.setOrderingName(atl.getOrdering());
-		modifiedAttributeType.setSingleValue(atl.isSingleValue());
-		modifiedAttributeType.setSubstrName(atl.getSubstr());
-		modifiedAttributeType.setSuperiorName(atl.getSuperior());
-		modifiedAttributeType.setSyntaxOid(atl.getOid());
-		modifiedAttributeType.setUsage(atl.getUsage());
-	}
-
-	/**
-	 * Refreshes the UI.
-	 */
-	public void refreshUI() {
-		fillInUiFields();
-	}
+public class AttributeTypeEditorSourceCodePage extends FormPage
+{
+    /** The page ID */
+    public static final String ID = AttributeTypeEditor.ID + "sourceCodePage"; //$NON-NLS-1$
+
+    /** The page title */
+    public static String TITLE = "Source Code";
+
+    /** The modified attribute type */
+    private AttributeTypeImpl modifiedAttributeType;
+
+    /** The Schema Source Viewer */
+    private SchemaSourceViewer schemaSourceViewer;
+
+    /** The flag to indicate if the user can leave the Source Code page */
+    private boolean canLeaveThePage = true;
+
+    /** The listener of the Schema Source Editor Widget */
+    private ModifyListener schemaSourceViewerListener = new ModifyListener()
+    {
+        public void modifyText( ModifyEvent e )
+        {
+            canLeaveThePage = true;
+            try
+            {
+                ( ( AttributeTypeEditor ) getEditor() ).setDirty( true );
+                OpenLdapSchemaParser parser = new OpenLdapSchemaParser();
+                parser.parse( schemaSourceViewer.getTextWidget().getText() );
+                List attributeTypes = parser.getAttributeTypes();
+                if ( attributeTypes.size() != 1 )
+                {
+                    // Throw an exception and return
+                }
+                else
+                {
+                    updateAttributeType( ( AttributeTypeLiteral ) attributeTypes.get( 0 )
);
+                }
+            }
+            catch ( IOException e1 )
+            {
+                canLeaveThePage = false;
+            }
+            catch ( ParseException exception )
+            {
+                canLeaveThePage = false;
+            }
+        }
+    };
+
+
+    /**
+     * Default constructor
+     * 
+     * @param editor
+     *            the associated editor
+     */
+    public AttributeTypeEditorSourceCodePage( FormEditor editor )
+    {
+        super( editor, ID, TITLE );
+    }
+
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.eclipse.ui.forms.editor.FormPage#createFormContent(org.eclipse.ui.forms.IManagedForm)
+     */
+    protected void createFormContent( IManagedForm managedForm )
+    {
+        ScrolledForm form = managedForm.getForm();
+        FormToolkit toolkit = managedForm.getToolkit();
+        GridLayout layout = new GridLayout();
+        layout.marginWidth = 0;
+        layout.marginHeight = 0;
+        form.getBody().setLayout( layout );
+        toolkit.paintBordersFor( form.getBody() );
+
+        modifiedAttributeType = ( ( AttributeTypeEditor ) getEditor() ).getModifiedAttributeType();
+
+        // SOURCE CODE Field
+        schemaSourceViewer = new SchemaSourceViewer( form.getBody(), null, null, false, SWT.BORDER
| SWT.H_SCROLL
+            | SWT.V_SCROLL );
+        GridData gd = new GridData( SWT.FILL, SWT.FILL, true, true );
+        gd.heightHint = 10;
+        schemaSourceViewer.getTextWidget().setLayoutData( gd );
+
+        // set text font
+        Font font = JFaceResources.getFont( JFaceResources.TEXT_FONT );
+        schemaSourceViewer.getTextWidget().setFont( font );
+
+        IDocument document = new Document();
+        schemaSourceViewer.setDocument( document );
+
+        // Initialization from the "input" attribute type
+        fillInUiFields();
+
+        schemaSourceViewer.getTextWidget().addModifyListener( schemaSourceViewerListener
);
+    }
+
+
+    /**
+     * Fills in the User Interface.
+     */
+    private void fillInUiFields()
+    {
+        // SOURCE CODE Field
+        schemaSourceViewer.getDocument().set( SchemaExporter.toSourceCode( modifiedAttributeType
) );
+    }
+
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.eclipse.ui.forms.editor.FormPage#canLeaveThePage()
+     */
+    public boolean canLeaveThePage()
+    {
+        return canLeaveThePage;
+    }
+
+
+    /**
+     * Updates the Modified Attribute Type from the given Attribute Type
+     * Literal.
+     * 
+     * @param atl
+     *            the Attribute Type Literal
+     */
+    private void updateAttributeType( AttributeTypeLiteral atl )
+    {
+        modifiedAttributeType.setCanUserModify( !atl.isNoUserModification() );
+        modifiedAttributeType.setCollective( atl.isCollective() );
+        modifiedAttributeType.setDescription( atl.getDescription() );
+        modifiedAttributeType.setEqualityName( atl.getEquality() );
+        modifiedAttributeType.setLength( atl.getLength() );
+        modifiedAttributeType.setNames( atl.getNames() );
+        modifiedAttributeType.setObsolete( atl.isObsolete() );
+        modifiedAttributeType.setOid( atl.getOid() );
+        modifiedAttributeType.setOrderingName( atl.getOrdering() );
+        modifiedAttributeType.setSingleValue( atl.isSingleValue() );
+        modifiedAttributeType.setSubstrName( atl.getSubstr() );
+        modifiedAttributeType.setSuperiorName( atl.getSuperior() );
+        modifiedAttributeType.setSyntaxOid( atl.getOid() );
+        modifiedAttributeType.setUsage( atl.getUsage() );
+    }
+
+
+    /**
+     * Refreshes the UI.
+     */
+    public void refreshUI()
+    {
+        fillInUiFields();
+    }
 }

Modified: directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/editors/objectclass/ObjectClassEditorSourceCodePage.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/editors/objectclass/ObjectClassEditorSourceCodePage.java?view=diff&rev=554698&r1=554697&r2=554698
==============================================================================
--- directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/editors/objectclass/ObjectClassEditorSourceCodePage.java
(original)
+++ directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/editors/objectclass/ObjectClassEditorSourceCodePage.java
Mon Jul  9 09:39:01 2007
@@ -27,8 +27,8 @@
 
 import org.apache.directory.server.core.tools.schema.ObjectClassLiteral;
 import org.apache.directory.server.core.tools.schema.OpenLdapSchemaParser;
-import org.apache.directory.studio.apacheds.schemaeditor.PluginUtils;
 import org.apache.directory.studio.apacheds.schemaeditor.model.ObjectClassImpl;
+import org.apache.directory.studio.apacheds.schemaeditor.model.openldapfile.SchemaExporter;
 import org.apache.directory.studio.apacheds.schemaeditor.view.widget.SchemaSourceViewer;
 import org.eclipse.jface.resource.JFaceResources;
 import org.eclipse.jface.text.Document;
@@ -153,7 +153,7 @@
     private void fillInUiFields()
     {
         // SOURCE CODE Field
-        schemaSourceViewer.getDocument().set( PluginUtils.toSourceCode( modifiedObjectClass
) );
+        schemaSourceViewer.getDocument().set( SchemaExporter.toSourceCode( modifiedObjectClass
) );
     }
 
 

Modified: directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/editors/schema/SchemaEditorSourceCodePage.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/editors/schema/SchemaEditorSourceCodePage.java?view=diff&rev=554698&r1=554697&r2=554698
==============================================================================
--- directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/editors/schema/SchemaEditorSourceCodePage.java
(original)
+++ directory/studio/trunk/studio-apacheds-schemaeditor/src/main/java/org/apache/directory/studio/apacheds/schemaeditor/view/editors/schema/SchemaEditorSourceCodePage.java
Mon Jul  9 09:39:01 2007
@@ -29,6 +29,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.apache.directory.studio.apacheds.schemaeditor.model.openldapfile.SchemaExporter;
 import org.apache.directory.studio.apacheds.schemaeditor.view.widget.SchemaSourceViewer;
 import org.eclipse.jface.resource.JFaceResources;
 import org.eclipse.jface.text.Document;
@@ -75,6 +76,7 @@
             fillInUiFields();
         }
 
+
         /* (non-Javadoc)
          * @see org.apache.directory.studio.apacheds.schemaeditor.controller.SchemaListener#attributeTypeModified(org.apache.directory.studio.apacheds.schemaeditor.model.AttributeTypeImpl)
          */
@@ -83,6 +85,7 @@
             fillInUiFields();
         }
 
+
         /* (non-Javadoc)
          * @see org.apache.directory.studio.apacheds.schemaeditor.controller.SchemaListener#attributeTypeRemoved(org.apache.directory.studio.apacheds.schemaeditor.model.AttributeTypeImpl)
          */
@@ -91,6 +94,7 @@
             fillInUiFields();
         }
 
+
         /* (non-Javadoc)
          * @see org.apache.directory.studio.apacheds.schemaeditor.controller.SchemaListener#matchingRuleAdded(org.apache.directory.studio.apacheds.schemaeditor.model.MatchingRuleImpl)
          */
@@ -99,14 +103,16 @@
             fillInUiFields();
         }
 
+
         /* (non-Javadoc)
          * @see org.apache.directory.studio.apacheds.schemaeditor.controller.SchemaListener#matchingRuleModified(org.apache.directory.studio.apacheds.schemaeditor.model.MatchingRuleImpl)
          */
         public void matchingRuleModified( MatchingRuleImpl mr )
         {
-            fillInUiFields(); 
+            fillInUiFields();
         }
 
+
         /* (non-Javadoc)
          * @see org.apache.directory.studio.apacheds.schemaeditor.controller.SchemaListener#matchingRuleRemoved(org.apache.directory.studio.apacheds.schemaeditor.model.MatchingRuleImpl)
          */
@@ -115,6 +121,7 @@
             fillInUiFields();
         }
 
+
         /* (non-Javadoc)
          * @see org.apache.directory.studio.apacheds.schemaeditor.controller.SchemaListener#objectClassAdded(org.apache.directory.studio.apacheds.schemaeditor.model.ObjectClassImpl)
          */
@@ -123,6 +130,7 @@
             fillInUiFields();
         }
 
+
         /* (non-Javadoc)
          * @see org.apache.directory.studio.apacheds.schemaeditor.controller.SchemaListener#objectClassModified(org.apache.directory.studio.apacheds.schemaeditor.model.ObjectClassImpl)
          */
@@ -131,6 +139,7 @@
             fillInUiFields();
         }
 
+
         /* (non-Javadoc)
          * @see org.apache.directory.studio.apacheds.schemaeditor.controller.SchemaListener#objectClassRemoved(org.apache.directory.studio.apacheds.schemaeditor.model.ObjectClassImpl)
          */
@@ -139,6 +148,7 @@
             fillInUiFields();
         }
 
+
         /* (non-Javadoc)
          * @see org.apache.directory.studio.apacheds.schemaeditor.controller.SchemaListener#syntaxAdded(org.apache.directory.studio.apacheds.schemaeditor.model.SyntaxImpl)
          */
@@ -147,6 +157,7 @@
             fillInUiFields();
         }
 
+
         /* (non-Javadoc)
          * @see org.apache.directory.studio.apacheds.schemaeditor.controller.SchemaListener#syntaxModified(org.apache.directory.studio.apacheds.schemaeditor.model.SyntaxImpl)
          */
@@ -155,6 +166,7 @@
             fillInUiFields();
         }
 
+
         /* (non-Javadoc)
          * @see org.apache.directory.studio.apacheds.schemaeditor.controller.SchemaListener#syntaxRemoved(org.apache.directory.studio.apacheds.schemaeditor.model.SyntaxImpl)
          */
@@ -216,20 +228,6 @@
      */
     private void fillInUiFields()
     {
-        StringBuffer sb = new StringBuffer();
-
-        for ( AttributeTypeImpl at : schema.getAttributeTypes() )
-        {
-            sb.append( PluginUtils.toSourceCode( at ) );
-            sb.append( "\n" ); //$NON-NLS-1$
-        }
-
-        for ( ObjectClassImpl oc : schema.getObjectClasses() )
-        {
-            sb.append( PluginUtils.toSourceCode( oc ) );
-            sb.append( "\n" ); //$NON-NLS-1$
-        }
-
-        schemaSourceViewer.getDocument().set( sb.toString() );
+        schemaSourceViewer.getDocument().set( SchemaExporter.toSourceCode( schema ) );
     }
 }



Mime
View raw message