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;
27
28import gov.nist.javax.sip.header.*;
29import gov.nist.core.*;
30import java.text.ParseException;
31
32/**
33 * Parser for Require header.
34 *
35 * @version 1.2 $Revision: 1.7 $ $Date: 2009/07/17 18:58:04 $
36 *
37 * @author Olivier Deruelle
38 * @author M. Ranganathan   <br/>
39 *
40 *
41 *
42 * @version 1.0
43 */
44public class RequireParser extends HeaderParser {
45
46    /**
47     * Creates a new instance of RequireParser
48     * @param require the header to parse
49     */
50    public RequireParser(String require) {
51        super(require);
52    }
53
54    /**
55     * Constructor
56     * @param lexer the lexer to use to parse the header
57     */
58    protected RequireParser(Lexer lexer) {
59        super(lexer);
60    }
61
62    /**
63     * parse the String message
64     * @return SIPHeader (RequireList object)
65     * @throws SIPParseException if the message does not respect the spec.
66     */
67    public SIPHeader parse() throws ParseException {
68        RequireList requireList = new RequireList();
69        if (debug)
70            dbg_enter("RequireParser.parse");
71
72        try {
73            headerName(TokenTypes.REQUIRE);
74
75            while (lexer.lookAhead(0) != '\n') {
76                Require r = new Require();
77                r.setHeaderName(SIPHeaderNames.REQUIRE);
78
79                // Parsing the option tag
80                this.lexer.match(TokenTypes.ID);
81                Token token = lexer.getNextToken();
82                r.setOptionTag(token.getTokenValue());
83                this.lexer.SPorHT();
84
85                requireList.add(r);
86
87                while (lexer.lookAhead(0) == ',') {
88                    this.lexer.match(',');
89                    this.lexer.SPorHT();
90
91                    r = new Require();
92
93                    // Parsing the option tag
94                    this.lexer.match(TokenTypes.ID);
95                    token = lexer.getNextToken();
96                    r.setOptionTag(token.getTokenValue());
97                    this.lexer.SPorHT();
98
99                    requireList.add(r);
100                }
101
102            }
103        } finally {
104            if (debug)
105                dbg_leave("RequireParser.parse");
106        }
107
108        return requireList;
109    }
110
111    /** Test program
112    public static void main(String args[]) throws ParseException {
113        String r[] = {
114            "Require: 100rel \n",
115            "Require: 100rel, 200ok , 389\n"
116        };
117
118        for (int i = 0; i < r.length; i++ ) {
119            RequireParser parser =
120            new RequireParser(r[i]);
121            RequireList rl= (RequireList) parser.parse();
122            System.out.println("encoded = " + rl.encode());
123        }
124    }
125     */
126
127}
128/*
129 * $Log: RequireParser.java,v $
130 * Revision 1.7  2009/07/17 18:58:04  emcho
131 * Converts indentation tabs to spaces so that we have a uniform indentation policy in the whole project.
132 *
133 * Revision 1.6  2006/07/13 09:02:18  mranga
134 * Issue number:
135 * Obtained from:
136 * Submitted by:  jeroen van bemmel
137 * Reviewed by:   mranga
138 * Moved some changes from jain-sip-1.2 to java.net
139 *
140 * CVS: ----------------------------------------------------------------------
141 * CVS: Issue number:
142 * CVS:   If this change addresses one or more issues,
143 * CVS:   then enter the issue number(s) here.
144 * CVS: Obtained from:
145 * CVS:   If this change has been taken from another system,
146 * CVS:   then name the system in this line, otherwise delete it.
147 * CVS: Submitted by:
148 * CVS:   If this code has been contributed to the project by someone else; i.e.,
149 * CVS:   they sent us a patch or a set of diffs, then include their name/email
150 * CVS:   address here. If this is your work then delete this line.
151 * CVS: Reviewed by:
152 * CVS:   If we are doing pre-commit code reviews and someone else has
153 * CVS:   reviewed your changes, include their name(s) here.
154 * CVS:   If you have not had it reviewed then delete this line.
155 *
156 * Revision 1.3  2006/06/19 06:47:27  mranga
157 * javadoc fixups
158 *
159 * Revision 1.2  2006/06/16 15:26:28  mranga
160 * Added NIST disclaimer to all public domain files. Clean up some javadoc. Fixed a leak
161 *
162 * Revision 1.1.1.1  2005/10/04 17:12:36  mranga
163 *
164 * Import
165 *
166 *
167 * Revision 1.4  2004/01/22 13:26:31  sverker
168 * Issue number:
169 * Obtained from:
170 * Submitted by:  sverker
171 * Reviewed by:   mranga
172 *
173 * Major reformat of code to conform with style guide. Resolved compiler and javadoc warnings. Added CVS tags.
174 *
175 * CVS: ----------------------------------------------------------------------
176 * CVS: Issue number:
177 * CVS:   If this change addresses one or more issues,
178 * CVS:   then enter the issue number(s) here.
179 * CVS: Obtained from:
180 * CVS:   If this change has been taken from another system,
181 * CVS:   then name the system in this line, otherwise delete it.
182 * CVS: Submitted by:
183 * CVS:   If this code has been contributed to the project by someone else; i.e.,
184 * CVS:   they sent us a patch or a set of diffs, then include their name/email
185 * CVS:   address here. If this is your work then delete this line.
186 * CVS: Reviewed by:
187 * CVS:   If we are doing pre-commit code reviews and someone else has
188 * CVS:   reviewed your changes, include their name(s) here.
189 * CVS:   If you have not had it reviewed then delete this line.
190 *
191 */
192