1 package gov.nist.javax.sip.parser.extensions;
2 
3 import gov.nist.javax.sip.header.*;
4 import gov.nist.javax.sip.header.extensions.*;
5 import gov.nist.javax.sip.parser.*;
6 
7 import java.text.ParseException;
8 import javax.sip.*;
9 
10 /**
11  * Parser for SIP MinSE Parser.
12  *
13  *    Min-SE  =  "Min-SE" HCOLON delta-seconds *(SEMI generic-param)
14  *
15  * @author P. Musgrave <pmusgrave@newheights.com>
16  *
17  * <a href="{@docRoot}/uncopyright.html">This code is in the public domain.</a>
18  */
19 public class MinSEParser extends ParametersParser {
20 
21     /**
22      * protected constructor.
23      * @param text is the text of the header to parse
24      */
MinSEParser(String text)25     public MinSEParser(String text) {
26         super(text);
27     }
28 
29     /**
30      * constructor.
31      * @param lexer is the lexer passed in from the enclosing parser.
32      */
MinSEParser(Lexer lexer)33     protected MinSEParser(Lexer lexer) {
34         super(lexer);
35     }
36 
37     /**
38      * Parse the header.
39      */
parse()40     public SIPHeader parse() throws ParseException {
41         MinSE minse = new MinSE();
42         if (debug)
43             dbg_enter("parse");
44         try {
45             headerName(TokenTypes.MINSE_TO);
46 
47             String nextId = lexer.getNextId();
48             try {
49                 int delta = Integer.parseInt(nextId);
50                 minse.setExpires(delta);
51             } catch (NumberFormatException ex) {
52                 throw createParseException("bad integer format");
53             } catch (InvalidArgumentException ex) {
54                 throw createParseException(ex.getMessage());
55             }
56             this.lexer.SPorHT();
57             super.parse(minse);
58             return minse;
59 
60         } finally {
61             if (debug)
62                 dbg_leave("parse");
63         }
64 
65     }
66 
main(String args[])67     public static void main(String args[]) throws ParseException {
68         String to[] =
69             {   "Min-SE: 30\n",
70                 "Min-SE: 45;some-param=somevalue\n",
71             };
72 
73         for (int i = 0; i < to.length; i++) {
74             MinSEParser tp = new MinSEParser(to[i]);
75             MinSE t = (MinSE) tp.parse();
76             System.out.println("encoded = " + t.encode());
77             System.out.println("\ntime=" + t.getExpires() );
78             if ( t.getParameter("some-param") != null)
79                 System.out.println("some-param=" + t.getParameter("some-param") );
80 
81         }
82     }
83 
84 
85 
86 
87 }
88