FileDocCategorySizeDatePackage
Header.javaAPI DocphoneME MR2 API (J2ME)18435Wed May 02 18:00:42 BST 2007gov.nist.siplite.header

Header

public abstract class Header extends GenericObject
Generic SipHeader class All the Headers inherit of this class
version
JAIN-SIP-1.1 This code is in the public domain.

Fields Summary
public static final String
ERROR_INFO
Constant ERROR_INFO field.
public static final String
MIME_VERSION
Constant MIME_VERSION field.
public static final String
IN_REPLY_TO
Constant IN_REPLY_TO field.
public static final String
ALLOW
Constant ALLOW field.
public static final String
ALLOW_EVENTS
Constant ALLOW_EVENTS field.
public static final String
CONTENT_LANGUAGE
Constant CONTENT_LANGUAGE field.
public static final String
CALL_INFO
Constant CALL_INFO field.
public static final String
CSEQ
Constant CSEQ field.
public static final String
ALERT_INFO
Constant ALERT_INFO field.
public static final String
ACCEPT_ENCODING
Constant ACCEPT_ENCODING field.
public static final String
ACCEPT
Constant ACCEPT field.
public static final String
ENCRYPTION
Constant ENCRYPTION field.
public static final String
ACCEPT_LANGUAGE
Constant ACCEPT_LANGUAGE field.
public static final String
ACCEPT_CONTACT
Constant ACCEPT_CONTACT field.
public static final String
RECORD_ROUTE
Constant RECORD_ROUTE field.
public static final String
TIMESTAMP
Constant TIMESTAMP field.
public static final String
TO
Constant TO field.
public static final String
VIA
Constant VIA field.
public static final String
FROM
Constant FROM field.
public static final String
CALL_ID
Constant CALL_ID field.
public static final String
AUTHENTICATION_INFO
Constant AUTHENTICATION_INFO field.
public static final String
AUTHORIZATION
Constant AUTHORIZATION field.
public static final String
PROXY_AUTHENTICATE
Constant PROXY_AUTHENTICATE field.
public static final String
SERVER
Constant SERVER field.
public static final String
UNSUPPORTED
Constant UNSUPPORTED field.
public static final String
RETRY_AFTER
Constant RETRY_AFTER field.
public static final String
CONTENT_TYPE
Constant CONTENT_TYP field.
public static final String
CONTENT_ENCODING
Constant CONTENT_ENCODING field.
public static final String
CONTENT_LENGTH
Constant CONTENT_LENGTH field.
public static final String
HIDE
Constant HIDE field.
public static final String
ROUTE
Constant ROUTE field.
public static final String
CONTACT
Constant CONTACT field.
public static final String
WWW_AUTHENTICATE
Constant WWW_AUTHENTICATE field.
public static final String
MAX_FORWARDS
Constant MAX_FORWARDS field.
public static final String
ORGANIZATION
Constant ORGANIZATION field.
public static final String
PROXY_AUTHORIZATION
Constant PROXY_AUTHORIZATION field.
public static final String
PROXY_REQUIRE
Constant PROXY_REQUIRE field.
public static final String
REQUIRE
Constant REQUIRE field.
public static final String
CONTENT_DISPOSITION
Constant CONTENT_DISPOSITION field.
public static final String
SUBJECT
Constant SUBJECT field.
public static final String
USER_AGENT
Constant USER_AGENT field.
public static final String
WARNING
Constant WARNING field.
public static final String
PRIORITY
Constant PRIORITY field.
public static final String
DATE
Constant DATE field.
public static final String
MIN_EXPIRES
Constant MIN_EXPIRES field.
public static final String
EXPIRES
Constant EXPIRES field.
public static final String
RESPONSE_KEY
Constant RESPONSE_KEY field.
public static final String
WARN_AGENT
Constant WARN_AGENT field.
public static final String
SUPPORTED
Constant SUPPORTED field.
public static final String
EVENT
Constant EVENT field.
public static final String
EXTENSION
Constant EXTENSION field.
public static final String
SUBSCRIPTION_STATE
Constant SUBSCRIPTION_STATE field.
public static final String
SIP_ETAG
Constant SIP_ETAG field (RFC 3903, p. 21).
public static final String
SIP_IF_MATCH
Constant SIP_IF_MATCH field (RFC 3903, p. 22).
public static final String
REFER_TO
Constant Refer-To field (RFC 3515, p. 3).
public static final String
RSEQ
Constant RSEQ field (RFC 3262, p. 11).
public static final String
RACK
Constant RAck field (RFC 3262, p. 11).
public String
headerName
Name of the header.
public String
headerValue
Value of the header.
public static final String[]
parameterLessHeaders
Array of the headers that can not have any parameters. NOTE: If the size of this array is changed, getStringHash() method also must be changed!
Constructors Summary
public Header()
Default constructor.


           
       
