Class ParserUtil

java.lang.Object
org.apache.directory.api.util.ParserUtil

public final class ParserUtil extends Object
An utility class used when parsing some of LDAP elements
Author:
Apache Directory Project
  • Field Details

  • Method Details

    • hasMoreChars

      public static boolean hasMoreChars(Position pos)
      Checks if there are more characters.
      Parameters:
      pos - the pos
      Returns:
      true if more characters are available
    • skipSpaces

      public static boolean skipSpaces(String str, Position pos, boolean optional)
      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 process
      pos - The current position in the string
      optional - A flag indication if at least one space must be present
      Returns:
      true if some space were removed, false otherwise
    • parseInteger

      public static int parseInteger(String str, Position pos) throws ParseException
      Parse an integer
        INTEGER: DIGIT | ( LDIGIT ( DIGIT )+ ) 
        DIGIT: '0' | LDIGIT 
        LDIGIT: '1'..'9'
      
      Parameters:
      str - The string to process
      pos - 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

      public static boolean skipComment(String str, Position pos)
      Skip any comments at the beginning of a string
      Parameters:
      str - The string to process
      pos - The current position in the string
      Returns:
      true if a comment has been removed, false otherwise
    • matchChar

      public static void matchChar(String str, char c, Position pos) throws ParseException
      Match a specific character at the current position in the string. If present, move forward the current position.
      Parameters:
      str - The string to process
      c - The expected character
      pos - The current position in the string
      Throws:
      ParseException - If the required character is not found at current position
    • matchChar

      public static void matchChar(byte[] bytes, byte b, Position pos) throws ParseException
      Match a specific character at the current position in the string. If present, move forward the current position.
      Parameters:
      bytes - The byte[] to process
      b - The expected byte
      pos - The current position in the string
      Throws:
      ParseException - If the required character is not found at current position
    • isMatchChar

      public static boolean isMatchChar(String str, char c, Position pos)
      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 process
      c - The expected character
      pos - The current position in the string
      Returns:
      true if the character is present at the current position, false if the character is not present or if we are at the end of the string.
    • isMatchChar

      public static boolean isMatchChar(byte c, Position pos)
      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 character
      pos - The current position in the string
      Returns:
      true if the character is present at the current position, false if the character is not present or if we are at the end of the string.
    • parseNumericOid

      public static String parseNumericOid(String str, Position pos)
      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 parse
      pos - The current position in the string
      Returns:
      The parsed NumericOid
    • getDollarToken

      public static String getDollarToken(String str, Position pos)
      Get a token (which is a suite of alphabetic or dash characters prefixed with a '$'
      Parameters:
      str - The string to parse
      pos - The current position in the string
      Returns:
      The found token
    • getToken

      public static String getToken(String schema, Position pos)
      Get a token (which is a suite of alphabetic or dash characters
      Parameters:
      schema - The schema to parse
      pos - The current position in the schema
      Returns:
      The found token
    • parseDescr

      public static String parseDescr(String str, Position pos) throws ParseException
      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 parse
      pos - 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

      public static String parseOid(String str, Position pos) throws ParseException
      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 / numericoid
      
      The 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 parse
      pos - The current position in the schema
      Returns:
      The found oid
      Throws:
      ParseException - If the oid is incorrect
    • parseQuotedSafeUtf8

      public static String parseQuotedSafeUtf8(String str, Position pos) throws ParseException
      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 parse
      pos - 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