Class ParserUtil
java.lang.Object
org.apache.directory.api.util.ParserUtil
An utility class used when parsing some of LDAP elements
- Author:
- Apache Directory Project
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final charThe various found charactersstatic final charstatic final charstatic final charstatic final charstatic final StringA terminaison token.static final charstatic final charstatic final charstatic final charstatic final charstatic final charstatic final booleanstatic final charstatic final charstatic final charstatic final charstatic final charstatic final charstatic final charstatic final charstatic final charstatic final charstatic final booleanDefine two constants for optional or mandatory elements -
Method Summary
Modifier and TypeMethodDescriptionstatic StringgetDollarToken(String str, Position pos) Get a token (which is a suite of alphabetic or dash characters prefixed with a '$'static StringGet a token (which is a suite of alphabetic or dash charactersstatic booleanhasMoreChars(Position pos) Checks if there are more characters.static booleanisMatchChar(byte c, Position pos) Check if a specific character is present at the current position in the string.static booleanisMatchChar(String str, char c, Position pos) Check if a specific character is present at the current position in the string.static voidMatch a specific character at the current position in the string.static voidMatch a specific character at the current position in the string.static StringparseDescr(String str, Position pos) Parse the Descr, following this grammar:static intparseInteger(String str, Position pos) Parse an integerstatic StringparseNumericOid(String str, Position pos) Parse a Numeric OID, which grammar is:static StringParse an oid.static StringparseQuotedSafeUtf8(String str, Position pos) Parse a DistinguishedName, following this grammar:static booleanskipComment(String str, Position pos) Skip any comments at the beginning of a stringstatic booleanskipSpaces(String str, Position pos, boolean optional) Skip spaces at the current position of the string.
-
Field Details
-
ZERO_N
public static final boolean ZERO_NDefine two constants for optional or mandatory elements- See Also:
-
ONE_N
public static final boolean ONE_N- See Also:
-
COLON
public static final char COLONThe various found characters- See Also:
-
COMMA
public static final char COMMA- See Also:
-
DOLLAR
public static final char DOLLAR- See Also:
-
DOT
public static final char DOT- See Also:
-
DQUOTE
public static final char DQUOTE- See Also:
-
EQUAL
public static final char EQUAL- See Also:
-
ESC
public static final char ESC- See Also:
-
HYPHEN
public static final char HYPHEN- See Also:
-
LANGLE
public static final char LANGLE- See Also:
-
LCURLY
public static final char LCURLY- See Also:
-
LPAREN
public static final char LPAREN- See Also:
-
PLUS
public static final char PLUS- See Also:
-
RANGLE
public static final char RANGLE- See Also:
-
RCURLY
public static final char RCURLY- See Also:
-
RPAREN
public static final char RPAREN- See Also:
-
SEMI_COLON
public static final char SEMI_COLON- See Also:
-
SEP
public static final char SEP- See Also:
-
SHARP
public static final char SHARP- See Also:
-
SPACE
public static final char SPACE- See Also:
-
USCORE
public static final char USCORE- See Also:
-
ZERO
public static final char ZERO- See Also:
-
END
-
-
Method Details
-
hasMoreChars
Checks if there are more characters.- Parameters:
pos- the pos- Returns:
trueif more characters are available
-
skipSpaces
Skip spaces at the current position of the string. It may require a first space to be present, or not.- Parameters:
str- The string to processpos- The current position in the stringoptional- A flag indication if at least one space must be present- Returns:
trueif some space were removed,falseotherwise
-
parseInteger
Parse an integerINTEGER: DIGIT | ( LDIGIT ( DIGIT )+ ) DIGIT: '0' | LDIGIT LDIGIT: '1'..'9'
- Parameters:
str- The string to processpos- The current position in the string- Returns:
- The parsed integer
- Throws:
ParseException- If the parsed integer overflows (2^32-1) or we don't have any digit
-
skipComment
-
matchChar
Match a specific character at the current position in the string. If present, move forward the current position.- Parameters:
str- The string to processc- The expected characterpos- The current position in the string- Throws:
ParseException- If the required character is not found at current position
-
matchChar
Match a specific character at the current position in the string. If present, move forward the current position.- Parameters:
bytes- The byte[] to processb- The expected bytepos- The current position in the string- Throws:
ParseException- If the required character is not found at current position
-
isMatchChar
Check if a specific character is present at the current position in the string. If the character is found, the position will be moved forward.- Parameters:
str- The string to processc- The expected characterpos- The current position in the string- Returns:
trueif the character is present at the current position,falseif the character is not present or if we are at the end of the string.
-
isMatchChar
Check if a specific character is present at the current position in the string. If the character is found, the position will be moved forward.- Parameters:
c- The expected characterpos- The current position in the string- Returns:
trueif the character is present at the current position,falseif the character is not present or if we are at the end of the string.
-
parseNumericOid
Parse a Numeric OID, which grammar is:DIGIT = %x30 / LDIGIT ; "0"-"9" LDIGIT = %x31-39 ; "1"-"9" DOT = %x2E ; period (".") number = DIGIT / ( LDIGIT 1*DIGIT ) numericoid = number 1*( DOT number )- Parameters:
str- The string to parsepos- The current position in the string- Returns:
- The parsed NumericOid
-
getDollarToken
-
getToken
-
parseDescr
Parse the Descr, following this grammar:ALPHA = %x41-5A / %x61-7A ; "A"-"Z" / "a"-"z" DIGIT = %x30 / LDIGIT ; "0"-"9" LDIGIT = %x31-39 ; "1"-"9" HYPHEN = %x2D ; hyphen ("-") keychar = ALPHA / DIGIT / HYPHEN leadkeychar = ALPHA keystring = leadkeychar *keychar descr = keystring- Parameters:
str- The str to parsepos- The current position in the string- Returns:
- The found descr
- Throws:
ParseException- If there is a missing starting or ending quote, or if the descr is wrong
-
parseOid
Parse an oid. It follows this grammar:numericoid = number 1*( DOT number ) number = DIGIT / ( LDIGIT 1*DIGIT ) DIGIT = %x30 / LDIGIT ; "0"-"9" LDIGIT = %x31-39 ; "1"-"9" descr = keystring keystring = leadkeychar *keychar leadkeychar = ALPHA keychar = ALPHA / DIGIT / HYPHEN ALPHA = %x41-5A / %x61-7A ; "A"-"Z" / "a"-"z" DIGIT = %x30 / LDIGIT ; "0"-"9" HYPHEN = %x2D ; hyphen ("-") oid = descr / numericoidThe only difference between a descr and a OID is that descr starts with a letter while an OID starts with a digit.- Parameters:
str- The schema to parsepos- The current position in the schema- Returns:
- The found oid
- Throws:
ParseException- If the oid is incorrect
-
parseQuotedSafeUtf8
Parse a DistinguishedName, following this grammar:StringValue = dquote *SafeUTF8Character dquote dquote = %x22 ; " (double quote) SafeUTF8Character = %x00-21 / %x23-7F / ; ASCII minus dquote dquote dquote / ; escaped double quote %xC0-DF %x80-BF / ; 2 byte UTF-8 character %xE0-EF 2(%x80-BF) / ; 3 byte UTF-8 character %xF0-F7 3(%x80-BF) ; 4 byte UTF-8 character- Parameters:
str- The string to parsepos- The current position in the string- Returns:
- The found DN string
- Throws:
ParseException- If there is a missing starting or ending dquote, or if the DN is incorrect
-