Source Code Cross Referenced for HeaderParser.java in  » 6.0-JDK-Modules » j2me » gov » nist » siplite » parser » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » 6.0 JDK Modules » j2me » gov.nist.siplite.parser 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Portions Copyright  2000-2007 Sun Microsystems, Inc. All Rights
003:         * Reserved.  Use is subject to license terms.
004:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
005:         * 
006:         * This program is free software; you can redistribute it and/or
007:         * modify it under the terms of the GNU General Public License version
008:         * 2 only, as published by the Free Software Foundation.
009:         * 
010:         * This program is distributed in the hope that it will be useful, but
011:         * WITHOUT ANY WARRANTY; without even the implied warranty of
012:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013:         * General Public License version 2 for more details (a copy is
014:         * included at /legal/license.txt).
015:         * 
016:         * You should have received a copy of the GNU General Public License
017:         * version 2 along with this work; if not, write to the Free Software
018:         * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
019:         * 02110-1301 USA
020:         * 
021:         * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
022:         * Clara, CA 95054 or visit www.sun.com if you need additional
023:         * information or have any questions.
024:         */
025:        package gov.nist.siplite.parser;
026:
027:        import gov.nist.siplite.SIPConstants;
028:        import gov.nist.siplite.header.*;
029:        import gov.nist.core.*;
030:        import java.util.*;
031:
032:        /**
033:         * Generic header parser class. The parsers for various headers extend this
034:         * class. To create a parser for a new header, extend this class and change
035:         * the createParser class.
036:         *
037:         * @version JAIN-SIP-1.1
038:         *
039:         *
040:         * <a href="{@docRoot}/uncopyright.html">This code is in the public domain.</a>
041:         *
042:         */
043:        public class HeaderParser extends Parser {
044:
045:            /**
046:             * Parses the weekday field.
047:             * @return an integer with the calendar content for wkday.
048:             */
049:            protected int wkday() throws ParseException {
050:                dbg_enter("wkday");
051:                try {
052:                    String tok = lexer.ttoken();
053:                    String id = tok.toLowerCase();
054:
055:                    if (Utils.equalsIgnoreCase(SIPConstants.TOKEN_DAY_MON, id))
056:                        return Calendar.MONDAY;
057:                    else if (Utils.equalsIgnoreCase(SIPConstants.TOKEN_DAY_TUE,
058:                            id))
059:                        return Calendar.TUESDAY;
060:                    else if (Utils.equalsIgnoreCase(SIPConstants.TOKEN_DAY_WED,
061:                            id))
062:                        return Calendar.WEDNESDAY;
063:                    else if (Utils.equalsIgnoreCase(SIPConstants.TOKEN_DAY_THU,
064:                            id))
065:                        return Calendar.THURSDAY;
066:                    else if (Utils.equalsIgnoreCase(SIPConstants.TOKEN_DAY_FRI,
067:                            id))
068:                        return Calendar.FRIDAY;
069:                    else if (Utils.equalsIgnoreCase(SIPConstants.TOKEN_DAY_SAT,
070:                            id))
071:                        return Calendar.SATURDAY;
072:                    else if (Utils.equalsIgnoreCase(SIPConstants.TOKEN_DAY_SUN,
073:                            id))
074:                        return Calendar.SUNDAY;
075:                    else
076:                        throw createParseException("bad wkday");
077:                } finally {
078:                    dbg_leave("wkday");
079:                }
080:
081:            }
082:
083:            /**
084:             * Parses and return a date field.
085:             * @return a date structure with the parsed value.
086:             */
087:            protected Calendar date() throws ParseException {
088:                String errorMsg = "bad date field";
089:                try {
090:                    Calendar retval = Calendar.getInstance(TimeZone
091:                            .getTimeZone("GMT"));
092:                    String s1 = lexer.number();
093:                    int day = Integer.parseInt(s1);
094:                    if (day <= 0 || day >= 31)
095:                        throw createParseException("Bad day ");
096:                    retval.set(Calendar.DAY_OF_MONTH, day);
097:                    lexer.match(' ');
098:                    String month = lexer.ttoken().toLowerCase();
099:                    if (month.equals("jan")) {
100:                        retval.set(Calendar.MONTH, Calendar.JANUARY);
101:                    } else if (month.equals("feb")) {
102:                        retval.set(Calendar.MONTH, Calendar.FEBRUARY);
103:                    } else if (month.equals("mar")) {
104:                        retval.set(Calendar.MONTH, Calendar.MARCH);
105:                    } else if (month.equals("apr")) {
106:                        retval.set(Calendar.MONTH, Calendar.APRIL);
107:                    } else if (month.equals("may")) {
108:                        retval.set(Calendar.MONTH, Calendar.MAY);
109:                    } else if (month.equals("jun")) {
110:                        retval.set(Calendar.MONTH, Calendar.JUNE);
111:                    } else if (month.equals("jul")) {
112:                        retval.set(Calendar.MONTH, Calendar.JULY);
113:                    } else if (month.equals("aug")) {
114:                        retval.set(Calendar.MONTH, Calendar.AUGUST);
115:                    } else if (month.equals("sep")) {
116:                        retval.set(Calendar.MONTH, Calendar.SEPTEMBER);
117:                    } else if (month.equals("oct")) {
118:                        retval.set(Calendar.MONTH, Calendar.OCTOBER);
119:                    } else if (month.equals("nov")) {
120:                        retval.set(Calendar.MONTH, Calendar.NOVEMBER);
121:                    } else if (month.equals("dec")) {
122:                        retval.set(Calendar.MONTH, Calendar.DECEMBER);
123:                    }
124:                    lexer.match(' ');
125:                    String s2 = lexer.number();
126:                    int yr = Integer.parseInt(s2);
127:                    retval.set(Calendar.YEAR, yr);
128:                    return retval;
129:
130:                } catch (ParseException ex) {
131:                    throw createParseException(errorMsg);
132:                } catch (NumberFormatException nfe) {
133:                    throw createParseException(errorMsg);
134:                }
135:            }
136:
137:            /**
138:             * Sets the time field. This has the format hour:minute:second.
139:             * @param calendar input data for setting the time
140:             * @exception ParseException if a parsing error occurs
141:             */
142:            protected void time(Calendar calendar) throws ParseException {
143:                String errorMsg = "error processing time ";
144:                try {
145:                    String s = lexer.number();
146:                    int hour = Integer.parseInt(s);
147:                    calendar.set(Calendar.HOUR_OF_DAY, hour);
148:                    lexer.match(':');
149:                    s = lexer.number();
150:                    int min = Integer.parseInt(s);
151:                    calendar.set(Calendar.MINUTE, min);
152:                    lexer.match(':');
153:                    s = lexer.number();
154:                    int sec = Integer.parseInt(s);
155:                    calendar.set(Calendar.SECOND, sec);
156:                } catch (ParseException ex) {
157:                    throw createParseException(errorMsg);
158:                } catch (NumberFormatException nfe) {
159:                    throw createParseException(errorMsg);
160:                }
161:            }
162:
163:            /** Default constructor. */
164:            protected HeaderParser() {
165:            }
166:
167:            /**
168:             * Sets the header to be parsed.
169:             * @param header the string to be processed.
170:             */
171:            public void setHeaderToParse(String header) throws ParseException {
172:                if (this .lexer == null)
173:                    this .lexer = new Lexer("command_keywordLexer", header);
174:                else
175:                    throw createParseException("header already set");
176:            }
177:
178:            /**
179:             * Creates new HeaderParser.
180:             * @param header String to parse.
181:             */
182:            protected HeaderParser(String header) {
183:                this .lexer = new Lexer("command_keywordLexer", header);
184:            }
185:
186:            /**
187:             * Constructor with initial lexer engine.
188:             * @param lexer initial lexer engine
189:             */
190:            protected HeaderParser(Lexer lexer) {
191:                this .lexer = lexer;
192:                this .lexer.selectLexer("command_keywordLexer");
193:            }
194:
195:            /**
196:             * Parses the SIP header from the buffer and return a parsed
197:             * structure.
198:             * @return the parsed header value
199:             * @throws ParseException if there was an error parsing.
200:             */
201:            public Header parse() throws ParseException {
202:                String name = lexer.getNextToken(':');
203:                lexer.consume(1);
204:                String body = lexer.getLine().trim();
205:                // we dont set any fields because the header is
206:                // ok
207:                ExtensionHeader retval = new ExtensionHeader(name, body, body);
208:                return retval;
209:
210:            }
211:
212:            /**
213:             * Parses the header name until the colon and chew WS after that.
214:             * @param tok the separator token
215:             */
216:            protected void headerName(int tok) throws ParseException {
217:                this .lexer.match(tok);
218:                this .lexer.SPorHT();
219:                this .lexer.match(':');
220:                this.lexer.SPorHT();
221:            }
222:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.