com.waveset.ui.util
Class RequestState

java.lang.Object
  extended bycom.waveset.ui.util.RequestState
All Implemented Interfaces:
UIConstants

public class RequestState
extends java.lang.Object
implements UIConstants

A collection of objects that define the state of a single HTTP request. These are provided by the servlet engine to the servlet or JSP page.

This collection is needed in several contexts, so it is convenient to package them all in one object that can be passed around.

We also includes a Waveset Session since in the Lighthouse environment you almost always have to have one of these.


Field Summary
static java.lang.String code_id
           
static java.lang.String OPTION_PREFIX
          A prefix we look for in request parameter names.
static java.lang.String POST_NULL
          Special value we post when the end result is to set the target attribute to null.
protected static Trace trace
           
 
Fields inherited from interface com.waveset.ui.UIConstants
ACTIVITYSTATUS_JAR, APPLICATION_OCTET_STREAM, COLON, COMMAND_APPLY, COMMAND_APPROVE, COMMAND_CANCEL, COMMAND_COMPARE, COMMAND_CREATE, COMMAND_DELETE, COMMAND_EDIT, COMMAND_EXPORT, COMMAND_EXTRACT, COMMAND_EXTRACT_DOTDOTDOT, COMMAND_FIRST, COMMAND_GOTOPAGE, COMMAND_IMPORT, COMMAND_LOAD, COMMAND_LOAD_DOTDOTDOT, COMMAND_NEW, COMMAND_NEW_DOTDOTDOT, COMMAND_NEW_LABEL, COMMAND_NEXT, COMMAND_PREVIOUS, COMMAND_REGENERATE, COMMAND_REJECT, COMMAND_RENAME, COMMAND_REPLACE, COMMAND_RESULTS, COMMAND_RUN, COMMAND_SAVE, COMMAND_SAVE_AS, COMMAND_SEARCH, COMMAND_STOP, CONTENT, CONTENT_DISPOSITION, CONTENT_TYPE, DASHBOARD_JAR, DOTDOTDOT, EQUALS, FILENAME, HIDDEN_ACTIVE_CONTROL, HIDDEN_COMMAND, HIDDEN_ERROR, HIDDEN_ID, HIDDEN_MESSAGE, LOGIN_CHANGE_VIEW, LOGIN_ERROR, LOGIN_INFO_ATTR_NAMES, LOGIN_MODULE_EXCEPTIONS, LOGIN_MODULE_INDEX, LOGIN_MODULE_PASSWORD_EXPIRED, LOGIN_MODULE_SUCCEEDED, LOGIN_WARNING, MAX_POST_FILE_SIZE_DEFAULT, MAX_POST_FILE_SIZE_PROPERTY, MULTI_PART_FORM_DATA, MULTISELECT_DELIM, MULTISELECT_JAR, NAME, OBFUSCATE_LOGIN_MODULE_EXCEPTIONS, QUOTE, SELECT, SPACE, TRANSACTION_SIGNER_JAR, TREETABLE_JAR, URL_ENCODED, VISUALIZATION_JAR
 
Constructor Summary
RequestState(javax.servlet.http.HttpSession hs, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp, LighthouseContext lighthouseContext, PageInformation pi)
           
 
Method Summary
 void cleanup()
           
 java.lang.String encodeAbsoluteURL(java.lang.String url)
          Encode a response URL.
 java.lang.String encodeAbsoluteURL(java.lang.String url, boolean needSession)
          Encode a response URL.
 java.lang.String encodeURL(java.lang.String url)
          Encode a response URL.
 java.lang.String getAttribute(java.lang.String name)
          Return the value of a session attribute, coercing to a string.
static boolean getBooleanParameter(javax.servlet.ServletRequest req, java.lang.String name)
           
static boolean getBooleanParameter(javax.servlet.ServletRequest req, java.lang.String name, boolean defaultValue)
          Return the value of a boolean parameter.
 boolean getBooleanParameter(java.lang.String name)
           
 boolean getBooleanParameter(java.lang.String name, boolean defaultValue)
           
 int getContentLength()
           
static int getContentLength(RequestState req)
           
 javax.servlet.http.HttpSession getHttpSession()
           
static int getIntParameter(javax.servlet.ServletRequest req, java.lang.String name)
          Return the value of an int parameter.
static int getIntParameter(javax.servlet.ServletRequest req, java.lang.String name, int defaultValue)
          Return the value of an int parameter.
 int getIntParameter(java.lang.String name)
          Return the value of an int parameter.
 int getIntParameter(java.lang.String name, int defaultValue)
          Return the value of an int parameter.
 LighthouseContext getLighthouseContext()
           
 java.util.Locale getLocale()
           
 java.lang.String getLocalizedString(int value)
          Localize an integer.
static java.lang.String getLocalizedString(java.util.Locale locale, int value)
           
static java.lang.String getLocalizedString(java.util.Locale locale, java.lang.Object value)
          Coerce an object to a string.
 java.lang.String getLocalizedString(java.lang.Object value)
           
