Class Portlets


  • public class Portlets
    extends java.lang.Object
    Utilities to handle portlet.
    Author:
    tomyeh
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int APPEND_PARAM
      Whether to append params if both uri and params contain the same parameter.
      static int IGNORE_PARAM
      Whether to ignore params if both uri and params contain the same parameter.
      static int OVERWRITE_URI
      Whether to overwrite uri if both uri and params contain the same parameter.
    • Constructor Summary

      Constructors 
      Constructor Description
      Portlets()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String generateURI​(java.lang.String uri, java.util.Map params, int mode)
      Generates URI by appending the parameters.
      static javax.portlet.PortletRequestDispatcher getRequestDispatcher​(javax.portlet.PortletContext ctx, java.lang.String uri, java.util.Map params, int mode)
      Returns the request dispatch of the specified URI.
      static java.net.URL getResource​(javax.portlet.PortletContext ctx, java.lang.String uri)
      Returns the resource of the specified uri.
      static java.io.InputStream getResourceAsStream​(javax.portlet.PortletContext ctx, java.lang.String uri)
      Returns the resource stream of the specified uri.
      static void include​(javax.portlet.PortletContext ctx, javax.portlet.RenderRequest request, javax.portlet.RenderResponse response, java.lang.String uri, java.util.Map params, int mode)
      Includes the resource at the specified URI.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Portlets

        public Portlets()
    • Method Detail

      • include

        public static final void include​(javax.portlet.PortletContext ctx,
                                         javax.portlet.RenderRequest request,
                                         javax.portlet.RenderResponse response,
                                         java.lang.String uri,
                                         java.util.Map params,
                                         int mode)
                                  throws java.io.IOException,
                                         javax.portlet.PortletException
        Includes the resource at the specified URI. It enhances RequestDispatcher to allow the inclusion with a parameter map -- actually converting parameters to a query string and appending it to uri.

        NOTE: don't include query parameters in uri.

        Parameters:
        uri - the URI to include. It is OK to relevant (without leading '/'). If starts with "/", the context path of request is assumed. To reference to foreign context, use "~ctx/" where ctx is the context path of the foreign context (without leading '/').
        params - the parameter map; null to ignore
        mode - one of OVERWRITE_URI, IGNORE_PARAM, and APPEND_PARAM. It defines how to handle if both uri and params contains the same parameter.
        Throws:
        java.io.IOException
        javax.portlet.PortletException
      • getRequestDispatcher

        public static final javax.portlet.PortletRequestDispatcher getRequestDispatcher​(javax.portlet.PortletContext ctx,
                                                                                        java.lang.String uri,
                                                                                        java.util.Map params,
                                                                                        int mode)
                                                                                 throws javax.portlet.PortletException
        Returns the request dispatch of the specified URI.
        Parameters:
        ctx - the context used to resolve a foreign context. It is required only if uri starts with "~".
        uri - the URI to include. It is OK to relevant (without leading '/'). If starts with "/", the context path of request is assumed. To reference to foreign context, use "~ctx/" where ctx is the context path of the foreign context (without leading '/').
        params - the parameter map; null to ignore
        mode - one of OVERWRITE_URI, IGNORE_PARAM, and APPEND_PARAM. It defines how to handle if both uri and params contains the same parameter.
        Throws:
        javax.portlet.PortletException
      • generateURI

        public static final java.lang.String generateURI​(java.lang.String uri,
                                                         java.util.Map params,
                                                         int mode)
        Generates URI by appending the parameters.
        Parameters:
        params - the parameters to append to the query string
        mode - one of OVERWRITE_URI, IGNORE_PARAM, and APPEND_PARAM. It defines how to handle if both uri and params contains the same parameter. mode is used only if both uri contains query string and params is not empty.