directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r232201 - in /directory/shared/ldap/trunk/common/src: java/org/apache/ldap/common/ldif/LdifParserImpl.java test/org/apache/ldap/common/ldif/LdifParserImplTest.java
Date Fri, 12 Aug 2005 04:30:25 GMT
Author: akarasulu
Date: Thu Aug 11 21:30:20 2005
New Revision: 232201

URL: http://svn.apache.org/viewcvs?rev=232201&view=rev
Log:
Added code to handle comments.  For the issue DIRLDAP-24:

   http://issues.apache.org/jira/browse/DIRLDAP-24

Modified:
    directory/shared/ldap/trunk/common/src/java/org/apache/ldap/common/ldif/LdifParserImpl.java
    directory/shared/ldap/trunk/common/src/test/org/apache/ldap/common/ldif/LdifParserImplTest.java

Modified: directory/shared/ldap/trunk/common/src/java/org/apache/ldap/common/ldif/LdifParserImpl.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/trunk/common/src/java/org/apache/ldap/common/ldif/LdifParserImpl.java?rev=232201&r1=232200&r2=232201&view=diff
==============================================================================
--- directory/shared/ldap/trunk/common/src/java/org/apache/ldap/common/ldif/LdifParserImpl.java
(original)
+++ directory/shared/ldap/trunk/common/src/java/org/apache/ldap/common/ldif/LdifParserImpl.java
Thu Aug 11 21:30:20 2005
@@ -84,6 +84,24 @@
         {
             while ( ( line = in.readLine() ) != null )
             {
+                // check and see if we have a comment on this line and if so
+                // we need to forgo the entire line or chop off the comment
+                int asteriskIndex = line.indexOf( '#' );
+                if ( asteriskIndex != -1 )
+                {
+                    if ( asteriskIndex < 3 )
+                    {
+                        continue;
+                    }
+
+                    line = line.substring( 0, asteriskIndex ).trim();
+
+                    if ( line.equals( "" ) )
+                    {
+                        continue;
+                    }
+                }
+
                 // Try to advance to ':' if one exists.
                 if ( ( index = line.indexOf( ':' ) ) == -1 )
                 {
@@ -92,7 +110,7 @@
                         + "attribute value pair.\n{" + ldif + "}",
                         ResultCodeEnum.OTHER );
                 }
-    
+
                 // Capture data while at first colon.
                 attrName = line.substring( 0, index ).trim();
     

Modified: directory/shared/ldap/trunk/common/src/test/org/apache/ldap/common/ldif/LdifParserImplTest.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/trunk/common/src/test/org/apache/ldap/common/ldif/LdifParserImplTest.java?rev=232201&r1=232200&r2=232201&view=diff
==============================================================================
--- directory/shared/ldap/trunk/common/src/test/org/apache/ldap/common/ldif/LdifParserImplTest.java
(original)
+++ directory/shared/ldap/trunk/common/src/test/org/apache/ldap/common/ldif/LdifParserImplTest.java
Thu Aug 11 21:30:20 2005
@@ -39,6 +39,32 @@
         Attribute attr = attrs.get( "objectClass" );
         assertTrue( attr.contains( "apApplication" ) );
         assertTrue( attr.contains( "top" ) );
+    }
 
+
+    public void testLdifParserComments() throws NamingException
+    {
+        String ldif = "#comment\n" +
+                "dn: cn=app1,ou=applications,ou=conf,dc=apache,dc=org\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:";
+        LdifParser parser = new LdifParserImpl();
+        Attributes attrs = new LockableAttributesImpl();
+        parser.parse( attrs, ldif );
+
+        assertNotNull( attrs );
+
+        Attribute attr = attrs.get( "objectClass" );
+        assertTrue( attr.contains( "apApplication" ) );
+        assertTrue( attr.contains( "top" ) );
+
+        assertEquals( "app1", attrs.get( "cn" ).get() );
     }
 }



Mime
View raw message