|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface PortletContext
The 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.
Method Summary | |
---|---|
java.lang.Object | getAttribute(java.lang.String name)
Returns the portlet container attribute with the given name, or null if there is no attribute by that name. |
java.util.Enumeration<java.lang.String> | getAttributeNames()
Returns an Enumeration containing the attribute names available within this portlet context, or an empty Enumeration if no attributes are available. |
java.util.Enumeration<java.lang.String> | getContainerRuntimeOptions()
Returns the container container runtime options keys supported by this portlet container. |
java.lang.String | getInitParameter(java.lang.String name)
Returns a String containing the value of the named context-wide initialization parameter, or null if the parameter does not exist. |
java.util.Enumeration<java.lang.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. |
java.lang.String | getMimeType(java.lang.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(java.lang.String name)
Returns a PortletRequestDispatcher object that acts as a wrapper for the named servlet. |
java.lang.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. |
java.lang.String | getRealPath(java.lang.String path)
Returns a String containing the real path for a given virtual path. |
PortletRequestDispatcher | getRequestDispatcher(java.lang.String path)
Returns a PortletRequestDispatcher object that acts as a wrapper for the resource located at the given path. |
java.net.URL | getResource(java.lang.String path)
Returns a URL to the resource that is mapped to a specified path. |
java.io.InputStream | getResourceAsStream(java.lang.String path)
Returns the resource located at the given path as an InputStream object. |
java.util.Set<java.lang.String> | getResourcePaths(java.lang.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. |
java.lang.String | getServerInfo()
Returns the name and version of the portlet container in which the portlet is running. |
void | log(java.lang.String msg)
Writes the specified message to a portlet log file, usually an event log. |
void | log(java.lang.String message,
java.lang.Throwable throwable)
Writes an explanatory message and a stack trace for a given Throwable exception to the portlet log file. |
void | removeAttribute(java.lang.String name)
Removes the attribute with the given name from the portlet context. |
void | setAttribute(java.lang.String name,
java.lang.Object object)
Binds an object to a given attribute name in this portlet context. |
Method Detail |
---|
java.lang.String getServerInfo()
The form of the returned string is containername/versionnumber.
PortletRequestDispatcher getRequestDispatcher(java.lang.String path)
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.
PortletRequestDispatcher getNamedDispatcher(java.lang.String name)
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.
java.io.InputStream getResourceAsStream(java.lang.String path)
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).
int getMajorVersion()
int getMinorVersion()
java.lang.String getMimeType(java.lang.String file)
java.lang.String getRealPath(java.lang.String path)
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).
java.util.Set<java.lang.String> getResourcePaths(java.lang.String path)
java.net.URL getResource(java.lang.String path) throws java.net.MalformedURLException
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.
java.lang.Object getAttribute(java.lang.String name)
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.*.
java.util.Enumeration<java.lang.String> getAttributeNames()
java.lang.String getInitParameter(java.lang.String name)
java.util.Enumeration<java.lang.String> getInitParameterNames()
void log(java.lang.String msg)
This method mapps to the ServletContext.log method. The portlet container may in addition log this message in a portlet container specific log file.
void log(java.lang.String message, java.lang.Throwable throwable)
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.
void removeAttribute(java.lang.String name)
void setAttribute(java.lang.String name, java.lang.Object object)
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.*.
java.lang.String getPortletContextName()
java.util.Enumeration<java.lang.String> getContainerRuntimeOptions()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |