You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2009/01/16 12:18:27 UTC

svn commit: r734976 - in /directory/shared/trunk: convert/src/main/java/org/apache/directory/shared/converter/schema/ ldap/src/main/java/org/apache/directory/shared/ldap/ldif/

Author: elecharny
Date: Fri Jan 16 03:18:25 2009
New Revision: 734976

URL: http://svn.apache.org/viewvc?rev=734976&view=rev
Log:
Modified the ConvertToLdif methods to get the DN being generated if needed. It will fix DIRSHARED-22

Modified:
    directory/shared/trunk/convert/src/main/java/org/apache/directory/shared/converter/schema/AttributeTypeHolder.java
    directory/shared/trunk/convert/src/main/java/org/apache/directory/shared/converter/schema/ObjectClassHolder.java
    directory/shared/trunk/convert/src/main/java/org/apache/directory/shared/converter/schema/SchemaElementImpl.java
    directory/shared/trunk/convert/src/main/java/org/apache/directory/shared/converter/schema/SchemaToLdif.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifUtils.java

Modified: directory/shared/trunk/convert/src/main/java/org/apache/directory/shared/converter/schema/AttributeTypeHolder.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/convert/src/main/java/org/apache/directory/shared/converter/schema/AttributeTypeHolder.java?rev=734976&r1=734975&r2=734976&view=diff
==============================================================================
--- directory/shared/trunk/convert/src/main/java/org/apache/directory/shared/converter/schema/AttributeTypeHolder.java (original)
+++ directory/shared/trunk/convert/src/main/java/org/apache/directory/shared/converter/schema/AttributeTypeHolder.java Fri Jan 16 03:18:25 2009
@@ -23,10 +23,9 @@
 import javax.naming.NamingException;
 
 import org.apache.directory.shared.ldap.entry.Entry;
-import org.apache.directory.shared.ldap.entry.EntryAttribute;
-import org.apache.directory.shared.ldap.entry.client.DefaultClientAttribute;
 import org.apache.directory.shared.ldap.entry.client.DefaultClientEntry;
 import org.apache.directory.shared.ldap.ldif.LdifUtils;
+import org.apache.directory.shared.ldap.name.LdapDN;
 import org.apache.directory.shared.ldap.name.Rdn;
 import org.apache.directory.shared.ldap.schema.UsageEnum;
 
@@ -423,11 +422,8 @@
         String dn = "m-oid=" + oid + ", ou=attributeTypes" + ", cn=" + Rdn.escapeValue( schemaName ) + ", ou=schema";
 
         // First dump the DN only
-        Entry entry = new DefaultClientEntry();
-        EntryAttribute attribute = new DefaultClientAttribute( "dn", dn );
-
-        entry.put( attribute );
-        sb.append( LdifUtils.convertToLdif( entry ) );
+        Entry entry = new DefaultClientEntry( new LdapDN( dn ) );
+        sb.append( LdifUtils.convertEntryToLdif( entry ) );
 
         return sb.toString();
     }

Modified: directory/shared/trunk/convert/src/main/java/org/apache/directory/shared/converter/schema/ObjectClassHolder.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/convert/src/main/java/org/apache/directory/shared/converter/schema/ObjectClassHolder.java?rev=734976&r1=734975&r2=734976&view=diff
==============================================================================
--- directory/shared/trunk/convert/src/main/java/org/apache/directory/shared/converter/schema/ObjectClassHolder.java (original)
+++ directory/shared/trunk/convert/src/main/java/org/apache/directory/shared/converter/schema/ObjectClassHolder.java Fri Jan 16 03:18:25 2009
@@ -26,10 +26,9 @@
 import javax.naming.NamingException;
 
 import org.apache.directory.shared.ldap.entry.Entry;
-import org.apache.directory.shared.ldap.entry.EntryAttribute;
-import org.apache.directory.shared.ldap.entry.client.DefaultClientAttribute;
 import org.apache.directory.shared.ldap.entry.client.DefaultClientEntry;
 import org.apache.directory.shared.ldap.ldif.LdifUtils;
+import org.apache.directory.shared.ldap.name.LdapDN;
 import org.apache.directory.shared.ldap.name.Rdn;
 import org.apache.directory.shared.ldap.schema.ObjectClassTypeEnum;
 
