• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 */
26 package gov.nist.javax.sip.parser;
27 
28 import gov.nist.javax.sip.header.*;
29 import gov.nist.core.*;
30 import java.text.ParseException;
31 
32 /**
33  * Parser for ContentLanguage header.
34  *
35  * @version 1.2 $Revision: 1.8 $ $Date: 2009/07/17 18:57:58 $
36  *
37  * @author Olivier Deruelle   <br/>
38  * @author M. Ranganathan   <br/>
39  *
40  *
41  *
42  * @version 1.0
43  */
44 public class ContentEncodingParser extends HeaderParser {
45 
46     /**
47      * Creates a new instance of ContentEncodingParser
48      * @param contentEncoding the header to parse
49      */
ContentEncodingParser(String contentEncoding)50     public ContentEncodingParser(String contentEncoding) {
51         super(contentEncoding);
52     }
53 
54     /**
55      * Constructor
56      * @param lexer the lexer to use to parse the header
57      */
ContentEncodingParser(Lexer lexer)58     protected ContentEncodingParser(Lexer lexer) {
59         super(lexer);
60     }
61 
62     /**
63      * parse the ContentEncodingHeader String header
64      * @return SIPHeader (ContentEncodingList object)
65      * @throws SIPParseException if the message does not respect the spec.
66      */
parse()67     public SIPHeader parse() throws ParseException {
68 
69         if (debug)
70             dbg_enter("ContentEncodingParser.parse");
71         ContentEncodingList list = new ContentEncodingList();
72 
73         try {
74             headerName(TokenTypes.CONTENT_ENCODING);
75 
76             while (lexer.lookAhead(0) != '\n') {
77                 ContentEncoding cl = new ContentEncoding();
78                 cl.setHeaderName(SIPHeaderNames.CONTENT_ENCODING);
79 
80                 this.lexer.SPorHT();
81                 this.lexer.match(TokenTypes.ID);
82 
83                 Token token = lexer.getNextToken();
84                 cl.setEncoding(token.getTokenValue());
85 
86                 this.lexer.SPorHT();
87                 list.add(cl);
88 
89                 while (lexer.lookAhead(0) == ',') {
90                     cl = new ContentEncoding();
91                     this.lexer.match(',');
92                     this.lexer.SPorHT();
93                     this.lexer.match(TokenTypes.ID);
94                     this.lexer.SPorHT();
95                     token = lexer.getNextToken();
96                     cl.setEncoding(token.getTokenValue());
97                     this.lexer.SPorHT();
98                     list.add(cl);
99                 }
100             }
101 
102             return list;
103         } catch (ParseException ex) {
104             throw createParseException(ex.getMessage());
105         } finally {
106             if (debug)
107                 dbg_leave("ContentEncodingParser.parse");
108         }
109     }
110 
111 
112 }
113 /*
114  * $Log: ContentEncodingParser.java,v $
115  * Revision 1.8  2009/07/17 18:57:58  emcho
116  * Converts indentation tabs to spaces so that we have a uniform indentation policy in the whole project.
117  *
118  * Revision 1.7  2006/07/13 09:01:56  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:35  mranga
148  *
149  * Import
150  *
151  *
152  * Revision 1.5  2004/07/28 14:13:55  mranga
153  * Submitted by:  mranga
154  *
155  * Move out the test code to a separate test/unit class.
156  * Fixed some encode methods.
157  *
158  * Revision 1.4  2004/01/22 13:26:31  sverker
159  * Issue number:
160  * Obtained from:
161  * Submitted by:  sverker
162  * Reviewed by:   mranga
163  *
164  * Major reformat of code to conform with style guide. Resolved compiler and javadoc warnings. Added CVS tags.
165  *
166  * CVS: ----------------------------------------------------------------------
167  * CVS: Issue number:
168  * CVS:   If this change addresses one or more issues,
169  * CVS:   then enter the issue number(s) here.
170  * CVS: Obtained from:
171  * CVS:   If this change has been taken from another system,
172  * CVS:   then name the system in this line, otherwise delete it.
173  * CVS: Submitted by:
174  * CVS:   If this code has been contributed to the project by someone else; i.e.,
175  * CVS:   they sent us a patch or a set of diffs, then include their name/email
176  * CVS:   address here. If this is your work then delete this line.
177  * CVS: Reviewed by:
178  * CVS:   If we are doing pre-commit code reviews and someone else has
179  * CVS:   reviewed your changes, include their name(s) here.
180  * CVS:   If you have not had it reviewed then delete this line.
181  *
182  */
183