Methods Summary |
---|
protected java.lang.String | domainLabel()Gets the domain name.
StringBuffer retval = new StringBuffer();
char la;
if (debug) dbg_enter("domainLabel");
try {
while (lexer.hasMoreChars()) {
la = lexer.lookAhead(0);
if (LexerCore.isAlpha(la)) {
lexer.consume(1);
retval.append(la);
} else if (LexerCore.isDigit(la)) {
lexer.consume(1);
retval.append(la);
} else if (la == '-") {
lexer.consume(1);
retval.append(la);
} else
break;
}
// Debug.println("returning " + retval.toString());
if (retval.length() == 0) {
throw new ParseException("Error parsing domain label "
+ lexer.getBuffer(), lexer.getPtr());
}
return retval.toString();
} finally {
if (debug) dbg_leave("domainLabel");
}
|
public java.lang.String | hostName()Gets the host name.
if (debug) dbg_enter("host");
try {
StringBuffer hname = new StringBuffer();
// IPv6 referene
if (lexer.lookAhead(0) == '[") {
hname.append(ipv6Reference());
}
// IPv4 address or hostname
else {
String nextTok = domainLabel();
hname.append(nextTok);
while (lexer.hasMoreChars()) {
// Reached the end of the buffer.
if (lexer.lookAhead(0) == '.") {
lexer.consume(1);
nextTok = domainLabel();
hname.append(".");
hname.append(nextTok);
} else
break;
}
}
return hname.toString();
} finally {
if (debug) dbg_leave("host");
}
|
public HostPort | hostPort()Gets the host name and port number.
if (debug) dbg_enter("hostPort");
try {
int m = lexer.markInputPosition();
String hostName = this.hostName();
Host host = new Host();
HostPort hp = new HostPort();
boolean parsePort = false;
if (StringTokenizer.isDigitString(hostName)) { // maybe server URI
lexer.rewindInputPosition(m); // try to port parsing
parsePort = true;
} else { // save hostname
host.setHostname(hostName);
}
hp.setHost(host);
// For some headers (for ex., Via) there may be spaces
// between the host name and the port number.
lexer.SPorHT();
// Has a port?
if (!parsePort && lexer.hasMoreChars() &&
lexer.lookAhead(0) == ':") {
lexer.consume(1);
lexer.SPorHT();
parsePort = true;
}
if (parsePort) {
parsePort(lexer, hp);
}
return hp;
} finally {
if (debug) dbg_leave("hostPort");
}
|
protected java.lang.String | ipv6Reference()Gets the IPV6 reference.
StringBuffer retval = new StringBuffer();
if (debug) dbg_enter("domainLabel");
try {
while (lexer.hasMoreChars()) {
char la = lexer.lookAhead(0);
if (LexerCore.isHexDigit(la)) {
lexer.consume(1);
retval.append(la);
} else if (la == '."
|| la == ':"
|| la == '[") {
lexer.consume(1);
retval.append(la);
} else if (la == ']") {
lexer.consume(1);
retval.append(la);
return retval.toString();
} else
break;
}
throw new ParseException
(lexer.getBuffer() + ": Illegal Host name ",
lexer.getPtr());
} finally {
if (debug) dbg_leave("domainLabel");
}
|
public static void | parsePort(LexerCore lexer, HostPort hp)Port parsing method.
All port symbols must be digital. Port length must be >0.
Resulting port value stores in input HostPort instance.
try {
String port = lexer.number();
if (port.length() == 0) { // nondigit port symbols
throw new ParseException("Port format error",
lexer.getPtr());
} else {
hp.setPort(Integer.parseInt(port));
}
} catch (NumberFormatException nfe) {
throw new ParseException
(lexer.getBuffer() + " :Error parsing port ",
lexer.getPtr());
} catch (IllegalArgumentException iae) {
// setPort can throw IAE
throw new ParseException(iae.getMessage(),
lexer.getPtr());
}
|