directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r359003 - /directory/shared/ldap/branches/DN-refactoring/common/src/main/java/org/apache/ldap/common/name/RdnParser.java
Date Sun, 25 Dec 2005 19:24:39 GMT
Author: elecharny
Date: Sun Dec 25 11:24:33 2005
New Revision: 359003

URL: http://svn.apache.org/viewcvs?rev=359003&view=rev
Log:
Renammed the class from RDNParser to RdnParser

Added:
    directory/shared/ldap/branches/DN-refactoring/common/src/main/java/org/apache/ldap/common/name/RdnParser.java
      - copied, changed from r356646, directory/shared/ldap/branches/DN-refactoring/common/src/main/java/org/apache/ldap/common/name/RDNParser.java

Copied: directory/shared/ldap/branches/DN-refactoring/common/src/main/java/org/apache/ldap/common/name/RdnParser.java
(from r356646, directory/shared/ldap/branches/DN-refactoring/common/src/main/java/org/apache/ldap/common/name/RDNParser.java)
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/branches/DN-refactoring/common/src/main/java/org/apache/ldap/common/name/RdnParser.java?p2=directory/shared/ldap/branches/DN-refactoring/common/src/main/java/org/apache/ldap/common/name/RdnParser.java&p1=directory/shared/ldap/branches/DN-refactoring/common/src/main/java/org/apache/ldap/common/name/RDNParser.java&r1=356646&r2=359003&rev=359003&view=diff
==============================================================================
--- directory/shared/ldap/branches/DN-refactoring/common/src/main/java/org/apache/ldap/common/name/RDNParser.java
(original)
+++ directory/shared/ldap/branches/DN-refactoring/common/src/main/java/org/apache/ldap/common/name/RdnParser.java
Sun Dec 25 11:24:33 2005
@@ -76,7 +76,7 @@
  * 
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-public class RDNParser
+public class RdnParser
 {
     /**
      * Parse this rule : <br>
@@ -349,7 +349,7 @@
      * @param pos The current position in the byte buffer
      * @return The new position in the char buffer, or PARSING_ERROR if the rule does not
apply to the char buffer
      */
-    private static int parseNameComponents( char[] chars, int pos, LdapRDN rdn ) throws InvalidNameException
+    private static int parseNameComponents( char[] chars, int pos, Rdn rdn ) throws InvalidNameException
     {
         int newPos = 0;
         String type = null;
@@ -412,6 +412,132 @@
     }
 
     /**
+     * Parse this rule : <br>
+     * <p>
+     * &lt;attributeValue&gt;     ::= &lt;pairs-or-strings&gt; | '#' &lt;hexstring&gt;
|'"' &lt;quotechar-or-pairs&gt; '"' <br>
+     * &lt;pairs-or-strings&gt;    ::= '\' &lt;pairchar&gt; &lt;pairs-or-strings&gt;
| &lt;stringchar&gt; &lt;pairs-or-strings&gt; |  | e <br>
+     * &lt;quotechar-or-pairs&gt;    ::= &lt;quotechar&gt; &lt;quotechar-or-pairs&gt;
| '\' &lt;pairchar&gt; &lt;quotechar-or-pairs&gt; | e <br>
+     * </p>
+     * 
+     * @param chars The char array to parse
+     * @param pos The current position in the char array
+     * @return The new position in the char array, or PARSING_ERROR if the rule does not
apply to the char array
+     */
+    public static int unescapeValue( String value ) throws IllegalArgumentException
+    {
+    	char[] chars = value.toCharArray();
+    	int pos = 0;
+    	
+        if ( StringUtils.isCharASCII( chars, pos, '#' ) )
+        {
+            pos++;
+
+            // <attributeValue> ::= '#' <hexstring>
+            if ( ( pos = DNUtils.parseHexString( chars, pos ) ) == DNUtils.PARSING_ERROR
)
+            {
+
+                throw new IllegalArgumentException();
+            }
+
+            return StringUtils.trimLeft( chars, pos );
+        }
+        else if ( StringUtils.isCharASCII( chars, pos, '"' ) )
+        {
+            pos++;
+            int nbBytes = 0;
+
+            // <attributeValue>     ::= '"' <quotechar-or-pair> '"'
+            // <quotechar-or-pairs>    ::= <quotechar> <quotechar-or-pairs>
| '\' <pairchar> <quotechar-or-pairs> | e
+            while ( true )
+            {
+                if ( StringUtils.isCharASCII( chars, pos, '\\' ) )
+                {
+                    pos++;
+
+                    if ( DNUtils.isPairChar( chars, pos ) )
+                    {
+                        pos++;
+                    }
+                    else
+                    {
+                        return DNUtils.PARSING_ERROR;
+                    }
+                }
+                else if ( (nbBytes = DNUtils.isQuoteChar( chars, pos ) ) != DNUtils.PARSING_ERROR
)
+                {
+                    pos += nbBytes;
+                }
+                else
+                {
+                    break;
+                }
+            }
+
+            if ( StringUtils.isCharASCII( chars, pos, '"' ) )
+            {
+                pos++;
+
+                return StringUtils.trimLeft( chars, pos );
+            }
+            else
+            {
+                return DNUtils.PARSING_ERROR;
+            }
+        }
+        else
+        {
+            while ( true )
+            {
+                if ( StringUtils.isCharASCII( chars, pos, '\\' ) )
+                {
+                    // '\' <pairchar> <pairs-or-strings>
+                    pos++;
+
+                    if ( DNUtils.isPairChar( chars, pos ) == false )
+                    {
+                        return DNUtils.PARSING_ERROR;
+                    }
+                    else
+                    {
+                        pos++;
+                    }
+                }
+                else
+                {
+                    int nbChars = 0;
+                    
+                    // <stringchar> <pairs-or-strings>
+                    if ( ( nbChars = DNUtils.isStringChar( chars, pos )) != DNUtils.PARSING_ERROR
)
+                    {
+                        // A special case : if we have some spaces before the '+' character,
+                        // we MUST skip them.
+                        if ( StringUtils.isCharASCII( chars, pos, ' ') )
+                        {
+                            pos = StringUtils.trimLeft( chars, pos );
+
+                            if ( ( DNUtils.isStringChar( chars, pos ) == DNUtils.PARSING_ERROR
) &&
+                                    ( StringUtils.isCharASCII( chars, pos, '\\' ) == false
) )
+                            {
+                                // Ok, we are done with the stringchar.
+                                return pos;
+                            }
+                        }
+                        else
+                        {
+                            // An unicode char could be more than one byte long 
+                            pos += nbChars;
+                        }
+                    }
+                    else
+                    {
+                        return pos;
+                    }
+                }
+            }
+        }
+    }
+
+    /**
      * Parse a NameComponent : <br>
      * <p>
      * &lt;name-component&gt;    ::= &lt;attributeType&gt; &lt;spaces&gt;
'=' &lt;spaces&gt; &lt;attributeValue&gt; &lt;nameComponents&gt;
@@ -421,7 +547,7 @@
      * @param pos The current position in the buffer
      * @return The new position in the char array, or PARSING_ERROR if the rule does not
apply to the char array 
      */
-    public static int parse( char[] chars, int pos, LdapRDN rdn ) throws InvalidNameException
+    public static int parse( char[] chars, int pos, Rdn rdn ) throws InvalidNameException
     {
         int newPos = 0;
         String type = null;
@@ -468,6 +594,7 @@
 
         int end = parseNameComponents( chars, newPos, rdn );
         rdn.setUpName( new String( chars, start, end - start ) );
+        rdn.normalizeString();
         return end;
     }
 
@@ -480,8 +607,9 @@
      * @param string The buffer to parse
      * @param rdn The RDN to fill. Beware that if the RDN is not empty, the new AttributeTypeAndValue
will be added. 
      */
-    public static void parse( String string, LdapRDN rdn ) throws InvalidNameException
+    public static void parse( String string, Rdn rdn ) throws InvalidNameException
     {
         parse( string.toCharArray(), 0, rdn );
+        rdn.normalizeString();
     }
 }



Mime
View raw message