private void parse()

in ldap/model/src/main/java/org/apache/directory/api/ldap/model/url/LdapUrl.java [198:363]


    private void parse( char[] chars ) throws LdapURLEncodingException
    {
        scheme = LDAP_SCHEME;
        host = null;
        port = -1;
        dn = null;
        attributes = new ArrayList<>();
        scope = SearchScope.OBJECT;
        filter = null;
        extensionList = new ArrayList<>( 2 );

        if ( ( chars == null ) || ( chars.length == 0 ) )
        {
            host = "";
            return;
        }

        // ldapurl = scheme "://" [hostport] ["/"
        // [dn ["?" [attributes] ["?" [scope]
        // ["?" [filter] ["?" extensions]]]]]]
        // scheme = "ldap"
        // The scheme (mandatory)
        int pos = Strings.areEquals( chars, 0, LDAP_SCHEME );
        
        if ( pos == StringConstants.NOT_EQUAL )
        {
            // Might be LDAPS
            pos = Strings.areEquals( chars, 0, LDAPS_SCHEME );
            
            if ( pos == StringConstants.NOT_EQUAL )
            {
                throw new LdapURLEncodingException( I18n.err( I18n.ERR_13030_LDAP_URL_MUST_START_WITH_LDAP ) );
            }
        }
        
        scheme = new String( chars, 0, pos );

        // The hostport, if it exists
        if ( pos == chars.length )
        {
            return;
        }
        
        pos = parseHostPort( chars, pos );
        
        if ( pos == INVALID )
        {
            throw new LdapURLEncodingException( I18n.err( I18n.ERR_13031_INVALID_HOST_PORT ) );
        }

        if ( pos == chars.length )
        {
            return;
        }

        // An optional '/'
        if ( !Chars.isCharASCII( chars, pos, '/' ) )
        {
            throw new LdapURLEncodingException( I18n.err( I18n.ERR_13032_SLASH_EXPECTED, pos, chars[pos] ) );
        }

        pos++;

        if ( pos == chars.length )
        {
            return;
        }

        // An optional Dn
        pos = parseDN( chars, pos );
        
        if ( pos == INVALID )
        {
            throw new LdapURLEncodingException( I18n.err( I18n.ERR_13033_INVALID_DN ) );
        }

        if ( pos == chars.length )
        {
            return;
        }

        // Optionals attributes
        if ( !Chars.isCharASCII( chars, pos, '?' ) )
        {
            throw new LdapURLEncodingException( I18n.err( I18n.ERR_13034_QUESTION_MARK_EXPECTED, pos, chars[pos] ) );
        }

        pos++;

        pos = parseAttributes( chars, pos );
        
        if ( pos == INVALID )
        {
            throw new LdapURLEncodingException( I18n.err( I18n.ERR_13035_INVALID_ATTRIBUTES ) );
        }

        if ( pos == chars.length )
        {
            return;
        }

        // Optional scope
        if ( !Chars.isCharASCII( chars, pos, '?' ) )
        {
            throw new LdapURLEncodingException( I18n.err( I18n.ERR_13034_QUESTION_MARK_EXPECTED, pos, chars[pos] ) );
        }

        pos++;

        pos = parseScope( chars, pos );
        
        if ( pos == INVALID )
        {
            throw new LdapURLEncodingException( I18n.err( I18n.ERR_13036_INVALID_SCOPE ) );
        }

        if ( pos == chars.length )
        {
            return;
        }

        // Optional filter
        if ( !Chars.isCharASCII( chars, pos, '?' ) )
        {
            throw new LdapURLEncodingException( I18n.err( I18n.ERR_13034_QUESTION_MARK_EXPECTED, pos, chars[pos] ) );
        }

        pos++;

        if ( pos == chars.length )
        {
            return;
        }

        pos = parseFilter( chars, pos );
        
        if ( pos == INVALID )
        {
            throw new LdapURLEncodingException( I18n.err( I18n.ERR_13037_INVALID_FILTER ) );
        }

        if ( pos == chars.length )
        {
            return;
        }

        // Optional extensions
        if ( !Chars.isCharASCII( chars, pos, '?' ) )
        {
            throw new LdapURLEncodingException( I18n.err( I18n.ERR_13034_QUESTION_MARK_EXPECTED, pos, chars[pos] ) );
        }

        pos++;

        pos = parseExtensions( chars, pos );
        
        if ( pos == INVALID )
        {
            throw new LdapURLEncodingException( I18n.err( I18n.ERR_13038_INVALID_EXTENSIONS ) );
        }

        if ( pos != chars.length )
        {
            throw new LdapURLEncodingException( I18n.err( I18n.ERR_13039_INVALID_CHAR_AT_LDAP_URL_END ) );
        }
    }