directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r307424 - /directory/shared/ldap/trunk/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/primitives/DNParser.java
Date Sun, 09 Oct 2005 13:41:15 GMT
Author: elecharny
Date: Sun Oct  9 06:41:11 2005
New Revision: 307424

URL: http://svn.apache.org/viewcvs?rev=307424&view=rev
Log:
The DNParser has been added to decouple the class which stores DNs and the parsing
of a DN.

Added:
    directory/shared/ldap/trunk/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/primitives/DNParser.java

Added: directory/shared/ldap/trunk/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/primitives/DNParser.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/trunk/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/primitives/DNParser.java?rev=307424&view=auto
==============================================================================
--- directory/shared/ldap/trunk/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/primitives/DNParser.java
(added)
+++ directory/shared/ldap/trunk/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/primitives/DNParser.java
Sun Oct  9 06:41:11 2005
@@ -0,0 +1,100 @@
+/*
+ *   Copyright 2005 The Apache Software Foundation
+ *
+ *   Licensed 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.asn1new.ldap.codec.primitives;
+
+import java.util.List;
+
+import javax.naming.InvalidNameException;
+
+import org.apache.asn1new.ldap.codec.utils.DNUtils;
+import org.apache.asn1new.util.StringUtils;
+
+/**
+ * This class parses a DN. 
+ * 
+ * The DN MUST respect this BNF grammar (as of RFC2253, par. 3, and RFC1779, fig. 1) <br>
+ * 
+ * <p>
+ *-    &lt;distinguishedName&gt;      ::= &lt;name&gt; | e <br>
+ *-    &lt;name&gt;                   ::= &lt;name-component&gt; &lt;name-components&gt;
<br>
+ *-    &lt;name-components&gt;        ::= &lt;spaces&gt; &lt;separator&gt;
&lt;spaces&gt; &lt;name-component&gt; &lt;name-components&gt; | e
<br>
+ *-    &lt;name-component&gt;         ::= &lt;attributeType&gt; &lt;spaces&gt;
'=' &lt;spaces&gt; &lt;attributeValue&gt; &lt;attributeTypeAndValues&gt;
<br>
+ *-    &lt;attributeTypeAndValues&gt; ::= &lt;spaces&gt; '+' &lt;spaces&gt;
&lt;attributeType&gt; &lt;spaces&gt; '=' &lt;spaces&gt; &lt;attributeValue&gt;
&lt;attributeTypeAndValues&gt; | e <br>
+ *-    &lt;attributeType&gt;          ::= [a-zA-Z] &lt;keychars&gt; | &lt;oidPrefix&gt;
[0-9] &lt;digits&gt; &lt;oids&gt; | [0-9] &lt;digits&gt; &lt;oids&gt;
<br>
+ *-    &lt;keychars&gt;               ::= [a-zA-Z] &lt;keychars&gt; | [0-9]
&lt;keychars&gt; | '-' &lt;keychars&gt; | e <br>
+ *-    &lt;oidPrefix&gt;              ::= 'OID.' | 'oid.' | e <br>
+ *-    &lt;oids&gt;                   ::= '.' [0-9] &lt;digits&gt; &lt;oids&gt;
| e <br>
+ *-    &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>
+ *-    &lt;pairchar&gt;               ::= ',' | '=' | '+' | '&lt;' | '&gt;'
| '#' | ';' | '\' | '"' | [0-9a-fA-F] [0-9a-fA-F]  <br>
+ *-    &lt;hexstring&gt;              ::= [0-9a-fA-F] [0-9a-fA-F] &lt;hexpairs&gt;
<br>
+ *-    &lt;hexpairs&gt;               ::= [0-9a-fA-F] [0-9a-fA-F] &lt;hexpairs&gt;
| e <br>
+ *-    &lt;digits&gt;                 ::= [0-9] &lt;digits&gt; | e <br>
+ *-    &lt;stringchar&gt;             ::= [0x00-0xFF] - [,=+&lt;&gt;#;\"\n\r]
<br>
+ *-    &lt;quotechar&gt;              ::= [0x00-0xFF] - [\"] <br>
+ *-    &lt;separator&gt;              ::= ',' | ';' <br>
+ *-    &lt;spaces&gt;                 ::= ' ' &lt;spaces&gt; | e <br>
+ * </p>
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class DNParser
+{
+    public static void parse( String dn, List rdns ) throws InvalidNameException
+    {
+        // We won't decode the LdapDN using the bytes.
+        char[] chars = dn.trim().toCharArray();
+        
+        if ( chars.length == 0 )
+        {
+            // Wa have an empty DN, just get out of the function.
+            return;
+        }
+        
+        int pos = 0;
+        LdapRDN rdn = new LdapRDN();
+
+        // <name>             ::= <name-component> <name-components>
+        // <name-components> ::= <spaces> <separator> <spaces> <name-component>
<name-components> | e
+        if ( ( pos = RDNParser.parse( chars, pos, rdn ) ) != DNUtils.PARSING_ERROR )
+        {
+            do
+            {
+                rdns.add( rdn.clone() );
+                rdn.clear();
+
+                if ( ( StringUtils.isCharASCII( chars, pos, ',' ) == false ) &&
+                     ( StringUtils.isCharASCII( chars, pos, ';' ) == false ) )
+                {
+
+                    break;
+                }
+
+                chars[pos] = ',';
+                pos++;
+
+                //pos = StringUtils.trimLeft( chars, pos );
+            }
+            while ( ( pos = RDNParser.parse( chars, pos, rdn ) ) != DNUtils.PARSING_ERROR
);
+        }
+        else
+        {
+            throw new InvalidNameException( "Bad DN : " + new String( chars ) );
+        }
+    }
+}



Mime
View raw message