Java Code Examples for org.apache.directory.api.util.Strings#isCharASCII()

The following examples show how to use org.apache.directory.api.util.Strings#isCharASCII() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AttributeUtils.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Parse attribute's options :
 * 
 * <pre>
 * options = *( ';' option )
 * option = 1*keychar
 * keychar = 'a'-z' | 'A'-'Z' / '0'-'9' / '-'
 * </pre>
 * 
 * @param str The parsed option
 * @param pos The position in the parsed option string
 * @exception ParseException The parsed option is invalid
 */
private static void parseOptions( char[] str, Position pos ) throws ParseException
{
    while ( Strings.isCharASCII( str, pos.start, ';' ) )
    {
        pos.start++;

        // We have an option
        if ( !Chars.isAlphaDigitMinus( str, pos.start ) )
        {
            // We must have at least one keychar
            throw new ParseException( I18n.err( I18n.ERR_13201_EMPTY_OPTION_NOT_ALLOWED ), pos.start );
        }

        pos.start++;

        while ( Chars.isAlphaDigitMinus( str, pos.start ) )
        {
            pos.start++;
        }
    }
}
 
Example 2
Source File: AttributeUtils.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Parse attribute's options :
 * 
 * <pre>
 * options = *( ';' option )
 * option = 1*keychar
 * keychar = 'a'-z' | 'A'-'Z' / '0'-'9' / '-'
 * </pre>
 * 
 * @param bytes The parsed option
 * @param pos The position in the parsed option bytes
 * @exception ParseException The parsed option is invalid
 */
private static void parseOptions( byte[] bytes, Position pos ) throws ParseException
{
    while ( Strings.isCharASCII( bytes, pos.start, ';' ) )
    {
        pos.start++;

        // We have an option
        if ( !Chars.isAlphaDigitMinus( bytes, pos.start ) )
        {
            // We must have at least one keychar
            throw new ParseException( I18n.err( I18n.ERR_13201_EMPTY_OPTION_NOT_ALLOWED ), pos.start );
        }

        pos.start++;

        while ( Chars.isAlphaDigitMinus( bytes, pos.start ) )
        {
            pos.start++;
        }
    }
}
 
Example 3
Source File: AttributeUtils.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Parse an OID.
 *
 * numericoid = number 1*( '.' number )
 * number = '0'-'9' / ( '1'-'9' 1*'0'-'9' )
 *
 * @param str The OID to parse
 * @param pos The current position in the string
 * @throws ParseException If we don't have a valid OID
 */
private static void parseOID( char[] str, Position pos ) throws ParseException
{
    // We have an OID
    parseNumber( str, pos );

    // We must have at least one '.' number
    if ( !Strings.isCharASCII( str, pos.start, '.' ) )
    {
        throw new ParseException( I18n.err( I18n.ERR_13221_INVALID_OID_MISSING_DOT ), pos.start );
    }

    pos.start++;

    if ( !parseNumber( str, pos ) )
    {
        throw new ParseException( I18n.err( I18n.ERR_13202_INVALID_OID_MISSING_NUMBER ), pos.start );
    }

    while ( true )
    {
        // Break if we get something which is not a '.'
        if ( !Strings.isCharASCII( str, pos.start, '.' ) )
        {
            break;
        }

        pos.start++;

        if ( !parseNumber( str, pos ) )
        {
            throw new ParseException( I18n.err( I18n.ERR_13202_INVALID_OID_MISSING_NUMBER ), pos.start );
        }
    }
}
 
Example 4
Source File: AttributeUtils.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Parse an OID.
 *
 * numericoid = number 1*( '.' number )
 * number = '0'-'9' / ( '1'-'9' 1*'0'-'9' )
 *
 * @param bytes The OID to parse
 * @param pos The current position in the string
 * @throws ParseException If we don't have a valid OID
 */
private static void parseOID( byte[] bytes, Position pos ) throws ParseException
{
    // We have an OID
    parseNumber( bytes, pos );

    // We must have at least one '.' number
    if ( !Strings.isCharASCII( bytes, pos.start, '.' ) )
    {
        throw new ParseException( I18n.err( I18n.ERR_13221_INVALID_OID_MISSING_DOT ), pos.start );
    }

    pos.start++;

    if ( !parseNumber( bytes, pos ) )
    {
        throw new ParseException( I18n.err( I18n.ERR_13202_INVALID_OID_MISSING_NUMBER ), pos.start );
    }

    while ( true )
    {
        // Break if we get something which is not a '.'
        if ( !Strings.isCharASCII( bytes, pos.start, '.' ) )
        {
            break;
        }

        pos.start++;

        if ( !parseNumber( bytes, pos ) )
        {
            throw new ParseException( I18n.err( I18n.ERR_13202_INVALID_OID_MISSING_NUMBER ), pos.start );
        }
    }
}
 
