org.apache.tapestry.web
Class ServletWebContext

java.lang.Object
  extended by org.apache.tapestry.web.ServletWebContext
All Implemented Interfaces:
Describable, AttributeHolder, InitializationParameterHolder, WebContext

public class ServletWebContext
extends Object
implements WebContext

Adapts ServletContext as WebContext.

Since:
4.0
Author:
Howard M. Lewis Ship

Constructor Summary
ServletWebContext(ServletContext context)
           
 
Method Summary
 void describeTo(DescriptionReceiver receiver)
          Invoked to have the receiver describe itself (largely in terms of properties and values).
 Object getAttribute(String name)
          Returns the named object, or null if no attribute has been stored with the given name.
 List getAttributeNames()
          Returns a list of all known attributes in ascending alphabetical order.
 List getInitParameterNames()
          Returns a sorted list of the names of all initialization parameters (which may be the empty list).
 String getInitParameterValue(String name)
          Returns the value of the named parameter, or null if the reciever does not have such a parameter.
 String getMimeType(String resourcePath)
          Returns the MIME type of the specified file, or null if the MIME type is not known.
 String getRealPath(String path)
          Returns a String containing the real path for a given virtual path.
 URL getResource(String path)
          Returns a URL to the resource that is mapped to a specified path.
 InputStream getResourceAsStream(String path)
          Returns the resource located at the named path as an InputStream object.
 Set getResourcePaths(String path)
          Returns a directory-like listing of all the paths to resources within the web application whose longest sub-path matches the supplied path argument.
 void setAttribute(String name, 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

ServletWebContext

public ServletWebContext(ServletContext context)
Method Detail

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

getAttributeNames

public 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 Object getAttribute(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(String name,
                         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.

getResource

public URL getResource(String path)
Description copied from interface: WebContext
Returns a URL to the resource that is mapped to a specified path. The path must begin with a "/" and is interpreted as relative to the current context root.

Specified by:
getResource in interface WebContext

getInitParameterValue

public String getInitParameterValue(String name)
Description copied from interface: InitializationParameterHolder
Returns the value of the named parameter, or null if the reciever does not have such a parameter.

Specified by:
getInitParameterValue in interface InitializationParameterHolder
Parameters:
name - the name of the parameter to retrieve
Returns:
the corresponding value, or null

getInitParameterNames

public List getInitParameterNames()
Description copied from interface: InitializationParameterHolder
Returns a sorted list of the names of all initialization parameters (which may be the empty list).

Specified by:
getInitParameterNames in interface InitializationParameterHolder
Returns:
List of String

getMimeType

public String getMimeType(String resourcePath)
Description copied from interface: WebContext
Returns the MIME type of the specified file, or null if the MIME type is not known.

Specified by:
getMimeType in interface WebContext

getRealPath

public String getRealPath(String path)
Description copied from interface: WebContext
Returns a String containing the real path for a given virtual path. For example, the path "/index.html" returns the absolute file path on the server's filesystem would be served by a request for "http://host/contextPath/index.html", where contextPath is the context path of this WebContext.

Specified by:
getRealPath in interface WebContext
Parameters:
path - a String specifying a virtual path
Returns:
a String specifying the real path, or null if the translation cannot be performed

getResourceAsStream

public InputStream getResourceAsStream(String path)
Description copied from interface: WebContext
Returns the resource located at the named path as an InputStream object.

Specified by:
getResourceAsStream in interface WebContext
Parameters:
path - a String specifying the path to the resource
Returns:
the InputStream returned to the servlet, or null if no resource exists at the specified path

getResourcePaths

public Set getResourcePaths(String path)
Description copied from interface: WebContext
Returns a directory-like listing of all the paths to resources within the web application whose longest sub-path matches the supplied path argument. Paths indicating subdirectory paths end with a slash (/). The returned paths are all relative to the root of the web application and have a leading '/'.

Specified by:
getResourcePaths in interface WebContext
Parameters:
path - partial path used to match the resources, which must start with a '/'
Returns:
a Set containing the directory listing, or null if there are no resources in the web application whose path begins with the supplied path.


Copyright © 2006-2008 Apache Software Foundation. All Rights Reserved.