Package com.jalios.jcms.taglib.settings
Class ControlUtils
- java.lang.Object
-
- com.jalios.jcms.taglib.settings.ControlUtils
-
public final class ControlUtils extends java.lang.Object
Utils class for <jalios:control> andControlSettings
.- Author:
- ndossantos
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ControlUtils.SelectDataItem
-
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 theStringBuilder
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 theStringBuilder
the given parameter as follows: paramName=paramValuestatic 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 ofargs
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 givenControlSettings
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 whenmultiple
parameter istrue
,value
parameter is notnull
andlabel
isnull
.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 attributestatic 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.
-
-
-
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 aString
, the method assumes that it is a Data ID and looks for the associated Data label - If
value
in parameter is aData
, the method looks for the Data label - If
value
in parameter is aWorkflow
, the method looks for the Workflow label - If
value
in parameter is aClass
, 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 labellabel
- Label to use if it's specified. It can be an I18N property.lang
- Language to resolve the label- Returns:
- Resolved label
- If
-
resolveSelectData
public 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- Parameters:
idValue
- the Id of the data (Optional)selectMode
- theSelectorSettings.SelectMode
- Returns:
ControlUtils.SelectDataItem
object
-
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 whenmultiple
parameter istrue
,value
parameter is notnull
andlabel
isnull
. This specific case is used for the Category chooser.- Parameters:
value
- Object to resolve and identify the labellabel
-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 ofargs
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 propertiesattrFormat
- format string representing a HTML attributeargs
- 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 givenControlSettings
from the given option name.
If the option value is not found, it returns the default value.- Parameters:
settings
-ControlSettings
containing the optionoptionName
- Option namedefaultValue
- 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 isnull
, the option is removed.- Parameters:
settings
-ControlSettings
optionName
- Option nameoptionValues
- 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 theStringBuilder
the given parameter as follows: paramName=paramValue- Parameters:
sb
- StringBuilderparamName
- Parameter nameparamValue
- Parameter value
-
appendQueryStringParam
public static void appendQueryStringParam(java.lang.StringBuilder sb, java.lang.String queryString)
Appends to theStringBuilder
the given query string.
If the StringBuilder is not empty, append '&' before the query string.- Parameters:
sb
- StringBuilderqueryString
- 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)
-
-