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;
27import gov.nist.javax.sip.header.*;
28import java.util.*;
29import java.text.ParseException;
30
31/**
32 * Parser for SIP Date field. Converts from SIP Date to the
33 * internal storage (Calendar)
34 *
35 * @version 1.2 $Revision: 1.11 $ $Date: 2009/07/17 18:57:59 $
36 */
37public class DateParser extends HeaderParser {
38
39    /**
40     * Constructor
41     * @param date message to parse to set
42     */
43    public DateParser(String date) {
44        super(date);
45    }
46
47    protected DateParser(Lexer lexer) {
48        super(lexer);
49    }
50
51    /**
52     * Parse method.
53     * @throws ParseException
54     * @return  the parsed Date header/
55     */
56    public SIPHeader parse() throws ParseException {
57        if (debug)
58            dbg_enter("DateParser.parse");
59        try {
60            headerName(TokenTypes.DATE);
61            wkday();
62            lexer.match(',');
63            lexer.match(' ');
64            Calendar cal = date();
65            lexer.match(' ');
66            time(cal);
67            lexer.match(' ');
68            String tzone = this.lexer.ttoken().toLowerCase();
69            if (!"gmt".equals(tzone))
70                throw createParseException("Bad Time Zone " + tzone);
71            this.lexer.match('\n');
72            SIPDateHeader retval = new SIPDateHeader();
73            retval.setDate(cal);
74            return retval;
75        } finally {
76            if (debug)
77                dbg_leave("DateParser.parse");
78
79        }
80
81    }
82
83
84}
85