directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r610856 [2/2] - in /directory: apacheds/branches/bigbang/core-entry/src/main/java/org/apache/directory/server/core/entry/ apacheds/branches/bigbang/core-entry/src/test/java/org/apache/directory/server/core/entry/ apacheds/branches/bigbang/c...
Date Thu, 10 Jan 2008 18:09:24 GMT
Modified: directory/apacheds/branches/bigbang/core-plugin/src/main/antlr/openldap.g
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-plugin/src/main/antlr/openldap.g?rev=610856&r1=610855&r2=610856&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core-plugin/src/main/antlr/openldap.g (original)
+++ directory/apacheds/branches/bigbang/core-plugin/src/main/antlr/openldap.g Thu Jan 10 10:09:16 2008
@@ -102,7 +102,7 @@
 
 DESC
     :
-        "desc" WS QUOTE ( ~'\'' )+ QUOTE
+        "desc" WS QUOTE ( ~'\'' )* QUOTE
     ;
 
 SYNTAX
@@ -297,30 +297,40 @@
 }
     : d:DESC
     {
-        String desc = d.getText().split( "'" )[1];
-        String[] quoted = desc.split( "\"" );
-
-        if ( quoted.length == 1 )
-        {
-            objectClass.setDescription( desc );
+        String text = d.getText();
+        String[] elems = text.split( "'" );
+        
+        if ( elems.length == 1 )
+        { 
+            objectClass.setDescription( "" );
         }
         else
         {
-            StringBuffer buf = new StringBuffer();
-            for ( int ii = 0; ii < quoted.length; ii++ )
-            {
-                if ( ii < quoted.length - 1 )
-                {
-                    buf.append( quoted[ii] ).append( "\\" ).append( "\"" );
-                }
-                else
-                {
-                    buf.append( quoted[ii] );
-                }
-            }
-
-            objectClass.setDescription( buf.toString() );
-        }
+	        String desc = elems[1];
+	        String[] quoted = desc.split( "\"" );
+	
+	        if ( quoted.length == 1 )
+	        {
+	            objectClass.setDescription( desc );
+	        }
+	        else
+	        {
+	            StringBuffer buf = new StringBuffer();
+	            for ( int ii = 0; ii < quoted.length; ii++ )
+	            {
+	                if ( ii < quoted.length - 1 )
+	                {
+	                    buf.append( quoted[ii] ).append( "\\" ).append( "\"" );
+	                }
+	                else
+	                {
+	                    buf.append( quoted[ii] );
+	                }
+	            }
+	
+	            objectClass.setDescription( buf.toString() );
+	        }
+	    }
     }
     ;
 
@@ -396,29 +406,39 @@
 }
     : d:DESC
     {
-        String desc = d.getText().split( "'" )[1];
-        String[] quoted = desc.split( "\"" );
-
-        if ( quoted.length == 1 )
+        String text = d.getText();
+        String[] elems = text.split( "'" );
+        
+        if ( elems.length == 1 )
         {
-            type.setDescription( desc );
+            type.setDescription( "" );
         }
         else
         {
-            StringBuffer buf = new StringBuffer();
-            for ( int ii = 0; ii < quoted.length; ii++ )
+            String desc = elems[1];
+            String[] quoted = desc.split( "\"" );
+
+            if ( quoted.length == 1 )
             {
-                if ( ii < quoted.length - 1 )
-                {
-                    buf.append( quoted[ii] ).append( "\\" ).append( "\"" );
-                }
-                else
+                type.setDescription( desc );
+            }
+            else
+            {
+                StringBuffer buf = new StringBuffer();
+                for ( int ii = 0; ii < quoted.length; ii++ )
                 {
-                    buf.append( quoted[ii] );
+                    if ( ii < quoted.length - 1 )
+                    {
+                        buf.append( quoted[ii] ).append( "\\" ).append( "\"" );
+                    }
+                    else
+                    {
+                        buf.append( quoted[ii] );
+                    }
                 }
-            }
 
-            type.setDescription( buf.toString() );
+                type.setDescription( buf.toString() );
+            }
         }
     }
     ;

Modified: directory/apacheds/branches/bigbang/core-plugin/src/test/java/org/apache/directory/server/core/tools/schema/OpenLdapSchemaParserTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-plugin/src/test/java/org/apache/directory/server/core/tools/schema/OpenLdapSchemaParserTest.java?rev=610856&r1=610855&r2=610856&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core-plugin/src/test/java/org/apache/directory/server/core/tools/schema/OpenLdapSchemaParserTest.java (original)
+++ directory/apacheds/branches/bigbang/core-plugin/src/test/java/org/apache/directory/server/core/tools/schema/OpenLdapSchemaParserTest.java Thu Jan 10 10:09:16 2008
@@ -232,4 +232,72 @@
         assertEquals( "personalSignature", objectClass.getMay()[18] );
 
     }
+
+    public void testSimpleAttributeTypeEmptyDesc() throws Exception
+    {
+        String attributeTypeData = "attributetype ( 2.5.4.14 NAME 'searchGuide'\n"
+            + "        DESC ''\n"
+            + "        SYNTAX 1.3.6.1.4.1.1466.115.121.1.25 )";
+
+        parser.parse( attributeTypeData );
+        List attributeTypeList = parser.getAttributeTypes();
+        Map attributeTypes = mapAttributeTypes( attributeTypeList );
+        AttributeTypeLiteral type = ( AttributeTypeLiteral ) attributeTypes.get( "2.5.4.14" );
+
+        assertNotNull( type );
+        assertEquals( "2.5.4.14", type.getOid() );
+        assertEquals( "searchGuide", type.getNames()[0] );
+        assertEquals( "", type.getDescription() );
+        assertEquals( "1.3.6.1.4.1.1466.115.121.1.25", type.getSyntax() );
+    }
+
+
+    public void testObjectClassEmptyDesc() throws Exception
+    {
+        String objectClassData = "objectclass ( 0.9.2342.19200300.100.4.4\n"
+            + "\tNAME ( 'pilotPerson' 'newPilotPerson' )\n"
+            + "\tDESC ''\n"
+            + "\tSUP person STRUCTURAL\n"
+            + "\tMAY ( userid $ textEncodedORAddress $ rfc822Mailbox $\n"
+            + "\t\tfavouriteDrink $ roomNumber $ userClass $\n"
+            + "\t\thomeTelephoneNumber $ homePostalAddress $ secretary $\n"
+            + "\t\tpersonalTitle $ preferredDeliveryMethod $ businessCategory $\n"
+            + "\t\tjanetMailbox $ otherMailbox $ mobileTelephoneNumber $\n"
+            + "\t\tpagerTelephoneNumber $ organizationalStatus $\n"
+            + "\t\tmailPreferenceOption $ personalSignature )\n" + "\t)";
+        parser.parse( objectClassData );
+        List objectClassesList = parser.getObjectClassTypes();
+        Map objectClasses = mapObjectClasses( objectClassesList );
+        ObjectClassLiteral objectClass = ( ObjectClassLiteral ) objectClasses.get( "0.9.2342.19200300.100.4.4" );
+
+        assertNotNull( objectClass );
+        assertEquals( "0.9.2342.19200300.100.4.4", objectClass.getOid() );
+        assertEquals( "pilotPerson", objectClass.getNames()[0] );
+        assertEquals( "newPilotPerson", objectClass.getNames()[1] );
+        assertEquals( "", objectClass.getDescription() );
+        assertEquals( ObjectClassTypeEnum.STRUCTURAL, objectClass.getClassType() );
+        assertEquals( "person", objectClass.getSuperiors()[0] );
+
+        assertEquals( "userid", objectClass.getMay()[0] );
+        assertEquals( "textEncodedORAddress", objectClass.getMay()[1] );
+        assertEquals( "rfc822Mailbox", objectClass.getMay()[2] );
+        assertEquals( "favouriteDrink", objectClass.getMay()[3] );
+        assertEquals( "roomNumber", objectClass.getMay()[4] );
+        assertEquals( "userClass", objectClass.getMay()[5] );
+        assertEquals( "homeTelephoneNumber", objectClass.getMay()[6] );
+        assertEquals( "homePostalAddress", objectClass.getMay()[7] );
+        assertEquals( "secretary", objectClass.getMay()[8] );
+        assertEquals( "personalTitle", objectClass.getMay()[9] );
+        assertEquals( "preferredDeliveryMethod", objectClass.getMay()[10] );
+        assertEquals( "businessCategory", objectClass.getMay()[11] );
+        assertEquals( "janetMailbox", objectClass.getMay()[12] );
+        assertEquals( "otherMailbox", objectClass.getMay()[13] );
+        assertEquals( "mobileTelephoneNumber", objectClass.getMay()[14] );
+        assertEquals( "pagerTelephoneNumber", objectClass.getMay()[15] );
+        assertEquals( "organizationalStatus", objectClass.getMay()[16] );
+        assertEquals( "mailPreferenceOption", objectClass.getMay()[17] );
+        assertEquals( "personalSignature", objectClass.getMay()[18] );
+
+    }
+
 }

