PortletContext interface defines a portlet view
of the portlet container.
The PortletContext also makes resources available
to the portlet. Using the context, a portlet can access
the portlet log, and obtain URL references to resources.
There is one context per "portlet application" per Java Virtual Machine. (A
"portlet application" is a collection of portlets, servlets, and content installed
under a specific subset of the server URL namespace, such as /catalog.
They are possibly installed via a .war file.)
As a web application, a portlet application also has a servlet context.
The portlet context leverages most of its functionality from the
servlet context of the portlet application.
Attributes stored in the context are global for all users and all components in the portlet application.
In the case of a web application marked "distributed" in its deployment descriptor, there will be one context instance for each virtual machine. In this situation, the context cannot be used as a location to share global information (because the information is not truly global). Use an external resource, such as a database to achieve sharing on a global scope.
| Modifier and Type | Method and Description |
|---|---|
| public Object | Returns: anObject containing the value
of the attribute, or null
if no attribute exists matching the given
namea name)String specifying the name
of the attributeReturns the portlet container attribute with the given name, or null if there is no attribute by that name. |
| public Enumeration | Returns: anEnumeration of attribute namesReturns an |
| public ClassLoader | Returns: the class loader for this portlet application.
Returns the class loader for this portlet context.
|
| public Enumeration | Returns: container runtime options keys supported by this container as String values.Returns the container container runtime options keys supported by this portlet container. |
| public String | Returns: the context path for this portlet application.
Returns the context path for this portlet application.
|
| public int | Returns: the major version
Returns the major version of the
Portlet API used by the portlet application running in this PortletContext.
|
| public int | Returns: the minor version
Returns the minor version of the
Portlet API used by the portlet application running in this PortletContext.
|
| public String | Returns: aString containing the value
of the initialization parameter, or
null if the parameter does not exist.a name)String containing the name of the
requested parameterReturns a String containing the value of the named context-wide
initialization parameter, or |
| public Enumeration | Returns: anEnumeration of String
objects containing the names of the context
initialization parametersReturns the names of the context initialization parameters as an
|
| public int | Returns: the major versionReturns the major version of the Portlet API that this portlet container supports. |
| public String | Returns: aString specifying the MIME type of the filea file)String specifying the name
of a fileReturns the MIME type of the specified file, or |
| public int | Returns: the minor versionReturns the minor version of the Portlet API that this portlet container supports. |
| public PortletRequestDispatcher | Returns: aPortletRequestDispatcher object
that acts as a wrapper for the named servleta name)String specifying the name
of a servlet to be wrappedReturns a |
| public String | Returns: The name of the web application or null if no name has been declared in the deployment descriptor.Returns the name of this portlet application correponding to this PortletContext as specified
in the |
| public String | Returns: aString specifying the real path,
or null if the transformation cannot be performed.a path)String specifying a virtual pathReturns a |
| public PortletRequestDispatcher | Returns: aPortletRequestDispatcher object
that acts as a wrapper for the resource
at the specified path.a path)String specifying the pathname
to the resourceReturns a |
| public URL | Returns: the resource located at the named path, ornull if there is no resource
at that patha path)String specifying
the path to the resourceReturns a URL to the resource that is mapped to a specified path. |
| public InputStream | Returns: the input streamthe path to the resource path)Returns the resource located at the given path as an InputStream object. |
| public Set | Returns: a Set containing the directory listing, ornull if there
are no resources in the web application of which the path
begins with the supplied path.the partial path used to match the resources, which must start with a slash 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. |
| public String | Returns: the string containing at least name and version numberReturns the name and version of the portlet container in which the portlet is running. |
| public void | |
| public void | |
| public void | removeAttribute(String
a name)String specifying the name
of the attribute to be removedRemoves the attribute with the given name from the portlet context. |
| public void | setAttribute(String
a name, Object String specifying the name
of the attributean object)Object representing the
attribute to be boundBinds an object to a given attribute name in this portlet context. |
| getAttribute | back to summary |
|---|---|
| public Object getAttribute(String name) Returns the portlet container attribute with the given name,
or null if there is no attribute by that name.
An attribute allows a portlet container to give the
portlet additional information not
already provided by this interface.
A list of supported attributes can be retrieved using
The attribute is returned as a
| |
| getAttributeNames | back to summary |
|---|---|
| public Enumeration Returns an
| |
| getClassLoader | back to summary |
|---|---|
| public ClassLoader getClassLoader()
Returns the class loader for this portlet context.
| |
| getContainerRuntimeOptions | back to summary |
|---|---|
| public Enumeration Returns the container container runtime options keys supported by this portlet container.
| |
| getContextPath | back to summary |
|---|---|
| public String getContextPath()
Returns the context path for this portlet application.
| |
| getEffectiveMajorVersion | back to summary |
|---|---|
| public int getEffectiveMajorVersion()
Returns the major version of the
Portlet API used by the portlet application running in this PortletContext.
| |
| getEffectiveMinorVersion | back to summary |
|---|---|
| public int getEffectiveMinorVersion()
Returns the minor version of the
Portlet API used by the portlet application running in this PortletContext.
| |
| getInitParameter | back to summary |
|---|---|
| public String getInitParameter(String name) Returns a String containing the value of the named context-wide
initialization parameter, or
| |
| getInitParameterNames | back to summary |
|---|---|
| public Enumeration Returns the names of the context initialization parameters as an
| |
| getMajorVersion | back to summary |
|---|---|
| public int getMajorVersion() Returns the major version of the Portlet API that this portlet container supports.
| |
| getMimeType | back to summary |
|---|---|
| public String getMimeType(String file) Returns the MIME type of the specified file, or | |
| getMinorVersion | back to summary |
|---|---|
| public int getMinorVersion() Returns the minor version of the Portlet API that this portlet container supports.
| |
| getNamedDispatcher | back to summary |
|---|---|
| public PortletRequestDispatcher getNamedDispatcher(String name) Returns a Servlets (and also JSP pages) may be given names via server administration or via a web application deployment descriptor. This method returns
| |
| getPortletContextName | back to summary |
|---|---|
| public String getPortletContextName() Returns the name of this portlet application correponding to this PortletContext as specified
in the
| |
| getRealPath | back to summary |
|---|---|
| public String getRealPath(String path) Returns a 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 | |
| getRequestDispatcher | back to summary |
|---|---|
| public PortletRequestDispatcher getRequestDispatcher(String path) Returns a The pathname must begin with a slash ( This method returns
| |
| getResource | back to summary |
|---|---|
| public URL getResource(String path) throws MalformedURLException Returns a URL to the resource that is mapped to a specified
path. The path must begin with a slash ( 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 The portlet container must implement the URL handlers
and This method returns 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 This method has a different purpose than
| |
| getResourceAsStream | back to summary |
|---|---|
| public InputStream getResourceAsStream(String path) Returns the resource located at the given path as an InputStream object. The data in the InputStream can be of any type or length. The method returns null if no resource exists at the given path.
In order to access protected resources the path has to be prefixed with
| |
| getResourcePaths | back to summary |
|---|---|
| public Set 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. Paths indicating subdirectory paths
end with a slash ( | |
| getServerInfo | back to summary |
|---|---|
| public String getServerInfo() Returns the name and version of the portlet container in which the portlet is running.
The form of the returned string is
| |
| log | back to summary |
|---|---|
| public void log(String msg) Writes the specified message to a portlet log file, usually an event log. The name and type of the portlet log file is specific to the portlet container.
This method mapps to the
| |
| log | back to summary |
|---|---|
| public void log(String message, Throwable throwable) Writes an explanatory message and a stack trace for a given Throwable exception to the portlet log file. The name and type of the portlet log file is specific to the portlet container, usually an event log.
This method is mapped to the | |
| removeAttribute | back to summary |
|---|---|
| public void removeAttribute(String name) Removes the attribute with the given name from the portlet context.
After removal, subsequent calls to
| |
| setAttribute | back to summary |
|---|---|
| public void setAttribute(String name, Object object) Binds an object to a given attribute name in this portlet context. If the name specified is already used for an attribute, this method removes the old attribute and binds the name to the new attribute.
If a null value is passed, the effect is the same as calling
Attribute names should follow the same convention as package
names. The Java Portlet API specification reserves names
matching
| |