org.benow.web
Class QueryParams

java.lang.Object
  extended by org.benow.web.QueryParams

public class QueryParams
extends java.lang.Object

A wrapper around a query string. Allows for individual access to named parameters of varying types (String,int,etc). The original query string is also held within the QueryParameters and may be fetched with getQueryString().


Constructor Summary
QueryParams(javax.servlet.http.HttpServletRequest request)
           
 
Method Summary
 void absorbElements(org.w3c.dom.Element parentOfToAbsorb)
          absorbs all child elements of the given element
 void absorbElements(org.w3c.dom.NodeList nodes)
          absorbs the given elements

<paramName>value</paramName>

 void addParam(java.lang.String name, java.lang.String value)
           
 void clearCopiedItems(java.lang.Object toClear)
           
 java.lang.Class<?> getAsClass(java.lang.String paramName)
           
 java.lang.Class<?> getAsClass(java.lang.String paramName, java.lang.Class<?> defaultClass)
           
 boolean getBoolean(java.lang.String param)
          Returns true if the parameter starts with 't' or is 'on', ie True, TRUE, T,true, trippy, on, On would return true Flubber, mysogeny, false, xenophobe, null, off would return false
 boolean getBoolean(java.lang.String name, boolean defaultVal)
           
 org.benow.java.mime.MimeType getContentType()
           
 javax.servlet.http.Cookie getCookie(java.lang.String named)
          Gets a cookie with the given name from the request.
protected  java.lang.String getCookieValue(java.lang.String named, java.lang.String defaultValue)
          Gets the value of the cookie with the given name, returning the default if the cookie does not exist.
 java.util.Map getCopiedItems()
           
 java.util.Collection<java.lang.Object> getCopiedItems(java.lang.Class<?> ofClass)
           
static QueryParams getCurrentParams()
           
 java.lang.String getFileName()
           
 int getInt(java.lang.String name)
          Gets an int from the parameters.
 int getInt(java.lang.String name, int defaultVal)
          Gets an int from the parameters, returning the default if either the parameter does not exist, or it is not an integer.
 java.lang.Integer getInteger(java.lang.String name)
           
 java.lang.Integer getInteger(java.lang.String name, java.lang.Integer defaultVal)
           
 long getLong(java.lang.String name)
           
 long getLong(java.lang.String name, long defaultVal)
           
 java.util.List<ParameterValuePair> getPairsStartingWith(java.lang.String prefix)
          Gets a list of ParameterValuePairs for all Parameters starting with the given prefix.
 java.util.Map<java.lang.String,java.lang.String[]> getParams()
           
 java.lang.String getQueryString()
          Gets the original query string that this object was created from.
 java.lang.String getRequestURL()
           
 javax.servlet.http.HttpSession getSession()
          Returns the session for the given request context.
 java.lang.String getString(java.lang.String name)
          Gets a string from the parameters.
 java.lang.String getString(java.lang.String name, java.lang.String defaultValue)
          Gets a value from the parameters.
 UploadedFile getUploadedFile()
          Gets the first UploadedFile in a multipart file upload, throwing an exception if no file parts were given in the request.
 java.util.Map<java.lang.String,UploadedFile> getUploadedFiles()
          Returns a list of UploadedFiles that were included in a multipart request.
 java.util.List<java.lang.String> getValues(java.lang.String name)
           
 java.lang.String[] getValuesArray(java.lang.String name)
          Gets values for a parameter of a given name.
 java.lang.String[] getVirtualPathItems()
          Gets the virtual path items associated with the request.
 boolean hasCopiedItems()
           
 boolean hasCopiedItems(java.lang.Class<?> ofClass)
           
 boolean hasParam(java.lang.String name)
          Returns true if a parameter of the given name exists.
 void removeCookie(java.lang.String name)
           
 void setContentType(org.benow.java.mime.MimeType type)
           
 void setFileName(java.lang.String fileName)
           
 void toElement(org.w3c.dom.Document doc, org.w3c.dom.Element parent)
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

QueryParams

public QueryParams(javax.servlet.http.HttpServletRequest request)
            throws WebException
Throws:
WebException
Method Detail

getParams

public java.util.Map<java.lang.String,java.lang.String[]> getParams()

getSession

public javax.servlet.http.HttpSession getSession()
Returns the session for the given request context. If the session does not exist, a new session is returned.

Returns:
the session associated with the client

getCookie

public javax.servlet.http.Cookie getCookie(java.lang.String named)
Gets a cookie with the given name from the request.

Parameters:
named -
Returns:
cookie for name

getCookieValue

protected java.lang.String getCookieValue(java.lang.String named,
                                          java.lang.String defaultValue)
Gets the value of the cookie with the given name, returning the default if the cookie does not exist.

Parameters:
named -
defaultValue -
Returns:
value of named cookie

getVirtualPathItems

public java.lang.String[] getVirtualPathItems()
Gets the virtual path items associated with the request. ie: if the request is for http://some.org/site/project/web which resolves to the virtual file: /opt/jetty/webapps/site/project/web, with the actual servlet base of: /opt/jetty/webapps/site/ then the path items are: ["project","web"].