static java.lang.String getLocalizedString(java.lang.String value, java.util.Locale locale)
           
 java.lang.String getMethod()
           
 java.lang.Object getOption(java.lang.String name)
           
 java.util.Map getOptions()
           
 PageInformation getPageInformation()
           
static java.lang.String getParameter(java.util.Map parameterMap, java.lang.String name)
          Return from the specified map of parameter values a single value for the specified parameter.
static java.lang.String getParameter(RequestState req, java.lang.String name)
           
static java.lang.String getParameter(javax.servlet.ServletRequest r, java.lang.String name)
          Return the value of a parameter, collapsing empty strings to null.
 java.lang.String getParameter(java.lang.String name)
          Return the value of a parameter from the HttpRequest that was supplied to our constructor.
 java.util.Map getParameterMap()
           
static java.lang.String[] getParameterValues(java.util.Map parameterMap, java.lang.String name)
          Return from the specified map of parameter values the values of the specified parameter.
 java.lang.String[] getParameterValues(java.lang.String name)
          Return all values of a parameter.
 java.lang.String getQueryString()
           
 BufferedRequest getRequest()
           
 java.lang.String getRequestURI()
           
 javax.servlet.http.HttpServletResponse getResponse()
           
static java.lang.String getString(java.util.Locale locale, java.lang.Object value)
           
 Session getWavesetSession()
           
static boolean hasParameter(javax.servlet.ServletRequest req, java.lang.String name)
           
 boolean hasParameter(java.lang.String name)
          Return true if the request has a value for the named parameter.
 void removeAttribute(java.lang.String name)
          Remove a session attribute.
 void setAttribute(java.lang.String name, java.lang.String value)
          Set a session attribute.
 void setLighthouseContext(LighthouseContext lighthouseContext)
           
 void setLocale(java.util.Locale locale)
           
 void setOption(java.lang.String name, java.lang.Object value)
           
 void setOptions(java.util.Map options)
           
 void setParameter(java.lang.String name, java.lang.Object value)
          Set a post parameter override.
 void setTrace(boolean b)
           
 void setWavesetSession(Session session)
           
 boolean testOption(java.lang.String name)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

code_id

public static final java.lang.String code_id
See Also:
Constant Field Values

trace

protected static Trace trace

OPTION_PREFIX

public static final java.lang.String OPTION_PREFIX
A prefix we look for in request parameter names. Parameters with this prefix will be converted into entries in our "options" map.

See Also:
Constant Field Values

POST_NULL

public static final java.lang.String POST_NULL
Special value we post when the end result is to set the target attribute to null.

See Also:
Constant Field Values
Constructor Detail

RequestState

public RequestState(javax.servlet.http.HttpSession hs,
                    javax.servlet.http.HttpServletRequest req,
                    javax.servlet.http.HttpServletResponse resp,
                    LighthouseContext lighthouseContext,
                    PageInformation pi)
             throws WavesetException
Method Detail

setOption

public void setOption(java.lang.String name,
                      java.lang.Object value)

setOptions

public void setOptions(java.util.Map options)

setTrace

public void setTrace(boolean b)

setLocale

public void setLocale(java.util.Locale locale)

setWavesetSession

public void setWavesetSession(Session session)

cleanup

public void cleanup()
             throws WavesetException
Throws:
WavesetException

getHttpSession

public javax.servlet.http.HttpSession getHttpSession()

getRequest

public BufferedRequest getRequest()

getResponse

public javax.servlet.http.HttpServletResponse getResponse()

getLighthouseContext

public LighthouseContext getLighthouseContext()

setLighthouseContext

public void setLighthouseContext(LighthouseContext lighthouseContext)

getWavesetSession

public Session getWavesetSession()

getOptions

public java.util.Map getOptions()

getLocale

public java.util.Locale getLocale()

getPageInformation

public PageInformation getPageInformation()

getOption

public java.lang.Object getOption(java.lang.String name)

testOption

public boolean testOption(java.lang.String name)

setParameter

public void setParameter(java.lang.String name,
                         java.lang.Object value)
Set a post parameter override. The entries in this map will be returned by getParameter even if there was a real post parameter with the same name. Intended for use by JSPs to make emergency repairs to the post data before passing it along to GenericEditForm.

This only works for simple String parameters right now.


getParameter

public static java.lang.String getParameter(javax.servlet.ServletRequest r,
                                            java.lang.String name)
Return the value of a parameter, collapsing empty strings to null.

Originally this would trim strings, but that isn't always desired so we stopped. Collapsing empty strings to null has also been done for some time, and is more heavily used so don't remove that.

Note that you can't tell the difference between a posted parameter with a null value and a parameter that was never posted. To do that, you have to get the Enumeration of names and check. UPDATE 1/30/02: It can sometimes happen with generated forms that the same field appears more than once, which results in a multi-valued post parameter. In these cases, pick the first value that is non-null.


getParameter

public static java.lang.String getParameter(RequestState req,
                                            java.lang.String name)

getParameter

public java.lang.String getParameter(java.lang.String name)
Return the value of a parameter from the HttpRequest that was supplied to our constructor.