Example 5
Source File: ObjectIdentifierFirstComponentComparator.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Get the OID from the SchemaObject description
 * 
 * @param s The string cntaining the OID
 * @return The found OID
 */
private String getNumericOid( String s )
{
    // Get the OID from the strings now
    int pos = 0;

    if ( !Strings.isCharASCII( s, pos++, '(' ) )
    {
        return null;
    }

    while ( Strings.isCharASCII( s, pos, ' ' ) )
    {
        pos++;
    }

    int start = pos;

    while ( Chars.isDigit( s, pos ) || Strings.isCharASCII( s, pos, '.' ) )
    {
        pos++;
    }

    String numericOid = s.substring( start, pos );

    if ( Oid.isOid( numericOid ) )
    {
        return numericOid;
    }
    else
    {
        return null;
    }
}
 
Example 6
Source File: FilterParser.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Skip the white spaces (0x20, 0x09, 0x0a and 0x0d)
 * 
 * @param filter The filter being parsed
 * @param pos The current position in the filter
 */
private static void skipWhiteSpaces( byte[] filter, Position pos )
{
    while ( Strings.isCharASCII( filter, pos.start, ' ' )
            || Strings.isCharASCII( filter, pos.start, '\t' )
            || Strings.isCharASCII( filter, pos.start, '\n' ) )
    {
        pos.start++;
    }
}
 
Example 7
Source File: BitStringSyntaxChecker.java    From directory-ldap-api with Apache License 2.0 4 votes vote down vote up
/**
 * A shared and static method used to check that the string is a BitString.
 * A BitString is a string of bits, between quotes and followed by a 'B' :
 * 
 * '01010110'B for instance
 * 
 * @param strValue The string to check
 * @return <code>true</code> if the string is a BitString
 */
public static boolean isValid( String strValue )
{
    if ( strValue.length() == 0 )
    {
        if ( LOG.isDebugEnabled() )
        {
            LOG.debug( I18n.err( I18n.ERR_13210_SYNTAX_INVALID, strValue ) );
        }
        
        return false;
    }

    int pos = 0;

    // Check that the String respect the syntax : ' ([01]+) ' B
    if ( !Strings.isCharASCII( strValue, pos++, '\'' ) )
    {
        if ( LOG.isDebugEnabled() )
        {
            LOG.debug( I18n.err( I18n.ERR_13210_SYNTAX_INVALID, strValue ) );
        }
        
        return false;
    }

    // We must have at least one bit
    if ( !Chars.isBit( strValue, pos++ ) )
    {
        if ( LOG.isDebugEnabled() )
        {
            LOG.debug( I18n.err( I18n.ERR_13210_SYNTAX_INVALID, strValue ) );
        }
        
        return false;
    }

    while ( Chars.isBit( strValue, pos ) )
    {
        // Loop until we get a char which is not a 0 or a 1
        pos++;
    }

    // Now, we must have a simple quote 
    if ( !Strings.isCharASCII( strValue, pos++, '\'' ) )
    {
        if ( LOG.isDebugEnabled() )
        {
            LOG.debug( I18n.err( I18n.ERR_13210_SYNTAX_INVALID, strValue ) );
        }
        
        return false;
    }

    // followed by a 'B'
    if ( !Strings.isCharASCII( strValue, pos, 'B' ) )
    {
        if ( LOG.isDebugEnabled() )
        {
            LOG.debug( I18n.err( I18n.ERR_13210_SYNTAX_INVALID, strValue ) );
        }
        
        return false;
    }

    if ( LOG.isDebugEnabled() )
    {
        LOG.debug( I18n.msg( I18n.MSG_13701_SYNTAX_VALID, strValue ) );
    }
    
    return true;
}
 
Example 8
Source File: FilterParser.java    From directory-ldap-api with Apache License 2.0 4 votes vote down vote up
/**
 * Parse a substring
 * 
 * @param schemaManager The {@link SchemaManager}
 * @param attribute The filter's attribute
 * @param initial The filter's initial part
 * @param filterBytes The filter bytes to parse
 * @param pos The position in the filter bytes
 * @return the created {@link ExprNode}
 * @throws ParseException If the Node can't be parsed
 * @throws LdapException If we met an error while parsing a filter element
 */