Modified: directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/DefaultDirectoryService.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/DefaultDirectoryService.java?rev=610856&r1=610855&r2=610856&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/DefaultDirectoryService.java (original)
+++ directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/DefaultDirectoryService.java Thu Jan 10 10:09:16 2008
@@ -121,7 +121,7 @@
  * @org.apache.xbean.XBean
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-public class DefaultDirectoryService implements  DirectoryService
+public class DefaultDirectoryService implements DirectoryService
 {
     private static final Logger LOG = LoggerFactory.getLogger( DefaultDirectoryService.class );
 
@@ -1500,22 +1500,23 @@
     /**
      * Create a new ServerEntry
      * 
-     * @param dn The DN for this new entry
      * @param ldif The String representing the attributes, as a LDIF file
+     * @param dn The DN for this new entry
      */
-    public ServerEntry newEntry( String dn, String ldif )
+    public ServerEntry newEntry( String ldif, String dn )
     {
         try
         {
             Attributes entry = readEntry( ldif );
             
-            return new DefaultServerEntry( registries, new LdapDN( dn) );
+            ServerEntry serverEntry = ServerEntryUtils.toServerEntry( entry, new LdapDN( dn ), registries );
+            return serverEntry;
         }
         catch ( Exception e )
         {
+        	LOG.error( "Cannot build an entry for '{}' and this DN :'{}'", ldif, dn );
             // do nothing
             return null;
         }
     }
-    
 }

Modified: directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/DirectoryService.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/DirectoryService.java?rev=610856&r1=610855&r2=610856&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/DirectoryService.java (original)
+++ directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/DirectoryService.java Thu Jan 10 10:09:16 2008
@@ -386,8 +386,8 @@
     /**
      * Create a new ServerEntry
      * 
-     * @param dn The DN for this new entry
      * @param ldif The String representing the attributes, as a LDIF file
+     * @param dn The DN for this new entry
      */
-    ServerEntry newEntry( String dn, String ldif );
+    ServerEntry newEntry( String ldif, String dn );
 }

Modified: directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/partition/DefaultPartitionNexus.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/partition/DefaultPartitionNexus.java?rev=610856&r1=610855&r2=610856&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/partition/DefaultPartitionNexus.java (original)
+++ directory/apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/partition/DefaultPartitionNexus.java Thu Jan 10 10:09:16 2008
@@ -22,6 +22,7 @@
 
 import org.apache.directory.server.constants.ServerDNConstants;
 import org.apache.directory.server.core.DirectoryService;
+import org.apache.directory.server.core.entry.DefaultServerAttribute;
 import org.apache.directory.server.core.entry.DefaultServerEntry;
 import org.apache.directory.server.core.entry.ServerAttribute;
 import org.apache.directory.server.core.entry.ServerEntry;
@@ -189,8 +190,6 @@
             SchemaConstants.TOP_OC,
             SchemaConstants.EXTENSIBLE_OBJECT_OC );
 
-        rootDSE.set( SchemaConstants.NAMING_CONTEXTS_AT );
-        
         // Add the 'vendor' name and version infos
         rootDSE.put( SchemaConstants.VENDOR_NAME_AT, ASF );
 
@@ -385,7 +384,7 @@
         
         if ( override != null )
         {
-            ServerEntry systemEntry = ServerEntryUtils.toServerEntry( override.getContextEntryAttr(), new LdapDN( override.getSuffix() ), registries );
+            ServerEntry systemEntry = override.getContextEntry();
             ServerAttribute objectClassAttr = systemEntry.get( SchemaConstants.OBJECT_CLASS_AT );
             
             if ( objectClassAttr == null )
@@ -491,7 +490,18 @@
             partitions.put( key, system );
             partitionLookupTree.recursivelyAddPartition( partitionLookupTree, system.getSuffixDn(), 0, system );
             ServerAttribute namingContexts = rootDSE.get( SchemaConstants.NAMING_CONTEXTS_AT );
-            namingContexts.add( system.getUpSuffixDn().getUpName() );
+            
+            if ( namingContexts == null )
+            {
+                namingContexts = new DefaultServerAttribute( 
+                    registries.getAttributeTypeRegistry().lookup( SchemaConstants.NAMING_CONTEXTS_AT ), 
+                    system.getUpSuffixDn().getUpName() );
+                rootDSE.put( namingContexts );
+            }
+            else
+            {
+                namingContexts.add( system.getUpSuffixDn().getUpName() );
+            }
         }
 
         return system;
@@ -685,7 +695,16 @@
         		throw new ConfigurationException( "The current partition does not have any user provided suffix: " + partition.getId() );
         	}
         	
-            namingContexts.add( partitionUpSuffix.getUpName() );
+        	if ( namingContexts == null )
+        	{
+        	    namingContexts = new DefaultServerAttribute( 
+        	        registries.getAttributeTypeRegistry().lookup( SchemaConstants.NAMING_CONTEXTS_AT ), partitionUpSuffix.getUpName() );
+        	    rootDSE.put( namingContexts );
+        	}
+        	else
+        	{
+        	    namingContexts.add( partitionUpSuffix.getUpName() );
+        	}
         }
     }
 
@@ -701,7 +720,11 @@
         }
 
         ServerAttribute namingContexts = rootDSE.get( SchemaConstants.NAMING_CONTEXTS_AT );
-        namingContexts.remove( partition.getUpSuffixDn().getUpName() );
+        
+        if ( namingContexts != null )
+        {
+            namingContexts.remove( partition.getUpSuffixDn().getUpName() );
+        }
 
         // Create a new partition list. 
         // This is easier to create a new structure from scratch than to reorganize
@@ -811,7 +834,12 @@
     private void unregister( Partition partition ) throws NamingException
     {
         ServerAttribute namingContexts = rootDSE.get( SchemaConstants.NAMING_CONTEXTS_AT );
-        namingContexts.remove( partition.getSuffixDn().getUpName() );
+        
+        if ( namingContexts != null )
+        {
+            namingContexts.remove( partition.getSuffixDn().getUpName() );
+        }
+        
         partitions.remove( partition.getSuffixDn().toString() );
     }
 

Modified: directory/apacheds/branches/bigbang/core/src/test/java/org/apache/directory/server/core/authz/support/MaxImmSubFilterTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core/src/test/java/org/apache/directory/server/core/authz/support/MaxImmSubFilterTest.java?rev=610856&r1=610855&r2=610856&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core/src/test/java/org/apache/directory/server/core/authz/support/MaxImmSubFilterTest.java (original)
+++ directory/apacheds/branches/bigbang/core/src/test/java/org/apache/directory/server/core/authz/support/MaxImmSubFilterTest.java Thu Jan 10 10:09:16 2008
@@ -502,7 +502,7 @@
             return null;
         }
         
-        public ServerEntry newEntry( String dn, String ldif )
+        public ServerEntry newEntry( String ldif, String dn )
         {
             return null;
         }

Modified: directory/apacheds/branches/bigbang/core/src/test/java/org/apache/directory/server/core/interceptor/InterceptorChainTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core/src/test/java/org/apache/directory/server/core/interceptor/InterceptorChainTest.java?rev=610856&r1=610855&r2=610856&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core/src/test/java/org/apache/directory/server/core/interceptor/InterceptorChainTest.java (original)
+++ directory/apacheds/branches/bigbang/core/src/test/java/org/apache/directory/server/core/interceptor/InterceptorChainTest.java Thu Jan 10 10:09:16 2008
@@ -552,7 +552,7 @@
         }
 
         
-        public ServerEntry newEntry( String dn, String ldif )
+        public ServerEntry newEntry( String ldif, String dn )
         {
             return null;
         }

Modified: directory/apacheds/branches/bigbang/server-unit/src/test/java/org/apache/directory/server/DIRSERVER951ITest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/server-unit/src/test/java/org/apache/directory/server/DIRSERVER951ITest.java?rev=610856&r1=610855&r2=610856&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/server-unit/src/test/java/org/apache/directory/server/DIRSERVER951ITest.java (original)
+++ directory/apacheds/branches/bigbang/server-unit/src/test/java/org/apache/directory/server/DIRSERVER951ITest.java Thu Jan 10 10:09:16 2008
@@ -20,20 +20,18 @@
 package org.apache.directory.server;
 
 
+import org.apache.directory.server.core.entry.DefaultServerEntry;
+import org.apache.directory.server.core.entry.ServerEntry;
 import org.apache.directory.server.core.partition.Oid;
 import org.apache.directory.server.core.partition.impl.btree.Index;
 import org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmIndex;
 import org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmPartition;
 import org.apache.directory.server.unit.AbstractServerTest;
-import org.apache.directory.shared.ldap.message.AttributeImpl;
-import org.apache.directory.shared.ldap.message.AttributesImpl;
+import org.apache.directory.shared.ldap.name.LdapDN;
 import org.apache.directory.shared.ldap.util.DateUtils;
-import org.apache.directory.shared.ldap.util.NamespaceTools;
 
 import javax.naming.NamingEnumeration;
 import javax.naming.NamingException;
-import javax.naming.directory.Attribute;
-import javax.naming.directory.Attributes;
 import javax.naming.directory.SearchControls;
 import javax.naming.directory.SearchResult;
 import javax.naming.ldap.LdapContext;
@@ -68,7 +66,7 @@
 
 
     @Override
