directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From seelm...@apache.org
Subject svn commit: r631387 - in /directory/studio/branches/1.1.0/ldif-parser: ./ src/main/java/org/apache/directory/studio/ldifparser/model/ src/main/java/org/apache/directory/studio/ldifparser/model/lines/ src/main/java/org/apache/directory/studio/ldifparser...
Date Tue, 26 Feb 2008 21:26:07 GMT
Author: seelmann
Date: Tue Feb 26 13:26:04 2008
New Revision: 631387

URL: http://svn.apache.org/viewvc?rev=631387&view=rev
Log:
Fix for DIRSTUDIO-285 (Export into LDIF format could be corrupted): Fixed detection of first
colon in the formatting method

Added:
    directory/studio/branches/1.1.0/ldif-parser/src/test/java/org/
    directory/studio/branches/1.1.0/ldif-parser/src/test/java/org/apache/
    directory/studio/branches/1.1.0/ldif-parser/src/test/java/org/apache/directory/
    directory/studio/branches/1.1.0/ldif-parser/src/test/java/org/apache/directory/studio/
    directory/studio/branches/1.1.0/ldif-parser/src/test/java/org/apache/directory/studio/ldifparser/
    directory/studio/branches/1.1.0/ldif-parser/src/test/java/org/apache/directory/studio/ldifparser/model/
    directory/studio/branches/1.1.0/ldif-parser/src/test/java/org/apache/directory/studio/ldifparser/model/lines/
    directory/studio/branches/1.1.0/ldif-parser/src/test/java/org/apache/directory/studio/ldifparser/model/lines/LdifAttrValLineTest.java
    directory/studio/branches/1.1.0/ldif-parser/src/test/java/org/apache/directory/studio/ldifparser/model/lines/LdifDnLineTest.java
    directory/studio/branches/1.1.0/ldif-parser/src/test/java/org/apache/directory/studio/ldifparser/parser/
    directory/studio/branches/1.1.0/ldif-parser/src/test/java/org/apache/directory/studio/ldifparser/parser/LdifParserTest.java
Modified:
    directory/studio/branches/1.1.0/ldif-parser/pom.xml
    directory/studio/branches/1.1.0/ldif-parser/src/main/java/org/apache/directory/studio/ldifparser/model/LdifEnumeration.java
    directory/studio/branches/1.1.0/ldif-parser/src/main/java/org/apache/directory/studio/ldifparser/model/lines/LdifLineBase.java
    directory/studio/branches/1.1.0/ldif-parser/src/main/java/org/apache/directory/studio/ldifparser/model/lines/LdifValueLineBase.java
    directory/studio/branches/1.1.0/ldif-parser/src/main/java/org/apache/directory/studio/ldifparser/parser/LdifParser.java

Modified: directory/studio/branches/1.1.0/ldif-parser/pom.xml
URL: http://svn.apache.org/viewvc/directory/studio/branches/1.1.0/ldif-parser/pom.xml?rev=631387&r1=631386&r2=631387&view=diff
==============================================================================
--- directory/studio/branches/1.1.0/ldif-parser/pom.xml (original)
+++ directory/studio/branches/1.1.0/ldif-parser/pom.xml Tue Feb 26 13:26:04 2008
@@ -80,18 +80,19 @@
           </archive>
         </configuration>
       </plugin>
-      <!-- No tests to run -->
       <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-surefire-plugin</artifactId>
-        <configuration>
-          <skip>true</skip>
-        </configuration>
       </plugin>
     </plugins>
   </build>
 
   <dependencies>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <scope>test</scope>
+    </dependency>
     <dependency>
       <groupId>commons-codec</groupId>
       <artifactId>commons-codec</artifactId>

