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