-    protected void configureDirectoryService()
+    protected void configureDirectoryService() throws NamingException
     {
         JdbmPartition systemCfg = new JdbmPartition();
         systemCfg.setId( "system" );
@@ -92,16 +90,13 @@
         systemCfg.setIndexedAttributes( indexedAttrs );
 
         // Add context entry for system partition
-        Attributes systemEntry = new AttributesImpl();
-        Attribute objectClassAttr = new AttributeImpl( "objectClass" );
-        objectClassAttr.add( "top" );
-        objectClassAttr.add( "account" );
-        //objectClassAttr.add( "extensibleObject" );
-        systemEntry.put( objectClassAttr );
+        LdapDN systemDn = new LdapDN( "ou=system" );
+        ServerEntry systemEntry = new DefaultServerEntry( directoryService.getRegistries(), systemDn );
+        
+        systemEntry.put( "objectClass", "top", "account" );
         systemEntry.put( "creatorsName", "uid=admin,ou=system" );
         systemEntry.put( "createTimestamp", DateUtils.getGeneralizedTime() );
-        systemEntry.put( NamespaceTools.getRdnAttribute( "ou=system" ),
-            NamespaceTools.getRdnValue( "ou=system" ) );
+        systemEntry.put( "ou", "system" );
         systemEntry.put( "uid", "testUid" );
         systemCfg.setContextEntry( systemEntry );
 

Modified: directory/apacheds/branches/bigbang/server-unit/src/test/java/org/apache/directory/server/NegationOperatorITest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/server-unit/src/test/java/org/apache/directory/server/NegationOperatorITest.java?rev=610856&r1=610855&r2=610856&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/server-unit/src/test/java/org/apache/directory/server/NegationOperatorITest.java (original)
+++ directory/apacheds/branches/bigbang/server-unit/src/test/java/org/apache/directory/server/NegationOperatorITest.java Thu Jan 10 10:09:16 2008
@@ -26,22 +26,20 @@
 
 import javax.naming.NamingEnumeration;
 import javax.naming.NamingException;
-import javax.naming.directory.Attribute;
-import javax.naming.directory.Attributes;
 import javax.naming.directory.SearchControls;
 import javax.naming.directory.SearchResult;
 import javax.naming.ldap.LdapContext;
 
+import org.apache.directory.server.core.entry.DefaultServerEntry;
+import org.apache.directory.server.core.entry.ServerEntry;
 import org.apache.directory.server.core.partition.impl.btree.Index;
 import org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmIndex;
 import org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmPartition;
 import org.apache.directory.server.unit.AbstractServerTest;
 import org.apache.directory.shared.ldap.constants.SchemaConstants;
 import org.apache.directory.shared.ldap.ldif.Entry;
-import org.apache.directory.shared.ldap.message.AttributeImpl;
-import org.apache.directory.shared.ldap.message.AttributesImpl;
+import org.apache.directory.shared.ldap.name.LdapDN;
 import org.apache.directory.shared.ldap.util.DateUtils;
-import org.apache.directory.shared.ldap.util.NamespaceTools;
 
 
 /**
@@ -73,7 +71,7 @@
 
 
     @Override
-    protected void configureDirectoryService()
+    protected void configureDirectoryService() throws NamingException
     {
         if ( this.getName().indexOf( "Indexed" ) != -1 )
         {
@@ -92,16 +90,14 @@
             system.setIndexedAttributes( indexedAttrs );
 
             // Add context entry for system partition
-            Attributes systemEntry = new AttributesImpl();
-            Attribute objectClassAttr = new AttributeImpl( SchemaConstants.OBJECT_CLASS_AT );
-            objectClassAttr.add( SchemaConstants.TOP_OC );
-            objectClassAttr.add( SchemaConstants.ORGANIZATIONAL_UNIT_OC );
-            objectClassAttr.add( SchemaConstants.EXTENSIBLE_OBJECT_OC );
-            systemEntry.put( objectClassAttr );
+            LdapDN systemDn = new LdapDN( "ou=system" );
+            ServerEntry systemEntry = new DefaultServerEntry( directoryService.getRegistries(), systemDn );
+            
+            systemEntry.put( "objectClass", "top", "organizationalUnit", "extensibleObject" ); 
+
             systemEntry.put( SchemaConstants.CREATORS_NAME_AT, "uid=admin, ou=system" );
             systemEntry.put( SchemaConstants.CREATE_TIMESTAMP_AT, DateUtils.getGeneralizedTime() );
-            systemEntry.put( NamespaceTools.getRdnAttribute( "ou=system" ),
-                NamespaceTools.getRdnValue( "ou=system" ) );
+            systemEntry.put( "ou", "system" );
             system.setContextEntry( systemEntry );
 
             directoryService.setSystemPartition( system );

Modified: directory/apacheds/branches/bigbang/server-xml/src/main/resources/server.xml
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/server-xml/src/main/resources/server.xml?rev=610856&r1=610855&r2=610856&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/server-xml/src/main/resources/server.xml (original)
+++ directory/apacheds/branches/bigbang/server-xml/src/main/resources/server.xml Thu Jan 10 10:09:16 2008
@@ -24,14 +24,15 @@
           <jdbmIndex attributeId="uid" cacheSize="100"/>
           <jdbmIndex attributeId="objectClass" cacheSize="100"/>
         </indexedAttributes>
-        <contextEntry>
+        <contextEntry>#systemContextEntry</contextEntry>
+        <!-- contextEntry>
           <value xmlns="http://www.springframework.org/schema/beans">
             objectClass: top
             objectClass: organizationalUnit
             objectClass: extensibleObject
             ou: system
           </value>
-        </contextEntry>
+        </contextEntry -->
       </jdbmPartition>
     </systemPartition>
 
@@ -55,14 +56,15 @@
           <jdbmIndex attributeId="uid" cacheSize="100"/>
           <jdbmIndex attributeId="objectClass" cacheSize="100"/>
         </indexedAttributes>
-        <contextEntry>
+        <contextEntry>#exampleContextEntry</contextEntry>
+        <!-- contextEntry>
           <value xmlns="http://www.springframework.org/schema/beans">
             objectClass: top
             objectClass: domain
             objectClass: extensibleObject
             dc: example
           </value>
-        </contextEntry>
+        </contextEntry -->
       </jdbmPartition>
     </partitions>
 
@@ -190,6 +192,40 @@
     <ldapServer>#ldapServer</ldapServer>
     <ldapsServer>#ldapsServer</ldapsServer>
   </apacheDS>
+
+  <spring:bean id="systemContextEntry" 
+	class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
+    <spring:property name="targetObject"><spring:ref local='directoryService'/></spring:property>
+    <spring:property name="targetMethod"><spring:value>newEntry</spring:value></spring:property>
+    <spring:property name="arguments">
+      <spring:list>
+        <spring:value xmlns="http://www.springframework.org/schema/beans">
+          objectClass: top
+          objectClass: organizationalUnit
+          objectClass: extensibleObject
+          ou: system
+        </spring:value>
+        <spring:value>ou=system</spring:value>
+      </spring:list>
+    </spring:property>
+  </spring:bean>
+  
+  <spring:bean id="exampleContextEntry" 
+	class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
+    <spring:property name="targetObject"><spring:ref local='directoryService'/></spring:property>
+    <spring:property name="targetMethod"><spring:value>newEntry</spring:value></spring:property>
+    <spring:property name="arguments">
+      <spring:list>
+        <spring:value xmlns="http://www.springframework.org/schema/beans">
+          objectClass: top
+          objectClass: domain
+          objectClass: extensibleObject
+          dc: example
+        </spring:value>
+        <spring:value>dc=example,dc=com</spring:value>
+      </spring:list>
+    </spring:property>
+  </spring:bean>
 
   <!-- another bean I didn't convert -->
   <spring:bean class="org.springframework.beans.factory.config.CustomEditorConfigurer">

Added: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifAttributesReader.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifAttributesReader.java?rev=610856&view=auto
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifAttributesReader.java (added)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifAttributesReader.java Thu Jan 10 10:09:16 2008
@@ -0,0 +1,294 @@
+/*
+ *  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.shared.ldap.ldif;
+
+import java.io.BufferedReader;
+import java.io.StringReader;
+import java.util.ArrayList;
+import java.util.Iterator;
+
+import javax.naming.NamingException;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.BasicAttributes;
+
+import org.apache.directory.shared.ldap.util.StringTools;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * <pre>
+ *  &lt;ldif-file&gt; ::= &quot;version:&quot; &lt;fill&gt; &lt;number&gt; &lt;seps&gt; &lt;dn-spec&gt; &lt;sep&gt; &lt;ldif-content-change&gt;
+ *  
+ *  &lt;ldif-content-change&gt; ::= 
+ *    &lt;number&gt; &lt;oid&gt; &lt;options-e&gt; &lt;value-spec&gt; &lt;sep&gt; &lt;attrval-specs-e&gt; &lt;ldif-attrval-record-e&gt; | 
+ *    &lt;alpha&gt; &lt;chars-e&gt; &lt;options-e&gt; &lt;value-spec&gt; &lt;sep&gt; &lt;attrval-specs-e&gt; &lt;ldif-attrval-record-e&gt; | 
+ *    &quot;control:&quot; &lt;fill&gt; &lt;number&gt; &lt;oid&gt; &lt;spaces-e&gt; &lt;criticality&gt; &lt;value-spec-e&gt; &lt;sep&gt; &lt;controls-e&gt; 
+ *        &quot;changetype:&quot; &lt;fill&gt; &lt;changerecord-type&gt; &lt;ldif-change-record-e&gt; |
+ *    &quot;changetype:&quot; &lt;fill&gt; &lt;changerecord-type&gt; &lt;ldif-change-record-e&gt;
+ *                              
+ *  &lt;ldif-attrval-record-e&gt; ::= &lt;seps&gt; &lt;dn-spec&gt; &lt;sep&gt; &lt;attributeType&gt; 
+ *    &lt;options-e&gt; &lt;value-spec&gt; &lt;sep&gt; &lt;attrval-specs-e&gt; 
+ *    &lt;ldif-attrval-record-e&gt; | e
+ *                              
+ *  &lt;ldif-change-record-e&gt; ::= &lt;seps&gt; &lt;dn-spec&gt; &lt;sep&gt; &lt;controls-e&gt; 
+ *    &quot;changetype:&quot; &lt;fill&gt; &lt;changerecord-type&gt; &lt;ldif-change-record-e&gt; | e
+ *                              
+ *  &lt;dn-spec&gt; ::= &quot;dn:&quot; &lt;fill&gt; &lt;safe-string&gt; | &quot;dn::&quot; &lt;fill&gt; &lt;base64-string&gt;
+ *                              
+ *  &lt;controls-e&gt; ::= &quot;control:&quot; &lt;fill&gt; &lt;number&gt; &lt;oid&gt; &lt;spaces-e&gt; &lt;criticality&gt; 
+ *    &lt;value-spec-e&gt; &lt;sep&gt; &lt;controls-e&gt; | e
+ *                              
+ *  &lt;criticality&gt; ::= &quot;true&quot; | &quot;false&quot; | e
+ *                              
+ *  &lt;oid&gt; ::= '.' &lt;number&gt; &lt;oid&gt; | e
+ *                              
+ *  &lt;attrval-specs-e&gt; ::= &lt;number&gt; &lt;oid&gt; &lt;options-e&gt; &lt;value-spec&gt; &lt;sep&gt; &lt;attrval-specs-e&gt; | 
+ *    &lt;alpha&gt; &lt;chars-e&gt; &lt;options-e&gt; &lt;value-spec&gt; &lt;sep&gt; &lt;attrval-specs-e&gt; | e
+ *                              
+ *  &lt;value-spec-e&gt; ::= &lt;value-spec&gt; | e
+ *  
+ *  &lt;value-spec&gt; ::= ':' &lt;fill&gt; &lt;safe-string-e&gt; | 
+ *    &quot;::&quot; &lt;fill&gt; &lt;base64-chars&gt; | 
+ *    &quot;:&lt;&quot; &lt;fill&gt; &lt;url&gt;
+ *  
+ *  &lt;attributeType&gt; ::= &lt;number&gt; &lt;oid&gt; | &lt;alpha&gt; &lt;chars-e&gt;
+ *  
+ *  &lt;options-e&gt; ::= ';' &lt;char&gt; &lt;chars-e&gt; &lt;options-e&gt; |e
+ *                              
+ *  &lt;chars-e&gt; ::= &lt;char&gt; &lt;chars-e&gt; |  e
+ *  
+ *  &lt;changerecord-type&gt; ::= &quot;add&quot; &lt;sep&gt; &lt;attributeType&gt; &lt;options-e&gt; &lt;value-spec&gt; &lt;sep&gt; &lt;attrval-specs-e&gt; | 
+ *    &quot;delete&quot; &lt;sep&gt; | 
+ *    &quot;modify&quot; &lt;sep&gt; &lt;mod-type&gt; &lt;fill&gt; &lt;attributeType&gt; &lt;options-e&gt; &lt;sep&gt; &lt;attrval-specs-e&gt; &lt;sep&gt; '-' &lt;sep&gt; &lt;mod-specs-e&gt; | 
+ *    &quot;moddn&quot; &lt;sep&gt; &lt;newrdn&gt; &lt;sep&gt; &quot;deleteoldrdn:&quot; &lt;fill&gt; &lt;0-1&gt; &lt;sep&gt; &lt;newsuperior-e&gt; &lt;sep&gt; |
+ *    &quot;modrdn&quot; &lt;sep&gt; &lt;newrdn&gt; &lt;sep&gt; &quot;deleteoldrdn:&quot; &lt;fill&gt; &lt;0-1&gt; &lt;sep&gt; &lt;newsuperior-e&gt; &lt;sep&gt;
+ *  
+ *  &lt;newrdn&gt; ::= ':' &lt;fill&gt; &lt;safe-string&gt; | &quot;::&quot; &lt;fill&gt; &lt;base64-chars&gt;
+ *  
+ *  &lt;newsuperior-e&gt; ::= &quot;newsuperior&quot; &lt;newrdn&gt; | e
+ *  
+ *  &lt;mod-specs-e&gt; ::= &lt;mod-type&gt; &lt;fill&gt; &lt;attributeType&gt; &lt;options-e&gt; 
+ *    &lt;sep&gt; &lt;attrval-specs-e&gt; &lt;sep&gt; '-' &lt;sep&gt; &lt;mod-specs-e&gt; | e
+ *  
+ *  &lt;mod-type&gt; ::= &quot;add:&quot; | &quot;delete:&quot; | &quot;replace:&quot;
+ *  
+ *  &lt;url&gt; ::= &lt;a Uniform Resource Locator, as defined in [6]&gt;
+ *  
+ *  
+ *  
+ *  LEXICAL
+ *  -------
+ *  
+ *  &lt;fill&gt;           ::= ' ' &lt;fill&gt; | e
+ *  &lt;char&gt;           ::= &lt;alpha&gt; | &lt;digit&gt; | '-'
+ *  &lt;number&gt;         ::= &lt;digit&gt; &lt;digits&gt;
+ *  &lt;0-1&gt;            ::= '0' | '1'
+ *  &lt;digits&gt;         ::= &lt;digit&gt; &lt;digits&gt; | e
+ *  &lt;digit&gt;          ::= '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9'
+ *  &lt;seps&gt;           ::= &lt;sep&gt; &lt;seps-e&gt; 
+ *  &lt;seps-e&gt;         ::= &lt;sep&gt; &lt;seps-e&gt; | e
+ *  &lt;sep&gt;            ::= 0x0D 0x0A | 0x0A
+ *  &lt;spaces&gt;         ::= ' ' &lt;spaces-e&gt;
+ *  &lt;spaces-e&gt;       ::= ' ' &lt;spaces-e&gt; | e
+ *  &lt;safe-string-e&gt;  ::= &lt;safe-string&gt; | e
+ *  &lt;safe-string&gt;    ::= &lt;safe-init-char&gt; &lt;safe-chars&gt;
+ *  &lt;safe-init-char&gt; ::= [0x01-0x09] | 0x0B | 0x0C | [0x0E-0x1F] | [0x21-0x39] | 0x3B | [0x3D-0x7F]
+ *  &lt;safe-chars&gt;     ::= &lt;safe-char&gt; &lt;safe-chars&gt; | e
+ *  &lt;safe-char&gt;      ::= [0x01-0x09] | 0x0B | 0x0C | [0x0E-0x7F]
+ *  &lt;base64-string&gt;  ::= &lt;base64-char&gt; &lt;base64-chars&gt;
+ *  &lt;base64-chars&gt;   ::= &lt;base64-char&gt; &lt;base64-chars&gt; | e
+ *  &lt;base64-char&gt;    ::= 0x2B | 0x2F | [0x30-0x39] | 0x3D | [0x41-9x5A] | [0x61-0x7A]
+ *  &lt;alpha&gt;          ::= [0x41-0x5A] | [0x61-0x7A]
+ *  
+ *  COMMENTS
+ *  --------
+ *  - The ldap-oid VN is not correct in the RFC-2849. It has been changed from 1*DIGIT 0*1(&quot;.&quot; 1*DIGIT) to
+ *  DIGIT+ (&quot;.&quot; DIGIT+)*
+ *  - The mod-spec lacks a sep between *attrval-spec and &quot;-&quot;.
+ *  - The BASE64-UTF8-STRING should be BASE64-CHAR BASE64-STRING
+ *  - The ValueSpec rule must accept multilines values. In this case, we have a LF followed by a 
+ *  single space before the continued value.
+ * </pre>
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class LdifAttributesReader extends LdifReader
+{
+    /** A logger */
+    private static final Logger LOG = LoggerFactory.getLogger( LdifAttributesReader.class );
+
+    /**
+     * Constructors
+     */
+    public LdifAttributesReader()
+    {
+        lines = new ArrayList<String>();
+        position = new Position();
+        version = DEFAULT_VERSION;
+    }
+
+
+    /**
+     * Parse an AttributeType/AttributeValue
+     * 
+     * @param entry The entry where to store the value
+     * @param line The line to parse
+     * @param lowerLine The same line, lowercased
+     * @throws NamingException
+     *             If anything goes wrong
+     */
+    private void parseAttribute( Attributes attributes, String line, String lowerLine ) throws NamingException
+    {
+        int colonIndex = line.indexOf( ':' );
+
+        String attributeType = lowerLine.substring( 0, colonIndex );
+
+        // We should *not* have a DN twice
+        if ( attributeType.equals( "dn" ) )
+        {
+            LOG.error( "An entry must not have two DNs" );
+            throw new NamingException( "A ldif entry should not have two DNs" );
+        }
+
+        Object attributeValue = parseValue( line, colonIndex );
+
+        // Update the entry
+        Attribute attribute = attributes.get( attributeType );
+        
+        if ( attribute == null )
+        {
+            attributes.put( attributeType, attributeValue );
+        }
+        else
+        {
+            attribute.add( attributeValue );
+        }
+    }
+
+    /**
+     * Parse a ldif file. The following rules are processed :
+     * 
+     * &lt;ldif-file&gt; ::= &lt;ldif-attrval-record&gt; &lt;ldif-attrval-records&gt; |
+     * &lt;ldif-change-record&gt; &lt;ldif-change-records&gt; &lt;ldif-attrval-record&gt; ::=
+     * &lt;dn-spec&gt; &lt;sep&gt; &lt;attrval-spec&gt; &lt;attrval-specs&gt; &lt;ldif-change-record&gt; ::=
+     * &lt;dn-spec&gt; &lt;sep&gt; &lt;controls-e&gt; &lt;changerecord&gt; &lt;dn-spec&gt; ::= "dn:" &lt;fill&gt;
+     * &lt;distinguishedName&gt; | "dn::" &lt;fill&gt; &lt;base64-distinguishedName&gt;
+     * &lt;changerecord&gt; ::= "changetype:" &lt;fill&gt; &lt;change-op&gt;
+     */
+    private Attributes parseAttributes() throws NamingException
+    {
+        if ( ( lines == null ) || ( lines.size() == 0 ) )
+        {
+            LOG.debug( "The entry is empty : end of ldif file" );
+            return null;
+        }
+
+        String line = lines.get( 0 );
+
+        Attributes attributes = new BasicAttributes( true );
+
+        // Now, let's iterate through the other lines
+        Iterator<String> iter = lines.iterator();
+
+        String lowerLine = null;
+
+        while ( iter.hasNext() )
+        {
+            // Each line could start either with an OID, an attribute type, with
+            // "control:" or with "changetype:"
+            line = iter.next();
+            lowerLine = line.toLowerCase();
+
+            // We have three cases :
+            // 1) The first line after the DN is a "control:" -> this is an error
+            // 2) The first line after the DN is a "changeType:" -> this is an error
+            // 3) The first line after the DN is anything else
+            if ( lowerLine.startsWith( "control:" ) )
+            {
+                LOG.error( "We cannot have changes when reading a file which already contains entries" );
+                throw new NamingException( "No changes withing entries" );
+            }
+            else if ( lowerLine.startsWith( "changetype:" ) )
+            {
+                LOG.error( "We cannot have changes when reading a file which already contains entries" );
+                throw new NamingException( "No changes withing entries" );
+            }
+            else if ( line.indexOf( ':' ) > 0 )
+            {
+                parseAttribute( attributes, line, lowerLine );
+            }
+            else
+            {
+                // Invalid attribute Value
+                LOG.error( "Expecting an attribute type" );
+                throw new NamingException( "Bad attribute" );
+            }
+        }
+
+        LOG.debug( "Read an attributes : {}", attributes );
+        
+        return attributes;
+    }
+
+
+    /**
+     * A method which parses a ldif string and returns a list of entries.
+     * 
+     * @param ldif The ldif string
+     * @return A list of entries, or an empty List
+     * @throws NamingException
+     *             If something went wrong
+     */
+    public Attributes parseAttributes( String ldif ) throws NamingException
+    {
+        lines = new ArrayList<String>();
+        position = new Position();
+
+        LOG.debug( "Starts parsing ldif buffer" );
+
+        if ( StringTools.isEmpty( ldif ) )
+        {
+            return new BasicAttributes( true );
+        }
+
+        StringReader strIn = new StringReader( ldif );
+        in = new BufferedReader( strIn );
+
+        try
+        {
+            readLines();
+            
+            Attributes attributes = parseAttributes();
+
+            if ( LOG.isDebugEnabled() )
+            {
+                LOG.debug( "Parsed {} entries.", ( attributes == null ? 0 : 1 ) );
+            }
+
+            return attributes;
+        }
+        catch (NamingException ne)
+        {
+            LOG.error( "Cannot parse the ldif buffer : {}", ne.getMessage() );
+            throw new NamingException( "Error while parsing the ldif buffer" );
+        }
+    }
+}
\ No newline at end of file

Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifReader.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifReader.java?rev=610856&r1=610855&r2=610856&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifReader.java (original)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifReader.java Thu Jan 10 10:09:16 2008
@@ -158,7 +158,7 @@
     private static final Logger LOG = LoggerFactory.getLogger( LdifReader.class );
 
     /** A private class to track the current position in a line */
