Class PortalUtils


  • public class PortalUtils
    extends Object
    Provides utility methods related to portals.
    • Field Detail

      • PROPERTY_CLIENT_LOGO_URL

        public static final String PROPERTY_CLIENT_LOGO_URL
        The auxiliary property holding the URL of the client logo
        See Also:
        Constant Field Values
    • Constructor Detail

      • PortalUtils

        public PortalUtils()
    • Method Detail

      • renderTemplate

        public static String renderTemplate​(String template,
                                            org.apache.click.Page page)
        Render the Velocity template contents using the context of the provided page.
        Parameters:
        template - velocity template
        page - the page context
        Returns:
        the rendered velocity template
      • getPortal

        public static Portal getPortal​(HttpServletRequest request)
        Return the SmartForm Manager portal associated with the specified request. The portal is looked up by context path.
        Parameters:
        request - the HTTP servlet request
        Returns:
        the portal associated from the request, null if no portal matches the request context
      • getFormLandingPagePath

        public static String getFormLandingPagePath​(Form form,
                                                    Portal portal)
        Return the landing page URL for the given form.
        Parameters:
        form - the non-null form
        portal - a forms portal (required)
        Returns:
        the full landing page URL
      • getFormLandingPagePath

        public static String getFormLandingPagePath​(Portal portal,
                                                    String formCode)
        Return the landing page URL for the given portal and form code.
        Parameters:
        portal - the non-null portal
        formCode - the form code of a form associated with the portal
        Returns:
        the full landing page URL
      • getFriendlyFormURL

        public static String getFriendlyFormURL​(Form form,
                                                Portal portal)
        Return the Friendly URL for a given form
        Parameters:
        form - the non-null form containing references to a valid client and portal
        portal - a forms portal
        Returns:
        the full Friendly URL
      • getFriendlyFormURL

        public static String getFriendlyFormURL​(String portalContext,
                                                String clientCode,
                                                String formName)
        Return the Friendly URL for a given form, client and portal
        Parameters:
        portalContext - the URL associated with the portal
        clientCode - the client code of the client that the form belongs to
        formName - the name of the form
        Returns:
        the full Friendly URL
      • getFormRenderURL

        @Deprecated
        public static String getFormRenderURL​(String portalContext,
                                              String formCode)
        Deprecated.
        Return the URL to access a rendered form.
        Parameters:
        portalContext - the URL associated with the form's portal
        formCode - the form code of the form
        Returns:
        the full form render URL
      • getFormRenderURL

        public static String getFormRenderURL​(Form form,
                                              TemplateVersion templateVersion,
                                              boolean includePDFParams)
        Return the form render URL including PDF open parameters if a PDF form
        Parameters:
        form - the form
        templateVersion - the template version
        includePDFParams - include the PDF open parameters
        Returns:
        the PDF form render URL
      • getFormRenderURL

        public static String getFormRenderURL​(String portalContext,
                                              String formCode,
                                              boolean pdfForm)
        Return the URL to access a rendered form.
        Parameters:
        portalContext - the URL associated with the form's portal
        formCode - the form code of the form
        pdfForm - the is a PDF form
        Returns:
        the full form render URL
      • getFormRenderURL

        public static String getFormRenderURL​(String portalContext,
                                              String formCode,
                                              String formType)
        Return the URL to access a rendered form.
        Parameters:
        portalContext - the URL associated with the form's portal
        formCode - the form code of the form
        formType - the form type
        Returns:
        the full form render URL
        Since:
        17.10.0
      • getFormRenderURL

        public static String getFormRenderURL​(String portalContext,
                                              TemplateVersion version)
        Return the URL to access a rendered form.
        Parameters:
        portalContext - the URL associated with the form's portal
        version - the form version
        Returns:
        the full form render URL
        Since:
        17.10.0
      • getSecureFormRenderURL

        public static String getSecureFormRenderURL​(Form form,
                                                    Portal portal)
        Return the URL to access a rendered form. Users will have to log on to access the form.
        Parameters:
        form - the non-null form
        portal - a forms portal (required)
        Returns:
        the full secure form render URL
      • getSecureFormRenderURL

        public static String getSecureFormRenderURL​(TemplateVersion version,
                                                    Portal portal)
        Return the URL to access a rendered form. Users will have to log on to access the form.
        Parameters:
        version - the form version to render
        portal - a forms portal (required)
        Returns:
        the full secure form render URL
        Since:
        18.10.0
      • getSecureFormRenderURL

        public static String getSecureFormRenderURL​(Submission submission,
                                                    Portal portal)
        Return the URL to access a rendered saved form. Users will have to log on to access the form. When rendering the form, the original form template version will be used.
        Parameters:
        submission - the non-null saved submission which is associated with a valid portal (required)
        portal - a forms portal (required)
        Returns:
        the full secure form render URL, or null if neither the submission nor the form is not associated with the portal
      • getSecureFormRenderURL

        public static String getSecureFormRenderURL​(Submission submission,
                                                    Portal portal,
                                                    boolean useCurrentTemplateVersion)
        Return the URL to access a rendered saved form. Users will have to log on to access the form.
        Parameters:
        submission - the non-null saved submission which is associated with a valid portal (required)
        portal - a forms portal (required)
        useCurrentTemplateVersion - a flag that determines whether to use the form's current template version when rendering the receipt, or to use the same template version that was used when the form was originally rendered
        Returns:
        the full secure form render URL
      • getFormRenderURL

        public static String getFormRenderURL​(Form form,
                                              Portal portal)
        Return the URL to access a rendered form.
        Parameters:
        form - the non-null form
        portal - a forms portal (required)
        Returns:
        the full form render URL
      • getFormRenderURL

        public static String getFormRenderURL​(Form form,
                                              Portal portal,
                                              boolean includeSessionId)
        Return the URL to access a rendered form.
        Parameters:
        form - the non-null form which is associated with a valid portal
        portal - a forms portal (required)
        includeSessionId - specify whether to include the jsessionid in the URL
        Returns:
        the full form render URL
      • getFormRenderURL

        public static String getFormRenderURL​(Submission submission,
                                              Portal portal)
        Return the URL to access a rendered saved form. When rendering the form, the original form template version will be used.
        Parameters:
        submission - the non-null saved submission
        portal - a forms portal
        Returns:
        the full form render URL
      • getFormDataServletUrl

        public static String getFormDataServletUrl​(Portal portal,
                                                   boolean htmlForm)
        Return the URL to access the dynamic form data servlet.
        Parameters:
        portal - the non-null portal
        htmlForm - whether the form in question is a HTML form
        Returns:
        the full dynamic form data servlet URL
      • getSavedFormRenderURL

        public static String getSavedFormRenderURL​(Submission submission,
                                                   Portal portal,
                                                   boolean useCurrentTemplateVersion)
        Return the URL to access a rendered saved form, including additional PDF zoom parameters. Users will have to log on to access the form.
        Parameters:
        submission - the non-null saved submission
        portal - a form portal that the submission is visible on
        useCurrentTemplateVersion - a flag that determines whether to use the form's current template version when rendering the receipt, or to use the same template version that was used when the form was originally rendered
        Returns:
        the full form render URL or null if the submission is not associated with a portal
      • getFormReceiptURL

        public static String getFormReceiptURL​(Portal portal,
                                               String submitKey)
        Return the URL to access a rendered receipt.
        Parameters:
        portal - a forms portal associated with the submission or its form
        submitKey - the surrogate key of the submission
        Returns:
        the full receipt render URL
      • getFormReceiptURL

        public static String getFormReceiptURL​(Portal portal,
                                               String submitKey,
                                               String renderMode)
        Return the URL to access a rendered receipt.
        Parameters:
        portal - a forms portal associated with the submission or its form
        submitKey - the surrogate key of the submission
        renderMode - how to render the receipt to the user (see Params.REQUEST_RenderMode)
        Returns:
        the full receipt render URL, or null if the submission or portal could not be resolved
      • getSignatureReceiptURL

        public static String getSignatureReceiptURL​(Portal portal,
                                                    String submitKey,
                                                    String renderMode)
        Return the URL to access a signature receipt.
        Parameters:
        portal - a forms portal associated with the submission or its form
        submitKey - the surrogate key of the submission
        renderMode - how to render the receipt to the user (see Params.REQUEST_RenderMode)
        Returns:
        the full signature receipt render URL, or null if the submission or portal could not be resolved
      • getFormReceiptURL

        public static String getFormReceiptURL​(Submission submission,
                                               Portal portal)
        Return the URL to access a rendered receipt.
        Parameters:
        submission - the non-null submission associated with a valid portal
        portal - a forms portal on which the submission is visible
        Returns:
        the full receipt render URL, or null if the submission is not associated with a portal
      • getSecureFormReceiptURL

        public static String getSecureFormReceiptURL​(Submission submission,
                                                     Portal portal)
        Return the URL to securely access a rendered receipt (the user will be asked to log in).
        Parameters:
        submission - the non-null submission associated with a valid portal
        portal - a forms portal on which the submission is visible
        Returns:
        the full secure receipt render URL, or null if the submission is not associated with a portal
        Since:
        5.1.0
      • addContextToPath

        public static String addContextToPath​(Portal portal,
                                              String path)
        Return a URL locating a resource relative to a portal's context path. A slash character ('/') will be inserted between the two path components if necessary.
        Parameters:
        portal - the portal to be used to determine the context path
        path - the relative path to be appended to the portal context path
        Returns:
        the full URL combining the portal context and relative paths
      • addContextToPath

        public static String addContextToPath​(String portalContext,
                                              String path)
        Return a URL locating a resource relative to a portal's context path. A slash character ('/') will be inserted between the two path components if necessary.
        Parameters:
        portalContext - the portal context path
        path - the relative path to be appended to the portal context path
        Returns:
        the full URL combining the portal context and relative paths
      • addHttpsContextToPath

        public static String addHttpsContextToPath​(Portal portal,
                                                   String path)
        Return a URL locating a resource relative to a portal's context path. A slash character ('/') will be inserted between the two path components if necessary. This method will return a URL that uses the HTTPS protocol.
        Parameters:
        portal - the portal to be used to determine the context path
        path - the relative path to be appended to the portal context path
        Returns:
        the full URL combining the portal context and relative paths
      • addHttpsContextToPath

        public static String addHttpsContextToPath​(String portalContext,
                                                   String path)
        Return a URL locating a resource relative to a portal's context path. A slash character ('/') will be inserted between the two path components if necessary. This method will return a URL that uses the HTTPS protocol.
        Parameters:
        portalContext - the portal context path
        path - the relative path to be appended to the portal context path
        Returns:
        the full URL combining the portal context and relative paths
      • getDefaultPortalPath

        public static String getDefaultPortalPath​(String pathName)
                                           throws ApplicationException
        Return a URL locating a portal page on the default portal.
        Parameters:
        pathName - the name of the portal page that shall be located (_PortalPage.NAME_PROPERTY)
        Returns:
        the full URL of the specified portal page on the default portal
        Throws:
        ApplicationException - if no portal is marked as the default, or no PortalPage object with the specified name exists for the default portal
      • getPath

        public static String getPath​(Portal portal,
                                     String pageName)
                              throws ApplicationException
        Returns a URL locating a portal page on a given portal.
        Parameters:
        portal - the non-null portal
        pageName - the name (not empty) of the portal page that shall be located (_PortalPage.NAME_PROPERTY)
        Returns:
        the full URL of the specified portal page on the given portal
        Throws:
        ApplicationException - if no PortalPage object with the specified name exists for the portal
      • getAdminFormEditPath

        public static String getAdminFormEditPath​(Long formId)
        Return the form edit URL on the admin console.
        Parameters:
        formId - the OID of the form
        Returns:
        the URL to the form edit page, or an empty string if the admin console portal could not be located
        Since:
        4.0.0
      • getOptionalPath

        public static String getOptionalPath​(Portal portal,
                                             String pathName)
        Returns a URL locating a portal page on a given portal or null if page not defined
        Parameters:
        portal - the non-null portal
        pathName - the name (not empty) of the portal page that shall be located (_PortalPage.NAME_PROPERTY)
        Returns:
        the full URL of the specified portal page on the given portal
      • getAccountPendingPath

        public static String getAccountPendingPath​(Portal portal,
                                                   UserAccount userAccount)
        Return the account pending page path for the user.
        Parameters:
        portal - a forms portal (required)
        userAccount - the user account (required)
        Returns:
        the Account Pending page path on the portal for the specified user.
      • getFormErrorPath

        public static String getFormErrorPath​(Portal portal)
        Return the URL to the "Form Error" page on the given portal.
        Parameters:
        portal - the non-null portal
        Returns:
        the full URL of the "Form Error" portal page
      • getFormLandingPath

        public static String getFormLandingPath​(Portal portal)
        Return the URL to the "Form Landing" page on the given portal.
        Parameters:
        portal - the non-null portal
        Returns:
        the full URL of the "Form Landing" portal page
      • getFormPath

        public static String getFormPath​(Portal portal)
        Return the form 'plug-in' page path for the portal.
        Parameters:
        portal - the form portal
        Returns:
        the form 'plug-in' page path for the portal.
      • getFormPath

        public static String getFormPath​(Form form,
                                         Portal portal)
        Return the form 'plug-in' page path for the form.
        Parameters:
        form - the form (required)
        portal - a forms portal (required)
        Returns:
        the form 'plug-in' page path for the form, using the configured portal and form code.
      • getFormPageURL

        public static String getFormPageURL​(Form form,
                                            Portal portal)
        Return the URL to the form 'plugin' page for the portal.
        Parameters:
        form - the form to get the render URL for
        portal - a forms portal associated with the form
        Returns:
        the URL to the form 'plugin' page for the portal.
      • getFormPagePath

        public static String getFormPagePath​(Portal portal,
                                             String formCode,
                                             boolean registrationFlag)
        Return the form page URL for the given portal, form code and registration flag.
        Parameters:
        portal - the non-null portal
        formCode - the form code of a form associated with the portal
        registrationFlag - whether the form requires registration
        Returns:
        the full form page URL
      • getFormSavedUrl

        public static String getFormSavedUrl​(Portal portal,
                                             Submission submission)
        Provide a return to saved form URL.
        Parameters:
        portal - the associated portal
        submission - the form submission
        Returns:
        a return to saved form URL
        Since:
        3.6.0
      • getSaveChallengeUrl

        public static String getSaveChallengeUrl​(Portal portal,
                                                 Submission submission)
        Provide a return to form saved challenge URL.
        Parameters:
        portal - the associated portal
        submission - the form submission
        Returns:
        a return to form save challenge URL
        Since:
        4.0.0
      • getReceiptChallengeUrl

        public static String getReceiptChallengeUrl​(Portal portal,
                                                    Submission submission)
        Provide a receipt challenge URL.
        Parameters:
        portal - the associated portal
        submission - the form submission
        Returns:
        a receipt challenge URL
        Since:
        5.1.0
      • getSaveChallengeUrl

        public static String getSaveChallengeUrl​(Portal portal,
                                                 TemplateVersion version)
        Provide a return to form saved challenge URL.
        Parameters:
        portal - the associated portal
        version - the form template version
        Returns:
        a return to form save challenge URL
        Since:
        4.1.0
      • getFormSavedUrlWithReferenceNumber

        public static String getFormSavedUrlWithReferenceNumber​(Portal portal,
                                                                Submission submission)
        Provide a return to saved form URL with the submission reference number URL prefill parameter.
        Parameters:
        portal - the associated portal
        submission - the form submission
        Returns:
        a return to saved form URL
        Since:
        4.0.0
      • getNotAuthorizedPath

        public static String getNotAuthorizedPath​(Portal portal)
        Return the URL to the "Not Authorized" page on the given portal.
        Parameters:
        portal - the non-null portal
        Returns:
        the full URL of the "Not Authorized" portal page
      • getNotSupportedPath

        public static String getNotSupportedPath​(Portal portal)
        Return the URL to the "Not Supported" page on the given portal.
        Parameters:
        portal - the non-null portal
        Returns:
        the full URL of the "Not Supported" portal page
      • getOffLinePath

        public static String getOffLinePath​(Portal portal)
        Return the URL to the "Offline" page on the given portal.
        Parameters:
        portal - the non-null portal
        Returns:
        the full URL of the "Offline" portal page
      • isRequestingOfflinePath

        public static boolean isRequestingOfflinePath​(HttpServletRequest request,
                                                      Portal portal)
        Return whether a user is requesting the "Offline" page for the given portal
        Parameters:
        request - the HTTP servlet request
        portal - the non-null portal
        Returns:
        whether the request relates to the portal's "Offline" page
      • getServerBusyPath

        public static String getServerBusyPath​(Portal portal)
        Return the URL to the "Secure Form" page on the given portal.
        Parameters:
        portal - the non-null portal
        Returns:
        the full URL of the "Secure Form" portal page
      • getSessionExpiredPath

        public static String getSessionExpiredPath​(Portal portal)
        Return the form session expired page path for the portal.
        Parameters:
        portal - the form portal
        Returns:
        the form session expired page path for the portal
        Since:
        4.1.0
      • getSessionExpiredPath

        public static String getSessionExpiredPath​(Submission submission)
        Return the form session expired page path for the portal.
        Parameters:
        submission - the form submission
        Returns:
        the form session expired page path for the portal
        Since:
        5.0.0
      • getSessionReestablishedPath

        public static String getSessionReestablishedPath​(Portal portal)
        Return the form session reestablished page path for the portal.
        Parameters:
        portal - the form portal
        Returns:
        the form session reestablished page path for the portal
        Since:
        4.1.0
      • getSecureFormPath

        public static String getSecureFormPath​(Portal portal)
        Return the URL to the "Secure Form" page on the given portal.
        Parameters:
        portal - the non-null portal
        Returns:
        the full URL of the "Secure Form" portal page
      • getSubmissionCancelledPath

        public static String getSubmissionCancelledPath​(Submission submission,
                                                        Portal portal)
        Return the URL to the custom cancelled page URL specified on the submission's form or otherwise the "Submission Cancelled" page on the given portal.
        Parameters:
        submission - the submission (optional)
        portal - the non-null portal
        Returns:
        the full URL of the "Submission Cancelled" portal page
      • getSubmissionErrorsPath

        public static String getSubmissionErrorsPath​(Portal portal)
        Return the URL to the "Submission Errors" page on the given portal.
        Parameters:
        portal - the non-null portal
        Returns:
        the full URL of the "Submission Errors" portal page
      • getSubmissionExpiredPath

        public static String getSubmissionExpiredPath​(Portal portal)
        Return the URL to the "Submission Expired" page on the given portal.
        Parameters:
        portal - the non-null portal
        Returns:
        the full URL of the "Submission Expired" portal page
      • getSubmissionExpiredPath

        public static String getSubmissionExpiredPath​(Portal portal,
                                                      Form form)
        Return the URL to the "Submission Expired" page on the given portal and portal.
        Parameters:
        portal - the portal (required)
        form - the form (required)
        Returns:
        the full URL of the "Submission Expired" portal page
        Since:
        3.6.0
      • getSubmissionFailedPath

        public static String getSubmissionFailedPath​(Portal portal)
        Return the URL to the "Submission Failed" page on the given portal.
        Parameters:
        portal - the non-null portal
        Returns:
        the full URL of the "Submission Failed" portal page
      • getSubmissionSavedPath

        public static String getSubmissionSavedPath​(Portal portal)
        Return the URL to the "Submission Saved" page on the given portal.
        Parameters:
        portal - the non-null portal
        Returns:
        the full URL of the "Submission Saved" portal page
      • getPropertyDeploy

        public static String getPropertyDeploy​(Form form,
                                               String propertyName)
        Return the property deploy value for a specific form and property name
        Parameters:
        form - the form
        propertyName - the name of the property deploy that shall be resolved
        Returns:
        the value of the PropertyDeploy object for the given form and property name, or null if no such value exists
      • getFormVersionProperties

        public static Map<String,​String> getFormVersionProperties​(Form form,
                                                                        HttpServletRequest request)
        Return the form template version property value map.
        Parameters:
        form - the form
        request - the user request
        Returns:
        the added form properties map
        Since:
        4.0.0
      • addFormAndVersionProperties

        public static Map<String,​String> addFormAndVersionProperties​(org.apache.click.Page page,
                                                                           Form form)
        Add the form and template version property values to the given page model, and return the map.
        Parameters:
        page - the page to add the "form" and "formProperties" to
        form - the form
        Returns:
        the added form properties map.
      • setRedirectFromPagePath

        public static void setRedirectFromPagePath​(String pagePath,
                                                   Map<String,​?> params,
                                                   HttpServletRequest request,
                                                   HttpServletResponse response)
        Redirect the request to the specified location with the given parameters.
        Parameters:
        pagePath - the targeting page relative path (required)
        params - the request parameter (required))
        request - HttpServletRequest (required))
        response - HttpServletResponse (required))
        Since:
        21.11.0
      • getPortalContext

        public static String getPortalContext​(HttpServletRequest request)
        Extract the portal context URL from the given request
        Parameters:
        request - the HTTP servlet request
        Returns:
        The part of the URL consisting of protocol, host name and context path. For example, if the request URL is "http://www.formcenter.org/myportal/login.htm", the call will return "http://www.formcenter.org/myportal/".
      • createTemplateModel

        public static Map<String,​Object> createTemplateModel​(org.apache.click.Page page)
        Return a model of the specified Click page
        Parameters:
        page - the Click page
        Returns:
        a map containing all fields and their values
      • redirectToNextPage

        public static void redirectToNextPage​(Submission submission,
                                              HttpServletRequest request,
                                              HttpServletResponse response)
        Set a redirect to the next suitable page for a submission
        Parameters:
        submission - the submission (required)
        request - the HTTP servlet request (required)
        response - the HTTP servlet response (required)
      • getSafeFieldValue

        public static String getSafeFieldValue​(String value,
                                               Class entityClass,
                                               String propertyName)
        Return an escaped and Cayenne property length limited value.
        Parameters:
        value - the value to escape and length limit
        entityClass - the Cayenne entity class
        propertyName - the Cayenne entity field name
        Returns:
        the escaped and field length limited value
        Since:
        3.6.0
      • mergeSubmissionRedirectUrlTemplate

        public static String mergeSubmissionRedirectUrlTemplate​(String template,
                                                                Submission submission,
                                                                HttpServletRequest request)
        Merge a redirect URL Velocity template with a model consisting of the submission ($submission), the HTTP servlet request ($request) and the data extract values ($formDataMap).
        Parameters:
        template - the URL template string (required)
        submission - the submission (required)
        request - the HTTP servlet request (optional though the template string may contain references to it)
        Returns:
        the string resulting from the merge operation
        Since:
        4.1.0
      • onSubmitCheck

        public static boolean onSubmitCheck​(org.apache.click.control.Form form,
                                            org.apache.click.Page page,
                                            Class<? extends org.apache.click.Page> pageClass)
        Calls the performSubmitCheck
        Returns:
        true if the submit is OK otherwise performs a redirect
        Since:
        19.11.0
      • onSubmitCheck

        public static boolean onSubmitCheck​(org.apache.click.control.Form form,
                                            String pagePath,
                                            HttpServletRequest request,
                                            HttpServletResponse response)
        Calls the performSubmitCheck
        Parameters:
        form - org.apache.click.control.Form (required))
        pagePath - the targeting page relative path (required)
        request - HttpServletRequest (required))
        response - HttpServletResponse (required))
        Returns:
        boolean true if the submit is OK otherwise performs a redirect
        Since:
        21.11.0
      • performSubmitCheck

        public static boolean performSubmitCheck​(org.apache.click.control.Form form)
        Perform a back button submit check, returning true if the request is valid or false otherwise. This method will add a submit check token to the form as a hidden field, and to the session.
        Returns:
        true if the submit is OK or false otherwise
        Since:
        19.11.0