Modified: directory/studio/branches/1.1.0/ldif-parser/src/main/java/org/apache/directory/studio/ldifparser/model/LdifEnumeration.java
URL: http://svn.apache.org/viewvc/directory/studio/branches/1.1.0/ldif-parser/src/main/java/org/apache/directory/studio/ldifparser/model/LdifEnumeration.java?rev=631387&r1=631386&r2=631387&view=diff
==============================================================================
--- directory/studio/branches/1.1.0/ldif-parser/src/main/java/org/apache/directory/studio/ldifparser/model/LdifEnumeration.java
(original)
+++ directory/studio/branches/1.1.0/ldif-parser/src/main/java/org/apache/directory/studio/ldifparser/model/LdifEnumeration.java
Tue Feb 26 13:26:04 2008
@@ -21,8 +21,6 @@
 package org.apache.directory.studio.ldifparser.model;
 
 
-import java.util.Iterator;
-
 import org.apache.directory.studio.ldifparser.model.container.LdifContainer;
 
 

Modified: directory/studio/branches/1.1.0/ldif-parser/src/main/java/org/apache/directory/studio/ldifparser/model/lines/LdifLineBase.java
URL: http://svn.apache.org/viewvc/directory/studio/branches/1.1.0/ldif-parser/src/main/java/org/apache/directory/studio/ldifparser/model/lines/LdifLineBase.java?rev=631387&r1=631386&r2=631387&view=diff
==============================================================================
--- directory/studio/branches/1.1.0/ldif-parser/src/main/java/org/apache/directory/studio/ldifparser/model/lines/LdifLineBase.java
(original)
+++ directory/studio/branches/1.1.0/ldif-parser/src/main/java/org/apache/directory/studio/ldifparser/model/lines/LdifLineBase.java
Tue Feb 26 13:26:04 2008
@@ -33,9 +33,9 @@
 public abstract class LdifLineBase implements LdifPart
 {
 
-    private String rawNewLine;
+    protected String rawNewLine;
 
-    private int offset;
+    protected int offset;
 
 
     protected LdifLineBase()
@@ -106,27 +106,11 @@
     }
 
 
-    public final String toFormattedString( LdifFormatParameters formatParameters )
+    public String toFormattedString( LdifFormatParameters formatParameters )
     {
         String raw = toRawString();
         String unfolded = unfold( raw );
 
-        if ( this instanceof LdifValueLineBase )
-        {
-            if ( unfolded.indexOf( "::" ) > -1 )
-            {
-                unfolded = unfolded.replaceFirst( "::[ ]*", formatParameters.isSpaceAfterColon()
? ":: " : "::" );
-            }
-            else if ( unfolded.indexOf( ":<" ) > -1 )
-            {
-                unfolded = unfolded.replaceFirst( ":<[ ]*", formatParameters.isSpaceAfterColon()
? ":< " : ":<" );
-            }
-            else if ( unfolded.indexOf( ":" ) > -1 )
-            {
-                unfolded = unfolded.replaceFirst( ":[ ]*", formatParameters.isSpaceAfterColon()
? ": " : ":" );
-            }
-        }
-
         if ( rawNewLine != null )
         {
             int index = unfolded.lastIndexOf( rawNewLine );
@@ -137,14 +121,7 @@
             }
         }
 
-        if ( this instanceof LdifValueLineBase )
-        {
-            return fold( unfolded, 0, formatParameters );
-        }
-        else
-        {
-            return unfolded;
-        }
+        return unfolded;
     }
 
 

Modified: directory/studio/branches/1.1.0/ldif-parser/src/main/java/org/apache/directory/studio/ldifparser/model/lines/LdifValueLineBase.java
URL: http://svn.apache.org/viewvc/directory/studio/branches/1.1.0/ldif-parser/src/main/java/org/apache/directory/studio/ldifparser/model/lines/LdifValueLineBase.java?rev=631387&r1=631386&r2=631387&view=diff
==============================================================================
--- directory/studio/branches/1.1.0/ldif-parser/src/main/java/org/apache/directory/studio/ldifparser/model/lines/LdifValueLineBase.java
(original)
+++ directory/studio/branches/1.1.0/ldif-parser/src/main/java/org/apache/directory/studio/ldifparser/model/lines/LdifValueLineBase.java
Tue Feb 26 13:26:04 2008
@@ -25,6 +25,7 @@
 import java.io.FileInputStream;
 import java.io.IOException;
 