private static ExprNode parseSubstring( SchemaManager schemaManager, String attribute, Value initial,
    byte[] filterBytes, Position pos ) throws ParseException, LdapException
{
    SubstringNode node;

    if ( schemaManager != null )
    {
        AttributeType attributeType = schemaManager.lookupAttributeTypeRegistry( attribute );

        if ( attributeType != null )
        {
            node = new SubstringNode( schemaManager.lookupAttributeTypeRegistry( attribute ) );
        }
        else
        {
            return null;
        }
    }
    else
    {
        node = new SubstringNode( attribute );
    }

    if ( ( initial != null ) && !initial.isNull() )
    {
        // We have a substring starting with a value : val*...
        // Set the initial value. It must be a String
        String initialStr = initial.getString();
        node.setInitial( initialStr );
    }

    if ( Strings.isCharASCII( filterBytes, pos.start, ')' ) )
    {
        // No any or final, we are done
        return node;
    }

    //
    while ( true )
    {
        Value assertionValue = parseAssertionValue( schemaManager, attribute, filterBytes, pos );

        // Is there anything else but a ')' after the value ?
        if ( Strings.isCharASCII( filterBytes, pos.start, ')' ) )
        {
            // Nope : as we have had [initial] '*' (any '*' ) *,
            // this is the final
            if ( !assertionValue.isNull() )
            {
                String finalStr = assertionValue.getString();
                node.setFinal( finalStr );
            }

            return node;
        }
        else if ( Strings.isCharASCII( filterBytes, pos.start, '*' ) )
        {
            // We have a '*' : it's an any
            // If the value is empty, that means we have more than
            // one consecutive '*' : do nothing in this case.
            if ( !assertionValue.isNull() )
            {
                String anyStr = assertionValue.getString();
                node.addAny( anyStr );
            }

            pos.start++;

            // Skip any following '*'
            while ( Strings.isCharASCII( filterBytes, pos.start, '*' ) )
            {
                pos.start++;
            }

            // that may have been the closing '*'
            if ( Strings.isCharASCII( filterBytes, pos.start, ')' ) )
            {
                return node;
            }

        }
        else
        {
            // This is an error
            throw new ParseException( I18n.err( I18n.ERR_13309_BAD_SUBSTRING ), pos.start );
        }
    }
}
 
Example 9
Source File: FilterParser.java    From directory-ldap-api with Apache License 2.0 4 votes vote down vote up
/**
 * Parse the grammar rule :
 * <pre>
 * filter ::= WSP* '(' WSP* filterComp WSP* ')' WSP*
 * </pre>
 * 
 * @param schemaManager The {@link SchemaManager}
 * @param filterBytes The filter bytes to parse
 * @param pos The position in the filter bytes
 * @param relaxed If the filter is analyzed in relaxed mode or not
 * @return the created {@link ExprNode}
 * @throws ParseException If the Node can't be parsed
 * @throws LdapException If we met an error while parsing a filter element
 */
private static ExprNode parseFilterInternal( SchemaManager schemaManager, byte[] filterBytes, Position pos,
    boolean relaxed ) throws ParseException, LdapException
{
    // Skip spaces
    skipWhiteSpaces( filterBytes, pos );
    
    // Check for the left '('
    if ( !Strings.isCharASCII( filterBytes, pos.start, '(' ) )
    {
        // No more node, get out
        if ( ( pos.start == 0 ) && ( pos.length != 0 ) )
        {
            throw new ParseException( I18n.err( I18n.ERR_13314_FILTER_MISSING_OPEN_PAR ), 0 );
        }
        else
        {
            return UndefinedNode.UNDEFINED_NODE;
        }
    }

    pos.start++;

    // Skip spaces
    skipWhiteSpaces( filterBytes, pos );
    
    // parse the filter component
    ExprNode node = parseFilterComp( schemaManager, filterBytes, pos, relaxed );

    if ( node == UndefinedNode.UNDEFINED_NODE )
    {
        return UndefinedNode.UNDEFINED_NODE;
    }

    // Skip spaces
    skipWhiteSpaces( filterBytes, pos );
    
    // Check that we have a right ')'
    if ( !Strings.isCharASCII( filterBytes, pos.start, ')' ) )
    {
        throw new ParseException( I18n.err( I18n.ERR_13315_FILTER_MISSING_CLOSE_PAR ), pos.start );
    }

    pos.start++;

    // Skip spaces
    skipWhiteSpaces( filterBytes, pos );
    
    return node;
}