org.xlightweb
Class Header

Package class diagram package Header
java.lang.Object
  extended by org.xlightweb.Header
All Implemented Interfaces:
Cloneable, IHeader
Direct Known Subclasses:
HttpRequestHeader, HttpResponseHeader

public class Header
extends Object
implements IHeader, Cloneable

Implementation base for a header


Constructor Summary
Header()
          constructor
Header(String contentType)
          constructor
 
Method Summary
 void addHeader(String headername, String headervalue)
          Adds a header with the given name and value.
 void addHeaderLine(String line)
          adds a header line
 void addHeaderlines(String... lines)
          adds raw header lines
protected  Object clone()
          
 boolean containsHeader(String headername)
          Returns a boolean indicating whether the named header has already been set.
 List<ContentType> getAccept()
          
 String getCharacterEncoding()
          Returns the name of the character encoding used in the body of this message.
 String getContentType()
          Returns the MIME type of the body of the messag, or null if the type is not known.
 String getDisposition()
          returns the content disposition header of the part, or null if the type is not known.
 String getDispositionParam(String name)
          returns the content disposition param value or null if not set

see also rfc2183
 String getDispositionType()
          returns the content disposition type or null if not set

see also rfc2183
 String getHeader(String headername)
          Returns the value of the specified header as a String.
 String getHeader(String headername, String dflt)
          Returns the value of the specified header as a String.
 List<String> getHeaderList(String headername)
          Returns all the values of the specified header as an List of String objects.
 Enumeration getHeaderNames()
          Returns an enumeration of all the header names.
 Set<String> getHeaderNameSet()
          Returns an set of all the header names.
 Enumeration getHeaders(String headername)
          Returns all the values of the specified header as an Enumeration of String objects.
 String getTransferEncoding()
          returns the Transfer-Encoding header parameter or null if the header is not set
 void removeHeader(String headername)
          removes a header with the given name
 void setContentType(String contentType)
          sets the MIME type of the body of the part
 void setHeader(String headername, String headervalue)
          Sets a header with the given name and value.
 void setTransferEncoding(String transferEncoding)
          sets the Transfer-Encoding parameter
 String toString()
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Header

public Header()
constructor


Header

public Header(String contentType)
constructor

Parameters:
contentType - the contentType
Method Detail

addHeaderLine

public final void addHeaderLine(String line)
adds a header line

Specified by:
addHeaderLine in interface IHeader
Parameters:
line - the header line

addHeaderlines

public final void addHeaderlines(String... lines)
adds raw header lines

Specified by:
addHeaderlines in interface IHeader
Parameters:
lines - the headerlines

setHeader

public final void setHeader(String headername,
                            String headervalue)
Sets a header with the given name and value. If the header had already been set, the new value overwrites the previous one.