+import org.apache.directory.studio.ldifparser.LdifFormatParameters;
 import org.apache.directory.studio.ldifparser.LdifUtils;
 
 
@@ -79,6 +80,45 @@
     public String toRawString()
     {
         return this.getRawLineStart() + this.getRawValueType() + this.getRawValue() + this.getRawNewLine();
+    }
+
+
+    public String toFormattedString( LdifFormatParameters formatParameters )
+    {
+        String raw = toRawString();
+        String unfolded = unfold( raw );
+
+        // Fix for DIRSTUDIO-285: We must take care that we only check
+        // the first colon in the line. If there is another :: or :< 
+        // in the value we must not use that as separator.
+        int firstColonIndex = unfolded.indexOf( ":" );
+        int firstDoubleColonIndex = unfolded.indexOf( "::" );
+        int firstColonLessIndex = unfolded.indexOf( ":<" );
+
+        if ( firstDoubleColonIndex > -1 && firstDoubleColonIndex == firstColonIndex
)
+        {
+            unfolded = unfolded.replaceFirst( "::[ ]*", formatParameters.isSpaceAfterColon()
? ":: " : "::" );
+        }
+        else if ( firstColonLessIndex > -1 && firstColonLessIndex == firstColonIndex
)
+        {
+            unfolded = unfolded.replaceFirst( ":<[ ]*", formatParameters.isSpaceAfterColon()
? ":< " : ":<" );
+        }
+        else if ( firstColonIndex > -1 )
+        {
+            unfolded = unfolded.replaceFirst( ":[ ]*", formatParameters.isSpaceAfterColon()
? ": " : ":" );
+        }
+
+        if ( rawNewLine != null )
+        {
+            int index = unfolded.lastIndexOf( rawNewLine );
+            if ( index > -1 )
+            {
+                unfolded = unfolded.substring( 0, unfolded.length() - rawNewLine.length()
);
+                unfolded = unfolded + formatParameters.getLineSeparator();
+            }
+        }
+
+        return fold( unfolded, 0, formatParameters );
     }
 
 

Modified: directory/studio/branches/1.1.0/ldif-parser/src/main/java/org/apache/directory/studio/ldifparser/parser/LdifParser.java
URL: http://svn.apache.org/viewvc/directory/studio/branches/1.1.0/ldif-parser/src/main/java/org/apache/directory/studio/ldifparser/parser/LdifParser.java?rev=631387&r1=631386&r2=631387&view=diff
==============================================================================
--- directory/studio/branches/1.1.0/ldif-parser/src/main/java/org/apache/directory/studio/ldifparser/parser/LdifParser.java
(original)
+++ directory/studio/branches/1.1.0/ldif-parser/src/main/java/org/apache/directory/studio/ldifparser/parser/LdifParser.java
Tue Feb 26 13:26:04 2008
@@ -75,17 +75,20 @@
     public LdifFile parse( String ldif )
     {
         LdifFile model = new LdifFile();
-        LdifEnumeration enumeration = this.parse( new StringReader( ldif ) );
-        try
+        if ( ldif != null )
         {
-            while ( enumeration.hasNext() )
+            LdifEnumeration enumeration = this.parse( new StringReader( ldif ) );
+            try
+            {
+                while ( enumeration.hasNext() )
+                {
+                    LdifContainer container = enumeration.next();
+                    model.addContainer( container );
+                }
+            }
+            catch ( Exception e )
             {
-                LdifContainer container = enumeration.next();
-                model.addContainer( container );
             }
-        }
-        catch ( Exception e )
-        {
         }
         return model;
     }

