org.apache.tapestry.web
Class ServletWebRequest

java.lang.Object
  extended byorg.apache.tapestry.web.ServletWebRequest
All Implemented Interfaces:
AttributeHolder, Describable, WebRequest

public class ServletWebRequest
extends java.lang.Object
implements WebRequest

Adapter from HttpServletRequest to WebRequest.

Since:
4.0
Author:
Howard M. Lewis Ship

Constructor Summary
ServletWebRequest(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
           
 
Method Summary
 void describeTo(DescriptionReceiver receiver)
          Invoked to have the receiver describe itself (largely in terms of properties and values).
 void forward(java.lang.String URL)
          Redirects to the indicated URL.
 java.lang.String getActivationPath()
          Returns HttpServletRequest.getServletPath().
 java.lang.Object getAttribute(java.lang.String name)
          Returns the named object, or null if no attribute has been stored with the given name.
 java.util.List getAttributeNames()
          Returns a list of all known attributes in ascending alphabetical order.
 java.lang.String getContextPath()
          Returns the portion of the request URI that indicates the context of the request.
 java.lang.String getHeader(java.lang.String name)
          Returns the value of the specified request header.
 java.util.Locale getLocale()
          Returns the preferred locale to which content should be localized, as specified by the client or by the container.
 java.util.List getParameterNames()
          Returns the names of all query parameters for this request.
 java.lang.String getParameterValue(java.lang.String parameterName)
          Returns a parameter value.
 java.lang.String[] getParameterValues(java.lang.String parameterName)
          Returns all parameter values for a particular parameter name.
 java.lang.String getPathInfo()
          Return any additional path info beyond the servlet path itself.
 java.lang.String getRemoteUser()
          Returns the login of the user making this request, if the user has been authenticated, or null if the user has not been authenticated.
 java.lang.String getRequestURI()
          Returns the path portion of the request which triggered this request.
 java.lang.String getScheme()
          Returns the name of the scheme used to make this request.
 java.lang.String getServerName()
          Returns the host name of the server that received the request.
 int getServerPort()
          Returns the port number on which this request was received.
 WebSession getSession(boolean create)
          Returns the current WebSessionassociated with this request, possibly creating it if it does not already exist.
 java.security.Principal getUserPrincipal()
          Returns a java.security.Principal object containing the name of the current authenticated user.
 boolean isUserInRole(java.lang.String role)
          * Returns a boolean indicating whether the authenticated user is included in the specified logical "role".
 void setAttribute(java.lang.String name, java.lang.Object attribute)
          Updates the attribute, replacing (or removing) its value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ServletWebRequest

public ServletWebRequest(javax.servlet.http.HttpServletRequest request,
                         javax.servlet.http.HttpServletResponse response)
Method Detail

getParameterNames

public java.util.List getParameterNames()
Description copied from interface: WebRequest
Returns the names of all query parameters for this request. Note that this may return an empty list if an HTML form submission uploads files (with a request encoding of multipart/form-data). Accessing query parameters in such an event requires parsing of the request input stream.

Specified by:
getParameterNames in interface WebRequest

getParameterValue

public java.lang.String getParameterValue(java.lang.String parameterName)
Description copied from interface: WebRequest
Returns a parameter value. If the parameter was submitted with multiple values, then the first submitted value is returned. May return null if no parameter was submitted with the given name.

Specified by:
getParameterValue in interface WebRequest
Parameters:
parameterName - name of parameter to obtain
Returns:
the corresponding value, or null if a value for the parameter was not submitted in the request
See Also:
WebRequest.getParameterValues(String)

getParameterValues

public java.lang.String[] getParameterValues(java.lang.String parameterName)
Description copied from interface: WebRequest
Returns all parameter values for a particular parameter name. May return null.

The caller should not modify the returned value.

Specified by:
getParameterValues in interface WebRequest
Parameters:
parameterName - name of parameter to obtain
Returns:
the corresponding values, or null if no values for the parameter were submitted in the request
See Also:
WebRequest.getParameterValue(String)

getContextPath

public java.lang.String getContextPath()
Description copied from interface: WebRequest
Returns the portion of the request URI that indicates the context of the request. The context path always comes first in a request URI. The path starts with a "/" character but does not end with a "/" character.

Specified by:
getContextPath in interface WebRequest

getSession

public WebSession getSession(boolean create)
Description copied from interface: WebRequest
Returns the current WebSessionassociated with this request, possibly creating it if it does not already exist. If create is false and the request has no valid session, this method returns null. To make sure the session is properly maintained, you must call this method before the response is committed.

Specified by:
getSession in interface WebRequest
Parameters:
create - if true, the session will be created and returned if it does not already exist

getAttributeNames

public java.util.List getAttributeNames()
Description copied from interface: AttributeHolder
Returns a list of all known attributes in ascending alphabetical order. May be empty (but won't be null).

Specified by:
getAttributeNames in interface AttributeHolder

getAttribute

public java.lang.Object getAttribute(java.lang.String name)
Description copied from interface: AttributeHolder
Returns the named object, or null if no attribute has been stored with the given name.

Specified by:
getAttribute in interface AttributeHolder

setAttribute

public void setAttribute(java.lang.String name,
                         java.lang.Object attribute)
Description copied from interface: AttributeHolder
Updates the attribute, replacing (or removing) its value. For certain implementations, the attribute may need to be serializable (for example, a WebSession  attribute in a clustered application).

Specified by:
setAttribute in interface AttributeHolder
Parameters:
name - the name of the attribute to update
attribute - the new value for the attribute, or null to delete the attribute entirely.

getScheme

public java.lang.String getScheme()
Description copied from interface: WebRequest
Returns the name of the scheme used to make this request. For example, http, https, or ftp. Different schemes have different rules for constructing URLs, as noted in RFC 1738.

Specified by:
getScheme in interface WebRequest

getServerName

public java.lang.String getServerName()
Description copied from interface: WebRequest
Returns the host name of the server that received the request. Note that behind a firewall, this may be obscured (i.e., it may be the name of the firewall server, which is not necessarily visible to clients outside the firewall).

Specified by:
getServerName in interface WebRequest
See Also:
IRequestDecoder

getServerPort

public int getServerPort()
Description copied from interface: WebRequest
Returns the port number on which this request was received.

Specified by:
getServerPort in interface WebRequest

getRequestURI

public java.lang.String getRequestURI()
Description copied from interface: WebRequest
Returns the path portion of the request which triggered this request. Query parameters, scheme, server and port are omitted.

Note: portlets do not know their request URI.

Specified by:
getRequestURI in interface WebRequest

forward

public void forward(java.lang.String URL)
Description copied from interface: WebRequest
Redirects to the indicated URL. If the URL is local, then a forward occurs. Otherwise, a client side redirect is returned to the client browser.

Specified by:
forward in interface WebRequest

getActivationPath

public java.lang.String getActivationPath()
Returns HttpServletRequest.getServletPath().

Specified by:
getActivationPath in interface WebRequest

getPathInfo

public java.lang.String getPathInfo()
Description copied from interface: WebRequest
Return any additional path info beyond the servlet path itself. Path info, if non-null, begins with a path.

Specified by:
getPathInfo in interface WebRequest
Returns:
path info, or null if no path info

getLocale

public java.util.Locale getLocale()
Description copied from interface: WebRequest
Returns the preferred locale to which content should be localized, as specified by the client or by the container. May return null.

Specified by:
getLocale in interface WebRequest

describeTo

public void describeTo(DescriptionReceiver receiver)
Description copied from interface: Describable
Invoked to have the receiver describe itself (largely in terms of properties and values). If the caller does not invoke any methods on the receiver, then the a default description of the caller will be used (based on toString().

Specified by:
describeTo in interface Describable

getHeader

public java.lang.String getHeader(java.lang.String name)
Description copied from interface: WebRequest
Returns the value of the specified request header.

Specified by:
getHeader in interface WebRequest
Parameters:
name - the name of the header to retrieve
Returns:
the header value as a string, or null if the header is not in the request.

getRemoteUser

public java.lang.String getRemoteUser()
Description copied from interface: WebRequest
Returns the login of the user making this request, if the user has been authenticated, or null if the user has not been authenticated.

Specified by:
getRemoteUser in interface WebRequest
Returns:
a String specifying the login of the user making this request, or null if the user login is not known.

getUserPrincipal

public java.security.Principal getUserPrincipal()
Description copied from interface: WebRequest
Returns a java.security.Principal object containing the name of the current authenticated user.

Specified by:
getUserPrincipal in interface WebRequest
Returns:
a java.security.Principal containing the name of the user making this request, or null if the user has not been authenticated.

isUserInRole

public boolean isUserInRole(java.lang.String role)
Description copied from interface: WebRequest
* Returns a boolean indicating whether the authenticated user is included in the specified logical "role". Roles and role membership can be defined using deployment descriptors. If the user has not been authenticated, the method returns false.

Specified by:
isUserInRole in interface WebRequest
Parameters:
role - a String specifying the name of the role
Returns:
a boolean indicating whether the user making this request belongs to a given role; false if the user has not been authenticated.