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.address.GenericURI;
     29 import gov.nist.javax.sip.header.AlertInfo;
     30 import gov.nist.javax.sip.header.AlertInfoList;
     31 import gov.nist.javax.sip.header.SIPHeader;
     32 import gov.nist.javax.sip.header.SIPHeaderNames;
     33 
     34 import java.text.ParseException;
     35 
     36 /**
     37  * Parser for AlertInfo header.
     38  *
     39  * @version 1.2 $Revision: 1.10 $ $Date: 2009/11/07 23:35:49 $
     40  *
     41  * @author Olivier Deruelle
     42  * @author M. Ranganathan
     43  *
     44  */
     45 public class AlertInfoParser extends ParametersParser {
     46 
     47     /**
     48      * Creates a new instance of AlertInfo Parser
     49      * @param alertInfo  the header to parse
     50      */
     51     public AlertInfoParser(String alertInfo) {
     52         super(alertInfo);
     53     }
     54 
     55     /**
     56      * Constructor
     57      * @param lexer the lexer to use to parse the header
     58      */
     59     protected AlertInfoParser(Lexer lexer) {
     60         super(lexer);
     61     }
     62 
     63     /**
     64      * parse the AlertInfo  String header
     65      * @return SIPHeader (AlertInfoList  object)
     66      * @throws SIPParseException if the message does not respect the spec.
     67      */
     68     public SIPHeader parse() throws ParseException {
     69 
     70         if (debug)
     71             dbg_enter("AlertInfoParser.parse");
     72         AlertInfoList list = new AlertInfoList();
     73 
     74         try {
     75             headerName(TokenTypes.ALERT_INFO);
     76 
     77             while (lexer.lookAhead(0) != '\n') {
     78                 AlertInfo alertInfo = new AlertInfo();
     79                 alertInfo.setHeaderName(SIPHeaderNames.ALERT_INFO);
     80                 URLParser urlParser;
     81                 GenericURI uri;
     82 
     83                 do {
     84 	                this.lexer.SPorHT();
     85 	                if (this.lexer.lookAhead(0) == '<') {
     86 	                    this.lexer.match('<');
     87 	                    urlParser = new URLParser((Lexer) this.lexer);
     88 	                    uri = urlParser.uriReference( true );
     89 	                    alertInfo.setAlertInfo(uri);
     90 	                    this.lexer.match('>');
     91 	                } else {
     92 	                	/* This is non standard for Polycom support.
     93 	                	 * I know it is bad grammar but please do not remove. mranga
     94 	                	 */
     95 	                	String alertInfoStr = this.lexer.byteStringNoSemicolon();
     96 	                	alertInfo.setAlertInfo(alertInfoStr);
     97 	                }
     98 
     99 	                this.lexer.SPorHT();
    100 
    101 	                super.parse(alertInfo);
    102 	                list.add(alertInfo);
    103 
    104 	                if ( lexer.lookAhead(0) == ',' ) {
    105 	                	this.lexer.match(',');
    106 	                } else break;
    107                 } while (true);
    108             }
    109             return list;
    110         } finally {
    111             if (debug)
    112                 dbg_leave("AlertInfoParser.parse");
    113         }
    114     }
    115 }
    116 /*
    117  * $Log: AlertInfoParser.java,v $
    118  * Revision 1.10  2009/11/07 23:35:49  mranga
    119  * Fix Alert-Info ( loosen up parsing). Define AUTOMATIC_DIALOG_ERROR_HANDLING flag.
    120  *
    121  * Revision 1.9  2009/10/22 10:27:36  jbemmel
    122  * Fix for issue #230, restructured the code such that parsing for any address appearing without '<' '>'
    123  * stops at ';', then parameters are assigned to the header as expected
    124  *
    125  * Revision 1.8  2009/07/17 18:57:57  emcho
    126  * Converts indentation tabs to spaces so that we have a uniform indentation policy in the whole project.
    127  *
    128  * Revision 1.7  2007/10/18 17:48:09  mranga
    129  * Issue number:
    130  * Obtained from:
    131  * Submitted by:  mardy
    132  * Reviewed by:   mranga
    133  * Alert info patch to accept non standard alert info headers.
    134  *
    135  * Revision 1.6  2006/07/13 09:02:19  mranga
    136  * Issue number:
    137  * Obtained from:
    138  * Submitted by:  jeroen van bemmel
    139  * Reviewed by:   mranga
    140  * Moved some changes from jain-sip-1.2 to java.net
    141  *
    142  * CVS: ----------------------------------------------------------------------
    143  * CVS: Issue number:
    144  * CVS:   If this change addresses one or more issues,
    145  * CVS:   then enter the issue number(s) here.
    146  * CVS: Obtained from:
    147  * CVS:   If this change has been taken from another system,
    148  * CVS:   then name the system in this line, otherwise delete it.
    149  * CVS: Submitted by:
    150  * CVS:   If this code has been contributed to the project by someone else; i.e.,
    151  * CVS:   they sent us a patch or a set of diffs, then include their name/email
    152  * CVS:   address here. If this is your work then delete this line.
    153  * CVS: Reviewed by:
    154  * CVS:   If we are doing pre-commit code reviews and someone else has
    155  * CVS:   reviewed your changes, include their name(s) here.
    156  * CVS:   If you have not had it reviewed then delete this line.
    157  *
    158  * Revision 1.3  2006/06/19 06:47:27  mranga
    159  * javadoc fixups
    160  *
    161  * Revision 1.2  2006/06/16 15:26:28  mranga
    162  * Added NIST disclaimer to all public domain files. Clean up some javadoc. Fixed a leak
    163  *
    164  * Revision 1.1.1.1  2005/10/04 17:12:35  mranga
    165  *
    166  * Import
    167  *
    168  *
    169  * Revision 1.4  2004/01/22 13:26:31  sverker
    170  * Issue number:
    171  * Obtained from:
    172  * Submitted by:  sverker
    173  * Reviewed by:   mranga
    174  *
    175  * Major reformat of code to conform with style guide. Resolved compiler and javadoc warnings. Added CVS tags.
    176  *
    177  * CVS: ----------------------------------------------------------------------
    178  * CVS: Issue number:
    179  * CVS:   If this change addresses one or more issues,
    180  * CVS:   then enter the issue number(s) here.
    181  * CVS: Obtained from:
    182  * CVS:   If this change has been taken from another system,
    183  * CVS:   then name the system in this line, otherwise delete it.
    184  * CVS: Submitted by:
    185  * CVS:   If this code has been contributed to the project by someone else; i.e.,
    186  * CVS:   they sent us a patch or a set of diffs, then include their name/email
    187  * CVS:   address here. If this is your work then delete this line.
    188  * CVS: Reviewed by:
    189  * CVS:   If we are doing pre-commit code reviews and someone else has
    190  * CVS:   reviewed your changes, include their name(s) here.
    191  * CVS:   If you have not had it reviewed then delete this line.
    192  *
    193  */
    194