public class PortletContextWrapper extends Object implements PortletContext
PortletContextWrapper provides a convenient
implementation of the PortletContext interface
that can be subclassed by developers.
This class implements the Wrapper or Decorator pattern.
Methods default to calling through to the wrapped request object.
| Modifier and Type | Field and Description |
|---|---|
protected PortletContext |
wrapped |
| Constructor and Description |
|---|
PortletContextWrapper(PortletContext wrapped) |
| Modifier and Type | Method and Description |
|---|---|
Object |
getAttribute(String name)
Returns the portlet container attribute with the given name,
or null if there is no attribute by that name.
|
Enumeration<String> |
getAttributeNames()
Returns an
Enumeration containing the attribute names
available within this portlet context, or an empty
Enumeration if no attributes are available. |
ClassLoader |
getClassLoader()
Returns the class loader for this portlet context.
|
Enumeration<String> |
getContainerRuntimeOptions()
Returns the container container runtime options
keys supported by this portlet container.
|
String |
getContextPath()
Returns the context path for this portlet application.
|
int |
getEffectiveMajorVersion()
Returns the major version of the
Portlet API used by the portlet application running in this PortletContext.
|
int |
getEffectiveMinorVersion()
Returns the minor version of the
Portlet API used by the portlet application running in this PortletContext.
|
String |
getInitParameter(String name)
Returns a String containing the value of the named context-wide
initialization parameter, or
null if the parameter does not exist. |
Enumeration<String> |
getInitParameterNames()
Returns the names of the context initialization parameters as an
Enumeration of String objects, or an empty Enumeration if the context
has no initialization parameters. |
int |
getMajorVersion()
Returns the major version of the Portlet API that this portlet
container supports.
|
String |
getMimeType(String file)
Returns the MIME type of the specified file, or
null if
the MIME type is not known. |
int |
getMinorVersion()
Returns the minor version of the Portlet API that this portlet
container supports.
|
PortletRequestDispatcher |
getNamedDispatcher(String name)
Returns a
PortletRequestDispatcher object that acts
as a wrapper for the named servlet. |
PortletContext |
getPortletContext()
Gets the wrapped object.
|
String |
getPortletContextName()
Returns the name of this portlet application correponding to this PortletContext as specified
in the
web.xml deployment descriptor for this web application by the
display-name element. |
String |
getRealPath(String path)
Returns a
String containing the real path
for a given virtual path. |
PortletRequestDispatcher |
getRequestDispatcher(String path)
Returns a
PortletRequestDispatcher object that acts
as a wrapper for the resource located at the given 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 given path as an InputStream object.
|
Set<String> |
getResourcePaths(String path)
Returns a directory-like listing of all the paths to resources within
the web application longest sub-path of which
matches the supplied path argument.
|
String |
getServerInfo()
Returns the name and version of the portlet container in which the
portlet is running.
|
void |
log(String msg)
Writes the specified message to a portlet log file, usually an event log.
|
void |
log(String message,
Throwable throwable)
Writes an explanatory message and a stack trace for a given
Throwable exception to the portlet log file.
|
void |
removeAttribute(String name)
Removes the attribute with the given name from the portlet context.
|
void |
setAttribute(String name,
Object object)
Binds an object to a given attribute name in this portlet context.
|
void |
setPortletContext(PortletContext wrapped)
Sets the wrapped object.
|
protected PortletContext wrapped
public PortletContextWrapper(PortletContext wrapped)
public PortletContext getPortletContext()
public void setPortletContext(PortletContext wrapped)
wrapped - the wrapped object to set.IllegalArgumentException - if the PortletContext is null.public String getServerInfo()
PortletContext
The form of the returned string is containername/versionnumber.
getServerInfo in interface PortletContextpublic PortletRequestDispatcher getRequestDispatcher(String path)
PortletContextPortletRequestDispatcher object that acts
as a wrapper for the resource located at the given path.
A PortletRequestDispatcher object can be used include the
resource in a response. The resource can be dynamic or static.
The pathname must begin with a slash ( / ) and is interpreted as relative
to the current context root.
This method returns null if the PortletContext
cannot return a PortletRequestDispatcher
for any reason.
getRequestDispatcher in interface PortletContextpath - a String specifying the pathname
to the resourcePortletRequestDispatcher object
that acts as a wrapper for the resource
at the specified path.PortletRequestDispatcherpublic PortletRequestDispatcher getNamedDispatcher(String name)
PortletContextPortletRequestDispatcher object that acts
as a wrapper for the named servlet.
Servlets (and also JSP pages) may be given names via server administration or via a web application deployment descriptor.
This method returns null if the
PortletContext cannot return a
PortletRequestDispatcher for any reason.
getNamedDispatcher in interface PortletContextname - a String specifying the name
of a servlet to be wrappedPortletRequestDispatcher object
that acts as a wrapper for the named servletPortletRequestDispatcherpublic InputStream getResourceAsStream(String path)
PortletContext
In order to access protected resources the path has to be prefixed with
/WEB-INF/ (for example /WEB-INF/myportlet/myportlet.jsp).
Otherwise, the direct path is used
(for example /myportlet/myportlet.jsp).
getResourceAsStream in interface PortletContextpath - the path to the resourcepublic int getMajorVersion()
PortletContextgetMajorVersion in interface PortletContextPortletContext.getMinorVersion()public int getMinorVersion()
PortletContextgetMinorVersion in interface PortletContextPortletContext.getMajorVersion()public String getMimeType(String file)
PortletContextnull if
the MIME type is not known. The MIME type is determined
by the configuration of the portlet container and may be specified
in a web application deployment descriptor. Common MIME
types are text/html and image/gif.getMimeType in interface PortletContextfile - a String specifying the name
of a fileString specifying the MIME type of the filepublic String getRealPath(String path)
PortletContextString containing the real path
for a given virtual path. For example, the path /index.html
returns the absolute file path of the portlet container file system.
The real path returned will be in a form
appropriate to the computer and operating system on
which the portlet container is running, including the
proper path separators. This method returns null
if the portlet container cannot translate the virtual path
to a real path for any reason (such as when the content is
being made available from a .war archive).
getRealPath in interface PortletContextpath - a String specifying a virtual pathString specifying the real path,
or null if the transformation cannot be performed.public Set<String> getResourcePaths(String path)
PortletContext/). The returned paths are all
relative to the root of the web application and have a leading slash.
For example, for a web application
containing
/welcome.html
/catalog/index.html
/catalog/products.html
/catalog/offers/books.html
/catalog/offers/music.html
/customer/login.jsp
/WEB-INF/web.xml
/WEB-INF/classes/com.acme.OrderPortlet.class,
getResourcePaths("/") returns
{"/welcome.html", "/catalog/", "/customer/", "/WEB-INF/"}getResourcePaths("/catalog/") returns
{"/catalog/index.html", "/catalog/products.html", "/catalog/offers/"}.getResourcePaths in interface PortletContextpath - the partial path used to match the resources, which must start with a slashnull if there
are no resources in the web application of which the path
begins with the supplied path.public URL getResource(String path) throws MalformedURLException
PortletContext/) and is interpreted
as relative to the current context root.
This method allows the portlet container to make a resource
available to portlets from any source. Resources
can be located on a local or remote
file system, in a database, or in a .war file.
The portlet container must implement the URL handlers
and URLConnection objects that are necessary
to access the resource.
This method returns null
if no resource is mapped to the pathname.
Some containers may allow writing to the URL returned by this method using the methods of the URL class.
The resource content is returned directly, so be aware that
requesting a .jsp page returns the JSP source code.
Use a RequestDispatcher instead to include results of
an execution.
This method has a different purpose than
java.lang.Class.getResource,
which looks up resources based on a class loader. This
method does not use class loaders.
getResource in interface PortletContextpath - a String specifying
the path to the resourcenull if there is no resource
at that pathMalformedURLException - if the pathname is not given in
the correct formpublic Object getAttribute(String name)
PortletContextgetAttributeNames.
The attribute is returned as a java.lang.Object
or some subclass.
Attribute names should follow the same convention as package
names. The Java Portlet API specification reserves names
matching java.*, javax.*,
and sun.*.
getAttribute in interface PortletContextname - a String specifying the name
of the attributeObject containing the value
of the attribute, or null
if no attribute exists matching the given
namePortletContext.getAttributeNames()public Enumeration<String> getAttributeNames()
PortletContextEnumeration containing the attribute names
available within this portlet context, or an empty
Enumeration if no attributes are available. Use the
PortletContext.getAttribute(java.lang.String) method with an attribute name
to get the value of an attribute.getAttributeNames in interface PortletContextEnumeration of attribute namesPortletContext.getAttribute(java.lang.String)public String getInitParameter(String name)
PortletContextnull if the parameter does not exist.
This method provides configuration information which may be useful for
an entire "portlet application".getInitParameter in interface PortletContextname - a String containing the name of the
requested parameterString containing the value
of the initialization parameter, or
null if the parameter does not exist.PortletContext.getInitParameterNames()public Enumeration<String> getInitParameterNames()
PortletContextEnumeration of String objects, or an empty Enumeration if the context
has no initialization parameters.getInitParameterNames in interface PortletContextEnumeration of String
objects containing the names of the context
initialization parametersPortletContext.getInitParameter(java.lang.String)public void log(String msg)
PortletContext
This method mapps to the ServletContext.log method.
The portlet container may in addition log this message in a
portlet container specific log file.
log in interface PortletContextmsg - a String specifying the
message to be written to the log filepublic void log(String message, Throwable throwable)
PortletContext
This method is mapped to the ServletContext.log method.
The portlet container may in addition log this message in a
portlet container specific log file.
log in interface PortletContextmessage - a String that
describes the error or exceptionthrowable - the Throwable error
or exceptionpublic void removeAttribute(String name)
PortletContextPortletContext.getAttribute(java.lang.String) to retrieve the attribute's value
will return null.removeAttribute in interface PortletContextname - a String specifying the name
of the attribute to be removedpublic void setAttribute(String name, Object object)
PortletContext
If a null value is passed, the effect is the same as calling
removeAttribute().
Attribute names should follow the same convention as package
names. The Java Portlet API specification reserves names
matching java.*, javax.*, and
sun.*.
setAttribute in interface PortletContextname - a String specifying the name
of the attributeobject - an Object representing the
attribute to be boundpublic String getPortletContextName()
PortletContextweb.xml deployment descriptor for this web application by the
display-name element.getPortletContextName in interface PortletContextpublic Enumeration<String> getContainerRuntimeOptions()
PortletContextgetContainerRuntimeOptions in interface PortletContextpublic int getEffectiveMajorVersion()
PortletContextgetEffectiveMajorVersion in interface PortletContextPortletContext.getEffectiveMinorVersion()public int getEffectiveMinorVersion()
PortletContextgetEffectiveMinorVersion in interface PortletContextPortletContext.getEffectiveMajorVersion()public String getContextPath()
PortletContextgetContextPath in interface PortletContextpublic ClassLoader getClassLoader()
PortletContextgetClassLoader in interface PortletContextJava Portlet 3.0 API Specification. See the Copyright and License provided with this distribution. Use is subject to license terms.