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