HeaderParserpublic class HeaderParser extends Parser Generic header parser class. The parsers for various headers extend this
class. To create a parser for a new header, extend this class and change
the createParser class. |
Constructors Summary |
---|
protected HeaderParser()Default constructor.
| protected HeaderParser(String header)Creates new HeaderParser.
this.lexer = new Lexer("command_keywordLexer", header);
| protected HeaderParser(Lexer lexer)Constructor with initial lexer engine.
this.lexer = lexer;
this.lexer.selectLexer("command_keywordLexer");
|
Methods Summary |
---|
protected java.util.Calendar | date()Parses and return a date field.
String errorMsg = "bad date field";
try {
Calendar retval =
Calendar.getInstance(TimeZone.getTimeZone("GMT"));
String s1 = lexer.number();
int day = Integer.parseInt(s1);
if (day <= 0 || day >= 31)
throw createParseException("Bad day ");
retval.set(Calendar.DAY_OF_MONTH, day);
lexer.match(' ");
String month = lexer.ttoken().toLowerCase();
if (month.equals("jan")) {
retval.set(Calendar.MONTH, Calendar.JANUARY);
} else if (month.equals("feb")) {
retval.set(Calendar.MONTH, Calendar.FEBRUARY);
} else if (month.equals("mar")) {
retval.set(Calendar.MONTH, Calendar.MARCH);
} else if (month.equals("apr")) {
retval.set(Calendar.MONTH, Calendar.APRIL);
} else if (month.equals("may")) {
retval.set(Calendar.MONTH, Calendar.MAY);
} else if (month.equals("jun")) {
retval.set(Calendar.MONTH, Calendar.JUNE);
} else if (month.equals("jul")) {
retval.set(Calendar.MONTH, Calendar.JULY);
} else if (month.equals("aug")) {
retval.set(Calendar.MONTH, Calendar.AUGUST);
} else if (month.equals("sep")) {
retval.set(Calendar.MONTH, Calendar.SEPTEMBER);
} else if (month.equals("oct")) {
retval.set(Calendar.MONTH, Calendar.OCTOBER);
} else if (month.equals("nov")) {
retval.set(Calendar.MONTH, Calendar.NOVEMBER);
} else if (month.equals("dec")) {
retval.set(Calendar.MONTH, Calendar.DECEMBER);
}
lexer.match(' ");
String s2 = lexer.number();
int yr = Integer.parseInt(s2);
retval.set(Calendar.YEAR, yr);
return retval;
} catch (ParseException ex) {
throw createParseException(errorMsg);
} catch (NumberFormatException nfe) {
throw createParseException(errorMsg);
}
| protected void | headerName(int tok)Parses the header name until the colon and chew WS after that.
this.lexer.match(tok);
this.lexer.SPorHT();
this.lexer.match(':");
this.lexer.SPorHT();
| public Header | parse()Parses the SIP header from the buffer and return a parsed
structure.
String name = lexer.getNextToken(':");
lexer.consume(1);
String body = lexer.getLine().trim();
// we dont set any fields because the header is
// ok
ExtensionHeader retval = new ExtensionHeader(name, body, body);
return retval;
| public void | setHeaderToParse(java.lang.String header)Sets the header to be parsed.
if (this.lexer == null)
this.lexer = new Lexer("command_keywordLexer", header);
else throw createParseException("header already set");
| protected void | time(java.util.Calendar calendar)Sets the time field. This has the format hour:minute:second.
String errorMsg = "error processing time ";
try {
String s = lexer.number();
int hour = Integer.parseInt(s);
calendar.set(Calendar.HOUR_OF_DAY, hour);
lexer.match(':");
s = lexer.number();
int min = Integer.parseInt(s);
calendar.set(Calendar.MINUTE, min);
lexer.match(':");
s = lexer.number();
int sec = Integer.parseInt(s);
calendar.set(Calendar.SECOND, sec);
} catch (ParseException ex) {
throw createParseException(errorMsg);
} catch (NumberFormatException nfe) {
throw createParseException(errorMsg);
}
| protected int | wkday()Parses the weekday field.
dbg_enter("wkday");
try {
String tok = lexer.ttoken();
String id = tok.toLowerCase();
if (Utils.equalsIgnoreCase(SIPConstants.TOKEN_DAY_MON, id))
return Calendar.MONDAY;
else if (Utils.equalsIgnoreCase
(SIPConstants.TOKEN_DAY_TUE, id)) return Calendar.TUESDAY;
else if (Utils.equalsIgnoreCase(SIPConstants.TOKEN_DAY_WED, id))
return Calendar.WEDNESDAY;
else if (Utils.equalsIgnoreCase(SIPConstants.TOKEN_DAY_THU, id))
return Calendar.THURSDAY;
else if (Utils.equalsIgnoreCase
(SIPConstants.TOKEN_DAY_FRI, id))
return Calendar.FRIDAY;
else if (Utils.equalsIgnoreCase
(SIPConstants.TOKEN_DAY_SAT, id))
return Calendar.SATURDAY;
else if (Utils.equalsIgnoreCase
(SIPConstants.TOKEN_DAY_SUN, id)) return Calendar.SUNDAY;
else
throw createParseException("bad wkday");
} finally {
dbg_leave("wkday");
}
|
|