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

PhoneFieldParser

public class PhoneFieldParser extends SDPParser
Parser for the Phone field.
version
JAIN-SIP-1.1 This code is in the public domain.

Fields Summary
Constructors Summary
public PhoneFieldParser(String phoneField)
Creates new PhoneFieldParser.

param
phoneField the phone field to be parsed

        lexer = new Lexer("charLexer", phoneField);
    
protected PhoneFieldParser()
Default constructor.

        super();
    
Methods Summary
public java.lang.StringgetDisplayName(java.lang.String rest)
Gets the user friendly display name.

param
rest the remaining string to be parsed
return
the display name

        String retval = null;

        int begin = rest.indexOf("(");
        int end = rest.indexOf(")");

        if (begin != -1 && end != -1 && end > begin) {
            // p=+44-171-380-7777 (Mark Handley)
            retval = rest.substring(begin+1, end);
        } else {
            // The alternative RFC822 name quoting convention is 
            // also allowed for
            // email addresses. ex: p=Mark Handley <+44-171-380-7777>
            int ind = rest.indexOf("<");
            if (ind != -1) {
                retval = rest.substring(0, ind);
            } else {
                // There is no display name !!!
            }
        }

        return retval;
    
public java.lang.StringgetPhoneNumber(java.lang.String rest)
Gets the phone number.

param
rest the remaining string to be parsed
return
the phone number

        String phoneNumber = null;    

        int begin = rest.indexOf("(");

        if (begin != -1) {
            // p=+44-171-380-7777 (Mark Handley)
            phoneNumber = rest.substring(0, begin).trim();
        } else {
            // The alternative RFC822 name quoting convention is
            // also allowed for email addresses. ex: p=Mark
            // Handley <+44-171-380-7777>
            int ind = rest.indexOf("<");
            int end = rest.indexOf(">");

            if (ind != -1 && end != -1 && end > ind) {
                phoneNumber = rest.substring(ind+1, end);
            } else {
                // p=+44-171-380-7777
                phoneNumber = rest.trim();
            }
        }
        return phoneNumber;
    
public SDPFieldparse()
Perform the phone number field parsing

return
the parsed phone number field
exception
ParseException if a parsing error occurs

        return phoneField();
    
public PhoneFieldphoneField()
Perform the phone number field parsing

return
the parsed phone number field
exception
ParseException if a parsing error occurs

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

        PhoneField phoneField = new PhoneField();
        String rest = lexer.getRest();

        String displayName = getDisplayName(rest.trim());
        phoneField.setName(displayName);
        String phoneNumber = getPhoneNumber(rest);
        phoneField.setPhoneNumber(phoneNumber);

        return phoneField;