Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
  * Conditions Of Use
  *
  * This software was developed by employees of the National Institute of
  * Standards and Technology (NIST), an agency of the Federal Government.
  * Pursuant to title 15 Untied States Code Section 105, works of NIST
  * employees are not subject to copyright protection in the United States
  * and are considered to be in the public domain.  As a result, a formal
  * license is not needed to use the software.
 *
 * This software is provided by NIST as a service and is expressly
 * provided "AS IS."  NIST MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED
 * OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT
 * AND DATA ACCURACY.  NIST does not warrant or make any representations
 * regarding the use of the software or the results thereof, including but
 * not limited to the correctness, accuracy, reliability or usefulness of
 * the software.
 *
 * Permission to use this software is contingent upon your acceptance
 * of the terms of this agreement
 *
 * .
 *
 */
 package gov.nist.javax.sip.parser;
 
 import java.util.*;
Generic header parser class. The parsers for various headers extend this class. To create a parser for a new header, extend this class and change the createParser class.

Author(s):
M. Ranganathan
Version:
1.2 $Revision: 1.9 $ $Date: 2009-07-17 18:58:00 $
 
 public class HeaderParser extends Parser {

    
Parse the weekday field

Returns:
an integer with the calendar content for wkday.
 
     protected int wkday() throws ParseException {
         dbg_enter("wkday");
         try {
             String tok = .ttoken();
             String id = tok.toLowerCase();
 
             if (..equalsIgnoreCase(id))
                 return .;
             else if (..equalsIgnoreCase(id))
                 return .;
             else if (..equalsIgnoreCase(id))
                 return .;
             else if (..equalsIgnoreCase(id))
                 return .;
             else if (..equalsIgnoreCase(id))
                 return .;
             else if (..equalsIgnoreCase(id))
                 return .;
             else if (..equalsIgnoreCase(id))
                 return .;
             else
                 throw createParseException("bad wkday");
         } finally {
             dbg_leave("wkday");
         }
 
     }

    
parse and return a date field.

Returns:
a date structure with the parsed value.
 
     protected Calendar date() throws ParseException {
         try {
             Calendar retval = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
             String s1 = .number();
             int day = Integer.parseInt(s1);
             if (day <= 0 || day > 31)
                 throw createParseException("Bad day ");
             retval.set(.day);
             .match(' ');
             String month = .ttoken().toLowerCase();
             if (month.equals("jan")) {
                 retval.set(..);
             } else if (month.equals("feb")) {
                 retval.set(..);
             } else if (month.equals("mar")) {
                 retval.set(..);
             } else if (month.equals("apr")) {
                 retval.set(..);
             } else if (month.equals("may")) {
                retval.set(..);
            } else if (month.equals("jun")) {
                retval.set(..);
            } else if (month.equals("jul")) {
                retval.set(..);
            } else if (month.equals("aug")) {
                retval.set(..);
            } else if (month.equals("sep")) {
                retval.set(..);
            } else if (month.equals("oct")) {
                retval.set(..);
            } else if (month.equals("nov")) {
                retval.set(..);
            } else if (month.equals("dec")) {
                retval.set(..);
            }
            .match(' ');
            String s2 = .number();
            int yr = Integer.parseInt(s2);
            retval.set(.yr);
            return retval;
        } catch (Exception ex) {
            throw createParseException("bad date field");
        }
    }

    
Set the time field. This has the format hour:minute:second
    protected void time(Calendar calendarthrows ParseException {
        try {
            String s = .number();
            int hour = Integer.parseInt(s);
            calendar.set(.hour);
            .match(':');
            s = .number();
            int min = Integer.parseInt(s);
            calendar.set(.min);
            .match(':');
            s = .number();
            int sec = Integer.parseInt(s);
            calendar.set(.sec);
        } catch (Exception ex) {
            throw createParseException("error processing time ");
        }
    }

    
Creates new HeaderParser

Parameters:
String to parse.
    protected HeaderParser(String header) {
        this. = new Lexer("command_keywordLexer"header);
    }
    protected HeaderParser(Lexer lexer) {
        this. = lexer;
        this..selectLexer("command_keywordLexer");
    }

    
Parse the SIP header from the buffer and return a parsed structure.

Throws:
java.text.ParseException if there was an error parsing.
    public SIPHeader parse() throws ParseException {
        String name = .getNextToken(':');
        .consume(1);
        String body = .getLine().trim();
        // we dont set any fields because the header is
        // ok
        ExtensionHeaderImpl retval = new ExtensionHeaderImpl(name);
        retval.setValue(body);
        return retval;
    }

    
Parse the header name until the colon and chew WS after that.
    protected void headerName(int tokthrows ParseException {
        this..match(tok);
        this..SPorHT();
        this..match(':');
        this..SPorHT();
    }
New to GrepCode? Check out our FAQ X