Returns:
the virtual path items.

addParam

public void addParam(java.lang.String name,
                     java.lang.String value)

getUploadedFiles

public java.util.Map<java.lang.String,UploadedFile> getUploadedFiles()
Returns a list of UploadedFiles that were included in a multipart request.

Returns:
uploaded files

getUploadedFile

public UploadedFile getUploadedFile()
                             throws WebException
Gets the first UploadedFile in a multipart file upload, throwing an exception if no file parts were given in the request.

Returns:
first uploaded file
Throws:
WebException

getQueryString

public java.lang.String getQueryString()
Gets the original query string that this object was created from.

Returns:
query string

getString

public java.lang.String getString(java.lang.String name,
                                  java.lang.String defaultValue)
Gets a value from the parameters. If no value for the given name is found, the default will be returned.

Parameters:
name -
defaultValue -
Returns:
string value

getAsClass

public java.lang.Class<?> getAsClass(java.lang.String paramName)
                              throws WebException,
                                     java.lang.ClassNotFoundException
Throws:
WebException
java.lang.ClassNotFoundException

getAsClass

public java.lang.Class<?> getAsClass(java.lang.String paramName,
                                     java.lang.Class<?> defaultClass)
                              throws WebException,
                                     java.lang.ClassNotFoundException
Throws:
WebException
java.lang.ClassNotFoundException

hasParam

public boolean hasParam(java.lang.String name)
Returns true if a parameter of the given name exists.

Parameters:
name -
Returns:
param value
Throws:
WebException

getString

public java.lang.String getString(java.lang.String name)
                           throws WebException
Gets a string from the parameters.

Parameters:
name -
Returns:
param value
Throws:
WebException - on error getting named value from parameters

getInt

public int getInt(java.lang.String name,
                  int defaultVal)
Gets an int from the parameters, returning the default if either the parameter does not exist, or it is not an integer.

Parameters:
name -
defaultVal -
Returns:
int in string or default

getInt

public int getInt(java.lang.String name)
           throws WebException
Gets an int from the parameters.

Parameters:
name -
Returns:
int value of params
Throws:
WebException - if the parameter does not exist, or it is not an integer.

getInteger

public java.lang.Integer getInteger(java.lang.String name)
                             throws WebException
Throws:
WebException

getValuesArray

public java.lang.String[] getValuesArray(java.lang.String name)
Gets values for a parameter of a given name.

Parameters:
name -
Returns:
values for name

getPairsStartingWith

public java.util.List<ParameterValuePair> getPairsStartingWith(java.lang.String prefix)
Gets a list of ParameterValuePairs for all Parameters starting with the given prefix.

Parameters:
prefix -
Returns:
ParameterValuePairs with prefix
See Also:
ParameterValuePair

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

getBoolean

public boolean getBoolean(java.lang.String param)
Returns true if the parameter starts with 't' or is 'on', ie True, TRUE, T,true, trippy, on, On would return true Flubber, mysogeny, false, xenophobe, null, off would return false

Parameters:
param -
Returns:
boolean value of given param

getValues

public java.util.List<java.lang.String> getValues(java.lang.String name)
Parameters:
name -
Returns:
values for given param

getContentType

public org.benow.java.mime.MimeType getContentType()
Returns:
mime type

setContentType

public void setContentType(org.benow.java.mime.MimeType type)

getFileName

public java.lang.String getFileName()
Returns:
file name

setFileName

public void setFileName(java.lang.String fileName)
Parameters:
fileName -

getCopiedItems

public java.util.Map getCopiedItems()
Returns:
copied items as added to the session

hasCopiedItems

public boolean hasCopiedItems()

getCopiedItems

public java.util.Collection<java.lang.Object> getCopiedItems(java.lang.Class<?> ofClass)
                                                      throws java.lang.ClassNotFoundException
Parameters:
ofClass -
Returns:
copied items of given class
Throws:
java.lang.ClassNotFoundException

hasCopiedItems

public boolean hasCopiedItems(java.lang.Class<?> ofClass)

clearCopiedItems

public void clearCopiedItems(java.lang.Object toClear)
Parameters:
toClear -

removeCookie

public void removeCookie(java.lang.String name)

getLong

public long getLong(java.lang.String name)
             throws WebException
Throws:
WebException

getInteger

public java.lang.Integer getInteger(java.lang.String name,
                                    java.lang.Integer defaultVal)

getLong

public long getLong(java.lang.String name,
                    long defaultVal)
             throws WebException
Throws:
WebException

getBoolean

public boolean getBoolean(java.lang.String name,
                          boolean defaultVal)

getRequestURL

public java.lang.String getRequestURL()

getCurrentParams

public static QueryParams getCurrentParams()

absorbElements

public void absorbElements(org.w3c.dom.NodeList nodes)
absorbs the given elements

<paramName>value</paramName>

Parameters:
nodes -

toElement

public void toElement(org.w3c.dom.Document doc,
                      org.w3c.dom.Element parent)

absorbElements

public void absorbElements(org.w3c.dom.Element parentOfToAbsorb)
absorbs all child elements of the given element

Parameters:
parentOfToAbsorb -