This is the one generally called during post data assimilation, it will obey parameter value overrides specified by the setParameter method.


getParameterValues

public static java.lang.String[] getParameterValues(java.util.Map parameterMap,
                                                    java.lang.String name)
Return from the specified map of parameter values the values of the specified parameter.


getParameter

public static java.lang.String getParameter(java.util.Map parameterMap,
                                            java.lang.String name)
Return from the specified map of parameter values a single value for the specified parameter.


getBooleanParameter

public static boolean getBooleanParameter(javax.servlet.ServletRequest req,
                                          java.lang.String name,
                                          boolean defaultValue)
Return the value of a boolean parameter. If null, return the specified default. Note that unchecked checkboxes return null rather than "false". Truth is defined as the value being either "true" OR having a value equal to the name, which is another common convention.


getBooleanParameter

public static boolean getBooleanParameter(javax.servlet.ServletRequest req,
                                          java.lang.String name)

getBooleanParameter

public boolean getBooleanParameter(java.lang.String name)

getBooleanParameter

public boolean getBooleanParameter(java.lang.String name,
                                   boolean defaultValue)

getIntParameter

public static int getIntParameter(javax.servlet.ServletRequest req,
                                  java.lang.String name,
                                  int defaultValue)
Return the value of an int parameter. If null, return the specified default.


getIntParameter

public static int getIntParameter(javax.servlet.ServletRequest req,
                                  java.lang.String name)
Return the value of an int parameter. If null, return -1.


getIntParameter

public int getIntParameter(java.lang.String name)
Return the value of an int parameter. If null, return -1.


getIntParameter

public int getIntParameter(java.lang.String name,
                           int defaultValue)
Return the value of an int parameter. If null, return the specified default.


hasParameter

public boolean hasParameter(java.lang.String name)
Return true if the request has a value for the named parameter. This is sometimes important in order to tell the difference between a widget not having been used, and one that was used but which had a null value. Since we may iterate over the enumeration often, it would be more effecient to build a convenient Map once and reuse it, that won't however work with the static method.


hasParameter

public static boolean hasParameter(javax.servlet.ServletRequest req,
                                   java.lang.String name)

getParameterMap

public java.util.Map getParameterMap()
                              throws java.io.IOException,
                                     WavesetException
Returns:
an immutable map of parameters from the ServletRequest this contains.
Throws:
java.io.IOException
WavesetException

getAttribute

public java.lang.String getAttribute(java.lang.String name)
Return the value of a session attribute, coercing to a string.


getQueryString

public java.lang.String getQueryString()

getRequestURI

public java.lang.String getRequestURI()

getMethod

public java.lang.String getMethod()

setAttribute

public void setAttribute(java.lang.String name,
                         java.lang.String value)
Set a session attribute.


removeAttribute

public void removeAttribute(java.lang.String name)
Remove a session attribute.


encodeURL

public java.lang.String encodeURL(java.lang.String url)
Encode a response URL.


encodeAbsoluteURL

public java.lang.String encodeAbsoluteURL(java.lang.String url)
Encode a response URL. This is the one you usually want, it takes PageInformation into account. It is called "absolute" as it will use PageInforation to render a fully specified URL rather than a relative URL, something necessary when proxy servers are in use. We could just make this the behavior of encodeURL() above, but I'm not sure who all is depending on the current behavior.


encodeAbsoluteURL

public java.lang.String encodeAbsoluteURL(java.lang.String url,
                                          boolean needSession)
Encode a response URL. This is the one you usually want, it takes PageInformation into account. It is called "absolute" as it will use PageInforation to render a fully specified URL rather than a relative URL, something necessary when proxy servers are in use. We could just make this the behavior of encodeURL() above, but I'm not sure who all is depending on the current behavior.

Parameters:
url - the original url
needSession - Do we need the session id in the url. Added because for applet code base, we don't want the session id since it causes the applet loading to hose up

getContentLength

public int getContentLength()
Returns:
the content length for the specified request state.

getContentLength

public static int getContentLength(RequestState req)
Returns:
the content length for the specified request state.

getParameterValues

public java.lang.String[] getParameterValues(java.lang.String name)
Return all values of a parameter. Unlike getParameter above, we don't try to collapse empty strings.


getString

public static java.lang.String getString(java.util.Locale locale,
                                         java.lang.Object value)

getLocalizedString

public static java.lang.String getLocalizedString(java.util.Locale locale,
                                                  java.lang.Object value)
Coerce an object to a string.

If the result looks like a message catalog key, try to resolve it using the current request locale. General purpose enough to go in util, but we're evolving where message catalogs go, so we may need Session access.


getLocalizedString

public static java.lang.String getLocalizedString(java.lang.String value,
                                                  java.util.Locale locale)

getLocalizedString

public java.lang.String getLocalizedString(java.lang.Object value)

getLocalizedString

public java.lang.String getLocalizedString(int value)
Localize an integer.


getLocalizedString

public static java.lang.String getLocalizedString(java.util.Locale locale,
                                                  int value)