Class ToolUtils


  • public class ToolUtils
    extends Object
    A set of utilities provided by the portal for use by tools. Some of the methods pull the HttpServletRequest from ThreadLocal. This means they will fail badly if called before the RequestFilter is run. Generally this means that the calls are safe in core tool code.
    • Field Detail

      • PORTAL_INLINE_EXPERIMENTAL_DEFAULT

        public static final boolean PORTAL_INLINE_EXPERIMENTAL_DEFAULT
        See Also:
        Constant Field Values
    • Constructor Detail

      • ToolUtils

        public ToolUtils()
    • Method Detail

      • isInlineRequest

        public static boolean isInlineRequest​(HttpServletRequest req)
        Determine if this is an inline request.
        Type Parameters:
        code - req The request object. If you have no access to the request object, you can leave this null and we will try to pull the request from ThreadLocal - if we fail it is a RunTime exception.
        Returns:
        True if this is a request where a tool will be inlined.
      • getPageUrl

        public static String getPageUrl​(Site site,
                                        SitePage page)
        Captures the rules for getting the URL of a page suitable for a GET request (call only from the tool)
        Type Parameters:
        code - site The site that contains the page
        code - page The page URL. If this has a logged in session, we use it to set the default prefix if available. This will use the default prefix if called without a session (i.e. through /direct).
      • getPageUrl

        public static String getPageUrl​(HttpServletRequest req,
                                        Site site,
                                        SitePage page)
        Captures the rules for getting the URL of a page suitable for a GET request
        Type Parameters:
        code - req The request object. If you have no access to the request object, you can leave this null and we will try to pull the request from ThreadLocal - if we fail it is a RunTime exception.
        code - site The site that contains the page
        code - page The page URL. If this has a logged in session, we use it to set the default prefix if available. This will use the default prefix if called without a session (i.e. through /direct).
      • getPageUrl

        public static String getPageUrl​(HttpServletRequest req,
                                        Site site,
                                        SitePage page,
                                        String portalPrefix)
        Captures the rules for getting the URL of a page suitable for a GET request
        Type Parameters:
        code - req The request object.
        code - site The site that contains the page
        code - page The page
        code - portalPrefix The controlling portal. Typically "site". No slashes should be included
      • getPageUrl

        public static String getPageUrl​(HttpServletRequest req,
                                        Site site,
                                        SitePage page,
                                        String portalPrefix,
                                        boolean reset,
                                        String effectiveSiteId,
                                        String pageAlias)
        Captures the rules for getting the URL of a page suitable for a GET request
        Type Parameters:
        code - req The request object. If you have no access to the request object, you can leave this null and we will try to pull the request from ThreadLocal - if we fail it is a RunTime exception.
        code - site The site that contains the page
        code - page The page
        code - portalPrefix The controlling portal. Typically "site". No slashes should be included
        code - reset Should we reset the tool as part of this GET reference (typically true)
        code - effectiveSiteId The effective site ID
        code - pageAlias The alias for the page (typically null)
        Returns:
        The url for the page.
      • getToolPopupUrl

        public static String getToolPopupUrl​(ToolConfiguration pageTool)
        Captures the rules for the various tools and when they want a popup
        Type Parameters:
        code - pageTool The tools configuration object.
        Returns:
        The url to be uded in the popup of null of there is no tool-requested popup.
      • getPageForTool

        public static SitePage getPageForTool​(Site site,
                                              String toolId)
        Look through the pages in a site and find the page that corresponds to a tool.
        Type Parameters:
        code - site The site
        code - toolId The placement / tool ID
        Returns:
        The page if found otherwise null.
      • getPageUrlForTool

        public static String getPageUrlForTool​(HttpServletRequest req,
                                               Site site,
                                               ToolConfiguration pageTool)
        Look through the pages in a site and get the page URL for a tool.
        Type Parameters:
        code - req The request object. If you have no access to the request object, you can leave this null and we will try to pull the request from ThreadLocal - if we fail it is a RunTime exception.
        code - site The site
        code - pageTool The placement / tool configuration
        Returns:
        The page if found otherwise null.
      • isPortletPlacement

        public static boolean isPortletPlacement​(Placement placement)
        Determine if a particular placement is a JSR-168 portlet placement
        Type Parameters:
        code - placement The actual placement.
        Returns:
        Returns true for JSR_168 portlets
      • getToolBorderlessBaseUrl

        public static String getToolBorderlessBaseUrl()
        Get the base URL for tools with no "border" - (i.e. within an iframe)
      • getToolBaseUrl

        public static String getToolBaseUrl()
        Get the base URL for tools not including the ToolId (only works in tools)
      • getToolBaseUrl

        public static String getToolBaseUrl​(HttpServletRequest req)
        Get the base URL for tools not including the ToolId
        Type Parameters:
        code - req The request object. If you have no access to the request object, you can leave this null and we will try to pull the request from ThreadLocal - if we fail it is a RunTime exception.
        Returns:
        Returns true for JSR_168 portlets
      • getRequestFromThreadLocal

        public static HttpServletRequest getRequestFromThreadLocal()
        Get the servlet request from thread local - call only after RequestFilter has run
        Returns:
        Returns the current servlet request or throws runtime error
      • getRequestParameter

        public static String getRequestParameter​(String key)
        Retriece a request parameter from ThreadLocal (only works after RequestFilter runs)
        Type Parameters:
        code - key The request object
        Returns:
        Returns true for JSR_168 portlets