Gets the 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;