com.monoserv.http
Class HttpQueryString

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

public class HttpQueryString
extends java.lang.Object


Constructor Summary
HttpQueryString()
          Initializes the internal hashtable.
 
Method Summary
 void AddHeader(java.lang.String fieldName, java.lang.String fieldValue)
          This will add a header to the internal hashtable.
static java.lang.String decode(java.lang.String s)
           
 boolean DoesHeaderExist(java.lang.String fieldName)
          Returns true if the internal hashtable contains a key equal to the string provided.
static java.lang.String encode(java.lang.String s)
          Encode a string to the "x-www-form-urlencoded" form, enhanced with the UTF-8-in-URL proposal.
 java.util.Iterator GetFieldIterator()
          Returns an Iterator object for the key set so we can traverse through the elements.
 int GetFieldSize()
          Returns the size (or number of elements) for the internal hashtable
 java.lang.String GetFieldValue(java.lang.String fieldName)
          This will get the value of the requested field if it exists.
 java.lang.String GetQueryString()
          Takes all the values in the hash table and combines them into a string that is encoded to ensure that its HTTP safe.
static HttpQueryString makeQueryString(java.lang.String qs)
          Creates a HttpQueryString object based on the query string passed in from the HTTP message.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HttpQueryString

public HttpQueryString()
Initializes the internal hashtable.

Method Detail

GetFieldSize

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

Returns:
int An integer representing the number of elements

GetFieldIterator

public java.util.Iterator GetFieldIterator()
Returns an Iterator object for the key set so we can traverse through the elements.

Returns:
Iterator An iterator object from the key set in the hashtable.

AddHeader

public void AddHeader(java.lang.String fieldName,
                      java.lang.String fieldValue)
               throws InvalidQueryStringFieldName
This will add a header to the internal hashtable. The fieldname must be a valid non-zero length string to add successfully. If the value is null or blank, then an empty string is actually stored in the hashtable (not a null value).

Parameters:
fieldName - The name of the field in the query string
fieldValue - The value for the associated name
Throws:
InvalidQueryStringFieldName - If the field name is not valid.

GetFieldValue

public java.lang.String GetFieldValue(java.lang.String fieldName)
                               throws InvalidQueryStringFieldName
This will get the value of the requested field if it exists. Throws an exception if the field name is null or has a length() less than or equal to 0.

Parameters:
fieldName - The name of the field to reference.
Returns:
String The value of the string that is found (if any)
Throws:
InvalidQueryStringFieldName - If the fieldname fails the sanity check (see description).

GetQueryString

public java.lang.String GetQueryString()
Takes all the values in the hash table and combines them into a string that is encoded to ensure that its HTTP safe.

Returns:
String Returns the query string that is generated.

DoesHeaderExist

public boolean DoesHeaderExist(java.lang.String fieldName)
Returns true if the internal hashtable contains a key equal to the string provided.

Parameters:
fieldName - The field name to check for
Returns:
boolean True if it exist, false otherwise

makeQueryString

public static HttpQueryString makeQueryString(java.lang.String qs)
                                       throws java.lang.RuntimeException
Creates a HttpQueryString object based on the query string passed in from the HTTP message. -=Requirements=- If the query string starts with a '?' character, then an exception is thrown. If the query string does not contain any fields, then an exception is thrown. If the field name and field value are not seperated by an '=' sign then the field is ignored, and is printed to the standard error.

Parameters:
qs - A string representation of the query string
Returns:
HttpQueryString The query string object filled with the fields and their values.
Throws:
java.lang.RuntimeException - If any of the above requirements for the query string are not met.

decode

public static java.lang.String decode(java.lang.String s)

encode

public static java.lang.String encode(java.lang.String s)
Encode a string to the "x-www-form-urlencoded" form, enhanced with the UTF-8-in-URL proposal. This is what happens:

Parameters:
s - The string to be encoded
Returns:
The encoded string