FileDocCategorySizeDatePackage
Rfc2253Parser.javaAPI DocJava SE 5 API5628Fri Aug 26 14:57:40 BST 2005javax.naming.ldap

Rfc2253Parser

public final class Rfc2253Parser extends Object

Fields Summary
private final String
name
private final char[]
chars
private final int
len
private int
cur
Constructors Summary
Rfc2253Parser(String name)

	// index of first unconsumed char in "chars"

	/*
	 * Given an LDAP DN in string form, returns a parser for it.
	 */
	  
	    this.name = name;
	    len = name.length();
	    chars = name.toCharArray();
	
Methods Summary
private booleanatTerminator()

	    return (cur < len &&
		    (chars[cur] == '," ||
			chars[cur] == ';" ||
			chars[cur] == '+"));
	
private voidconsumeWhitespace()

	    while ((cur < len) && isWhitespace(chars[cur])) {
		++cur;
	    }
	
private javax.naming.ldap.RdndoParse(javax.naming.ldap.Rdn rdn)


	    while (cur < len) {
		consumeWhitespace();
		String attrType = parseAttrType();
		consumeWhitespace();
		if (cur >= len || chars[cur] != '=") {
		    throw new InvalidNameException("Invalid name: " + name);
		}
		++cur;		// consume '='
		consumeWhitespace();
		String value = parseAttrValue();
		consumeWhitespace();

		rdn.put(attrType, Rdn.unescapeValue(value));
		if (cur >= len || chars[cur] != '+") {
		    break;
		}
		++cur;		// consume '+'
	    }
	    rdn.sort();
	    return rdn;
	
private static booleanisWhitespace(char c)

	    return (c == ' " || c == '\r");
        
private java.lang.StringparseAttrType()


	    final int beg = cur;
	    while (cur < len) {
		char c = chars[cur];
		if (Character.isLetterOrDigit(c) ||
			c == '." ||
			c == '-" ||
			c == ' ") {
		    ++cur;
		} else {
		    break;
		}
	    }
	    // Back out any trailing spaces.
	    while ((cur > beg) && (chars[cur - 1] == ' ")) {
		--cur;
	    }

	    if (beg == cur) {
		throw new InvalidNameException("Invalid name: " + name);
	    }
	    return new String(chars, beg, cur - beg);
	
private java.lang.StringparseAttrValue()


	    if (cur < len && chars[cur] == '#") {
		return parseBinaryAttrValue();
	    } else if (cur < len && chars[cur] == '"") {
		return parseQuotedAttrValue();
	    } else {
		return parseStringAttrValue();
	    }
	
private java.lang.StringparseBinaryAttrValue()

	    final int beg = cur;
	    ++cur;			// consume '#'
	    while ((cur < len) &&
		    Character.isLetterOrDigit(chars[cur])) {
		++cur;
	    }
	    return new String(chars, beg, cur - beg);
	
java.util.ListparseDn()

	    cur = 0;

	    // ArrayList<Rdn> rdns =
	    //	new ArrayList<Rdn>(len / 3 + 10);  // leave room for growth

	    ArrayList rdns =
		new ArrayList(len / 3 + 10);  // leave room for growth

	    if (len == 0) {
		return rdns;
	    }

	    rdns.add(doParse(new Rdn()));
	    while (cur < len) {
		if (chars[cur] == '," || chars[cur] == ';") {
		    ++cur;
		    rdns.add(0, doParse(new Rdn()));
		} else {
		    throw new InvalidNameException("Invalid name: " + name);
		}
	    }
	    return rdns;
	
private java.lang.StringparseQuotedAttrValue()


	    final int beg = cur;
	    ++cur;			// consume '"'

	    while ((cur < len) && chars[cur] != '"") {
		if (chars[cur] == '\\") {
		    ++cur;		// consume backslash, then what follows
		}
		++cur;
	    }
	    if (cur >= len) {	// no closing quote
		throw new InvalidNameException("Invalid name: " + name);
	    }
	    ++cur;	// consume closing quote

	    return new String(chars, beg, cur - beg);
	
javax.naming.ldap.RdnparseRdn()

	    return parseRdn(new Rdn());
	
javax.naming.ldap.RdnparseRdn(javax.naming.ldap.Rdn rdn)

	    rdn = doParse(rdn);
	    if (cur < len) {
		throw new InvalidNameException("Invalid RDN: " + name);
	    }
	    return rdn;
	
private java.lang.StringparseStringAttrValue()


	    final int beg = cur;
	    int esc = -1;	// index of the most recently escaped character

	    while ((cur < len) && !atTerminator()) {
		if (chars[cur] == '\\") {
		    ++cur;		// consume backslash, then what follows
		    esc = cur;
		}
		++cur;
	    }
	    if (cur > len) {		// 'twas backslash followed by nothing
		throw new InvalidNameException("Invalid name: " + name);
	    }

	    // Trim off (unescaped) trailing whitespace.
	    int end;
	    for (end = cur; end > beg; end--) {
		if (!isWhitespace(chars[end - 1]) || (esc == end - 1)) {
		    break;
		}
	    }
	    return new String(chars, beg, end - beg);