FileDocCategorySizeDatePackage
AddressParser.javaAPI DocphoneME MR2 API (J2ME)3495Wed May 02 18:00:42 BST 2007gov.nist.siplite.parser

AddressParser

public class AddressParser extends Parser
Parser for addresses.
version
JAIN-SIP-1.1 This code is in the public domain.

Fields Summary
Constructors Summary
protected AddressParser(Lexer lexer)
Constructor with initial lexer engine.

param
lexer initial lexer engine to use

        this.lexer = lexer;
        this.lexer.selectLexer("charLexer");
    
public AddressParser(String address)
Constructor with initial addres.

param
address initial address

        this.lexer = new Lexer("charLexer", address);
    
Methods Summary
public Addressaddress()
Gets the address.

return
the parsed address

        Address retval = new Address();

        lexer.SPorHT();
        if (!lexer.hasMoreChars()) {
            throw createParseException("Empty address");
        }
        char next = lexer.lookAhead(0);
        // JSR 180: input string could be URL or display name <URL>
        // RFC 3261, ABNF:
        // display-name   =  *(token LWS)/ quoted-string
        String displayName = null;
        if (next == '*") { // "*" - stop parsing
            retval.setAddressType(Address.WILD_CARD);
            return retval;
        }
        if (next == '\"") { // quoted string
            displayName = "\"" + lexer.quotedString() + "\"";
            lexer.getString('<"); // skip till '<'
        } else if (lexer.getRest().indexOf('<") > -1) { // unquoted display name
            displayName = lexer.getString('<");
        }
        if (displayName != null) {
            try {
                retval.setDisplayName(displayName.trim());
            } catch (IllegalArgumentException exc) {
                throw createParseException("Wrong display name "+displayName);
            }
            retval.setAddressType(Address.NAME_ADDR);
        } else {
            retval.setAddressType(Address.ADDRESS_SPEC);
        }
        // Parsing URL
        lexer.SPorHT();
        URLParser uriParser = new URLParser((Lexer)lexer);
        URI uri = uriParser.uriReference();
        lexer.SPorHT();
        if (displayName != null) { // check for closing '>'
            lexer.match('>");
        }
        retval.setURI(uri);
        return retval;