FileDocCategorySizeDatePackage
ZoneFieldParser.javaAPI DocphoneME MR2 API (J2ME)4867Wed May 02 18:00:42 BST 2007gov.nist.javax.sdp.parser

ZoneFieldParser

public class ZoneFieldParser extends SDPParser
Parser For the Zone field.
version
JAIN-SIP-1.1 This code is in the public domain.

Fields Summary
Constructors Summary
public ZoneFieldParser(String zoneField)
Creates new ZoneFieldParser.

param
zoneField the time zone field to be parsed

        lexer = new Lexer("charLexer", zoneField);
    
protected ZoneFieldParser()
Default constructor.

        super();
    
Methods Summary
public java.lang.StringgetSign(java.lang.String tokenValue)
Gets the sign of the offset.

param
tokenValue to set
return
String

        if (tokenValue.startsWith("-"))
            return "-";
        else return "+";
    
public TypedTimegetTypedTime(java.lang.String tokenValue)
Gets the typed time.

param
tokenValue to set
return
TypedTime

        TypedTime typedTime = new TypedTime();
        String offset = null;
        if (tokenValue.startsWith("-"))
            offset = tokenValue.replace('-", ' ");
        else if (tokenValue.startsWith("+"))
            offset = tokenValue.replace('+", ' ");
        else offset = tokenValue;


        if (offset.endsWith("d")) {
            typedTime.setUnit("d");
            String t = offset.replace('d", ' ");

            typedTime.setTime(Integer.parseInt(t.trim()));
        } else
            if (offset.endsWith("h")) {
            typedTime.setUnit("h");
            String t = offset.replace('h", ' ");
            typedTime.setTime(Integer.parseInt(t.trim()));
        } else
            if (offset.endsWith("m")) {
            typedTime.setUnit("m");
            String t = offset.replace('m", ' ");
            typedTime.setTime(Integer.parseInt(t.trim()));
        } else {
            typedTime.setUnit("s");
            if (offset.endsWith("s")) {
                String t = offset.replace('s", ' ");
                typedTime.setTime(Integer.parseInt(t.trim()));
            } else
                typedTime.setTime(Integer.parseInt(offset.trim()));
        }
        return typedTime;
    
public SDPFieldparse()
Parses the Zone field string.

return
ZoneField
exception
ParseException if a parsing error occurs

        return this.zoneField();
    
public ZoneFieldzoneField()
Parses the Zone field string.

return
ZoneField
exception
ParseException if a parsing error occurs

        try {
            ZoneField zoneField = new ZoneField();


            lexer.match('z");
            lexer.SPorHT();
            lexer.match('=");
            lexer.SPorHT();

            // The zoneAdjustment list:
            while (lexer.lookAhead(0) != '\n") {
                ZoneAdjustment zoneAdjustment = new ZoneAdjustment();
                lexer.match(LexerCore.ID);
                Token time = lexer.getNextToken();
                lexer.SPorHT();
                zoneAdjustment.setTime(Long.parseLong(time.getTokenValue())); 

                lexer.match(LexerCore.ID);
                Token offset = lexer.getNextToken();
                lexer.SPorHT();
                String sign = getSign(offset.getTokenValue());
                TypedTime typedTime = getTypedTime(offset.getTokenValue());
                zoneAdjustment.setSign(sign);
                zoneAdjustment.setOffset(typedTime);

                zoneField.addZoneAdjustment(zoneAdjustment);
            }
            return zoneField;
        } catch (NumberFormatException e) {
            throw lexer.createParseException();
        }