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