01: /*
02: * Portions Copyright 2000-2007 Sun Microsystems, Inc. All Rights
03: * Reserved. Use is subject to license terms.
04: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
05: *
06: * This program is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU General Public License version
08: * 2 only, as published by the Free Software Foundation.
09: *
10: * This program is distributed in the hope that it will be useful, but
11: * WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * General Public License version 2 for more details (a copy is
14: * included at /legal/license.txt).
15: *
16: * You should have received a copy of the GNU General Public License
17: * version 2 along with this work; if not, write to the Free Software
18: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
19: * 02110-1301 USA
20: *
21: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
22: * Clara, CA 95054 or visit www.sun.com if you need additional
23: * information or have any questions.
24: */
25: package gov.nist.siplite.parser;
26:
27: import gov.nist.siplite.address.*;
28: import gov.nist.siplite.header.*;
29: import gov.nist.core.*;
30:
31: /**
32: * To Header parser.
33: *
34: * @version JAIN-SIP-1.1
35: *
36: *
37: * <a href="{@docRoot}/uncopyright.html">This code is in the public domain.</a>
38: *
39: */
40: public class ToParser extends AddressParametersParser {
41: /** Default constructor. */
42: protected ToParser() {
43: }
44:
45: /**
46: * Creates new ToParser with initial To header.
47: * @param to String to set
48: */
49: public ToParser(String to) {
50: super (to);
51: }
52:
53: /**
54: * Constructor with initial lexer engine.
55: * @param lexer initial lexer engine
56: */
57: protected ToParser(Lexer lexer) {
58: super (lexer);
59: }
60:
61: /**
62: * Invokes parser for To header field.
63: * @return the parsed To header
64: * @exception ParseException if a parsing error occurs
65: */
66: public Header parse() throws ParseException {
67:
68: headerName(TokenTypes.TO);
69: ToHeader to = new ToHeader();
70: super .parse(to);
71: this .lexer.match('\n');
72: if (((Address) to.getAddress()).getAddressType() == Address.ADDRESS_SPEC) {
73: // the parameters are header parameters.
74: if (to.getAddress().getURI() instanceof SipURI) {
75: SipURI sipUri = (SipURI) to.getAddress().getURI();
76: NameValueList parms = sipUri.getUriParms();
77: if (parms != null && !parms.isEmpty()) {
78: to.setParameters(parms);
79: sipUri.removeUriParms();
80: }
81: }
82: }
83: return to;
84: }
85: }
|