Class PortletContextWrapper
- java.lang.Object
-
- jakarta.portlet.filter.PortletContextWrapper
-
- All Implemented Interfaces:
PortletContext
public class PortletContextWrapper extends Object implements PortletContext
ThePortletContextWrapperprovides a convenient implementation of thePortletContextinterface that can be subclassed by developers. This class implements the Wrapper or Decorator pattern. Methods default to calling through to the wrapped request object.- Since:
- 3.0
-
-
Field Summary
Fields Modifier and Type Field Description protected PortletContextwrapped
-
Constructor Summary
Constructors Constructor Description PortletContextWrapper(PortletContext wrapped)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ObjectgetAttribute(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 anEnumerationcontaining the attribute names available within this portlet context, or an emptyEnumerationif no attributes are available.ClassLoadergetClassLoader()Returns the class loader for this portlet context.Enumeration<String>getContainerRuntimeOptions()Returns the container container runtime options keys supported by this portlet container.StringgetContextPath()Returns the context path for this portlet application.intgetEffectiveMajorVersion()Returns the major version of the Portlet API used by the portlet application running in this PortletContext.intgetEffectiveMinorVersion()Returns the minor version of the Portlet API used by the portlet application running in this PortletContext.StringgetInitParameter(String name)Returns a String containing the value of the named context-wide initialization parameter, ornullif the parameter does not exist.Enumeration<String>getInitParameterNames()Returns the names of the context initialization parameters as anEnumerationof String objects, or an empty Enumeration if the context has no initialization parameters.intgetMajorVersion()Returns the major version of the Portlet API that this portlet container supports.StringgetMimeType(String file)Returns the MIME type of the specified file, ornullif the MIME type is not known.intgetMinorVersion()Returns the minor version of the Portlet API that this portlet container supports.PortletRequestDispatchergetNamedDispatcher(String name)Returns aPortletRequestDispatcherobject that acts as a wrapper for the named servlet.PortletContextgetPortletContext()Gets the wrapped object.StringgetPortletContextName()Returns the name of this portlet application correponding to this PortletContext as specified in theweb.xmldeployment descriptor for this web application by thedisplay-nameelement.StringgetRealPath(String path)Returns aStringcontaining the real path for a given virtual path.PortletRequestDispatchergetRequestDispatcher(String path)Returns aPortletRequestDispatcherobject that acts as a wrapper for the resource located at the given path.URLgetResource(String path)Returns a URL to the resource that is mapped to a specified path.InputStreamgetResourceAsStream(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.StringgetServerInfo()Returns the name and version of the portlet container in which the portlet is running.voidlog(String msg)Writes the specified message to a portlet log file, usually an event log.voidlog(String message, Throwable throwable)Writes an explanatory message and a stack trace for a given Throwable exception to the portlet log file.voidremoveAttribute(String name)Removes the attribute with the given name from the portlet context.voidsetAttribute(String name, Object object)Binds an object to a given attribute name in this portlet context.voidsetPortletContext(PortletContext wrapped)Sets the wrapped object.
-
-
-
Field Detail
-
wrapped
protected PortletContext wrapped
-
-
Constructor Detail
-
PortletContextWrapper
public PortletContextWrapper(PortletContext wrapped)
- Parameters:
wrapped- the wrapped context
-
-
Method Detail
-
getPortletContext
public PortletContext getPortletContext()
Gets the wrapped object.- Returns:
- the wrapped object.
-
setPortletContext
public void setPortletContext(PortletContext wrapped)
Sets the wrapped object.- Parameters:
wrapped- the wrapped object to set.- Throws:
IllegalArgumentException- if the PortletContext is null.
-
getServerInfo
public String getServerInfo()
Description copied from interface:PortletContextReturns the name and version of the portlet container in which the portlet is running.The form of the returned string is
containername/versionnumber.- Specified by:
getServerInfoin interfacePortletContext- Returns:
- the string containing at least name and version number
-
getRequestDispatcher
public PortletRequestDispatcher getRequestDispatcher(String path)
Description copied from interface:PortletContextReturns aPortletRequestDispatcherobject that acts as a wrapper for the resource located at the given path. APortletRequestDispatcherobject 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
nullif thePortletContextcannot return aPortletRequestDispatcherfor any reason.- Specified by:
getRequestDispatcherin interfacePortletContext- Parameters:
path- aStringspecifying the pathname to the resource- Returns:
- a
PortletRequestDispatcherobject that acts as a wrapper for the resource at the specified path. - See Also:
PortletRequestDispatcher
-
getNamedDispatcher
public PortletRequestDispatcher getNamedDispatcher(String name)
Description copied from interface:PortletContextReturns aPortletRequestDispatcherobject 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
nullif thePortletContextcannot return aPortletRequestDispatcherfor any reason.- Specified by:
getNamedDispatcherin interfacePortletContext- Parameters:
name- aStringspecifying the name of a servlet to be wrapped- Returns:
- a
PortletRequestDispatcherobject that acts as a wrapper for the named servlet - See Also:
PortletRequestDispatcher
-
getResourceAsStream
public InputStream getResourceAsStream(String path)
Description copied from interface:PortletContextReturns 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
/WEB-INF/(for example/WEB-INF/myportlet/myportlet.jsp). Otherwise, the direct path is used (for example/myportlet/myportlet.jsp).- Specified by:
getResourceAsStreamin interfacePortletContext- Parameters:
path- the path to the resource- Returns:
- the input stream
-
getMajorVersion
public int getMajorVersion()
Description copied from interface:PortletContextReturns the major version of the Portlet API that this portlet container supports.- Specified by:
getMajorVersionin interfacePortletContext- Returns:
- the major version
- See Also:
PortletContext.getMinorVersion()
-
getMinorVersion
public int getMinorVersion()
Description copied from interface:PortletContextReturns the minor version of the Portlet API that this portlet container supports.- Specified by:
getMinorVersionin interfacePortletContext- Returns:
- the minor version
- See Also:
PortletContext.getMajorVersion()
-
getMimeType
public String getMimeType(String file)
Description copied from interface:PortletContextReturns the MIME type of the specified file, ornullif 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 aretext/htmlandimage/gif.- Specified by:
getMimeTypein interfacePortletContext- Parameters:
file- aStringspecifying the name of a file- Returns:
- a
Stringspecifying the MIME type of the file
-
getRealPath
public String getRealPath(String path)
Description copied from interface:PortletContextReturns aStringcontaining the real path for a given virtual path. For example, the path/index.htmlreturns 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
nullif 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.wararchive).- Specified by:
getRealPathin interfacePortletContext- Parameters:
path- aStringspecifying a virtual path- Returns:
- a
Stringspecifying the real path, or null if the transformation cannot be performed.
-
getResourcePaths
public Set<String> getResourcePaths(String path)
Description copied from interface:PortletContextReturns 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 (/). 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/"}.- Specified by:
getResourcePathsin interfacePortletContext- Parameters:
path- the partial path used to match the resources, which must start with a slash- Returns:
- a Set containing the directory listing, or
nullif there are no resources in the web application of which the path begins with the supplied path.
-
getResource
public URL getResource(String path) throws MalformedURLException
Description copied from interface:PortletContextReturns a URL to the resource that is mapped to a specified path. The path must begin with a slash (/) 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
.warfile.The portlet container must implement the URL handlers and
URLConnectionobjects that are necessary to access the resource.This method returns
nullif 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
.jsppage returns the JSP source code. Use aRequestDispatcherinstead 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.- Specified by:
getResourcein interfacePortletContext- Parameters:
path- aStringspecifying the path to the resource- Returns:
- the resource located at the named path,
or
nullif there is no resource at that path - Throws:
MalformedURLException- if the pathname is not given in the correct form
-
getAttribute
public Object getAttribute(String name)
Description copied from interface:PortletContextReturns 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 usinggetAttributeNames.The attribute is returned as a
java.lang.Objector some subclass. Attribute names should follow the same convention as package names. The Jakarta Portlet API specification reserves names matchingjava.*,jakarta.*, andsun.*.- Specified by:
getAttributein interfacePortletContext- Parameters:
name- aStringspecifying the name of the attribute- Returns:
- an
Objectcontaining the value of the attribute, ornullif no attribute exists matching the given name - See Also:
PortletContext.getAttributeNames()
-
getAttributeNames
public Enumeration<String> getAttributeNames()
Description copied from interface:PortletContextReturns anEnumerationcontaining the attribute names available within this portlet context, or an emptyEnumerationif no attributes are available. Use thePortletContext.getAttribute(java.lang.String)method with an attribute name to get the value of an attribute.- Specified by:
getAttributeNamesin interfacePortletContext- Returns:
- an
Enumerationof attribute names - See Also:
PortletContext.getAttribute(java.lang.String)
-
getInitParameter
public String getInitParameter(String name)
Description copied from interface:PortletContextReturns a String containing the value of the named context-wide initialization parameter, ornullif the parameter does not exist. This method provides configuration information which may be useful for an entire "portlet application".- Specified by:
getInitParameterin interfacePortletContext- Parameters:
name- aStringcontaining the name of the requested parameter- Returns:
- a
Stringcontaining the value of the initialization parameter, ornullif the parameter does not exist. - See Also:
PortletContext.getInitParameterNames()
-
getInitParameterNames
public Enumeration<String> getInitParameterNames()
Description copied from interface:PortletContextReturns the names of the context initialization parameters as anEnumerationof String objects, or an empty Enumeration if the context has no initialization parameters.- Specified by:
getInitParameterNamesin interfacePortletContext- Returns:
- an
EnumerationofStringobjects containing the names of the context initialization parameters - See Also:
PortletContext.getInitParameter(java.lang.String)
-
log
public void log(String msg)
Description copied from interface:PortletContextWrites 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
ServletContext.logmethod. The portlet container may in addition log this message in a portlet container specific log file.- Specified by:
login interfacePortletContext- Parameters:
msg- aStringspecifying the message to be written to the log file
-
log
public void log(String message, Throwable throwable)
Description copied from interface:PortletContextWrites 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
ServletContext.logmethod. The portlet container may in addition log this message in a portlet container specific log file.- Specified by:
login interfacePortletContext- Parameters:
message- aStringthat describes the error or exceptionthrowable- theThrowableerror or exception
-
removeAttribute
public void removeAttribute(String name)
Description copied from interface:PortletContextRemoves the attribute with the given name from the portlet context. After removal, subsequent calls toPortletContext.getAttribute(java.lang.String)to retrieve the attribute's value will returnnull.- Specified by:
removeAttributein interfacePortletContext- Parameters:
name- aStringspecifying the name of the attribute to be removed
-
setAttribute
public void setAttribute(String name, Object object)
Description copied from interface:PortletContextBinds 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
removeAttribute().Attribute names should follow the same convention as package names. The Jakarta Portlet API specification reserves names matching
java.*,jakarta.*, andsun.*.- Specified by:
setAttributein interfacePortletContext- Parameters:
name- aStringspecifying the name of the attributeobject- anObjectrepresenting the attribute to be bound
-
getPortletContextName
public String getPortletContextName()
Description copied from interface:PortletContextReturns the name of this portlet application correponding to this PortletContext as specified in theweb.xmldeployment descriptor for this web application by thedisplay-nameelement.- Specified by:
getPortletContextNamein interfacePortletContext- Returns:
- The name of the web application or null if no name has been declared in the deployment descriptor.
-
getContainerRuntimeOptions
public Enumeration<String> getContainerRuntimeOptions()
Description copied from interface:PortletContextReturns the container container runtime options keys supported by this portlet container.- Specified by:
getContainerRuntimeOptionsin interfacePortletContext- Returns:
- container runtime options keys supported by this container as String values.
-
getEffectiveMajorVersion
public int getEffectiveMajorVersion()
Description copied from interface:PortletContextReturns the major version of the Portlet API used by the portlet application running in this PortletContext.- Specified by:
getEffectiveMajorVersionin interfacePortletContext- Returns:
- the major version
- See Also:
PortletContext.getEffectiveMinorVersion()
-
getEffectiveMinorVersion
public int getEffectiveMinorVersion()
Description copied from interface:PortletContextReturns the minor version of the Portlet API used by the portlet application running in this PortletContext.- Specified by:
getEffectiveMinorVersionin interfacePortletContext- Returns:
- the minor version
- See Also:
PortletContext.getEffectiveMajorVersion()
-
getContextPath
public String getContextPath()
Description copied from interface:PortletContextReturns the context path for this portlet application.- Specified by:
getContextPathin interfacePortletContext- Returns:
- the context path for this portlet application.
-
getClassLoader
public ClassLoader getClassLoader()
Description copied from interface:PortletContextReturns the class loader for this portlet context.- Specified by:
getClassLoaderin interfacePortletContext- Returns:
- the class loader for this portlet application.
-
-