@@ -216,11 +215,8 @@
         String dn = "m-oid=" + oid + ", ou=objectClasses" + ", cn=" + Rdn.escapeValue( schemaName ) + ", ou=schema";
 
         // First dump the DN only
-        Entry entry = new DefaultClientEntry();
-        EntryAttribute attribute = new DefaultClientAttribute( "dn", dn );
-
-        entry.put( attribute );
-        sb.append( LdifUtils.convertToLdif( entry ) );
+        Entry entry = new DefaultClientEntry( new LdapDN( dn ) );
+        sb.append( LdifUtils.convertEntryToLdif( entry ) );
 
         return sb.toString();
     }

Modified: directory/shared/trunk/convert/src/main/java/org/apache/directory/shared/converter/schema/SchemaElementImpl.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/convert/src/main/java/org/apache/directory/shared/converter/schema/SchemaElementImpl.java?rev=734976&r1=734975&r2=734976&view=diff
==============================================================================
--- directory/shared/trunk/convert/src/main/java/org/apache/directory/shared/converter/schema/SchemaElementImpl.java (original)
+++ directory/shared/trunk/convert/src/main/java/org/apache/directory/shared/converter/schema/SchemaElementImpl.java Fri Jan 16 03:18:25 2009
@@ -157,7 +157,7 @@
             
             entry.put( attribute );
             
-            return LdifUtils.convertToLdif( entry );
+            return LdifUtils.convertAttributesToLdif( entry );
         }
     }
     
@@ -177,7 +177,7 @@
 
             entry.put( attribute );
             
-            return LdifUtils.convertToLdif( entry );
+            return LdifUtils.convertAttributesToLdif( entry );
         }
     }
     
@@ -206,7 +206,7 @@
             attribute.add( extension );
         }
 
-        sb.append( LdifUtils.convertToLdif( entry ) );
+        sb.append( LdifUtils.convertAttributesToLdif( entry ) );
         
         return sb.toString();
     }

Modified: directory/shared/trunk/convert/src/main/java/org/apache/directory/shared/converter/schema/SchemaToLdif.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/convert/src/main/java/org/apache/directory/shared/converter/schema/SchemaToLdif.java?rev=734976&r1=734975&r2=734976&view=diff
==============================================================================
--- directory/shared/trunk/convert/src/main/java/org/apache/directory/shared/converter/schema/SchemaToLdif.java (original)
+++ directory/shared/trunk/convert/src/main/java/org/apache/directory/shared/converter/schema/SchemaToLdif.java Fri Jan 16 03:18:25 2009
@@ -133,7 +133,7 @@
         // Iterate through each schema elemnts
         for ( SchemaElement element:elements )
         {
-            out.write(  element.toLdif( schema.getName() ) );
+            out.write( element.toLdif( schema.getName() ) );
             
             out.write( '\n' );
         }

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifUtils.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifUtils.java?rev=734976&r1=734975&r2=734976&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifUtils.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifUtils.java Fri Jan 16 03:18:25 2009
@@ -148,7 +148,7 @@
      */
     public static String convertToLdif( Attributes attrs ) throws NamingException
     {
-        return convertToLdif( AttributeUtils.toClientEntry( attrs, null ), DEFAULT_LINE_LENGTH );
+        return convertAttributesToLdif( AttributeUtils.toClientEntry( attrs, null ), DEFAULT_LINE_LENGTH );
     }
     
     
