org.apache.directory.shared.ldap.util
Class DNUtils

java.lang.Object
  extended by org.apache.directory.shared.ldap.util.DNUtils

public class DNUtils
extends java.lang.Object

Utility class used by the LdapDN Parser.

Version:
$Rev: 686082 $, $Date: 2008-08-15 01:12:09 +0200 (Fr, 15 Aug 2008) $
Author:
Apache Directory Project

Field Summary
static int BAD_HEX_PAIR
          If an hex pair contains only one char, this value is returned
static java.lang.String OID_LOWER
          "oid." static
static java.lang.String OID_UPPER
          "OID." static
static int ONE_BYTE
          A constant representing one byte length
static int ONE_CHAR
          A constant representing one char length
static int PARSING_ERROR
          A value if we got an error while parsing
static int PARSING_OK
          A value if we got a correct parsing
static int TWO_BYTES
          A constant representing two bytes length
static int TWO_CHARS
          A constant representing two chars length
 
Constructor Summary
DNUtils()
           
 
Method Summary
static int countPairChar(byte[] bytes, int index)
          Check if the current character is a Pair Char <pairchar> ::= ' ' | ',' | '=' | '+' | '<' | '>' | '#' | ';' | '\' | '"' | [0-9a-fA-F] [0-9a-fA-F]
static int isAciiStringChar(byte[] bytes, int index)
          Check if the current character is an ascii String Char.
static boolean isLUTF1(byte[] bytes, int index)
          Check if the current character is a LUTF1 (Lead UTF ascii char)
<LUTF1> ::= 0x01-1F | 0x21 | 0x24-2A | 0x2D-3A | 0x3D | 0x3F-5B | 0x5D-7F
static boolean isPairChar(byte[] bytes, int index)
          Check if the current character is a Pair Char <pairchar> ::= ' ' | ',' | '=' | '+' | '<' | '>' | '#' | ';' | '\' | '"' | [0-9a-fA-F] [0-9a-fA-F]
static boolean isPairCharOnly(char c)
          Check if the given char is a pair char only <pairCharOnly> ::= ' ' | ',' | '=' | '+' | '<' | '>' | '#' | ';' | '\' | '"'
