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;
27
28import gov.nist.javax.sip.header.*;
29import gov.nist.core.*;
30import java.text.ParseException;
31
32/**
33 * Parser for Priority header.
34 *
35 * @version 1.2 $Revision: 1.8 $ $Date: 2009/07/17 18:58:02 $
36 *
37 * @author Olivier Deruelle   <br/>
38 * @author M. Ranganathan   <br/>
39 *
40 *
41 *
42 * @version 1.0
43 */
44public class PriorityParser extends HeaderParser {
45
46    /**
47     * Creates a new instance of PriorityParser
48     * @param priority the header to parse
49     */
50    public PriorityParser(String priority) {
51        super(priority);
52    }
53
54    /**
55     * Constructor
56     * @param lexer the lexer to use to parse the header
57     */
58    protected PriorityParser(Lexer lexer) {
59        super(lexer);
60    }
61
62    /**
63     * parse the String header
64     * @return SIPHeader (Priority object)
65     * @throws SIPParseException if the message does not respect the spec.
66     */
67    public SIPHeader parse() throws ParseException {
68
69        if (debug)
70            dbg_enter("PriorityParser.parse");
71        Priority priority = new Priority();
72        try {
73            headerName(TokenTypes.PRIORITY);
74
75            priority.setHeaderName(SIPHeaderNames.PRIORITY);
76
77            this.lexer.SPorHT();
78            /*this.lexer.match(TokenTypes.ID);
79            Token token = lexer.getNextToken();
80
81            priority.setPriority(token.getTokenValue());
82            */
83            // This is in violation of the RFC but
84            // let us be generous in what we accept.
85            priority.setPriority(this.lexer.ttokenSafe());
86
87            this.lexer.SPorHT();
88            this.lexer.match('\n');
89
90            return priority;
91        } finally {
92            if (debug)
93                dbg_leave("PriorityParser.parse");
94        }
95    }
96
97
98    public static void main(String args[]) throws ParseException {
99    String p[] = {
100            "Priority: 8;a\n"
101            };
102
103    for (int i = 0; i < p.length; i++ ) {
104        PriorityParser parser =
105          new PriorityParser(p[i]);
106        Priority prio= (Priority) parser.parse();
107        System.out.println("encoded = " + prio.encode());
108    }
109    }
110
111}
112
113