@@ -160,43 +160,55 @@
      */
     public static String convertToLdif( Attributes attrs, int length ) throws NamingException
     {
-        return convertToLdif( AttributeUtils.toClientEntry( attrs, null ), length );
+        return convertAttributesToLdif( AttributeUtils.toClientEntry( attrs, null ), length );
     }
     
     
     /**
-     * Convert an Attributes as LDIF
+     * Convert an Attributes as LDIF. The DN is written.
      * @param attrs the Attributes to convert
      * @return the corresponding LDIF code as a String
      * @throws NamingException If a naming exception is encountered.
      */
     public static String convertToLdif( Attributes attrs, LdapDN dn, int length ) throws NamingException
     {
-        return convertToLdif( AttributeUtils.toClientEntry( attrs, dn ), length );
+        return convertEntryToLdif( AttributeUtils.toClientEntry( attrs, dn ), length );
     }
     
     
     /**
-     * Convert an Attributes as LDIF
+     * Convert an Attributes as LDIF. The DN is written.
      * @param attrs the Attributes to convert
      * @return the corresponding LDIF code as a String
      * @throws NamingException If a naming exception is encountered.
      */
     public static String convertToLdif( Attributes attrs, LdapDN dn ) throws NamingException
     {
-        return convertToLdif( AttributeUtils.toClientEntry( attrs, dn ), DEFAULT_LINE_LENGTH );
+        return convertEntryToLdif( AttributeUtils.toClientEntry( attrs, dn ), DEFAULT_LINE_LENGTH );
     }
     
     
     /**
-     * Convert an Entry as LDIF
-     * @param attrs the Entry to convert
+     * Convert an Entry to LDIF
+     * @param entry the Entry to convert
+     * @return the corresponding LDIF code as a String
+     * @throws NamingException If a naming exception is encountered.
+     */
+    public static String convertEntryToLdif( Entry entry ) throws NamingException
+    {
+        return convertEntryToLdif( entry, DEFAULT_LINE_LENGTH );
+    }
+    
+    
+    /**
+     * Convert all the Entry's attributes to LDIF. The DN is not written
+     * @param entry the Entry to convert
      * @return the corresponding LDIF code as a String
      * @throws NamingException If a naming exception is encountered.
      */
-    public static String convertToLdif( Entry attrs ) throws NamingException
+    public static String convertAttributesToLdif( Entry entry ) throws NamingException
     {
-        return convertToLdif( attrs, DEFAULT_LINE_LENGTH );
+        return convertAttributesToLdif( entry, DEFAULT_LINE_LENGTH );
     }
     
     
@@ -222,10 +234,26 @@
      * @return the corresponding LDIF code as a String
      * @throws NamingException If a naming exception is encountered.
      */
-    public static String convertToLdif( Entry entry, int length ) throws NamingException
+    public static String convertEntryToLdif( Entry entry, int length ) throws NamingException
     {
         StringBuilder sb = new StringBuilder();
         
+        if ( entry.getDn() != null )
+        {
+            // First, dump the DN
+            if ( isLDIFSafe( entry.getDn().getUpName() ) )
+            {
+                sb.append( stripLineToNChars( "dn: " + entry.getDn().getUpName(), length ) );
+            }
+            else
+            {
+                sb.append( stripLineToNChars( "dn:: " + encodeBase64( entry.getDn().getUpName() ), length ) );
+            }
+        
+            sb.append( '\n' );
+        }
+
+        // Then all the attributes
         for ( EntryAttribute attribute:entry )
         {
             sb.append( convertToLdif( attribute, length ) );
@@ -236,8 +264,29 @@
     
     
     /**
-     * Convert an Entry to LDIF
-     * @param entry the entry to convert
+     * Convert the Entry's attributes to LDIF. The DN is not written.
+     * @param entry the Entry to convert
+     * @param length the expected line length
+     * @return the corresponding LDIF code as a String
+     * @throws NamingException If a naming exception is encountered.
+     */
+    public static String convertAttributesToLdif( Entry entry, int length ) throws NamingException
+    {
+        StringBuilder sb = new StringBuilder();
+        
+        // Then all the attributes
+        for ( EntryAttribute attribute:entry )
+        {
+            sb.append( convertToLdif( attribute, length ) );
+        }
+        
+        return sb.toString();
+    }
+
+    
+    /**
+     * Convert an LdifEntry to LDIF
+     * @param entry the LdifEntry to convert
      * @return the corresponding LDIF as a String
      * @throws NamingException If a naming exception is encountered.
      */
@@ -245,10 +294,11 @@
     {
         return convertToLdif( entry, DEFAULT_LINE_LENGTH );
     }
+
     
     /**
-     * Convert an Entry to LDIF
-     * @param entry the entry to convert
+     * Convert an LdifEntry to LDIF
+     * @param entry the LdifEntry to convert
      * @param length The maximum line's length 
      * @return the corresponding LDIF as a String
      * @throws NamingException If a naming exception is encountered.