You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2005/10/09 15:41:15 UTC
svn commit: r307424 -
/directory/shared/ldap/trunk/apache2-provider/src/java/main/org/apache/asn1new/ldap/codec/primitives/DNParser.java
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>
+ *- <distinguishedName> ::= <name> | e <br>
+ *- <name> ::= <name-component> <name-components> <br>
+ *- <name-components> ::= <spaces> <separator> <spaces> <name-component> <name-components> | e <br>
+ *- <name-component> ::= <attributeType> <spaces> '=' <spaces> <attributeValue> <attributeTypeAndValues> <br>
+ *- <attributeTypeAndValues> ::= <spaces> '+' <spaces> <attributeType> <spaces> '=' <spaces> <attributeValue> <attributeTypeAndValues> | e <br>
+ *- <attributeType> ::= [a-zA-Z] <keychars> | <oidPrefix> [0-9] <digits> <oids> | [0-9] <digits> <oids> <br>
+ *- <keychars> ::= [a-zA-Z] <keychars> | [0-9] <keychars> | '-' <keychars> | e <br>
+ *- <oidPrefix> ::= 'OID.' | 'oid.' | e <br>
+ *- <oids> ::= '.' [0-9] <digits> <oids> | e <br>
+ *- <attributeValue> ::= <pairs-or-strings> | '#' <hexstring> |'"' <quotechar-or-pairs> '"' <br>
+ *- <pairs-or-strings> ::= '\' <pairchar> <pairs-or-strings> | <stringchar> <pairs-or-strings> | e <br>
+ *- <quotechar-or-pairs> ::= <quotechar> <quotechar-or-pairs> | '\' <pairchar> <quotechar-or-pairs> | e <br>
+ *- <pairchar> ::= ',' | '=' | '+' | '<' | '>' | '#' | ';' | '\' | '"' | [0-9a-fA-F] [0-9a-fA-F] <br>
+ *- <hexstring> ::= [0-9a-fA-F] [0-9a-fA-F] <hexpairs> <br>
+ *- <hexpairs> ::= [0-9a-fA-F] [0-9a-fA-F] <hexpairs> | e <br>
+ *- <digits> ::= [0-9] <digits> | e <br>
+ *- <stringchar> ::= [0x00-0xFF] - [,=+<>#;\"\n\r] <br>
+ *- <quotechar> ::= [0x00-0xFF] - [\"] <br>
+ *- <separator> ::= ',' | ';' <br>
+ *- <spaces> ::= ' ' <spaces> | 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 ) );
+ }
+ }
+}