Class PortletContextWrapper

  • All Implemented Interfaces:
    PortletContext

    public class PortletContextWrapper
    extends Object
    implements PortletContext
    The 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.
    Since:
    3.0
    • 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: PortletContext
        Returns 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:
        getServerInfo in interface PortletContext
        Returns:
        the string containing at least name and version number
      • getRequestDispatcher

        public PortletRequestDispatcher getRequestDispatcher​(String path)
        Description copied from interface: PortletContext
        Returns a PortletRequestDispatcher 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.

        Specified by:
        getRequestDispatcher in interface PortletContext
        Parameters:
        path - a String specifying the pathname to the resource
        Returns:
        a PortletRequestDispatcher object 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: PortletContext
        Returns a PortletRequestDispatcher 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.

        Specified by:
        getNamedDispatcher in interface PortletContext
        Parameters:
        name - a String specifying the name of a servlet to be wrapped
        Returns:
        a PortletRequestDispatcher object that acts as a wrapper for the named servlet
        See Also:
        PortletRequestDispatcher
      • getResourceAsStream

        public InputStream getResourceAsStream​(String path)
        Description copied from interface: PortletContext
        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 /WEB-INF/ (for example /WEB-INF/myportlet/myportlet.jsp). Otherwise, the direct path is used (for example /myportlet/myportlet.jsp).

        Specified by:
        getResourceAsStream in interface PortletContext
        Parameters:
        path - the path to the resource
        Returns:
        the input stream
      • getMimeType

        public String getMimeType​(String file)
        Description copied from interface: PortletContext
        Returns the MIME type of the specified file, or null 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.
        Specified by:
        getMimeType in interface PortletContext
        Parameters:
        file - a String specifying the name of a file
        Returns:
        a String specifying the MIME type of the file
      • getRealPath

        public String getRealPath​(String path)
        Description copied from interface: PortletContext
        Returns a String 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).

        Specified by:
        getRealPath in interface PortletContext
        Parameters:
        path - a String specifying a virtual path
        Returns:
        a String specifying the real path, or null if the transformation cannot be performed.
      • getResourcePaths

        public Set<String> getResourcePaths​(String path)
        Description copied from interface: PortletContext
        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 (/). 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:
        getResourcePaths in interface PortletContext
        Parameters:
        path - the partial path used to match the resources, which must start with a slash
        Returns:
        a Set containing the directory listing, or null if 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: PortletContext
        Returns 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 .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.

        Specified by:
        getResource in interface PortletContext
        Parameters:
        path - a String specifying the path to the resource
        Returns:
        the resource located at the named path, or null if 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: PortletContext
        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 getAttributeNames.

        The attribute is returned as a java.lang.Object or some subclass. Attribute names should follow the same convention as package names. The Jakarta Portlet API specification reserves names matching java.*, jakarta.*, and sun.*.

        Specified by:
        getAttribute in interface PortletContext
        Parameters:
        name - a String specifying the name of the attribute
        Returns:
        an Object containing the value of the attribute, or null if no attribute exists matching the given name
        See Also:
        PortletContext.getAttributeNames()
      • getInitParameter

        public String getInitParameter​(String name)
        Description copied from interface: PortletContext
        Returns a String containing the value of the named context-wide initialization parameter, or null if the parameter does not exist. This method provides configuration information which may be useful for an entire "portlet application".
        Specified by:
        getInitParameter in interface PortletContext
        Parameters:
        name - a String containing the name of the requested parameter
        Returns:
        a String containing the value of the initialization parameter, or null if the parameter does not exist.
        See Also:
        PortletContext.getInitParameterNames()
      • log

        public void log​(String msg)
        Description copied from interface: PortletContext
        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 ServletContext.log method. The portlet container may in addition log this message in a portlet container specific log file.

        Specified by:
        log in interface PortletContext
        Parameters:
        msg - a String specifying the message to be written to the log file
      • log

        public void log​(String message,
                        Throwable throwable)
        Description copied from interface: PortletContext
        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 ServletContext.log method. The portlet container may in addition log this message in a portlet container specific log file.

        Specified by:
        log in interface PortletContext
        Parameters:
        message - a String that describes the error or exception
        throwable - the Throwable error or exception
      • setAttribute

        public void setAttribute​(String name,
                                 Object object)
        Description copied from interface: PortletContext
        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 removeAttribute().

        Attribute names should follow the same convention as package names. The Jakarta Portlet API specification reserves names matching java.*, jakarta.*, and sun.*.

        Specified by:
        setAttribute in interface PortletContext
        Parameters:
        name - a String specifying the name of the attribute
        object - an Object representing the attribute to be bound
      • getPortletContextName

        public String getPortletContextName()
        Description copied from interface: PortletContext
        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.
        Specified by:
        getPortletContextName in interface PortletContext
        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: PortletContext
        Returns the container container runtime options keys supported by this portlet container.
        Specified by:
        getContainerRuntimeOptions in interface PortletContext
        Returns:
        container runtime options keys supported by this container as String values.
      • getContextPath

        public String getContextPath()
        Description copied from interface: PortletContext
        Returns the context path for this portlet application.
        Specified by:
        getContextPath in interface PortletContext
        Returns:
        the context path for this portlet application.
      • getClassLoader

        public ClassLoader getClassLoader()
        Description copied from interface: PortletContext
        Returns the class loader for this portlet context.
        Specified by:
        getClassLoader in interface PortletContext
        Returns:
        the class loader for this portlet application.