Class HtmlControlBlockConditionsHelper


  • public class HtmlControlBlockConditionsHelper
    extends java.lang.Object
    A helper for centralize all block parts rules of HTML Control.
    Since:
    14.0.0
    Version:
    $Revision: 25809 $ $Date: 2023-07-04 15:23:22 -0300 (Tue, 04 Jul 2023) $
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String applyBlocksConditionsOrPutScript​(HttpServletRequest request, java.lang.String htmlValue, boolean cacheEnable, java.lang.String websiteUrl, ITransaction transaction, java.lang.String serviceInstanceId)
      If the given cacheEnable parameter is false, the method will remove the HTML block parts that your if, else-if and else conditions are not met.
      static java.lang.String fixForEditorControl​(java.lang.String html)
      Fix value for load in form control.
      static java.lang.String getBlockConditionsInfo​(SessionConfig sessionConfig, ServiceInstanceConfig serviceInstance, java.lang.String htmlFieldValue, ITransaction transaction)
      Returns a JSON with information used for editing the block conditions.
      static java.lang.String getPublicHtml​(java.lang.String htmlValue)
      Removes the HTML block parts that are not public.
      static java.util.List<HtmlBlockMetaInfo> parseBlocksMetaInfo​(java.lang.String htmlValue)
      Parse the given HTML and returns the blocks meta info.
      static java.lang.String putMetaConfigurationForGetBlocksScript​(java.lang.String htmlValue, java.lang.Object pk, java.lang.String serviceInstanceId, java.lang.String sourceId, java.lang.String fieldId)
      Append in HTML the comment with meta information for client side script that will call a REST for put blocks conditions when exist render cache.
      static java.lang.String replaceHtmlBlocksWithExperiments​(java.lang.String serviceInstanceId, java.lang.String originalHtml)
      Replaces the blocks HTML with the linked experiment HTML (if any).
      static void validateBlocks​(java.lang.String fieldId, Source<?> source, java.lang.String html)
      Validate blocks.
      • Methods inherited from class java.lang.Object

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

      • HtmlControlBlockConditionsHelper

        public HtmlControlBlockConditionsHelper()
    • Method Detail

      • getBlockConditionsInfo

        public static java.lang.String getBlockConditionsInfo​(SessionConfig sessionConfig,
                                                              ServiceInstanceConfig serviceInstance,
                                                              java.lang.String htmlFieldValue,
                                                              ITransaction transaction)
                                                       throws PortalException
        Returns a JSON with information used for editing the block conditions.

        The JSON object returned has the following properties:

        • principals: information about principals referenced in the htmlFieldValue. An object with properties names equal to each principal identifier and the properties values equal to an object with the fields label, value and type of that principal.
        • businessContextProperties: an object with properties names equal to business context fields keys and properties values equal to to the property display name.
        Parameters:
        sessionConfig - the user session information.
        serviceInstance - the service instance the contains the HTML field.
        htmlFieldValue - all HTML of field.
        transaction - the transaction for persistence access.
        Returns:
        the JSON with the information.
        Throws:
        PortalException
        Since:
        16.0.0
      • applyBlocksConditionsOrPutScript

        public static java.lang.String applyBlocksConditionsOrPutScript​(HttpServletRequest request,
                                                                        java.lang.String htmlValue,
                                                                        boolean cacheEnable,
                                                                        java.lang.String websiteUrl,
                                                                        ITransaction transaction,
                                                                        java.lang.String serviceInstanceId)
                                                                 throws PortalException
        If the given cacheEnable parameter is false, the method will remove the HTML block parts that your if, else-if and else conditions are not met. Otherwise, the method will replace all conditions blocks with a temporary div and a script that will inject the appropriated HTML blocks.
        Parameters:
        request - the request used to evaluate block conditions.
        htmlValue - the HTML field value.
        cacheEnable - a flag to inform if the content will be rendered in cache.
        websiteUrl - the website URL.
        transaction - the transaction.
        serviceInstanceId - the service instance id.
        Returns:
        the HTML with HTML blocks whose conditions are met, or a HTML with script that will fill the conditions block in client side using REST.
        Throws:
        PortalException
        Since:
        16.0.0
      • getPublicHtml

        public static java.lang.String getPublicHtml​(java.lang.String htmlValue)
                                              throws PortalException
        Removes the HTML block parts that are not public.
        Parameters:
        htmlValue - the HTML field value.
        Returns:
        The HTML with only public blocks.
        Throws:
        PortalException
        Since:
        14.1.0
      • putMetaConfigurationForGetBlocksScript

        public static java.lang.String putMetaConfigurationForGetBlocksScript​(java.lang.String htmlValue,
                                                                              java.lang.Object pk,
                                                                              java.lang.String serviceInstanceId,
                                                                              java.lang.String sourceId,
                                                                              java.lang.String fieldId)
                                                                       throws UnexpectedException
        Append in HTML the comment with meta information for client side script that will call a REST for put blocks conditions when exist render cache.
        Parameters:
        htmlValue - the HTML field value.
        pk - the primary key value of register.
        serviceInstanceId - the service instance identifier.
        sourceId - the source identifier.
        fieldId - the field identifier.
        Returns:
        the HTML with comment of meta information for client side script that will call a REST for put blocks conditions when exist render cache.
        Throws:
        UnexpectedException
        Since:
        14.0.0
      • fixForEditorControl

        public static java.lang.String fixForEditorControl​(java.lang.String html)
        Fix value for load in form control.
        Parameters:
        html - the HTML value.
        Returns:
        the HTML fixed.
        Since:
        14.0.0
      • parseBlocksMetaInfo

        public static java.util.List<HtmlBlockMetaInfo> parseBlocksMetaInfo​(java.lang.String htmlValue)
                                                                     throws PortalException
        Parse the given HTML and returns the blocks meta info.
        Parameters:
        htmlValue - the HTML value
        Returns:
        the blocks meta info.
        Throws:
        PortalException
        Since:
        16.0.0
      • validateBlocks

        public static void validateBlocks​(java.lang.String fieldId,
                                          Source<?> source,
                                          java.lang.String html)
                                   throws PortalException
        Validate blocks.
        Parameters:
        html - all blocks HTML.
        Throws:
        PortalException
        Since:
        14.0.0
      • replaceHtmlBlocksWithExperiments

        public static java.lang.String replaceHtmlBlocksWithExperiments​(java.lang.String serviceInstanceId,
                                                                        java.lang.String originalHtml)
                                                                 throws PortalException
        Replaces the blocks HTML with the linked experiment HTML (if any).
        Parameters:
        serviceInstanceId - the service instance id
        originalHtml - the original HTML
        Returns:
        the changed HTML value
        Throws:
        PortalException
        Since:
        16.0.0