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 /*
     27  * ContentTypeParser.java
     28  *
     29  * Created on February 26, 2002, 2:42 PM
     30  */
     31 
     32 package gov.nist.javax.sip.parser;
     33 import gov.nist.core.*;
     34 import gov.nist.javax.sip.header.*;
     35 import java.text.ParseException;
     36 
     37 /**
     38  * Parser for content type header.
     39  *
     40  * @version 1.2 $Revision: 1.9 $ $Date: 2009/07/17 18:57:59 $
     41  *
     42  * @author M. Ranganathan   <br/>
     43  *
     44  *
     45  */
     46 public class ContentTypeParser extends ParametersParser {
     47 
     48     public ContentTypeParser(String contentType) {
     49         super(contentType);
     50     }
     51 
     52     protected ContentTypeParser(Lexer lexer) {
     53         super(lexer);
     54     }
     55 
     56     public SIPHeader parse() throws ParseException {
     57 
     58         ContentType contentType = new ContentType();
     59         if (debug)
     60             dbg_enter("ContentTypeParser.parse");
     61 
     62         try {
     63             this.headerName(TokenTypes.CONTENT_TYPE);
     64 
     65             // The type:
     66             lexer.match(TokenTypes.ID);
     67             Token type = lexer.getNextToken();
     68             this.lexer.SPorHT();
     69             contentType.setContentType(type.getTokenValue());
     70 
     71             // The sub-type:
     72             lexer.match('/');
     73             lexer.match(TokenTypes.ID);
     74             Token subType = lexer.getNextToken();
     75             this.lexer.SPorHT();
     76             contentType.setContentSubType(subType.getTokenValue());
     77             super.parse(contentType);
     78             this.lexer.match('\n');
     79         } finally {
     80             if (debug)
     81                 dbg_leave("ContentTypeParser.parse");
     82         }
     83         return contentType;
     84 
     85     }
     86 
     87 
     88 }
     89 
     90