Added: directory/studio/branches/1.1.0/ldif-parser/src/test/java/org/apache/directory/studio/ldifparser/model/lines/LdifAttrValLineTest.java
URL: http://svn.apache.org/viewvc/directory/studio/branches/1.1.0/ldif-parser/src/test/java/org/apache/directory/studio/ldifparser/model/lines/LdifAttrValLineTest.java?rev=631387&view=auto
==============================================================================
--- directory/studio/branches/1.1.0/ldif-parser/src/test/java/org/apache/directory/studio/ldifparser/model/lines/LdifAttrValLineTest.java
(added)
+++ directory/studio/branches/1.1.0/ldif-parser/src/test/java/org/apache/directory/studio/ldifparser/model/lines/LdifAttrValLineTest.java
Tue Feb 26 13:26:04 2008
@@ -0,0 +1,78 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+package org.apache.directory.studio.ldifparser.model.lines;
+
+
+import junit.framework.TestCase;
+
+import org.apache.directory.studio.ldifparser.LdifFormatParameters;
+
+
+public class LdifAttrValLineTest extends TestCase
+{
+
+    public void testToFormattedStringSimple()
+    {
+        LdifAttrValLine line = LdifAttrValLine.create( "cn", "abc" );
+        LdifFormatParameters formatParameters = new LdifFormatParameters( true, 78, "\n"
);
+        String formattedString = line.toFormattedString( formatParameters );
+        assertEquals( formattedString, "cn: abc\n" );
+    }
+
+
+    public void testToFormattedStringLineWrap()
+    {
+        LdifAttrValLine line = LdifAttrValLine.create( "cn",
+            "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxy"
);
+        LdifFormatParameters formatParameters = new LdifFormatParameters( true, 78, "\n"
);
+        String formattedString = line.toFormattedString( formatParameters );
+        assertEquals( formattedString,
+            "cn: abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvw\n
xyzabcdefghijklmnopqrstuvwxy\n" );
+    }
+
+
+    public void testToFormattedStringNoSpaceAfterColon()
+    {
+        LdifAttrValLine line = LdifAttrValLine.create( "cn", "abc" );
+        LdifFormatParameters formatParameters = new LdifFormatParameters( false, 78, "\n"
);
+        String formattedString = line.toFormattedString( formatParameters );
+        assertEquals( formattedString, "cn:abc\n" );
+    }
+
+
+    public void testToFormattedStringBase64()
+    {
+        LdifAttrValLine line = LdifAttrValLine.create( "cn", "\u00e4\u00f6\u00fc" );
+        LdifFormatParameters formatParameters = new LdifFormatParameters( true, 78, "\n"
);
+        String formattedString = line.toFormattedString( formatParameters );
+        assertEquals( formattedString, "cn:: w6TDtsO8\n" );
+    }
+
+
+    public void testToFormattedString_DIRSERVER_285()
+    {
+        LdifAttrValLine line = LdifAttrValLine.create( "cn", "abc::def:<ghi" );
+        LdifFormatParameters formatParameters = new LdifFormatParameters( true, 78, "\n"
);
+        String formattedString = line.toFormattedString( formatParameters );
+        assertEquals( formattedString, "cn: abc::def:<ghi\n" );
+    }
+
+}

Added: directory/studio/branches/1.1.0/ldif-parser/src/test/java/org/apache/directory/studio/ldifparser/model/lines/LdifDnLineTest.java
URL: http://svn.apache.org/viewvc/directory/studio/branches/1.1.0/ldif-parser/src/test/java/org/apache/directory/studio/ldifparser/model/lines/LdifDnLineTest.java?rev=631387&view=auto
==============================================================================
--- directory/studio/branches/1.1.0/ldif-parser/src/test/java/org/apache/directory/studio/ldifparser/model/lines/LdifDnLineTest.java
(added)
+++ directory/studio/branches/1.1.0/ldif-parser/src/test/java/org/apache/directory/studio/ldifparser/model/lines/LdifDnLineTest.java
Tue Feb 26 13:26:04 2008
@@ -0,0 +1,77 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+package org.apache.directory.studio.ldifparser.model.lines;
+
+
+import junit.framework.TestCase;
+
+import org.apache.directory.studio.ldifparser.LdifFormatParameters;
+
+
+public class LdifDnLineTest extends TestCase
+{
+
+    public void testToFormattedStringSimple()
+    {
+        LdifDnLine dnLine = LdifDnLine.create( "cn=abc,ou=department,o=org,dc=example,dc=com"
);
+        LdifFormatParameters formatParameters = new LdifFormatParameters( true, 78, "\n"
);
+        String formattedString = dnLine.toFormattedString( formatParameters );
+        assertEquals( formattedString, "dn: cn=abc,ou=department,o=org,dc=example,dc=com\n"
);
+    }
+
+
+    public void testToFormattedStringNewline()
+    {
+        LdifDnLine dnLine = LdifDnLine.create( "cn=abc,ou=department,o=org,dc=example,dc=com"
);
+        LdifFormatParameters formatParameters = new LdifFormatParameters( true, 78, "\r\n"
);
+        String formattedString = dnLine.toFormattedString( formatParameters );
+        assertEquals( formattedString, "dn: cn=abc,ou=department,o=org,dc=example,dc=com\r\n"
);
+    }
+
+
+    public void testToFormattedStringLineWrap()
+    {
+        LdifDnLine dnLine = LdifDnLine
+            .create( "cn=abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxy,ou=department,o=org,dc=example,dc=com"
);
+        LdifFormatParameters formatParameters = new LdifFormatParameters( true, 78, "\n"
);
+        String formattedString = dnLine.toFormattedString( formatParameters );
+        assertEquals( formattedString, "dn: cn=abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxy,ou=department,o=org"
+            + "\n ,dc=example,dc=com\n" );
+    }
+
+
+    public void testToFormattedStringNoSpaceAfterColon()
+    {
+        LdifDnLine dnLine = LdifDnLine.create( "cn=abc,ou=department,o=org,dc=example,dc=com"
);
+        LdifFormatParameters formatParameters = new LdifFormatParameters( false, 78, "\n"
);
+        String formattedString = dnLine.toFormattedString( formatParameters );
+        assertEquals( formattedString, "dn:cn=abc,ou=department,o=org,dc=example,dc=com\n"
);
+    }
+
+
+    public void testToFormattedStringBase64()
+    {
+        LdifDnLine dnLine = LdifDnLine.create( "cn=\u00e4\u00f6\u00fc,ou=department,o=org,dc=example,dc=com"
);
+        LdifFormatParameters formatParameters = new LdifFormatParameters( true, 78, "\n"
);
+        String formattedString = dnLine.toFormattedString( formatParameters );
+        assertEquals( formattedString, "dn:: Y249w6TDtsO8LG91PWRlcGFydG1lbnQsbz1vcmcsZGM9ZXhhbXBsZSxkYz1jb20=\n"
);
+    }
+}

Added: directory/studio/branches/1.1.0/ldif-parser/src/test/java/org/apache/directory/studio/ldifparser/parser/LdifParserTest.java
URL: http://svn.apache.org/viewvc/directory/studio/branches/1.1.0/ldif-parser/src/test/java/org/apache/directory/studio/ldifparser/parser/LdifParserTest.java?rev=631387&view=auto
==============================================================================
--- directory/studio/branches/1.1.0/ldif-parser/src/test/java/org/apache/directory/studio/ldifparser/parser/LdifParserTest.java
(added)
+++ directory/studio/branches/1.1.0/ldif-parser/src/test/java/org/apache/directory/studio/ldifparser/parser/LdifParserTest.java
Tue Feb 26 13:26:04 2008
@@ -0,0 +1,42 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+
+package org.apache.directory.studio.ldifparser.parser;
+
+
+import junit.framework.TestCase;
+
+import org.apache.directory.studio.ldifparser.model.LdifFile;
+
+
+public class LdifParserTest extends TestCase
+{
+
+    public void testLdifNull()
+    {
+        String ldif = null;
+
+        LdifParser parser = new LdifParser();
+        LdifFile model = parser.parse( ldif );
+
+        assertEquals( 0, model.getRecords().length );
+    }
+
+}



Mime
View raw message