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