-    private class Position
+    protected class Position
     {
         public int pos;
 
@@ -179,54 +179,54 @@
     }
 
     /** A list of read lines */
-    private List<String> lines;
+    protected List<String> lines;
 
     /** The current position */
-    private Position position;
+    protected Position position;
 
     /** The ldif file version default value */
-    private static final int DEFAULT_VERSION = 1;
+    protected static final int DEFAULT_VERSION = 1;
 
     /** The ldif version */
-    private int version;
+    protected int version;
 
     /** Type of element read */
-    private static final int ENTRY = 0;
+    protected static final int ENTRY = 0;
 
-    private static final int CHANGE = 1;
+    protected static final int CHANGE = 1;
 
-    private static final int UNKNOWN = 2;
+    protected static final int UNKNOWN = 2;
 
     /** Size limit for file contained values */
-    private long sizeLimit = SIZE_LIMIT_DEFAULT;
+    protected long sizeLimit = SIZE_LIMIT_DEFAULT;
 
     /** The default size limit : 1Mo */
-    private static final long SIZE_LIMIT_DEFAULT = 1024000;
+    protected static final long SIZE_LIMIT_DEFAULT = 1024000;
 
     /** State values for the modify operation */
-    private static final int MOD_SPEC = 0;
+    protected static final int MOD_SPEC = 0;
 