static int isQuoteChar(byte[] bytes, int index)
          Check if the current character is a Quote Char We are testing Unicode chars <quotechar> ::= [0x00-0xFFFF] - [\"]
static int isStringChar(byte[] bytes, int index)
          Check if the current character is a String Char.
static boolean isSUTF1(byte[] bytes, int index)
          Check if the current character is a SUTF1 (Stringchar UTF ascii char)
<LUTF1> ::= 0x01-20 | 0x23-2A | 0x2D-3A | 0x3D | 0x3F-5B | 0x5D-7F
static int parseAlphaASCII(byte[] bytes, int index)
          Walk the buffer while characters are Alpha characters : <alpha> ::= [0x41-0x5A] | [0x61-0x7A]
static int parseBase64String(byte[] bytes, int index)
          Walk the buffer while characters are Base64 characters : <base64-string> ::= <base64-char> <base64-chars> <base64-chars> ::= <base64-char> <base64-chars> | <base64-char> ::= 0x2B | 0x2F | [0x30-0x39] | 0x3D | [0x41-0x5A] | [0x61-0x7A]
static int parseHexPair(byte[] bytes, int index)
          Parse an hex pair <hexpair> ::= <hex> <hex>
static int parseHexString(byte[] bytes, byte[] hex, Position pos)
          Parse an hex string, which is a list of hex pairs <hexstring> ::= <hexpair> <hexpairs> <hexpairs> ::= <hexpair> <hexpairs> | e
static int parseHexString(byte[] bytes, int index)
          Parse an hex string, which is a list of hex pairs <hexstring> ::= <hexpair> <hexpairs> <hexpairs> ::= <hexpair> <hexpairs> | e
static int parseSafeString(byte[] bytes, int index)
          Walk the buffer while characters are Safe String characters : <safe-string> ::= <safe-init-char> <safe-chars> <safe-init-char> ::= [0x01-0x09] | 0x0B | 0x0C | [0x0E-0x1F] | [0x21-0x39] | 0x3B | [0x3D-0x7F] <safe-chars> ::= <safe-char> <safe-chars> | <safe-char> ::= [0x01-0x09] | 0x0B | 0x0C | [0x0E-0x7F]
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PARSING_ERROR

public static final int PARSING_ERROR
A value if we got an error while parsing

See Also:
Constant Field Values

PARSING_OK

public static final int PARSING_OK
A value if we got a correct parsing

See Also:
Constant Field Values

BAD_HEX_PAIR

public static final int BAD_HEX_PAIR
If an hex pair contains only one char, this value is returned

See Also:
Constant Field Values

ONE_CHAR

public static final int ONE_CHAR
A constant representing one char length

See Also:
Constant Field Values

TWO_CHARS

public static final int TWO_CHARS
A constant representing two chars length

See Also:
Constant Field Values

ONE_BYTE

public static final int ONE_BYTE
A constant representing one byte length

See Also:
Constant Field Values

TWO_BYTES

public static final int TWO_BYTES
A constant representing two bytes length

See Also:
Constant Field Values

OID_LOWER

public static final java.lang.String OID_LOWER
"oid." static

See Also:
Constant Field Values

OID_UPPER

public static final java.lang.String OID_UPPER
"OID." static

See Also:
Constant Field Values
Constructor Detail

DNUtils

public DNUtils()
Method Detail

parseSafeString

public static int parseSafeString(byte[] bytes,
                                  int index)
Walk the buffer while characters are Safe String characters : <safe-string> ::= <safe-init-char> <safe-chars> <safe-init-char> ::= [0x01-0x09] | 0x0B | 0x0C | [0x0E-0x1F] | [0x21-0x39] | 0x3B | [0x3D-0x7F] <safe-chars> ::= <safe-char> <safe-chars> | <safe-char> ::= [0x01-0x09] | 0x0B | 0x0C | [0x0E-0x7F]

Parameters:
bytes - The buffer which contains the data
index - Current position in the buffer
Returns:
The position of the first character which is not a Safe Char

parseAlphaASCII

public static int parseAlphaASCII(byte[] bytes,
                                  int index)
Walk the buffer while characters are Alpha characters : <alpha> ::= [0x41-0x5A] | [0x61-0x7A]

Parameters:
bytes - The buffer which contains the data
index - Current position in the buffer
Returns:
The position of the first character which is not an Alpha Char

isLUTF1

public static boolean isLUTF1(byte[] bytes,
                              int index)
Check if the current character is a LUTF1 (Lead UTF ascii char)
<LUTF1> ::= 0x01-1F | 0x21 | 0x24-2A | 0x2D-3A | 0x3D | 0x3F-5B | 0x5D-7F

Parameters:
bytes - The buffer containing the data
index - Current position in the buffer
Returns:
true if the current character is a LUTF1

isSUTF1

public static boolean isSUTF1(byte[] bytes,
                              int index)
Check if the current character is a SUTF1 (Stringchar UTF ascii char)
<LUTF1> ::= 0x01-20 | 0x23-2A | 0x2D-3A | 0x3D | 0x3F-5B | 0x5D-7F

Parameters:
bytes - The buffer containing the data
index - Current position in the buffer
Returns:
true if the current character is a SUTF1

isPairCharOnly

public static boolean isPairCharOnly(char c)
Check if the given char is a pair char only <pairCharOnly> ::= ' ' | ',' | '=' | '+' | '<' | '>' | '#' | ';' | '\' | '"'

Parameters:
c - the char we want to test
Returns:
true if the char is a pair char only

isPairChar

public static boolean isPairChar(byte[] bytes,
                                 int index)
Check if the current character is a Pair Char <pairchar> ::= ' ' | ',' | '=' | '+' | '<' | '>' | '#' | ';' | '\' | '"' | [0-9a-fA-F] [0-9a-fA-F]

Parameters:
bytes - The buffer which contains the data
index - Current position in the buffer
Returns:
true if the current character is a Pair Char

countPairChar

public static int countPairChar(byte[] bytes,
                                int index)
Check if the current character is a Pair Char <pairchar> ::= ' ' | ',' | '=' | '+' | '<' | '>' | '#' | ';' | '\' | '"' | [0-9a-fA-F] [0-9a-fA-F]

Parameters:
bytes - The byte array which contains the data
index - Current position in the byte array
Returns:
true if the current byte is a Pair Char

isStringChar

public static int isStringChar(byte[] bytes,
                               int index)
Check if the current character is a String Char. Chars are Unicode, not ASCII. <stringchar> ::= [0x00-0xFFFF] - [,=+<>#;\"\n\r]

Parameters:
bytes - The buffer which contains the data
index - Current position in the buffer
Returns:
The current char if it is a String Char, or '#' (this is simpler than throwing an exception :)

isAciiStringChar

public static int isAciiStringChar(byte[] bytes,
                                   int index)
Check if the current character is an ascii String Char.

<asciistringchar> ::= [0x00-0x7F] - [,=+<>#;\"\n\r]

Parameters:
bytes - The buffer which contains the data
index - Current position in the buffer
Returns:
The current char if it is a String Char, or '#' (this is simpler than throwing an exception :)

isQuoteChar

public static int isQuoteChar(byte[] bytes,
                              int index)
Check if the current character is a Quote Char We are testing Unicode chars <quotechar> ::= [0x00-0xFFFF] - [\"]

Parameters:
bytes - The buffer which contains the data
index - Current position in the buffer
Returns:
true if the current character is a Quote Char

parseHexPair

public static int parseHexPair(byte[] bytes,
                               int index)
Parse an hex pair <hexpair> ::= <hex> <hex>

Parameters:
bytes - The buffer which contains the data
index - Current position in the buffer
Returns:
The new position, -1 if the buffer does not contain an HexPair, -2 if the buffer contains an hex byte but not two.

parseHexString

public static int parseHexString(byte[] bytes,
                                 int index)
Parse an hex string, which is a list of hex pairs <hexstring> ::= <hexpair> <hexpairs> <hexpairs> ::= <hexpair> <hexpairs> | e

Parameters:
bytes - The buffer which contains the data
index - Current position in the buffer
Returns:
Return the first position which is not an hex pair, or -1 if there is no hexpair at the beginning or if an hexpair is invalid (if we have only one hex instead of 2)

parseHexString

public static int parseHexString(byte[] bytes,
                                 byte[] hex,
                                 Position pos)
Parse an hex string, which is a list of hex pairs <hexstring> ::= <hexpair> <hexpairs> <hexpairs> ::= <hexpair> <hexpairs> | e

Parameters:
bytes - The byte array which contains the data
hex - The result as a byte array
pos - Current position in the string
Returns:
Return the first position which is not an hex pair, or -1 if there is no hexpair at the beginning or if an hexpair is invalid (if we have only one hex instead of 2)

parseBase64String

public static int parseBase64String(byte[] bytes,
                                    int index)
Walk the buffer while characters are Base64 characters : <base64-string> ::= <base64-char> <base64-chars> <base64-chars> ::= <base64-char> <base64-chars> | <base64-char> ::= 0x2B | 0x2F | [0x30-0x39] | 0x3D | [0x41-0x5A] | [0x61-0x7A]

Parameters:
bytes - The buffer which contains the data
index - Current position in the buffer
Returns:
The position of the first character which is not a Base64 Char


Copyright © 2003-2009 Apache Software Foundation. All Rights Reserved.