1/*
2* Conditions Of Use
3*
4* This software was developed by employees of the National Institute of
5* Standards and Technology (NIST), an agency of the Federal Government.
6* Pursuant to title 15 Untied States Code Section 105, works of NIST
7* employees are not subject to copyright protection in the United States
8* and are considered to be in the public domain.  As a result, a formal
9* license is not needed to use the software.
10*
11* This software is provided by NIST as a service and is expressly
12* provided "AS IS."  NIST MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED
13* OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF
14* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT
15* AND DATA ACCURACY.  NIST does not warrant or make any representations
16* regarding the use of the software or the results thereof, including but
17* not limited to the correctness, accuracy, reliability or usefulness of
18* the software.
19*
20* Permission to use this software is contingent upon your acceptance
21* of the terms of this agreement
22*
23* .
24*
25*/
26package gov.nist.javax.sip.parser;
27import java.text.ParseException;
28import gov.nist.javax.sip.header.*;
29
30/**
31 * Parser for a list of route headers.
32 *
33 * @version 1.2
34 *
35 * @author Olivier Deruelle   <br/>
36 * @author M. Ranganathan   <br/>
37 *
38 *
39 *@version 1.0
40 */
41public class RouteParser extends AddressParametersParser {
42
43    /**
44     * Constructor
45     * @param route message to parse to set
46     */
47    public RouteParser(String route) {
48        super(route);
49    }
50
51    protected RouteParser(Lexer lexer) {
52        super(lexer);
53    }
54
55    /** parse the String message and generate the Route List Object
56     * @return SIPHeader the Route List object
57     * @throws SIPParseException if errors occur during the parsing
58     */
59    public SIPHeader parse() throws ParseException {
60        RouteList routeList = new RouteList();
61        if (debug)
62            dbg_enter("parse");
63
64        try {
65            this.lexer.match(TokenTypes.ROUTE);
66            this.lexer.SPorHT();
67            this.lexer.match(':');
68            this.lexer.SPorHT();
69            while (true) {
70                Route route = new Route();
71                super.parse(route);
72                routeList.add(route);
73                this.lexer.SPorHT();
74                char la = lexer.lookAhead(0);
75                if (la == ',') {
76                    this.lexer.match(',');
77                    this.lexer.SPorHT();
78                } else if (la == '\n')
79                    break;
80                else
81                    throw createParseException("unexpected char");
82            }
83            return routeList;
84        } finally {
85            if (debug)
86                dbg_leave("parse");
87        }
88
89    }
90
91    /**
92            public static void main(String args[]) throws ParseException {
93        String rou[] = {
94         "Route: <sip:alice@atlanta.com>\n",
95         "Route: sip:bob@biloxi.com \n",
96         "Route: sip:alice@atlanta.com, sip:bob@biloxi.com, sip:carol@chicago.com\n"
97             };
98
99            for (int i = 0; i < rou.length; i++ ) {
100                RouteParser rp =
101                  new RouteParser(rou[i]);
102                RouteList routeList = (RouteList) rp.parse();
103                System.out.println("encoded = " +routeList.encode());
104            }
105
106        }
107
108    */
109}
110/*
111 * $Log: RouteParser.java,v $
112 * Revision 1.8  2009/07/17 18:58:04  emcho
113 * Converts indentation tabs to spaces so that we have a uniform indentation policy in the whole project.
114 *
115 * Revision 1.7  2007/02/06 16:40:03  belangery
116 * Introduced simple code optimizations.
117 *
118 * Revision 1.6  2006/07/13 09:02:07  mranga
119 * Issue number:
120 * Obtained from:
121 * Submitted by:  jeroen van bemmel
122 * Reviewed by:   mranga
123 * Moved some changes from jain-sip-1.2 to java.net
124 *
125 * CVS: ----------------------------------------------------------------------
126 * CVS: Issue number:
127 * CVS:   If this change addresses one or more issues,
128 * CVS:   then enter the issue number(s) here.
129 * CVS: Obtained from:
130 * CVS:   If this change has been taken from another system,
131 * CVS:   then name the system in this line, otherwise delete it.
132 * CVS: Submitted by:
133 * CVS:   If this code has been contributed to the project by someone else; i.e.,
134 * CVS:   they sent us a patch or a set of diffs, then include their name/email
135 * CVS:   address here. If this is your work then delete this line.
136 * CVS: Reviewed by:
137 * CVS:   If we are doing pre-commit code reviews and someone else has
138 * CVS:   reviewed your changes, include their name(s) here.
139 * CVS:   If you have not had it reviewed then delete this line.
140 *
141 * Revision 1.3  2006/06/19 06:47:27  mranga
142 * javadoc fixups
143 *
144 * Revision 1.2  2006/06/16 15:26:28  mranga
145 * Added NIST disclaimer to all public domain files. Clean up some javadoc. Fixed a leak
146 *
147 * Revision 1.1.1.1  2005/10/04 17:12:36  mranga
148 *
149 * Import
150 *
151 *
152 * Revision 1.4  2004/01/22 13:26:32  sverker
153 * Issue number:
154 * Obtained from:
155 * Submitted by:  sverker
156 * Reviewed by:   mranga
157 *
158 * Major reformat of code to conform with style guide. Resolved compiler and javadoc warnings. Added CVS tags.
159 *
160 * CVS: ----------------------------------------------------------------------
161 * CVS: Issue number:
162 * CVS:   If this change addresses one or more issues,
163 * CVS:   then enter the issue number(s) here.
164 * CVS: Obtained from:
165 * CVS:   If this change has been taken from another system,
166 * CVS:   then name the system in this line, otherwise delete it.
167 * CVS: Submitted by:
168 * CVS:   If this code has been contributed to the project by someone else; i.e.,
169 * CVS:   they sent us a patch or a set of diffs, then include their name/email
170 * CVS:   address here. If this is your work then delete this line.
171 * CVS: Reviewed by:
172 * CVS:   If we are doing pre-commit code reviews and someone else has
173 * CVS:   reviewed your changes, include their name(s) here.
174 * CVS:   If you have not had it reviewed then delete this line.
175 *
176 */
177