public Header(String headerName)
Constructor given the name.

param
headerName the initial header field name

        this.headerName = headerName;
    
public Header(String headerName, String headerValue)
Constructor given the name and value.

param
headerName is the header name.
param
headerValue is the header value.

        this.headerName = headerName;
        this.headerValue = headerValue;
    
Methods Summary
public java.lang.Objectclone()
A place holder -- this should be overriden with an actual clone method.

return
need revisit copy of the current object

        return this;

    
public java.lang.Stringencode()
Encodes the header into a String.

return
String

        if (headerName == null) {
            return "";
        } else {
            return headerName + Separators.COLON + Separators.SP +
                encodeBody() + Separators.NEWLINE;
        }
    
protected abstract java.lang.StringencodeBody()
Gets the stuff that follows the headerName.

return
a string representation of the stuff that follows the headerName

public static java.lang.StringencodeCalendar(java.util.Calendar date)
A utility for encoding dates.

param
date the object to encode
return
the encode date string

        StringBuffer sbuf = new StringBuffer();
        int wkday = date.get(Calendar.DAY_OF_WEEK);
        switch (wkday) {
            case Calendar.MONDAY:
                sbuf.append("Mon");
                break;
            case Calendar.TUESDAY:
                sbuf.append("Tue");
                break;
            case Calendar.WEDNESDAY:
                sbuf.append("Wed");
                break;
            case Calendar.THURSDAY:
                sbuf.append("Thu");
                break;
            case Calendar.FRIDAY:
                sbuf.append("Fri");
                break;
            case Calendar.SATURDAY:
                sbuf.append("Sat");
                break;
            case Calendar.SUNDAY:
                sbuf.append("Sun");
                break;
            default:
                new Exception
                        ("bad day of week?? Huh?? " + wkday).printStackTrace();
                return null;
        }
        int day = date.get(Calendar.DAY_OF_MONTH);
        if (day < 10) sbuf.append(", 0" + day);
        else sbuf.append(", " + day);
        sbuf.append(" ");
        int month = date.get(Calendar.MONTH);
        switch (month) {
            case Calendar.JANUARY:
                sbuf.append("Jan");
                break;
            case Calendar.FEBRUARY:
                sbuf.append("Feb");
                break;
            case Calendar.MARCH:
                sbuf.append("Mar");
                break;
            case Calendar.APRIL:
                sbuf.append("Apr");
                break;
            case Calendar.MAY:
                sbuf.append("May");
                break;
            case Calendar.JUNE:
                sbuf.append("Jun");
                break;
            case Calendar.JULY:
                sbuf.append("Jul");
                break;
            case Calendar.AUGUST:
                sbuf.append("Aug");
                break;
            case Calendar.SEPTEMBER:
                sbuf.append("Sep");
                break;
            case Calendar.OCTOBER:
                sbuf.append("Oct");
                break;
            case Calendar.NOVEMBER:
                sbuf.append("Nov");
                break;
            case Calendar.DECEMBER:
                sbuf.append("Dec");
                break;
            default:
                return null;
        }

        sbuf.append(" ");
        int year = date.get(Calendar.YEAR);
        sbuf.append(year);
        sbuf.append(" ");
        int hour = date.get(Calendar.HOUR_OF_DAY);
        if (hour < 10) sbuf.append("0"+hour);
        else sbuf.append(hour);
        sbuf.append(":");
        int min = date.get(Calendar.MINUTE);
        if (min < 10) sbuf.append("0"+min);
        else sbuf.append(min);
        sbuf.append(":");
        int sec = date.get(Calendar.SECOND);
        if (sec < 10) sbuf.append("0"+sec);
        else sbuf.append(sec);

        sbuf.append(" GMT");
        return sbuf.toString();

    
