com.monoserv.http
Class HttpParameters

java.lang.Object
  extended by com.monoserv.http.HttpParameters

public class HttpParameters
extends java.lang.Object


Field Summary
static java.lang.String CRLF
          CRLF
 
Constructor Summary
HttpParameters()
          The constructor to initialize the internal hashtable.
 
Method Summary
 void AddParam(java.lang.String key, double value)
          Convience method for AddParam(String,String).
 void AddParam(java.lang.String key, int value)
          Convience method for AddParam(String,String).
 void AddParam(java.lang.String key, java.lang.String value)
          Adds a parameters to the hash table.
 boolean DoesHeaderExist(java.lang.String key)
          Performs a simple search to see if the header supplied exists in the internal hashtable.
 java.lang.String GetHeaderValue(java.lang.String idx)
          Returns the value for the supplied header.
 java.lang.String getHttpHeaders()
          Returns a string that is in the proper HTTP format for a response The format is
 java.util.Iterator<java.lang.String> GetIterator()
          Returns the key set iterator for the internal hashtable.
 int GetParamCount()
          Returns the size (or number of elements) for the internal hashtable.
static HttpParameters make(java.lang.String httpHeaders)
          This will take an unformatted string representation of HTTP headers in the standard format.
static HttpParameters makeBlank()
          Returns a blank parameters object
 java.lang.String toString()
          A convienence function to see what is in the object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

CRLF

public static java.lang.String CRLF
CRLF

Constructor Detail

HttpParameters

public HttpParameters()
The constructor to initialize the internal hashtable.

Method Detail

AddParam

public void AddParam(java.lang.String key,
                     int value)
Convience method for AddParam(String,String). Identical to calling AddParam(key, Integer.toString(value));

Parameters:
key - The name of the header
value - The value of the header
See Also:
AddParam(String,String)

AddParam

public void AddParam(java.lang.String key,
                     double value)
Convience method for AddParam(String,String). Identical to calling AddParam(key, Double.toString(value));

Parameters:
key - The name of the header
value - The value of the header
See Also:
AddParam(String,String)

AddParam

public void AddParam(java.lang.String key,
                     java.lang.String value)
              throws java.lang.RuntimeException
Adds a parameters to the hash table. If both the key and value have a length() of greater than 0, then the valud is added via the Hashtable.put() method. Else, a RuntimeException is thrown indicating an Invalid string for the pair. If a duplicate is supplied, it is overridden. No checks are performed to ensure that a duplicate is not overridden.

Parameters:
key - The actual name of the header
value - The value for the associated header.
Throws:
java.lang.RuntimeException - If either supplied string has a length less than or equal to 0.

GetIterator

public java.util.Iterator<java.lang.String> GetIterator()
Returns the key set iterator for the internal hashtable.

Returns:
Iterator An iterator to traverse through the keys in the hashtable.

GetHeaderValue

public java.lang.String GetHeaderValue(java.lang.String idx)
                                throws HeaderDoesNotExistException
Returns the value for the supplied header. If the header exists, then the associated value is returned. If it does not exist, it throws an exception stating so.

Parameters:
idx - The header to look up
Returns:
String A string value representing the header value if it exists
Throws:
HeaderDoesNotExistException - If the header does not exist.
See Also:
DoesHeaderExist(String)

DoesHeaderExist

public boolean DoesHeaderExist(java.lang.String key)
Performs a simple search to see if the header supplied exists in the internal hashtable. return ( params.size() > 0 && params.containsKey(key));

Parameters:
key - The key to search for
Returns:
boolean true if the key exists, false otherwise.

GetParamCount

public int GetParamCount()
Returns the size (or number of elements) for the internal hashtable.

Returns:
int Returns the number of elements in the hashtable.

toString

public java.lang.String toString()
A convienence function to see what is in the object. If the internal hashtable is null, then the string "Null" is returned. If the internal hashtalble is no elements, then the string "Empty" is returned. If the internal hashtable has 1 or more elements, then it will construct a string in the format of
   { HeaderName0="Value0"# HeaderName1="Value1"# ... HeaderNameN="ValueN" }
 

Overrides:
toString in class java.lang.Object
Returns:
String A representation of the object and its data.

make

public static HttpParameters make(java.lang.String httpHeaders)
This will take an unformatted string representation of HTTP headers in the standard format. It will fill a HttpParameters object with those values and return them as an HttpParameters Object. It will split the Headers based on the CRLF values and then parse them based on the colon to seperate the header name and the header value.

Parameters:
httpHeaders - A single string of all the http headers in the message
Returns:
HttpParameters An object with the parameters stored internally

getHttpHeaders

public java.lang.String getHttpHeaders()
Returns a string that is in the proper HTTP format for a response The format is
  HeaderName0: HeaderValue0\r\n
  HeaderNaem1: HeaderValue1\r\n
  ...
 
Although the HTTP protocol requires an extra CRLF to break between the headers and the body, it is not added here.


makeBlank

public static HttpParameters makeBlank()
Returns a blank parameters object

Returns:
HttpParameters An object with no elements in the hashtable.