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 Allow header.
34 *
35 * @version 1.2 $Revision: 1.8 $ $Date: 2009/07/17 18:57:57 $
36 *
37 * @author Olivier Deruelle
38 * @author M. Ranganathan
39 *
40 */
41public class AllowParser extends HeaderParser {
42
43    /**
44     * Creates a new instance of AllowParser
45     * @param allow the header to parse
46     */
47    public AllowParser(String allow) {
48        super(allow);
49    }
50
51    /**
52     * Constructor
53     * @param lexer the lexer to use to parse the header
54     */
55    protected AllowParser(Lexer lexer) {
56        super(lexer);
57    }
58
59    /**
60     * parse the Allow String header
61     * @return SIPHeader (AllowList object)
62     * @throws SIPParseException if the message does not respect the spec.
63     */
64    public SIPHeader parse() throws ParseException {
65
66        if (debug)
67            dbg_enter("AllowParser.parse");
68        AllowList list = new AllowList();
69
70        try {
71            headerName(TokenTypes.ALLOW);
72
73            Allow allow = new Allow();
74            allow.setHeaderName(SIPHeaderNames.ALLOW);
75
76            this.lexer.SPorHT();
77            this.lexer.match(TokenTypes.ID);
78            Token token = lexer.getNextToken();
79            allow.setMethod(token.getTokenValue());
80
81            list.add(allow);
82            this.lexer.SPorHT();
83            while (lexer.lookAhead(0) == ',') {
84                this.lexer.match(',');
85                this.lexer.SPorHT();
86
87                allow = new Allow();
88                this.lexer.match(TokenTypes.ID);
89                token = lexer.getNextToken();
90                allow.setMethod(token.getTokenValue());
91
92                list.add(allow);
93                this.lexer.SPorHT();
94            }
95            this.lexer.SPorHT();
96            this.lexer.match('\n');
97
98            return list;
99        } finally {
100            if (debug)
101                dbg_leave("AllowParser.parse");
102        }
103    }
104
105
106}
107/*
108 * $Log: AllowParser.java,v $
109 * Revision 1.8  2009/07/17 18:57:57  emcho
110 * Converts indentation tabs to spaces so that we have a uniform indentation policy in the whole project.
111 *
112 * Revision 1.7  2006/07/13 09:01:58  mranga
113 * Issue number:
114 * Obtained from:
115 * Submitted by:  jeroen van bemmel
116 * Reviewed by:   mranga
117 * Moved some changes from jain-sip-1.2 to java.net
118 *
119 * CVS: ----------------------------------------------------------------------
120 * CVS: Issue number:
121 * CVS:   If this change addresses one or more issues,
122 * CVS:   then enter the issue number(s) here.
123 * CVS: Obtained from:
124 * CVS:   If this change has been taken from another system,
125 * CVS:   then name the system in this line, otherwise delete it.
126 * CVS: Submitted by:
127 * CVS:   If this code has been contributed to the project by someone else; i.e.,
128 * CVS:   they sent us a patch or a set of diffs, then include their name/email
129 * CVS:   address here. If this is your work then delete this line.
130 * CVS: Reviewed by:
131 * CVS:   If we are doing pre-commit code reviews and someone else has
132 * CVS:   reviewed your changes, include their name(s) here.
133 * CVS:   If you have not had it reviewed then delete this line.
134 *
135 * Revision 1.3  2006/06/19 06:47:27  mranga
136 * javadoc fixups
137 *
138 * Revision 1.2  2006/06/16 15:26:28  mranga
139 * Added NIST disclaimer to all public domain files. Clean up some javadoc. Fixed a leak
140 *
141 * Revision 1.1.1.1  2005/10/04 17:12:35  mranga
142 *
143 * Import
144 *
145 *
146 * Revision 1.5  2004/07/28 14:13:54  mranga
147 * Submitted by:  mranga
148 *
149 * Move out the test code to a separate test/unit class.
150 * Fixed some encode methods.
151 *
152 * Revision 1.4  2004/01/22 13:26:31  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