Home | History | Annotate | Download | only in parser
      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 ProxyRequire header.
     34  * @version 1.2 $Revision: 1.7 $ $Date: 2009/07/17 18:58:02 $
     35  *
     36  * @author Olivier Deruelle   <br/>
     37  * @author M. Ranganathan   <br/>
     38  *
     39  *
     40  */
     41 public class ProxyRequireParser extends HeaderParser {
     42 
     43     /**
     44      * Creates a new instance of ProxyRequireParser
     45      * @param require the header to parse
     46      */
     47     public ProxyRequireParser(String require) {
     48         super(require);
     49     }
     50 
     51     /**
     52      * Constructor
     53      * @param lexer the lexer to use to parse the header
     54      */
     55     protected ProxyRequireParser(Lexer lexer) {
     56         super(lexer);
     57     }
     58 
     59     /**
     60      * parse the String message
     61      * @return SIPHeader (ProxyRequireList object)
     62      * @throws SIPParseException if the message does not respect the spec.
     63      */
     64     public SIPHeader parse() throws ParseException {
     65         ProxyRequireList list = new ProxyRequireList();
     66         if (debug)
     67             dbg_enter("ProxyRequireParser.parse");
     68 
     69         try {
     70             headerName(TokenTypes.PROXY_REQUIRE);
     71 
     72             while (lexer.lookAhead(0) != '\n') {
     73                 ProxyRequire r = new ProxyRequire();
     74                 r.setHeaderName(SIPHeaderNames.PROXY_REQUIRE);
     75 
     76                 // Parsing the option tag
     77                 this.lexer.match(TokenTypes.ID);
     78                 Token token = lexer.getNextToken();
     79                 r.setOptionTag(token.getTokenValue());
     80                 this.lexer.SPorHT();
     81 
     82                 list.add(r);
     83 
     84                 while (lexer.lookAhead(0) == ',') {
     85                     this.lexer.match(',');
     86                     this.lexer.SPorHT();
     87 
     88                     r = new ProxyRequire();
     89 
     90                     // Parsing the option tag
     91                     this.lexer.match(TokenTypes.ID);
     92                     token = lexer.getNextToken();
     93                     r.setOptionTag(token.getTokenValue());
     94                     this.lexer.SPorHT();
     95 
     96                     list.add(r);
     97                 }
     98 
     99             }
    100         } finally {
    101             if (debug)
    102                 dbg_leave("ProxyRequireParser.parse");
    103         }
    104 
    105         return list;
    106     }
    107 
    108     /** Test program
    109     public static void main(String args[]) throws ParseException {
    110         String r[] = {
    111             "Proxy-Require: foo \n",
    112             "Proxy-Require: foo1, foo2 , 389\n"
    113         };
    114 
    115         for (int i = 0; i < r.length; i++ ) {
    116             ProxyRequireParser parser =
    117             new ProxyRequireParser(r[i]);
    118             ProxyRequireList rl= (ProxyRequireList) parser.parse();
    119             System.out.println("encoded = " + rl.encode());
    120         }
    121     }
    122      */
    123 }
    124 /*
    125  * $Log: ProxyRequireParser.java,v $
    126  * Revision 1.7  2009/07/17 18:58:02  emcho
    127  * Converts indentation tabs to spaces so that we have a uniform indentation policy in the whole project.
    128  *
    129  * Revision 1.6  2006/07/13 09:02:15  mranga
    130  * Issue number:
    131  * Obtained from:
    132  * Submitted by:  jeroen van bemmel
    133  * Reviewed by:   mranga
    134  * Moved some changes from jain-sip-1.2 to java.net
    135  *
    136  * CVS: ----------------------------------------------------------------------
    137  * CVS: Issue number:
    138  * CVS:   If this change addresses one or more issues,
    139  * CVS:   then enter the issue number(s) here.
    140  * CVS: Obtained from:
    141  * CVS:   If this change has been taken from another system,
    142  * CVS:   then name the system in this line, otherwise delete it.
    143  * CVS: Submitted by:
    144  * CVS:   If this code has been contributed to the project by someone else; i.e.,
    145  * CVS:   they sent us a patch or a set of diffs, then include their name/email
    146  * CVS:   address here. If this is your work then delete this line.
    147  * CVS: Reviewed by:
    148  * CVS:   If we are doing pre-commit code reviews and someone else has
    149  * CVS:   reviewed your changes, include their name(s) here.
    150  * CVS:   If you have not had it reviewed then delete this line.
    151  *
    152  * Revision 1.3  2006/06/19 06:47:27  mranga
    153  * javadoc fixups
    154  *
    155  * Revision 1.2  2006/06/16 15:26:28  mranga
    156  * Added NIST disclaimer to all public domain files. Clean up some javadoc. Fixed a leak
    157  *
    158  * Revision 1.1.1.1  2005/10/04 17:12:35  mranga
    159  *
    160  * Import
    161  *
    162  *
    163  * Revision 1.4  2004/01/22 13:26:31  sverker
    164  * Issue number:
    165  * Obtained from:
    166  * Submitted by:  sverker
    167  * Reviewed by:   mranga
    168  *
    169  * Major reformat of code to conform with style guide. Resolved compiler and javadoc warnings. Added CVS tags.
    170  *
    171  * CVS: ----------------------------------------------------------------------
    172  * CVS: Issue number:
    173  * CVS:   If this change addresses one or more issues,
    174  * CVS:   then enter the issue number(s) here.
    175  * CVS: Obtained from:
    176  * CVS:   If this change has been taken from another system,
    177  * CVS:   then name the system in this line, otherwise delete it.
    178  * CVS: Submitted by:
    179  * CVS:   If this code has been contributed to the project by someone else; i.e.,
    180  * CVS:   they sent us a patch or a set of diffs, then include their name/email
    181  * CVS:   address here. If this is your work then delete this line.
    182  * CVS: Reviewed by:
    183  * CVS:   If we are doing pre-commit code reviews and someone else has
    184  * CVS:   reviewed your changes, include their name(s) here.
    185  * CVS:   If you have not had it reviewed then delete this line.
    186  *
    187  */
    188