directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1570803 - in /directory/shared/trunk/ldap/model/src: main/java/org/apache/directory/api/ldap/model/ldif/LdifReader.java test/java/org/apache/directory/api/ldap/model/ldif/LdifReaderTest.java
Date Sat, 22 Feb 2014 07:18:53 GMT
Author: elecharny
Date: Sat Feb 22 07:18:52 2014
New Revision: 1570803

URL: http://svn.apache.org/r1570803
Log:
Added a fix for DIRAPI-175 : empty DN is now accepted

Modified:
    directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/ldif/LdifReader.java
    directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/api/ldap/model/ldif/LdifReaderTest.java

Modified: directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/ldif/LdifReader.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/ldif/LdifReader.java?rev=1570803&r1=1570802&r2=1570803&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/ldif/LdifReader.java
(original)
+++ directory/shared/trunk/ldap/model/src/main/java/org/apache/directory/api/ldap/model/ldif/LdifReader.java
Sat Feb 22 07:18:52 2014
@@ -6,16 +6,16 @@
  *  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. 
- *  
+ *  under the License.
+ *
  */
 package org.apache.directory.api.ldap.model.ldif;
 
@@ -61,84 +61,84 @@ 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-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;

+ *
+ *  &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; ::= &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; 
+ *
+ *  &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;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;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; | 
+ *
+ *  &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;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; 
+ *    &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;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&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;
@@ -152,17 +152,17 @@ import org.slf4j.LoggerFactory;
  *  &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 
+ *  - 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 LdifReader implements Iterable<LdifEntry>, Closeable
@@ -229,13 +229,13 @@ public class LdifReader implements Itera
 
     /** the parsed entry's starting position */
     protected long entryOffset = 0;
-    
+
     /** the current offset of the reader */
     private long offset = 0;
-    
+
     /** the current line number being parsed by the reader */
     private int lineNumber;
-    
+
     /**
      * Constructors
      */
@@ -270,7 +270,7 @@ public class LdifReader implements Itera
 
     /**
      * A constructor which takes a file name
-     * 
+     *
      * @param ldifFileName A file name containing ldif formated input
      * @throws LdapLdifException If the file cannot be processed or if the format is incorrect
      */
@@ -315,7 +315,7 @@ public class LdifReader implements Itera
 
     /**
      * A constructor which takes a Reader
-     * 
+     *
      * @param in A Reader containing ldif formated input
      * @throws LdapException If the file cannot be processed or if the format is incorrect
      */
@@ -327,7 +327,7 @@ public class LdifReader implements Itera
 
     /**
      * A constructor which takes an InputStream
-     * 
+     *
      * @param in An InputStream containing ldif formated input
      * @throws LdapException If the file cannot be processed or if the format is incorrect
      */
@@ -339,7 +339,7 @@ public class LdifReader implements Itera
 
     /**
      * A constructor which takes a File
-     * 
+     *
      * @param file A File containing ldif formated input
      * @throws LdapLdifException If the file cannot be processed or if the format is incorrect
      */
@@ -400,7 +400,7 @@ public class LdifReader implements Itera
 
     /**
      * Set the maximum file size that can be accepted for an attribute value
-     * 
+     *
      * @param sizeLimit The size in bytes
      */
     public void setSizeLimit( long sizeLimit )
@@ -421,12 +421,12 @@ public class LdifReader implements Itera
 
     /**
      * Parse a number following the rules :
-     * 
+     *
      * &lt;number&gt; ::= &lt;digit&gt; &lt;digits&gt; &lt;digits&gt;
::= &lt;digit&gt; &lt;digits&gt; | e &lt;digit&gt;
      * ::= '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9'
-     * 
+     *
      * Check that the number is in the interval
-     * 
+     *
      * @param document The document containing the number to parse
      * @return a String representing the parsed number
      */
