001: /*
002: * Portions Copyright 2000-2007 Sun Microsystems, Inc. All Rights
003: * Reserved. Use is subject to license terms.
004: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
005: *
006: * This program is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU General Public License version
008: * 2 only, as published by the Free Software Foundation.
009: *
010: * This program is distributed in the hope that it will be useful, but
011: * WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * General Public License version 2 for more details (a copy is
014: * included at /legal/license.txt).
015: *
016: * You should have received a copy of the GNU General Public License
017: * version 2 along with this work; if not, write to the Free Software
018: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
019: * 02110-1301 USA
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
022: * Clara, CA 95054 or visit www.sun.com if you need additional
023: * information or have any questions.
024: */
025: package gov.nist.siplite.parser;
026:
027: import gov.nist.siplite.header.*;
028: import gov.nist.core.*;
029:
030: /**
031: * Parser for Event header.
032: *
033: * @version JAIN-SIP-1.1
034: *
035: * <a href="{@docRoot}/uncopyright.html">This code is in the public domain.</a>
036: *
037: * @version 1.0
038: */
039: public class EventParser extends ParametersParser {
040: /** Default constructor. */
041: EventParser() {
042: }
043:
044: /**
045: * Creates a new instance of EventParser.
046: * @param event the header to parse
047: */
048: public EventParser(String event) {
049: super (event);
050: }
051:
052: /**
053: * Constructor with initial lexer engine.
054: * @param lexer initial lexer engine
055: */
056: protected EventParser(Lexer lexer) {
057: super (lexer);
058: }
059:
060: /**
061: * Parses the String message.
062: * @return Header (Event object)
063: * @throws SIPParseException if the message does not respect the spec.
064: */
065: public Header parse() throws ParseException {
066:
067: if (debug)
068: dbg_enter("EventParser.parse");
069:
070: try {
071: headerName(TokenTypes.EVENT);
072: this .lexer.SPorHT();
073:
074: EventHeader event = new EventHeader();
075: this .lexer.match(TokenTypes.ID);
076: Token token = lexer.getNextToken();
077: String value = token.getTokenValue();
078:
079: event.setEventType(value);
080: super .parse(event);
081:
082: this .lexer.SPorHT();
083: this .lexer.match('\n');
084:
085: return event;
086:
087: } catch (ParseException ex) {
088: throw createParseException(ex.getMessage());
089: } finally {
090: if (debug)
091: dbg_leave("EventParser.parse");
092: }
093: }
094:
095: /*
096: public static void main(String args[]) throws ParseException {
097: String r[] = {
098: "Event: presence\n",
099: "Event: foo; param=abcd; id=1234\n",
100: "Event: foo.foo1; param=abcd; id=1234\n"
101: };
102:
103: for (int i = 0; i < r.length; i++) {
104: EventParser parser =
105: new EventParser(r[i]);
106: EventHeader e = (EventHeader) parser.parse();
107: System.out.println("encoded = " + e.encode());
108: System.out.println("encoded = " + e.clone());
109: System.out.println(e.getEventId());
110: System.out.println(e.match(e));
111: }
112: }
113: */
114: }
|