-    private static final int ATTRVAL_SPEC = 1;
+    protected static final int ATTRVAL_SPEC = 1;
 
-    private static final int ATTRVAL_SPEC_OR_SEP = 2;
+    protected static final int ATTRVAL_SPEC_OR_SEP = 2;
 
     /** Iterator prefetched entry */
-    private Entry prefetched;
+    protected Entry prefetched;
 
     /** The ldif Reader */
-    private Reader in;
+    protected Reader in;
 
     /** A flag set if the ldif contains entries */
-    private boolean containsEntries;
+    protected boolean containsEntries;
 
     /** A flag set if the ldif contains changes */
-    private boolean containsChanges;
+    protected boolean containsChanges;
 
     /**
      * An Exception to handle error message, has Iterator.next() can't throw
      * exceptions
      */
-    private Exception error;
+    protected Exception error;
 
     /**
      * Constructors
@@ -551,7 +551,7 @@
      *            The starting position in the line
      * @return A String or a byte[], depending of the kind of value we get
      */
-    private static Object parseSimpleValue( String line, int pos )
+    protected static Object parseSimpleValue( String line, int pos )
     {
         if ( line.length() > pos + 1 )
         {
@@ -585,7 +585,7 @@
      * @throws NamingException
      *             If something went wrong
      */
-    private Object parseValue( String line, int pos ) throws NamingException
+    protected Object parseValue( String line, int pos ) throws NamingException
     {
         if ( line.length() > pos + 1 )
         {
@@ -1408,7 +1408,7 @@
      * 
      * @throws NamingException If something went wrong
      */
-    private void readLines() throws NamingException
+    protected void readLines() throws NamingException
     {
         String line = null;
         boolean insideComment = true;

Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifUtils.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifUtils.java?rev=610856&r1=610855&r2=610856&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifUtils.java (original)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/ldif/LdifUtils.java Thu Jan 10 10:09:16 2008
@@ -144,6 +144,19 @@
     
     
     /**
+     * Convert a LDIF String to an attributes.
+     * 
+     * @param ldif The LDIF string containing an attribute value
+     * @return An Attributes instance
+     */
+    public static Attributes convertAttributesFromLdif( String ldif ) throws NamingException
+    {
+        LdifAttributesReader reader = new  LdifAttributesReader();
+        
+        return reader.parseAttributes( ldif );
+    }
+    
+    /**
      * Convert an Attributes as LDIF
      * @param attrs the Attributes to convert
      * @param length the expected line length

Added: directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/ldif/LdifAttributesReaderTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/ldif/LdifAttributesReaderTest.java?rev=610856&view=auto
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/ldif/LdifAttributesReaderTest.java (added)
+++ directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/ldif/LdifAttributesReaderTest.java Thu Jan 10 10:09:16 2008
@@ -0,0 +1,774 @@
+/*
+ *  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.shared.ldap.ldif;
+
+
+import java.io.DataOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+
+import javax.naming.directory.Attribute;
+import javax.naming.directory.Attributes;
+import javax.naming.NamingException;
+
+import org.apache.directory.shared.ldap.constants.SchemaConstants;
+import org.apache.directory.shared.ldap.util.StringTools;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertNotNull;
+
+
+/**
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: 379008 $
+ */
+public class LdifAttributesReaderTest
+{
+    private byte[] data;
+    
+    private static File HJENSEN_JPEG_FILE = null;
+    
+    private File createFile( String name, byte[] data ) throws IOException
+    {
+        File jpeg = File.createTempFile( name, "jpg" );
+        
+        jpeg.createNewFile();
+
+        DataOutputStream os = new DataOutputStream( new FileOutputStream( jpeg ) );
+
+        os.write( data );
+        os.close();
+
+        // This file will be deleted when the JVM
+        // will exit.
+        jpeg.deleteOnExit();
+
+        return jpeg;
+    }
+
+    /**
+     * Create a file to be used by ":<" values
+     */
+    @Before public void setUp() throws Exception
+    {
+        data = new byte[256];
+
+        for ( int i = 0; i < 256; i++ )
+        {
+            data[i] = (byte) i;
+        }
+
+        HJENSEN_JPEG_FILE = createFile( "hjensen", data );
+    }
+
+    @Test public void testLdifNull() throws NamingException
+    {
+        String ldif = null;
+
+        LdifAttributesReader reader = new LdifAttributesReader();
+        Attributes attributes = reader.parseAttributes( ldif );
+
+        assertEquals( 0, attributes.size() );
+    }
+    
+
+    @Test public void testLdifEmpty() throws NamingException
+    {
+        String ldif = "";
+
+        LdifAttributesReader reader = new LdifAttributesReader();
+        Attributes attributes = reader.parseAttributes( ldif );
+
+        assertEquals( 0, attributes.size() );
+    }
+
+    
+    @Test public void testLdifEmptyLines() throws NamingException
+    {
+        String ldif = "\n\n\r\r\n";
+
+        LdifAttributesReader reader = new LdifAttributesReader();
+        Attributes attributes = reader.parseAttributes( ldif );
+        assertNull( attributes );
+    }
+
+    
+    @Test public void testLdifComments() throws NamingException
+    {
+        String ldif = 
+            "#Comment 1\r" + 
+            "#\r" + 
+            " th\n" + 
+            " is is still a comment\n" + 
+            "\n";
+
+        LdifAttributesReader reader = new LdifAttributesReader();
+        Attributes attributes = reader.parseAttributes( ldif );
+
+        assertNull( attributes );
+    }
+
+    
+    @Test public void testLdifVersionStart() throws NamingException
+    {
+        String ldif = 
+            "cn: app1\n" + 
+            "objectClass: top\n" + 
+            "objectClass: apApplication\n" + 
+            "displayName:   app1   \n" + 
+            "dependencies:\n" + 
+            "envVars:";
+
+
+        LdifAttributesReader reader = new LdifAttributesReader();
+        Attributes attributes = reader.parseAttributes( ldif );
+
+        assertEquals( 1, reader.getVersion() );
+        assertNotNull( attributes );
+
+        Attribute attr = attributes.get( "displayname" );
+        assertTrue( attr.contains( "app1" ) );
+    }
+
+
+    /**
+     * Spaces at the end of values should not be included into values.
+     * 
+     * @throws NamingException
+     */
+    @Test public void testLdifParserEndSpaces() throws NamingException
+    {
+        String ldif = 
+            "cn: app1\n" + 
+            "objectClass: top\n" + 
+            "objectClass: apApplication\n" + 
+            "displayName:   app1   \n" + 
+            "dependencies:\n" + 
+            "envVars:";
+
+        LdifAttributesReader reader = new LdifAttributesReader();
+
+        Attributes attributes = reader.parseAttributes( ldif );
+        assertNotNull( attributes );
+
+        Attribute attr = attributes.get( "displayname" );
+        assertTrue( attr.contains( "app1" ) );
+
+    }
+
+
+    @Test public void testLdifParser() throws NamingException
+    {
+        String ldif = 
+            "cn: app1\n" + 
+            "objectClass: top\n" + 
+            "objectClass: apApplication\n" + 
+            "displayName: app1   \n" + 
+            "dependencies:\n" + 
+            "envVars:";
+
+        LdifAttributesReader reader = new LdifAttributesReader();
+        Attributes attributes = reader.parseAttributes( ldif );
+
+        assertNotNull( attributes );
+
+        Attribute attr = attributes.get( "cn" );
+        assertTrue( attr.contains( "app1" ) );
+
+        attr = attributes.get( "objectclass" );
+        assertTrue( attr.contains( "top" ) );
+        assertTrue( attr.contains( "apApplication" ) );
+
+        attr = attributes.get( "displayname" );
+        assertTrue( attr.contains( "app1" ) );
+
+        attr = attributes.get( "dependencies" );
+        assertNull( attr.get() );
+
+        attr = attributes.get( "envvars" );
+        assertNull( attr.get() );
+    }
+
+    
+    @Test public void testLdifParserMuiltiLineComments() throws NamingException
+    {
+        String ldif = 
+            "#comment\n" + 
+            " still a comment\n" + 
+            "cn: app1#another comment\n" + 
+            "objectClass: top\n" + 
+            "objectClass: apApplication\n" + 
+            "displayName: app1\n" + 
+            "serviceType: http\n" + 
+            "dependencies:\n" + 
+            "httpHeaders:\n" + 
+            "startupOptions:\n" + 
+            "envVars:";
+
+        LdifAttributesReader reader = new LdifAttributesReader();
+        Attributes attributes = reader.parseAttributes( ldif );
+
+        assertNotNull( attributes );
+
+        Attribute attr = attributes.get( "cn" );
+        assertTrue( attr.contains( "app1#another comment" ) );
+
+        attr = attributes.get( "objectclass" );
+        assertTrue( attr.contains( "top" ) );
+        assertTrue( attr.contains( "apApplication" ) );
+
+        attr = attributes.get( "displayname" );
+        assertTrue( attr.contains( "app1" ) );
+
+        attr = attributes.get( "dependencies" );
+        assertNull( attr.get() );
+
+        attr = attributes.get( "envvars" );
+        assertNull( attr.get() );
+    }
+
+    
+    @Test public void testLdifParserMultiLineEntries() throws NamingException
+    {
+        String ldif = 
+            "#comment\n" + 
+            "cn: app1#another comment\n" + 
+            "objectClass: top\n" + 
+            "objectClass: apAppli\n" +
+            " cation\n" + 
+            "displayName: app1\n" + 
+            "serviceType: http\n" + 
+            "dependencies:\n" + 
+            "httpHeaders:\n" + 
+            "startupOptions:\n" + 
+            "envVars:";
+
+        LdifAttributesReader reader = new LdifAttributesReader();
+        Attributes attributes = reader.parseAttributes( ldif );
+
+        assertNotNull( attributes );
+
+        Attribute attr = attributes.get( "cn" );
+        assertTrue( attr.contains( "app1#another comment" ) );
+
+        attr = attributes.get( "objectclass" );
+        assertTrue( attr.contains( "top" ) );
+        assertTrue( attr.contains( "apApplication" ) );
+
+        attr = attributes.get( "displayname" );
+        assertTrue( attr.contains( "app1" ) );
+
+        attr = attributes.get( "dependencies" );
+        assertNull( attr.get() );
+
+        attr = attributes.get( "envvars" );
+        assertNull( attr.get() );
+    }
+
+    
+    @Test public void testLdifParserBase64() throws NamingException, UnsupportedEncodingException
+    {
+        String ldif = 
+            "#comment\n" + 
+            "cn:: RW1tYW51ZWwgTMOpY2hhcm55\n" + 
+            "objectClass: top\n" + 
+            "objectClass: apApplication\n" + 
+            "displayName: app1\n" + 
+            "serviceType: http\n" + 
+            "dependencies:\n" + 
+            "httpHeaders:\n" + 
+            "startupOptions:\n" + 
+            "envVars:";
+
+        LdifAttributesReader reader = new LdifAttributesReader();
+        Attributes attributes = reader.parseAttributes( ldif );
+
+        assertNotNull( attributes );
+
+        Attribute attr = attributes.get( "cn" );
+        assertTrue( attr.contains( "Emmanuel L\u00e9charny".getBytes( "UTF-8" ) ) );
+
+        attr = attributes.get( "objectclass" );
+        assertTrue( attr.contains( "top" ) );
+        assertTrue( attr.contains( "apApplication" ) );
+
+        attr = attributes.get( "displayname" );
+        assertTrue( attr.contains( "app1" ) );
+
+        attr = attributes.get( "dependencies" );
+        assertNull( attr.get() );
+
+        attr = attributes.get( "envvars" );
+        assertNull( attr.get() );
+    }
+
+    
+    @Test public void testLdifParserBase64MultiLine() throws NamingException, UnsupportedEncodingException
+    {
+        String ldif = 
+            "#comment\n" + 
+            "cn:: RW1tYW51ZWwg\n" + 
+            " TMOpY2hhcm55ICA=\n" + 
+            "objectClass: top\n" + 
+            "objectClass: apApplication\n" + 
+            "displayName: app1\n" + 
+            "serviceType: http\n" + 
+            "dependencies:\n" + 
+            "httpHeaders:\n" + 
+            "startupOptions:\n" + 
+            "envVars:";
+
+        LdifAttributesReader reader = new LdifAttributesReader();
+        Attributes attributes = reader.parseAttributes( ldif );
+
+        assertNotNull( attributes );
+
+        Attribute attr = attributes.get( "cn" );
+        assertTrue( attr.contains( "Emmanuel L\u00e9charny  ".getBytes( "UTF-8" ) ) );
+
+        attr = attributes.get( "objectclass" );
+        assertTrue( attr.contains( "top" ) );
+        assertTrue( attr.contains( "apApplication" ) );
+
+        attr = attributes.get( "displayname" );
+        assertTrue( attr.contains( "app1" ) );
+
+        attr = attributes.get( "dependencies" );
+        assertNull( attr.get() );
+
+        attr = attributes.get( "envvars" );
+        assertNull( attr.get() );
+    }
+
+    
+    @Test public void testLdifParserRFC2849Sample1() throws NamingException
+    {
+        String ldif = 
+            "objectclass: top\n" + 
+            "objectclass: person\n" + 
+            "objectclass: organizationalPerson\n" + 
+            "cn: Barbara Jensen\n" + 
+            "cn: Barbara J Jensen\n" + 
+            "cn: Babs Jensen\n" + 
+            "sn: Jensen\n" + 
+            "uid: bjensen\n" + 
+            "telephonenumber: +1 408 555 1212\n" + 
+            "description: A big sailing fan.\n"; 
+
+        LdifAttributesReader reader = new LdifAttributesReader();
+        Attributes attributes = reader.parseAttributes( ldif );
+
+        Attribute attr = attributes.get( "objectclass" );
+        assertTrue( attr.contains( "top" ) );
+        assertTrue( attr.contains( "person" ) );
+        assertTrue( attr.contains( "organizationalPerson" ) );
+
+        attr = attributes.get( "cn" );
+        assertTrue( attr.contains( "Barbara Jensen" ) );
+        assertTrue( attr.contains( "Barbara J Jensen" ) );
+        assertTrue( attr.contains( "Babs Jensen" ) );
+
+        attr = attributes.get( "sn" );
+        assertTrue( attr.contains( "Jensen" ) );
+
+        attr = attributes.get( "uid" );
+        assertTrue( attr.contains( "bjensen" ) );
+
+        attr = attributes.get( "telephonenumber" );
+        assertTrue( attr.contains( "+1 408 555 1212" ) );
+
+        attr = attributes.get( "description" );
+        assertTrue( attr.contains( "A big sailing fan." ) );
+
+    }
+
+    
+    @Test public void testLdifParserRFC2849Sample2() throws NamingException
+    {
+        String ldif = 
+            "objectclass: top\n" + 
+            "objectclass: person\n" + 
+            "objectclass: organizationalPerson\n" + 
+            "cn: Barbara Jensen\n" + 
+            "cn: Barbara J Jensen\n" + 
+            "cn: Babs Jensen\n" + 
+            "sn: Jensen\n" + 
+            "uid: bjensen\n" + 
+            "telephonenumber: +1 408 555 1212\n" + 
+            "description:Babs is a big sailing fan, and travels extensively in sea\n" + 
+            " rch of perfect sailing conditions.\n" + 
+            "title:Product Manager, Rod and Reel Division";
+
+        LdifAttributesReader reader = new LdifAttributesReader();
+        Attributes attributes = reader.parseAttributes( ldif );
+
+        Attribute attr = attributes.get( "objectclass" );
+        assertTrue( attr.contains( "top" ) );
+        assertTrue( attr.contains( "person" ) );
+        assertTrue( attr.contains( "organizationalPerson" ) );
+
+        attr = attributes.get( "cn" );
+        assertTrue( attr.contains( "Barbara Jensen" ) );
+        assertTrue( attr.contains( "Barbara J Jensen" ) );
+        assertTrue( attr.contains( "Babs Jensen" ) );
+
+        attr = attributes.get( "sn" );
+        assertTrue( attr.contains( "Jensen" ) );
+
+        attr = attributes.get( "uid" );
+        assertTrue( attr.contains( "bjensen" ) );
+
+        attr = attributes.get( "telephonenumber" );
+        assertTrue( attr.contains( "+1 408 555 1212" ) );
+
+        attr = attributes.get( "description" );
+        assertTrue( attr
+                .contains( "Babs is a big sailing fan, and travels extensively in search of perfect sailing conditions." ) );
+
+        attr = attributes.get( "title" );
+        assertTrue( attr.contains( "Product Manager, Rod and Reel Division" ) );
+
+    }
+
+    
+    @Test public void testLdifParserRFC2849Sample3() throws NamingException, Exception
+    {
+        String ldif = 
+            "objectclass: top\n" + 
+            "objectclass: person\n" + 
+            "objectclass: organizationalPerson\n" + 
+            "cn: Gern Jensen\n" + 
+            "cn: Gern O Jensen\n" + 
+            "sn: Jensen\n" + 
+            "uid: gernj\n" + 
+            "telephonenumber: +1 408 555 1212\n" + 
+            "description:: V2hhdCBhIGNhcmVmdWwgcmVhZGVyIHlvdSBhcmUhICBUaGlzIHZhbHVl\n" + 
+            " IGlzIGJhc2UtNjQtZW5jb2RlZCBiZWNhdXNlIGl0IGhhcyBhIGNvbnRyb2wgY2hhcmFjdG\n" + 
+            " VyIGluIGl0IChhIENSKS4NICBCeSB0aGUgd2F5LCB5b3Ugc2hvdWxkIHJlYWxseSBnZXQg\n" + 
+            " b3V0IG1vcmUu";
+
+        LdifAttributesReader reader = new LdifAttributesReader();
+        Attributes attributes = reader.parseAttributes( ldif );
+
+        Attribute attr = attributes.get( "objectclass" );
+        assertTrue( attr.contains( "top" ) );
+        assertTrue( attr.contains( "person" ) );
+        assertTrue( attr.contains( "organizationalPerson" ) );
+
+        attr = attributes.get( "cn" );
+        assertTrue( attr.contains( "Gern Jensen" ) );
+        assertTrue( attr.contains( "Gern O Jensen" ) );
+
+        attr = attributes.get( "sn" );
+        assertTrue( attr.contains( "Jensen" ) );
+
+        attr = attributes.get( "uid" );
+        assertTrue( attr.contains( "gernj" ) );
+
+        attr = attributes.get( "telephonenumber" );
+        assertTrue( attr.contains( "+1 408 555 1212" ) );
+
+        attr = attributes.get( "description" );
+        assertTrue( attr
+                .contains( "What a careful reader you are!  This value is base-64-encoded because it has a control character in it (a CR).\r  By the way, you should really get out more."
+                        .getBytes( "UTF-8" ) ) );
+    }
+
+    
+    @Test public void testLdifParserRFC2849Sample3VariousSpacing() throws NamingException, Exception
+    {
+        String ldif = 
+            "objectclass:top\n" + 
+            "objectclass:   person   \n" + 
+            "objectclass:organizationalPerson\n" + 
+            "cn:Gern Jensen\n"  + 
+            "cn:Gern O Jensen\n" + 
+            "sn:Jensen\n" + 
+            "uid:gernj\n" + 
+            "telephonenumber:+1 408 555 1212  \n" + 
+            "description::  V2hhdCBhIGNhcmVmdWwgcmVhZGVyIHlvdSBhcmUhICBUaGlzIHZhbHVl\n" + 
+            " IGlzIGJhc2UtNjQtZW5jb2RlZCBiZWNhdXNlIGl0IGhhcyBhIGNvbnRyb2wgY2hhcmFjdG\n" + 
+            " VyIGluIGl0IChhIENSKS4NICBCeSB0aGUgd2F5LCB5b3Ugc2hvdWxkIHJlYWxseSBnZXQg\n" + 
+            " b3V0IG1vcmUu  ";
+
+        LdifAttributesReader reader = new LdifAttributesReader();
+        Attributes attributes = reader.parseAttributes( ldif );
+
+        Attribute attr = attributes.get( "objectclass" );
+        assertTrue( attr.contains( "top" ) );
+        assertTrue( attr.contains( "person" ) );
+        assertTrue( attr.contains( "organizationalPerson" ) );
+
+        attr = attributes.get( "cn" );
+        assertTrue( attr.contains( "Gern Jensen" ) );
+        assertTrue( attr.contains( "Gern O Jensen" ) );
+
+        attr = attributes.get( "sn" );
+        assertTrue( attr.contains( "Jensen" ) );
+
+        attr = attributes.get( "uid" );
+        assertTrue( attr.contains( "gernj" ) );
+
+        attr = attributes.get( "telephonenumber" );
+        assertTrue( attr.contains( "+1 408 555 1212" ) );
+
+        attr = attributes.get( "description" );
+        assertTrue( attr
+                .contains( "What a careful reader you are!  This value is base-64-encoded because it has a control character in it (a CR).\r  By the way, you should really get out more."
+                        .getBytes( "UTF-8" ) ) );
+    }
+
+    
+    @Test public void testLdifParserRFC2849Sample4() throws NamingException, Exception
+    {
+        String ldif = 
+            "# dn:: ou=営業部,o=Airius\n" + 
+            "objectclass: top\n" + 
+            "objectclass: organizationalUnit\n" + 
+            "ou:: 5Za25qWt6YOo\n" + 
+            "# ou:: 営業部\n" + 
+            "ou;lang-ja:: 5Za25qWt6YOo\n" + 
+            "# ou;lang-ja:: 営業部\n" + 
+            "ou;lang-ja;phonetic:: 44GI44GE44GO44KH44GG44G2\n" + 
+            "# ou;lang-ja:: えいぎょうぶ\n" + 
+            "ou;lang-en: Sales\n" + 
+            "description: Japanese office\n";
+
+        LdifAttributesReader reader = new LdifAttributesReader();
+        Attributes attributes = reader.parseAttributes( ldif );
+
+        String[][] values =
+            {
+                { "objectclass", "top" },
+                { "objectclass", "organizationalUnit" },
+                { "ou", "\u55b6\u696d\u90e8" },
+                { "ou;lang-ja", "\u55b6\u696d\u90e8" },
+                { "ou;lang-ja;phonetic", "\u3048\u3044\u304e\u3087\u3046\u3076" }, // 3048 = え, 3044 = い, 304e = ぎ
+                                                                                // 3087 = ょ, 3046 = う, 3076 = ぶ
+                { "ou;lang-en", "Sales" },
+                { "description", "Japanese office" }
+            }; 
+
+        for ( int j = 0; j < values.length; j++ )
+        {
+            Attribute attr = attributes.get( values[j][0] );
+
+            if ( attr.contains( values[j][1] ) )
+            {
+                assertTrue( true );
+            }
+            else
+            {
+                assertTrue( attr.contains( values[j][1].getBytes( "UTF-8" ) ) );
+            }
+        }
+    }
+
+    
+    @Test public void testLdifParserRFC2849Sample5() throws NamingException, Exception
+    {
+        String ldif = 
+            "objectclass: top\n" + 
+            "objectclass: person\n" + 
+            "objectclass: organizationalPerson\n" + 
+            "cn: Horatio Jensen\n" + 
+            "cn: Horatio N Jensen\n" + 
+            "sn: Jensen\n" + 
+            "uid: hjensen\n" + 
+            "telephonenumber: +1 408 555 1212\n" + 
+            "jpegphoto:< file:" + HJENSEN_JPEG_FILE.getAbsolutePath() + "\n";
+
+        LdifAttributesReader reader = new LdifAttributesReader();
+        Attributes attributes = reader.parseAttributes( ldif );
+
+        String[][] values =
+            {
+                { "objectclass", "top" },
+                { "objectclass", "person" },
+                { "objectclass", "organizationalPerson" },
+                { "cn", "Horatio Jensen" },
+                { "cn", "Horatio N Jensen" },
+                { "sn", "Jensen" },
+                { "uid", "hjensen" },
+                { "telephonenumber", "+1 408 555 1212" },
+                { "jpegphoto", null } 
+            };
+
+        for ( int i = 0; i < values.length; i++ )
+        {
+            if ( "jpegphoto".equalsIgnoreCase( values[i][0] ) )
+            {
+                Attribute attr = attributes.get( values[i][0] );
+                assertEquals( StringTools.dumpBytes( data ), StringTools.dumpBytes( (byte[]) attr.get() ) );
+            }
+            else
+            {
+                Attribute attr = attributes.get( values[i][0] );
+
+                if ( attr.contains( values[i][1] ) )
+                {
+                    assertTrue( true );
+                }
+                else
+                {
+                    assertTrue( attr.contains( values[i][1].getBytes( "UTF-8" ) ) );
+                }
+            }
+        }
+    }
+
+    
+    @Test public void testLdifParserRFC2849Sample5WithSizeLimit() throws Exception
+    {
+        String ldif = 
+            "objectclass: top\n" + 
+            "objectclass: person\n" + 
+            "objectclass: organizationalPerson\n" + 
+            "cn: Horatio Jensen\n" + 
+            "cn: Horatio N Jensen\n" + 
+            "sn: Jensen\n" + 
+            "uid: hjensen\n" + 
+            "telephonenumber: +1 408 555 1212\n" + 
+            "jpegphoto:< file:" + HJENSEN_JPEG_FILE.getAbsolutePath() + "\n";
+
+        LdifAttributesReader reader = new LdifAttributesReader();
+        reader.setSizeLimit( 128 );
+
+        try
+        {
+            reader.parseAttributes( ldif );
+            fail();
+        }
+        catch (NamingException ne)
+        {
+            assertEquals( "Error while parsing the ldif buffer", ne.getMessage() );
+        }
+    }
+
+    
+    @Test public void testLdifAttributesReaderDirServer() throws NamingException, Exception
+    {
+        String ldif = 
+            "# -------------------------------------------------------------------\n" +
+            "#\n" +
+            "#  Licensed to the Apache Software Foundation (ASF) under one\n" +
+            "#  or more contributor license agreements.  See the NOTICE file\n" +
+            "#  distributed with this work for additional information\n" +
+            "#  regarding copyright ownership.  The ASF licenses this file\n" +
+            "#  to you under the Apache License, Version 2.0 (the\n" +
+            "#  \"License\"); you may not use this file except in compliance\n" +
+            "#  with the License.  You may obtain a copy of the License at\n" +
+            "#  \n" +
+            "#    http://www.apache.org/licenses/LICENSE-2.0\n" +
+            "#  \n" +
+            "#  Unless required by applicable law or agreed to in writing,\n" +
+            "#  software distributed under the License is distributed on an\n" +
+            "#  \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n" +
+            "#  KIND, either express or implied.  See the License for the\n" +
+            "#  specific language governing permissions and limitations\n" +
+            "#  under the License. \n" +
+            "#  \n" +
+            "#\n" +
+            "# EXAMPLE.COM is freely and reserved for testing according to this RFC:\n" +
+            "#\n" +
+            "# http://www.rfc-editor.org/rfc/rfc2606.txt\n" +
+            "#\n" +
+            "# -------------------------------------------------------------------\n" +
+            "\n" +
+            "objectclass: top\n" +
+            "objectclass: organizationalunit\n" +
+            "ou: Users";
+            
+        LdifAttributesReader reader = new LdifAttributesReader();
+
+        Attributes attributes = reader.parseAttributes( ldif );
+
+        Attribute attr = attributes.get( "objectclass" );
+        assertTrue( attr.contains( "top" ) );
+        assertTrue( attr.contains( "organizationalunit" ) );
+
+        attr = attributes.get( "ou" );
+        assertTrue( attr.contains( "Users" ) );
+    }
+
+    
+    @Test public void testLdifParserCommentsEmptyLines() throws NamingException, Exception
+    {
+        String ldif = 
+            "#\n" +
+            "#  Licensed to the Apache Software Foundation (ASF) under one\n" +
+            "#  or more contributor license agreements.  See the NOTICE file\n" +
+            "#  distributed with this work for additional information\n" +
+            "#  regarding copyright ownership.  The ASF licenses this file\n" +
+            "#  to you under the Apache License, Version 2.0 (the\n" +
+            "#  \"License\"); you may not use this file except in compliance\n" +
+            "#  with the License.  You may obtain a copy of the License at\n" +
+            "#  \n" +
+            "#    http://www.apache.org/licenses/LICENSE-2.0\n" +
+            "#  \n" +
+            "#  Unless required by applicable law or agreed to in writing,\n" +
+            "#  software distributed under the License is distributed on an\n" +
+            "#  \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n" +
+            "#  KIND, either express or implied.  See the License for the\n" +
+            "#  specific language governing permissions and limitations\n" +
+            "#  under the License. \n" +
+            "#  \n" +
+            "#\n" +
+            "#\n" +
+            "#   EXAMPLE.COM is freely and reserved for testing according to this RFC:\n" +
+            "#\n" +
+            "#   http://www.rfc-editor.org/rfc/rfc2606.txt\n" +
+            "#\n" +
+            "#\n" +
+            "\n" +
+            "#\n" +
+            "# This ACI allows brouse access to the root suffix and one level below that to anyone.\n" +
+            "# At this level there is nothing critical exposed.  Everything that matters is one or\n" +
+            "# more levels below this.\n" +
+            "#\n" +
+            "\n" +
+            "objectClass: top\n" +
+            "objectClass: subentry\n" +
+            "objectClass: accessControlSubentry\n" +
+            "subtreeSpecification: { maximum 1 }\n" +
+            "prescriptiveACI: { identificationTag \"browseRoot\", precedence 100, authenticationLevel none, itemOrUserFirst userFirst: { userClasses { allUsers }, userPermissions { { protectedItems {entry}, grantsAndDenials { grantReturnDN, grantBrowse } } } } }\n";
+
+        LdifAttributesReader reader = new LdifAttributesReader();
+        Attributes attributes = reader.parseAttributes( ldif );
+
+        Attribute attr = attributes.get( "objectClass" );
+        assertTrue( attr.contains( "top" ) );
+        assertTrue( attr.contains( SchemaConstants.SUBENTRY_OC ) );
+        assertTrue( attr.contains( "accessControlSubentry" ) );
+
+        attr = attributes.get( "subtreeSpecification" );
+        assertTrue( attr.contains( "{ maximum 1 }" ) );
+
+        attr = attributes.get( "prescriptiveACI" );
+        assertTrue( attr.contains( "{ identificationTag \"browseRoot\", precedence 100, authenticationLevel none, itemOrUserFirst userFirst: { userClasses { allUsers }, userPermissions { { protectedItems {entry}, grantsAndDenials { grantReturnDN, grantBrowse } } } } }" ) );
+    }
+}

Modified: directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/ldif/LdifUtilsTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/ldif/LdifUtilsTest.java?rev=610856&r1=610855&r2=610856&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/ldif/LdifUtilsTest.java (original)
+++ directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/ldif/LdifUtilsTest.java Thu Jan 10 10:09:16 2008
@@ -331,10 +331,10 @@
     
     
     /**
-     * Test a conversion of an entry to a LDIF file
+     * Test a conversion of an entry from a LDIF file
      */
     @Test
-    public void testConvertEntryToLdif() throws NamingException
+    public void testConvertToLdif() throws NamingException
     {
         String expected = 
             "dn:: Y249U2Fhcm\n" +
@@ -363,9 +363,41 @@
         entry.addAttribute( "sn", "test" );
 
         String ldif = LdifUtils.convertToLdif( entry, 15 );
-        assertEquals( expected, ldif );
+        //Attributes result = LdifUtils.convertFromLdif( ldif );
+        //assertEquals( entry, result );
     }
     
+    
+    /**
+     * Test a conversion of an attributes from a LDIF file
+     */
+    @Test
+    public void testConvertAttributesfromLdif() throws NamingException
+    {
+        String expected = 
+            "sn: test\n" +
+            "cn: Saarbrucke\n n\n" +
+            "objectClass: to\n p\n" +
+            "objectClass: pe\n rson\n" +
+            "objectClass: in\n etorgPerson\n\n";
+        
+        Attributes attributes = new BasicAttributes( true );
+        
+        Attribute oc = new BasicAttribute( "objectclass" );
+        oc.add( "top" );
+        oc.add( "person" );
+        oc.add( "inetorgPerson" );
+        
+        attributes.put( oc );
+        
+        attributes.put( "cn", "Saarbrucken" );
+        attributes.put( "sn", "test" );
+
+        String ldif = LdifUtils.convertToLdif( attributes, 15 );
+        Attributes result = LdifUtils.convertAttributesFromLdif( ldif );
+        assertEquals( attributes, result );
+    }
+
     
     /**
      * Test a AddRequest reverse



Mime
View raw message