@@ -459,7 +459,7 @@ public class LdifReader implements Itera
 
     /**
      * Parse the changeType
-     * 
+     *
      * @param line The line which contains the changeType
      * @return The operation.
      */
@@ -496,7 +496,7 @@ public class LdifReader implements Itera
 
     /**
      * Parse the Dn of an entry
-     * 
+     *
      * @param line The line to parse
      * @return A Dn
      * @throws LdapLdifException If the Dn is invalid
@@ -514,9 +514,8 @@ public class LdifReader implements Itera
 
             if ( length == 3 )
             {
-                // The Dn is empty : error
-                LOG.error( I18n.err( I18n.ERR_12012_EMPTY_DN_NOT_ALLOWED ) );
-                throw new LdapLdifException( I18n.err( I18n.ERR_12013_NO_DN ) );
+                // The Dn is empty : it's a rootDSE
+                dn = "";
             }
             else if ( line.charAt( 3 ) == ':' )
             {
@@ -568,7 +567,7 @@ public class LdifReader implements Itera
 
     /**
      * Parse the value part.
-     * 
+     *
      * @param line The line which contains the value
      * @param pos The starting position in the line
      * @return A String or a byte[], depending of the kind of value we get
@@ -599,7 +598,7 @@ public class LdifReader implements Itera
 
     /**
      * Parse the value part.
-     * 
+     *
      * @param line The line which contains the value
      * @param pos The starting position in the line
      * @return A String or a byte[], depending of the kind of value we get
@@ -745,22 +744,22 @@ public class LdifReader implements Itera
 
 
     /**
-     * Parse a control. The grammar is : 
+     * Parse a control. The grammar is :
      * <pre>
-     * &lt;control&gt; ::= "control:" &lt;fill&gt; &lt;ldap-oid&gt;
&lt;critical-e&gt; &lt;value-spec-e&gt; &lt;sep&gt; 
-     * &lt;critical-e&gt; ::= &lt;spaces&gt; &lt;boolean&gt; | e

-     * &lt;boolean&gt; ::= "true" | "false" 
-     * &lt;value-spec-e&gt; ::= &lt;value-spec&gt; | e 
+     * &lt;control&gt; ::= "control:" &lt;fill&gt; &lt;ldap-oid&gt;
&lt;critical-e&gt; &lt;value-spec-e&gt; &lt;sep&gt;
+     * &lt;critical-e&gt; ::= &lt;spaces&gt; &lt;boolean&gt; | e
+     * &lt;boolean&gt; ::= "true" | "false"
+     * &lt;value-spec-e&gt; ::= &lt;value-spec&gt; | e
      * &lt;value-spec&gt; ::= ":" &lt;fill&gt; &lt;SAFE-STRING-e&gt;
| "::" &lt;fill&gt; &lt;BASE64-STRING&gt; | ":<" &lt;fill&gt; &lt;url&gt;
      * </pre>
-     * 
+     *
      * It can be read as :
-     * <pre> 
+     * <pre>
      * "control:" &lt;fill&gt; &lt;ldap-oid&gt; [ " "+ ( "true" |
      * "false") ] [ ":" &lt;fill&gt; &lt;SAFE-STRING-e&gt; | "::" &lt;fill&gt;
&lt;BASE64-STRING&gt; | ":<"
      * &lt;fill&gt; &lt;url&gt; ]
      * </pre>
-     * 
+     *
      * @param line The line containing the control
      * @return A control
      * @exception LdapLdifException If the control has no OID or if the OID is incorrect,
@@ -896,7 +895,7 @@ public class LdifReader implements Itera
 
     /**
      * Parse an AttributeType/AttributeValue
-     * 
+     *
      * @param line The line to parse
      * @return the parsed Attribute
      */
