Class ControlUtils


  • public final class ControlUtils
    extends java.lang.Object
    Utils class for <jalios:control> and ControlSettings.
    Author:
    ndossantos
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <T> T addOption​(ControlSettings<?> settings, java.lang.String optionName, T optionValues)
      Adds new option with the specified value(s).
      static void appendQueryStringParam​(java.lang.StringBuilder sb, java.lang.String queryString)
      Appends to the StringBuilder the given query string.
      If the StringBuilder is not empty, append '&' before the query string.
      static void appendQueryStringParam​(java.lang.StringBuilder sb, java.lang.String paramName, java.lang.String paramValue)
      Appends to the StringBuilder the given parameter as follows: paramName=paramValue
      static java.util.Map<java.lang.String,​java.lang.Object> autoFillAriaAttributes​(java.util.Map<java.lang.String,​java.lang.Object> ariaAttributesMap, java.lang.String fieldResource, java.lang.String fieldLabelId)  
      static java.lang.String[] convertObject​(java.lang.Object obj)
      Converts an Object to String[].
      static java.lang.String formatAriaAttributes​(java.util.Map<java.lang.String,​java.lang.Object> ariaAtttributes)
      Returns a formatted string using the specified map of aria attributes.
      static java.lang.String formatAttribute​(java.lang.String lang, java.lang.String attrFormat, java.lang.String... args)
      Returns a formatted string using the specified format string and arguments.
      The specified format string represents a HTML attribute.
      Each argument of args can be a I18N property and is encoded for use in HTML attribute.
      Example:
      static java.lang.String formatDataAttributes​(java.util.Map<java.lang.String,​java.lang.Object> dataAttributes)
      Returns a formatted string using the specified map of data attributes.
      static <T> T getOption​(ControlSettings<?> settings, java.lang.String optionName, T defaultValue)
      Returns the option value present on the given ControlSettings from the given option name.
      If the option value is not found, it returns the default value.
      static java.lang.String resolveLabel​(java.lang.Object value, java.lang.String label, boolean multiple, java.lang.String lang)
      Resolve the label from the given value.
      The label can be split when multiple parameter is true, value parameter is not null and label is null.
      static java.lang.String resolveLabel​(java.lang.Object value, java.lang.String label, java.lang.String lang)
      Resolve the label from the given value.
      static ControlUtils.SelectDataItem resolveSelectData​(java.lang.String idValue, SelectorSettings.SelectMode selectMode)
      Returns a SelectDataItem which is used for Select rendering (With handlebars) by producing a data attribute
      static java.lang.String resolveValue​(java.lang.Object value)
      Resolve the value from the given object.
      static java.lang.String[] resolveValues​(java.lang.Object values)
      Resolve the value from the given object.
      static java.lang.String[] resolveValues​(java.lang.Object[] values)
      Resolve the values from the given objects.
      • Methods inherited from class java.lang.Object

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

      • resolveLabel

        public static java.lang.String resolveLabel​(java.lang.Object value,
                                                    java.lang.String label,
                                                    java.lang.String lang)
        Resolve the label from the given value.
        • If label in parameter is not null, the method returns this label, resolved if it's a I18N Property.
        • If value in parameter is a String, the method assumes that it is a Data ID and looks for the associated Data label
        • If value in parameter is a Data, the method looks for the Data label
        • If value in parameter is a Workflow, the method looks for the Workflow label
        • If value in parameter is a Class, the method assumes that it is the Class of a generated Type, and returns the label of the Type
        • Else the method returns the String represention of the value object
        Parameters:
        value - Object to resolve and identify the label
        label - Label to use if it's specified. It can be an I18N property.
        lang - Language to resolve the label
        Returns:
        Resolved label
      • resolveLabel

        public static java.lang.String resolveLabel​(java.lang.Object value,
                                                    java.lang.String label,
                                                    boolean multiple,
                                                    java.lang.String lang)
        Resolve the label from the given value.
        The label can be split when multiple parameter is true, value parameter is not null and label is null. This specific case is used for the Category chooser.
        Parameters:
        value - Object to resolve and identify the label
        label -
        multiple -
        lang -
        Returns:
        Resolved label
        See Also:
        resolveLabel(Object, String, String), "/work/categoryChooser.jsp"
      • resolveValue

        public static java.lang.String resolveValue​(java.lang.Object value)
        Resolve the value from the given object. The Object is converted to String[], and the method returns the first item of the array.
        Parameters:
        value - Object to resolve
        Returns:
        Resolved value
        See Also:
        convertObject(Object)
      • resolveValues

        public static java.lang.String[] resolveValues​(java.lang.Object[] values)
        Resolve the values from the given objects.
        Parameters:
        values - Array of objects to resolve
        Returns:
        Array of resolved values
      • resolveValues

        public static java.lang.String[] resolveValues​(java.lang.Object values)
        Resolve the value from the given object. The value can be split into multiple values when the resolved values contains the delimiter ',' or ' '.
        Parameters:
        values - Object to resolve
        Returns:
        Array of resolved values
      • formatAttribute

        public static java.lang.String formatAttribute​(java.lang.String lang,
                                                       java.lang.String attrFormat,
                                                       java.lang.String... args)
        Returns a formatted string using the specified format string and arguments.
        The specified format string represents a HTML attribute.
        Each argument of args can be a I18N property and is encoded for use in HTML attribute.
        Example:
         String placeholder = ControlUtils.formatAttribute("placeholder=\"%s\"", ControlUtils.getOption(settings.getClass(), BasicSettings.PLACEHOLDER, ""))
         
        Parameters:
        lang - language to resolve the I18N properties
        attrFormat - format string representing a HTML attribute
        args - Arguments referenced by the format specifiers in the format string
        Returns:
        A formatted string representing a HTML attribute with encoded values
      • formatDataAttributes

        public static java.lang.String formatDataAttributes​(java.util.Map<java.lang.String,​java.lang.Object> dataAttributes)
        Returns a formatted string using the specified map of data attributes.
        Parameters:
        dataAttributes - Map of data attributes
        Returns:
        A formatted string representing the data attributes in parameter
      • formatAriaAttributes

        public static java.lang.String formatAriaAttributes​(java.util.Map<java.lang.String,​java.lang.Object> ariaAtttributes)
        Returns a formatted string using the specified map of aria attributes.
        Parameters:
        ariaAtttributes - Map of aria attributes
        Returns:
        A formatted string representing the aria attributes in parameter
      • convertObject

        public static java.lang.String[] convertObject​(java.lang.Object obj)
        Converts an Object to String[].
        Parameters:
        obj - the Object to convert
        Returns:
        the String[] representation
      • getOption

        public static <T> T getOption​(ControlSettings<?> settings,
                                      java.lang.String optionName,
                                      T defaultValue)
        Returns the option value present on the given ControlSettings from the given option name.
        If the option value is not found, it returns the default value.
        Parameters:
        settings - ControlSettings containing the option
        optionName - Option name
        defaultValue - Default value if option value if not found
        Returns:
        Option value
        See Also:
        ControlSettings.getOption(String)
      • addOption

        public static <T> T addOption​(ControlSettings<?> settings,
                                      java.lang.String optionName,
                                      T optionValues)
        Adds new option with the specified value(s). If the given value is null, the option is removed.
        Parameters:
        settings - ControlSettings
        optionName - Option name
        optionValues - Option value(s)
        Returns:
        the previous option value
      • appendQueryStringParam

        public static void appendQueryStringParam​(java.lang.StringBuilder sb,
                                                  java.lang.String paramName,
                                                  java.lang.String paramValue)
        Appends to the StringBuilder the given parameter as follows: paramName=paramValue
        Parameters:
        sb - StringBuilder
        paramName - Parameter name
        paramValue - Parameter value
      • appendQueryStringParam

        public static void appendQueryStringParam​(java.lang.StringBuilder sb,
                                                  java.lang.String queryString)
        Appends to the StringBuilder the given query string.
        If the StringBuilder is not empty, append '&' before the query string.
        Parameters:
        sb - StringBuilder
        queryString - String representing a query string
      • autoFillAriaAttributes

        public static java.util.Map<java.lang.String,​java.lang.Object> autoFillAriaAttributes​(java.util.Map<java.lang.String,​java.lang.Object> ariaAttributesMap,
                                                                                                    java.lang.String fieldResource,
                                                                                                    java.lang.String fieldLabelId)