Specified by:
setHeader in interface IHeader
Parameters:
headername - the name of the header
headervalue - the header value If it contains octet string, it should be encoded according to RFC 2047 (http://www.ietf.org/rfc/rfc2047.txt)

addHeader

public final void addHeader(String headername,
                            String headervalue)
Adds a header with the given name and value. This method allows headers to have multiple values.

Specified by:
addHeader in interface IHeader
Parameters:
headername - the name of the header
headervalue - the additional header value. If it contains octet string, it should be encoded according to RFC 2047 (http://www.ietf.org/rfc/rfc2047.txt)

removeHeader

public final void removeHeader(String headername)
removes a header with the given name

Specified by:
removeHeader in interface IHeader
Parameters:
headername - the name of the header

containsHeader

public boolean containsHeader(String headername)
Returns a boolean indicating whether the named header has already been set.

Specified by:
containsHeader in interface IHeader
Returns:
true if the named header has already been set; false otherwise

getHeaderNameSet

public Set<String> getHeaderNameSet()
Returns an set of all the header names. If the part has no headers, this method returns an empty Set.

Specified by:
getHeaderNameSet in interface IHeader
Returns:
an Set of all the header names

getHeaderNames

public final Enumeration getHeaderNames()
Returns an enumeration of all the header names. If the part has no headers, this method returns an empty enumeration.

Specified by:
getHeaderNames in interface IHeader
Returns:
an enumeration of all the header names

getHeaderList

public List<String> getHeaderList(String headername)
Returns all the values of the specified header as an List of String objects.

Some headers, such as Accept-Language can be set by part producer as several headers each with a different value rather than sending the header as a comma separated list.

Specified by:
getHeaderList in interface IHeader
Parameters:
headername - a String specifying the header name
Returns:
an List containing the values of the requested header. If the part does not have any headers of that name return an empty enumeration.

getHeaders

public final Enumeration getHeaders(String headername)
Returns all the values of the specified header as an Enumeration of String objects.

Some headers, such as Accept-Language can be set by part producer as several headers each with a different value rather than sending the header as a comma separated list.

Specified by:
getHeaders in interface IHeader
Parameters:
headername - a String specifying the header name
Returns:
an Enumeration containing the values of the requested header. If the part does not have any headers of that name return an empty enumeration.

getHeader

public String getHeader(String headername)
Returns the value of the specified header as a String. If the part did not include a header of the specified name, this method returns null. If there are multiple headers with the same name, this method returns the first head in the part.

Specified by:
getHeader in interface IHeader
Parameters:
headername - a String specifying the header name
Returns:
a String containing the value of the requested header, or null if the part does not have a header of that name

getHeader

public String getHeader(String headername,
                        String dflt)
Returns the value of the specified header as a String. If the part did not include a header of the specified name, this method returns null. If there are multiple headers with the same name, this method returns the first head in the part.

Specified by:
getHeader in interface IHeader
Parameters:
headername - a String specifying the header name
dflt - the default value if the header is not set
Returns:
a String containing the value of the requested header, or null if the part does not have a header of that name

setContentType

public final void setContentType(String contentType)
sets the MIME type of the body of the part

Specified by:
setContentType in interface IHeader
Parameters:
contentType - the MIME type of the body of the part

getCharacterEncoding

public final String getCharacterEncoding()
Returns the name of the character encoding used in the body of this message. If the header defines no encoding, the default encoding will be returned

Specified by:
getCharacterEncoding in interface IHeader
Returns:
a String containing the name of the character encoding

getContentType

public final String getContentType()
Returns the MIME type of the body of the messag, or null if the type is not known.

Specified by:
getContentType in interface IHeader
Returns:
a String containing the name of the MIME type of the message, or null if the type is not known

getAccept

public final List<ContentType> getAccept()


getDisposition

public final String getDisposition()
returns the content disposition header of the part, or null if the type is not known.

see also rfc2183

Specified by:
getDisposition in interface IHeader
Returns:
a String containing the name of the content disposition of the part, or null if the type is not known

getDispositionType

public final String getDispositionType()
returns the content disposition type or null if not set

see also rfc2183

Specified by:
getDispositionType in interface IHeader
Returns:
the content disposition type or null if not set

getDispositionParam

public final String getDispositionParam(String name)
returns the content disposition param value or null if not set

see also rfc2183

Specified by:
getDispositionParam in interface IHeader
Parameters:
name - the parameter name
Returns:
the content disposition param value or null if not set

getTransferEncoding

public final String getTransferEncoding()
returns the Transfer-Encoding header parameter or null if the header is not set

Specified by:
getTransferEncoding in interface IHeader
Returns:
the Transfer-Encoding header parameter or null if the header is not set

setTransferEncoding

public final void setTransferEncoding(String transferEncoding)
sets the Transfer-Encoding parameter

Specified by:
setTransferEncoding in interface IHeader
Parameters:
transferEncoding - the Transfer-Encoding parameter

clone

protected Object clone()
                throws CloneNotSupportedException

Overrides:
clone in class Object
Throws:
CloneNotSupportedException

toString

public String toString()
Overrides:
toString in class Object