@@ -928,7 +927,7 @@ public class LdifReader implements Itera
 
     /**
      * 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
@@ -956,7 +955,7 @@ public class LdifReader implements Itera
 
     /**
      * Parse a ModRDN operation
-     * 
+     *
      * @param entry The entry to update
      * @param iter The lines iterator
      * @throws LdapLdifException If anything goes wrong
@@ -1023,18 +1022,18 @@ public class LdifReader implements Itera
 
     /**
      * Parse a modify change type.
-     * 
+     *
      * The grammar is :
-     * <pre> 
-     * &lt;changerecord&gt; ::= "changetype:" FILL "modify" SEP &lt;mod-spec&gt;
&lt;mod-specs-e&gt; 
-     * &lt;mod-spec&gt; ::= "add:" &lt;mod-val&gt; | "delete:" &lt;mod-val-del&gt;
| "replace:" &lt;mod-val&gt; 
+     * <pre>
+     * &lt;changerecord&gt; ::= "changetype:" FILL "modify" SEP &lt;mod-spec&gt;
&lt;mod-specs-e&gt;
+     * &lt;mod-spec&gt; ::= "add:" &lt;mod-val&gt; | "delete:" &lt;mod-val-del&gt;
| "replace:" &lt;mod-val&gt;
      * &lt;mod-specs-e&gt; ::= &lt;mod-spec&gt;
-     * &lt;mod-specs-e&gt; | e 
-     * &lt;mod-val&gt; ::= FILL ATTRIBUTE-DESCRIPTION SEP ATTRVAL-SPEC &lt;attrval-specs-e&gt;
"-" SEP 
-     * &lt;mod-val-del&gt; ::= FILL ATTRIBUTE-DESCRIPTION SEP &lt;attrval-specs-e&gt;
"-" SEP 
+     * &lt;mod-specs-e&gt; | e
+     * &lt;mod-val&gt; ::= FILL ATTRIBUTE-DESCRIPTION SEP ATTRVAL-SPEC &lt;attrval-specs-e&gt;
"-" SEP
+     * &lt;mod-val-del&gt; ::= FILL ATTRIBUTE-DESCRIPTION SEP &lt;attrval-specs-e&gt;
"-" SEP
      * &lt;attrval-specs-e&gt; ::= ATTRVAL-SPEC &lt;attrval-specs&gt; | e
      * </pre>
-     * 
+     *
      * @param entry The entry to feed
      * @param iter The lines
      * @exception LdapLdifException If the modify operation is invalid
@@ -1182,31 +1181,31 @@ public class LdifReader implements Itera
     /**
      * Parse a change operation. We have to handle different cases depending on
      * the operation.
-     * <ul> 
-     * <li>1) Delete : there should *not* be any line after the "changetype: delete"
</li> 
+     * <ul>
+     * <li>1) Delete : there should *not* be any line after the "changetype: delete"
</li>
      * <li>2) Add : we must have a list of AttributeType : AttributeValue elements
</li>
      * <li>3) ModDN : we must have two following lines: a "newrdn:" and a "deleteoldrdn:"
</li>
      * <li>4) ModRDN : the very same, but a "newsuperior:" line is expected </li>
      * <li>5) Modify</li>
      * </ul>
-     * 
-     * The grammar is : 
+     *
+     * The grammar is :
      * <pre>
-     * &lt;changerecord&gt; ::= "changetype:" FILL "add" SEP &lt;attrval-spec&gt;
&lt;attrval-specs-e&gt; | 
+     * &lt;changerecord&gt; ::= "changetype:" FILL "add" SEP &lt;attrval-spec&gt;
&lt;attrval-specs-e&gt; |
      *     "changetype:" FILL "delete" |
-     *     "changetype:" FILL "modrdn" SEP &lt;newrdn&gt; SEP &lt;deleteoldrdn&gt;
SEP | 
-     *     // To be checked 
-     *     "changetype:" FILL "moddn" SEP &lt;newrdn&gt; SEP &lt;deleteoldrdn&gt;
SEP &lt;newsuperior&gt; SEP | 
-     *     "changetype:" FILL "modify" SEP &lt;mod-spec&gt; &lt;mod-specs-e&gt;

+     *     "changetype:" FILL "modrdn" SEP &lt;newrdn&gt; SEP &lt;deleteoldrdn&gt;
SEP |
+     *     // To be checked
+     *     "changetype:" FILL "moddn" SEP &lt;newrdn&gt; SEP &lt;deleteoldrdn&gt;
SEP &lt;newsuperior&gt; SEP |
+     *     "changetype:" FILL "modify" SEP &lt;mod-spec&gt; &lt;mod-specs-e&gt;
      * &lt;newrdn&gt; ::= "newrdn:" FILL Rdn | "newrdn::" FILL BASE64-Rdn
-     * &lt;deleteoldrdn&gt; ::= "deleteoldrdn:" FILL "0" | "deleteoldrdn:" FILL "1"

+     * &lt;deleteoldrdn&gt; ::= "deleteoldrdn:" FILL "0" | "deleteoldrdn:" FILL "1"
      * &lt;newsuperior&gt; ::= "newsuperior:" FILL Dn | "newsuperior::" FILL BASE64-Dn
-     * &lt;mod-specs-e&gt; ::= &lt;mod-spec&gt; &lt;mod-specs-e&gt;
| e 
-     * &lt;mod-spec&gt; ::= "add:" &lt;mod-val&gt; | "delete:" &lt;mod-val&gt;
| "replace:" &lt;mod-val&gt; 
+     * &lt;mod-specs-e&gt; ::= &lt;mod-spec&gt; &lt;mod-specs-e&gt;
| e
+     * &lt;mod-spec&gt; ::= "add:" &lt;mod-val&gt; | "delete:" &lt;mod-val&gt;
| "replace:" &lt;mod-val&gt;
      * &lt;mod-val&gt; ::= FILL ATTRIBUTE-DESCRIPTION SEP ATTRVAL-SPEC &lt;attrval-specs-e&gt;
"-" SEP
      * &lt;attrval-specs-e&gt; ::= ATTRVAL-SPEC &lt;attrval-specs&gt; | e
      * </pre>
-     * 
+     *
      * @param entry The entry to feed
      * @param iter The lines iterator
      * @param operation The change operation (add, modify, delete, moddn or modrdn)
@@ -1288,15 +1287,15 @@ public class LdifReader implements Itera
      * Parse a ldif file. The following rules are processed :
      * <pre>
      * &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;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;
      * </pre>
-     * 
+     *
      * @return the parsed ldifEntry
-     * @exception LdapException If the ldif file does not contain a valid entry 
+     * @exception LdapException If the ldif file does not contain a valid entry
      */
     private LdifEntry parseEntry() throws LdapException
     {
@@ -1310,7 +1309,7 @@ public class LdifReader implements Itera
         String line = lines.get( 0 );
 
         lineNumber -= ( lines.size() - 1 );
-        
+
         String name = parseDn( line );
 
         Dn dn = new Dn( name );
@@ -1319,7 +1318,7 @@ public class LdifReader implements Itera
         LdifEntry entry = new LdifEntry();
         entry.setLengthBeforeParsing( entryLen );
         entry.setOffset( entryOffset );
-        
+
         entry.setDn( dn );
 
         // We remove this dn from the lines
@@ -1346,7 +1345,7 @@ public class LdifReader implements Itera
         while ( iter.hasNext() )
         {
             lineNumber++;
-            
+
             // Each line could start either with an OID, an attribute type, with
             // "control:" or with "changetype:"
             line = iter.next();
@@ -1450,7 +1449,7 @@ public class LdifReader implements Itera
 
     /**
      * Parse the version from the ldif input.
-     * 
+     *
      * @return A number representing the version (default to 1)
      * @throws LdapLdifException If the version is incorrect or if the input is incorrect
      */
@@ -1509,9 +1508,9 @@ public class LdifReader implements Itera
             {
                 // include the version line as part of the first entry
                 int tmpEntryLen = entryLen;
-                
+
                 readLines();
-                
+
                 entryLen += tmpEntryLen;
             }
         }
@@ -1526,7 +1525,7 @@ public class LdifReader implements Itera
 
     /**
      * gets a line from the underlying data store
-     * 
+     *
      * @return a line of characters or null if EOF reached
      * @throws IOException on read failure
      */
@@ -1539,9 +1538,9 @@ public class LdifReader implements Itera
     /**
      * Reads an entry in a ldif buffer, and returns the resulting lines, without
      * comments, and unfolded.
-     * 
+     *
      * The lines represent *one* entry.
-     * 
+     *
      * @throws LdapLdifException If something went wrong
      */
     protected void readLines() throws LdapLdifException
@@ -1553,7 +1552,7 @@ public class LdifReader implements Itera
         lines.clear();
         entryLen = 0;
         entryOffset = offset;
-        
+
         StringBuffer sb = new StringBuffer();
 
         try
@@ -1561,7 +1560,7 @@ public class LdifReader implements Itera
             while ( ( line = getLine() ) != null )
             {
                 lineNumber++;
-                
+
                 if ( line.length() == 0 )
                 {
                     if ( isFirstLine )
@@ -1618,7 +1617,7 @@ public class LdifReader implements Itera
                         insideComment = false;
                         break;
                 }
-                
+
                 byte[] data = line.getBytes();
                 // FIXME might fail on windows in the new line issue, yet to check
                 offset += ( data.length + 1 );
@@ -1640,7 +1639,7 @@ public class LdifReader implements Itera
 
     /**
      * Parse a ldif file (using the default encoding).
-     * 
+     *
      * @param fileName The ldif file
      * @return A list of entries
      * @throws LdapLdifException If the parsing fails
@@ -1653,7 +1652,7 @@ public class LdifReader implements Itera
 
     /**
      * Parse a ldif file, decoding it using the given charset encoding
-     * 
+     *
      * @param fileName The ldif file
      * @param encoding The charset encoding to use
      * @return A list of entries
@@ -1714,7 +1713,7 @@ public class LdifReader implements Itera
 
     /**
      * 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 LdapLdifException If something went wrong
@@ -1772,7 +1771,7 @@ public class LdifReader implements Itera
     // ------------------------------------------------------------------------
     /**
      * Gets the next LDIF on the channel.
-     * 
+     *
      * @return the next LDIF as a String.
      */
     private LdifEntry nextInternal()
@@ -1813,7 +1812,7 @@ public class LdifReader implements Itera
 
     /**
      * Gets the next LDIF on the channel.
-     * 
+     *
      * @return the next LDIF as a String.
      */
     public LdifEntry next()
@@ -1824,7 +1823,7 @@ public class LdifReader implements Itera
 
     /**
      * Tests to see if another LDIF is on the input channel.
-     * 
+     *
      * @return true if another LDIF is available false otherwise.
      */
     private boolean hasNextInternal()
@@ -1835,7 +1834,7 @@ public class LdifReader implements Itera
 
     /**
      * Tests to see if another LDIF is on the input channel.
-     * 
+     *
      * @return true if another LDIF is available false otherwise.
      */
     public boolean hasNext()
@@ -1855,7 +1854,7 @@ public class LdifReader implements Itera
 
     /**
      * Always throws UnsupportedOperationException!
-     * 
+     *
      * @see java.util.Iterator#remove()
      */
     private void removeInternal()
@@ -1866,7 +1865,7 @@ public class LdifReader implements Itera
 
     /**
      * Always throws UnsupportedOperationException!
-     * 
+     *
      * @see java.util.Iterator#remove()
      */
     public void remove()
@@ -1923,7 +1922,7 @@ public class LdifReader implements Itera
     /**
      * The main entry point of the LdifParser. It reads a buffer and returns a
      * List of entries.
-     * 
+     *
      * @param reader The buffer being processed
      * @return A list of entries
      * @throws LdapException If something went wrong

Modified: directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/api/ldap/model/ldif/LdifReaderTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/api/ldap/model/ldif/LdifReaderTest.java?rev=1570803&r1=1570802&r2=1570803&view=diff
==============================================================================
--- directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/api/ldap/model/ldif/LdifReaderTest.java
(original)
+++ directory/shared/trunk/ldap/model/src/test/java/org/apache/directory/api/ldap/model/ldif/LdifReaderTest.java
Sat Feb 22 07:18:52 2014
@@ -6,16 +6,16 @@
  *  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. 
- *  
+ *  under the License.
+ *
  */
 package org.apache.directory.api.ldap.model.ldif;
 
@@ -53,7 +53,7 @@ import com.mycila.junit.concurrent.Concu
 
 /**
  * Test the LdifReader class
- * 
+ *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
 @RunWith(ConcurrentJunitRunner.class)
@@ -208,7 +208,7 @@ public class LdifReaderTest
         assertTrue( entry.isLdifContent() );
 
         assertEquals( ldif.length(), entry.getLengthBeforeParsing() );
-        
+
         assertEquals( "cn=app1,ou=applications,ou=conf,dc=apache,dc=org", entry.getDn().getName()
);
 
         Attribute attr = entry.get( "displayname" );
@@ -242,7 +242,7 @@ public class LdifReaderTest
 
     /**
      * Spaces at the end of values should not be included into values.
-     * 
+     *
      * @throws Exception
      */
     @Test
@@ -329,7 +329,7 @@ public class LdifReaderTest
 
     /**
      * Changes and entries should not be mixed
-     * 
+     *
      * @throws Exception
      */
     @Test
@@ -373,7 +373,7 @@ public class LdifReaderTest
 
     /**
      * Changes and entries should not be mixed
-     * 
+     *
      * @throws Exception
      */
     @Test
@@ -416,7 +416,7 @@ public class LdifReaderTest
 
     /**
      * Changes and entries should not be mixed
-     * 
+     *
      * @throws Exception
      */
     @Test
@@ -460,7 +460,7 @@ public class LdifReaderTest
 
     /**
      * Changes and entries should not be mixed
-     * 
+     *
      * @throws Exception
      */
     @Test
@@ -1044,7 +1044,7 @@ public class LdifReaderTest
         String[][][] values =
             {
                 {
-                    { "dn", "ou=\u55b6\u696d\u90e8,o=Airius" }, // 55b6 = ���,
696d = ���, 90e8 = ��� 
+                    { "dn", "ou=\u55b6\u696d\u90e8,o=Airius" }, // 55b6 = ���,
696d = ���, 90e8 = ���
                         { "objectclass", "top" },
                         { "objectclass", "organizationalUnit" },
                         { "ou", "\u55b6\u696d\u90e8" },
@@ -1062,8 +1062,8 @@ public class LdifReaderTest
                     { "objectclass", "inetOrgPerson" },
                     { "uid", "rogasawara" },
                     { "mail", "rogasawara@airius.co.jp" },
-                    { "givenname;lang-ja", "\u30ed\u30c9\u30cb\u30fc" }, // 30ed = ���,
30c9 = ���, 30cb = ���, 30fc = ���   
-                        { "sn;lang-ja", "\u5c0f\u7b20\u539f" }, // 5c0f = ���,
7b20 = ���, 539f = ���  
+                    { "givenname;lang-ja", "\u30ed\u30c9\u30cb\u30fc" }, // 30ed = ���,
30c9 = ���, 30cb = ���, 30fc = ���
+                        { "sn;lang-ja", "\u5c0f\u7b20\u539f" }, // 5c0f = ���,
7b20 = ���, 539f = ���
                         { "cn;lang-ja", "\u5c0f\u7b20\u539f \u30ed\u30c9\u30cb\u30fc" },
                         { "title;lang-ja", "\u55b6\u696d\u90e8 \u90e8\u9577" }, // 9577 =
���
                         { "preferredlanguage", "ja" },
@@ -1072,7 +1072,7 @@ public class LdifReaderTest
                         { "cn", "\u5c0f\u7b20\u539f \u30ed\u30c9\u30cb\u30fc" },
                         { "title", "\u55b6\u696d\u90e8 \u90e8\u9577" },
                         { "givenname;lang-ja;phonetic", "\u308d\u3069\u306b\u30fc" }, //
308d = ���,3069 = ���, 306b = ���
-                        { "sn;lang-ja;phonetic", "\u304a\u304c\u3055\u308f\u3089" }, // 304a
= ���, 304c = ���,3055 = ���,308f = ���,
3089 = ���    
+                        { "sn;lang-ja;phonetic", "\u304a\u304c\u3055\u308f\u3089" }, // 304a
= ���, 304c = ���,3055 = ���,308f = ���,
3089 = ���
                         { "cn;lang-ja;phonetic", "\u304a\u304c\u3055\u308f\u3089 \u308d\u3069\u306b\u30fc"
},
                         { "title;lang-ja;phonetic", "\u3048\u3044\u304e\u3087\u3046\u3076
\u3076\u3061\u3087\u3046" }, // 304E = ���, 3061 = ���
                         { "givenname;lang-en", "Rodney" },
@@ -1300,7 +1300,7 @@ public class LdifReaderTest
 
         String[][][] values =
             {
-                // First entry modification : ADD                
+                // First entry modification : ADD
                 {
                     { "dn", "cn=Fiona Jensen, ou=Marketing, dc=airius, dc=com" },
                     { "objectclass", "top" },
@@ -2050,7 +2050,7 @@ public class LdifReaderTest
 
     /**
      * Test that we can parse a LDIF with a modify changeType and see if the
-     * empty attribute and the attribute deletion aren't producing the same Modify entry

+     * empty attribute and the attribute deletion aren't producing the same Modify entry
      * @throws Exception
      */
     @Test
@@ -2085,10 +2085,10 @@ public class LdifReaderTest
         assertNotNull( modification.getAttribute().get() );
         assertNull( modification.getAttribute().getBytes() );
     }
-    
+
     /**
      * Test lengths when multiple entries are present
-     * 
+     *
      * @throws Exception
      */
     @Test
@@ -2106,12 +2106,12 @@ public class LdifReaderTest
                          "# Tree Delete Control defined in [9]. The criticality\n" +
                          "# field is \"true\" and the controlValue field is\n" +
                          "# absent, as required by [9].\n";
-        
+
         String version = "version:   1\n";
-        
+
         String ldif =
                 version +
-                ldif1 + 
+                ldif1 +
                 "\n" +
                 comment +
                 ldif1 + "\n";
@@ -2119,7 +2119,7 @@ public class LdifReaderTest
         LdifReader reader = new LdifReader();
 
         List<LdifEntry> lstEntries = null;
-        
+
         try
         {
             lstEntries = reader.parseLdif( ldif );
@@ -2132,23 +2132,23 @@ public class LdifReaderTest
         {
             reader.close();
         }
-        
+
         LdifEntry entry1 = lstEntries.get( 0 );
-        
+
         assertEquals( version.length() + ldif1.length(), entry1.getLengthBeforeParsing()
);
-        
+
         LdifEntry entry2 = lstEntries.get( 1 );
-        
+
         assertEquals( ldif1.length() + comment.length(), entry2.getLengthBeforeParsing()
);
-        
+
         byte[] data = ldif.getBytes();
-        
+
         String ldif1Bytes = new String( data, ( int ) entry1.getOffset(), entry1.getLengthBeforeParsing()
);
         assertNotNull( reader.parseLdif( ldif1Bytes ).get( 0 ) );
-        
+
         String ldif2Bytes = new String( data, ( int ) entry2.getOffset(), entry2.getLengthBeforeParsing()
);
         assertNotNull( reader.parseLdif( ldif2Bytes ).get( 0 ) );
-        
+
         File file = File.createTempFile( "offsetTest", "ldif" );
         file.deleteOnExit();
         FileWriter fw = new FileWriter( file );
@@ -2156,11 +2156,11 @@ public class LdifReaderTest
         fw.close();
 
         RandomAccessFile raf = new RandomAccessFile( file, "r" );
-        
+
         LdifReader fileReader = new LdifReader( file );
-        
+
         LdifEntry rafEntry1 = fileReader.next();
-        
+
         data = new byte[rafEntry1.getLengthBeforeParsing()];
         raf.read( data, ( int ) rafEntry1.getOffset(), data.length );
 
@@ -2170,11 +2170,11 @@ public class LdifReaderTest
         assertEquals( rafEntry1.getOffset(), reReadeRafEntry1.getOffset() );
         assertEquals( rafEntry1.getLengthBeforeParsing(), reReadeRafEntry1.getLengthBeforeParsing()
);
         reader.close();
-        
+
         LdifEntry rafEntry2 = fileReader.next();
-        
+
         data = new byte[rafEntry2.getLengthBeforeParsing()];
-        raf.readFully( data, ( int ) 0, data.length );
+        raf.readFully( data, 0, data.length );
 
         reader = new LdifReader();
         LdifEntry reReadeRafEntry2 = reader.parseLdif( new String( data ) ).get( 0 );
@@ -2183,7 +2183,7 @@ public class LdifReaderTest
         reader.close();
     }
 
-    
+
     @Test // for DIRAPI-174
     public void testLineNumber() throws Exception
     {
@@ -2203,7 +2203,7 @@ public class LdifReaderTest
         catch( Exception e )
         {
         }
-        
+
         assertEquals( 1, reader.getLineNumber() );
 
         ldif =
@@ -2242,7 +2242,7 @@ public class LdifReaderTest
         }
 
         assertEquals( 4, reader.getLineNumber() );
-        
+
         ldif =
             "version:   1\n" +
                 "dn: cn=app1,ou=applications,ou=conf,dc=apache,dc=org\n" +
@@ -2272,4 +2272,46 @@ public class LdifReaderTest
 
         assertEquals( 10, reader.getLineNumber() );
     }
+
+
+    @Test
+    public void testLdifParserRootDSE() throws Exception
+    {
+        String ldif =
+            "version:   1\n" +
+                "dn:\n" +
+                "cn: app1\n" +
+                "objectClass: top\n" +
+                "objectClass: apApplication\n" +
+                "displayName: app1   \n" +
+                "dependencies:\n" +
+                "envVars:";
+
+        LdifReader reader = new LdifReader();
+        List<LdifEntry> entries = reader.parseLdif( ldif );
+        reader.close();
+
+        assertNotNull( entries );
+
+        LdifEntry entry = entries.get( 0 );
+        assertTrue( entry.isLdifContent() );
+
+        assertEquals( "", entry.getDn().getName() );
+
+        Attribute attr = entry.get( "cn" );
+        assertTrue( attr.contains( "app1" ) );
+
+        attr = entry.get( "objectclass" );
+        assertTrue( attr.contains( "top" ) );
+        assertTrue( attr.contains( "apApplication" ) );
+
+        attr = entry.get( "displayname" );
+        assertTrue( attr.contains( "app1" ) );
+
+        attr = entry.get( "dependencies" );
+        assertNull( attr.get().getValue() );
+
+        attr = entry.get( "envvars" );
+        assertNull( attr.get().getValue() );
+    }
 }



Mime
View raw message