public java.lang.StringgetHeaderName()
Gets the header name.

return
headerName field

        return this.headerName;
    
public java.lang.StringgetHeaderValue()
Gets the header value.

return
headerValue field

        return this.encodeBody();
    
public java.lang.StringgetName()
Alias for getHeaderName.

return
headerName field

        return this.headerName;
    
public abstract NameValueListgetParameters()
Gets the parameters for the header as a nameValue list.

return
the name value list of header field paramaters

public static bytegetStringHash(java.lang.String s)
Calculates a signle-byte hash code of the string.

param
s is a string for which a hash code must be calculated
return
hash code (from 0 to parameterLessHeaders.length) of the string

        String sl = s.toLowerCase();
        int len  = sl.length(), headersCount = parameterLessHeaders.length;
        int hash = len;

        for (int i = 0; i < len; i++) {
            hash += sl.charAt(i);
        }

        hash  = (byte)(hash % headersCount);

        if (hash == 6) {
            hash = (hash + 9 + sl.charAt(0)) % headersCount;
        } else if (hash == 7) {
            hash = (hash + 13 + sl.charAt(0)) % headersCount;
        }

        // System.out.println("hash('" + s + "') = " + hash);

        return (byte)hash;
    
public abstract java.lang.ObjectgetValue()
Gets the value for the header as opaque object (returned value will depend upon the header. Note that this is not the same as the getHeaderValue above.

return
the header field value

public static booleanisAuthorization(java.lang.String name)
Checks if a header with the given name is an Authorization or Authentication header.

param
name the name of the header
return
true if the header is an Authorization or Authentication header

        if (name == null) {
            return false;
        }

        return (name.equalsIgnoreCase(Header.AUTHORIZATION) ||
                name.equalsIgnoreCase(Header.PROXY_AUTHORIZATION) ||
                name.equalsIgnoreCase(Header.PROXY_AUTHENTICATE) ||
                name.equalsIgnoreCase(Header.WWW_AUTHENTICATE));
    
public static booleanisParameterLess(java.lang.String name)
Checks if the specified header can have some parameters.

param
name the name of the header
return
true if the header can not have any parameters, false otherwise

        byte hash;

        // IMPL_NOTE: remove!!!
        // for (int i = 0; i < parameterLessHeaders.length; i++) {
        //     if (parameterLessHeaders[i] != null)
        //         getStringHash(parameterLessHeaders[i]);
        // }

        hash = getStringHash(name);

        return (parameterLessHeaders[hash] != null &&
                parameterLessHeaders[hash].equalsIgnoreCase(name));
    
public static booleanisReliableTagPresent(java.lang.String strOptionTags)
Search for the reliable tag, "100rel" in a "Require" Header value. This method is internally used to identify if the response received at UAC is reliable provisional response

param
strOptionTags List of option tags that is actually a value of Require Header
return
true if "100rel" tags is found; else false

        if (Utils.equalsIgnoreCase(strOptionTags, "100rel")) {
            return true;
        } else {
            String tag = null;
            // int tagsLength = strOptionTags.length();
            int delimIndex = strOptionTags.indexOf(Separators.COMMA);
            while (delimIndex > 0) {
                tag = strOptionTags.substring(0, delimIndex).trim();
                strOptionTags = strOptionTags.substring(delimIndex + 1,
                        strOptionTags.length()).trim();
                if (Utils.equalsIgnoreCase(tag, "100rel") ||
                    Utils.equalsIgnoreCase(strOptionTags, "100rel")) {
                    return true;
                }
                delimIndex = strOptionTags.indexOf(Separators.COMMA);
            }
        }
        return false;
    
public voidsetHeaderName(java.lang.String name)
Sets the header name field.

param
name is the header name to set.

        this.headerName = name;
    
public voidsetHeaderValue(java.lang.String value)
Sets the header value field.

param
value is the value field to set.

        this.headerValue = value;
    
public java.lang.StringtoString()
Returns the encoded text contents.

return
encode string of object contents

        return this.encode();