Package de.xima.fc.form.common
Class XItemUtil
- java.lang.Object
-
- de.xima.fc.form.common.XItemUtil
-
public class XItemUtil extends Object
-
-
Constructor Summary
Constructors Constructor Description XItemUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static void
addItem(XItem item, XForm form)
static void
fillXFormData(com.alibaba.fastjson.JSONObject persist, XForm form)
static XItem
findItemByName(IXForm xForm, String formFieldName)
Finds the item with the given name in the form.static XItem
findPage(Map<String,XItem> items, XItem item)
static XItem
findRepetitionContainer(XItem item, IXForm xForm)
Finds the closest parent item that is a repetition container for the given item.static Set<String>
getAcceptedFileExtensions(XItem xItem)
static Set<Class<? extends IXItemBasic>>
getBuiltinItemTypes()
Gets an (immutable) set of all builtinform item types
provided by the formcycle core.static IXItemBasic
getItemHandler(String className, Map<String,Class<? extends IXItemBasic>> xitems, Map<String,XItemWidgetWrapper> widgets)
static Map<String,List<XItem>>
getItemsByClasses(com.alibaba.fastjson.JSONObject persist, IFD2XItemProvider provider, Class<?>... classes)
Finds form items by their class name.static Map<String,List<XItem>>
getItemsByClasses(com.alibaba.fastjson.JSONObject persist, Map<String,Class<? extends IXItemBasic>> xItems, Map<String,XItemWidgetWrapper> widgets, Class<?>... classes)
Finds form items by their class name.static Map<String,List<XItem>>
getItemsByClassName(com.alibaba.fastjson.JSONObject persist, String... classNames)
Finds form items by their class name.static Map<String,XItem>
getItemsByIdMap(com.alibaba.fastjson.JSONObject persist)
static HashMap<String,XItem>
getItemsMap(com.alibaba.fastjson.JSONObject persist)
static Class<? extends IXItemBasic>
getItemTypeClass(XItem item, IFD2XItemProvider provider)
static Class<? extends IXItemBasic>
getItemTypeClass(String className, Map<String,Class<? extends IXItemBasic>> xitems, Map<String,XItemWidgetWrapper> widgets)
static String
getLabel(XItem xItem, Locale locale)
Returns the label of the given item in the given locale.static Long
getMaxFileSize(XItem xItem)
Returns the maximum file size for the given item.static int
getMaxRepetitions(XItem xItem)
Returns the maximum number of repetitions for the given item.static int
getMinRepetitions(XItem xItem)
Returns the minimum number of repetitions for the given item.static XItem
getXItem(com.alibaba.fastjson.JSONObject jsonObject, com.alibaba.fastjson.JSONObject version)
static XItem
getXItem(com.alibaba.fastjson.JSONObject jsonObject, IXFormRenderConfig xRenderConfig)
Deprecated.static XItem
getXItem(com.alibaba.fastjson.JSONObject jsonObject, IXFormRenderConfig xRenderConfig, com.alibaba.fastjson.JSONObject version)
Deprecated.ThexRenderConfig
is not needed.
-
-
-
Method Detail
-
fillXFormData
public static void fillXFormData(com.alibaba.fastjson.JSONObject persist, XForm form) throws com.alibaba.fastjson.JSONException
- Throws:
com.alibaba.fastjson.JSONException
-
findItemByName
public static XItem findItemByName(IXForm xForm, String formFieldName)
Finds the item with the given name in the form.- Parameters:
xForm
- Form in which to find the item.formFieldName
- Name of the item to find.- Returns:
- The item with the given name in the form or
null
if no such item exists.
-
findPage
public static XItem findPage(Map<String,XItem> items, XItem item)
- Parameters:
items
- Map between the ID of an item and the item itself.item
- Item for which to get the page.- Returns:
- The item representing the
XPage
which contains the given item.
-
findRepetitionContainer
public static XItem findRepetitionContainer(XItem item, IXForm xForm)
Finds the closest parent item that is a repetition container for the given item.- Parameters:
item
- Item for which to find the closest repetition container.xForm
- Form in which the item is located.- Returns:
- The closest parent item that is a repetition container for the given item.
-
getBuiltinItemTypes
public static Set<Class<? extends IXItemBasic>> getBuiltinItemTypes()
Gets an (immutable) set of all builtinform item types
provided by the formcycle core. This does not include items provided by widget plugins.- Returns:
- All builtin item types.
- Since:
- 8.1.0
-
getItemHandler
public static IXItemBasic getItemHandler(String className, Map<String,Class<? extends IXItemBasic>> xitems, Map<String,XItemWidgetWrapper> widgets)
- Parameters:
className
- (Simple) class name of the item type.xitems
- Map with all available built-in item types.widgets
- Map with all available plugin item types.- Returns:
- An instantiated handler for the given item type.
-
getItemTypeClass
public static Class<? extends IXItemBasic> getItemTypeClass(String className, Map<String,Class<? extends IXItemBasic>> xitems, Map<String,XItemWidgetWrapper> widgets)
- Parameters:
className
- (Simple) class name of the item type.xitems
- Map with all available built-in item types.widgets
- Map with all available plugin item types.- Returns:
- The class for the given item type.
-
getItemTypeClass
public static Class<? extends IXItemBasic> getItemTypeClass(XItem item, IFD2XItemProvider provider)
- Parameters:
item
- An item for which to find its handler class.provider
- Item provider with the known item classes.- Returns:
- The handler class for the given item.
-
getItemsByClassName
public static Map<String,List<XItem>> getItemsByClassName(com.alibaba.fastjson.JSONObject persist, String... classNames) throws com.alibaba.fastjson.JSONException
Finds form items by their class name. Only parses those items that match the given class names.- Parameters:
persist
- Persist JSON of the form.classNames
- All form item class names that should be returned. When null or empty, all types are returned.- Returns:
- A map between the item type (class name) and all form items of that type.
- Throws:
com.alibaba.fastjson.JSONException
- When the persist is invalid.
-
getItemsByClasses
public static Map<String,List<XItem>> getItemsByClasses(com.alibaba.fastjson.JSONObject persist, IFD2XItemProvider provider, Class<?>... classes) throws com.alibaba.fastjson.JSONException
Finds form items by their class name. Only parses those items that match the given class names.- Parameters:
persist
- Persist JSON of the form.provider
- Item provider with the known item classes.classes
- List of form item classes to return, can be a super class or super interface. When null or empty, all types are returned.- Returns:
- A map between the item type (class name) and all form items of that type.
- Throws:
com.alibaba.fastjson.JSONException
- When the persist is invalid.
-
getItemsByClasses
public static Map<String,List<XItem>> getItemsByClasses(com.alibaba.fastjson.JSONObject persist, Map<String,Class<? extends IXItemBasic>> xItems, Map<String,XItemWidgetWrapper> widgets, Class<?>... classes) throws com.alibaba.fastjson.JSONException
Finds form items by their class name. Only parses those items that match the given class names.- Parameters:
persist
- Persist JSON of the form.xItems
- Map with all available built-in item types.widgets
- Map with all available plugin item types.classes
- List of form item classes to return, can be a super class or super interface. When null or empty, all types are returned.- Returns:
- A map between the item type (class name) and all form items of that type.
- Throws:
com.alibaba.fastjson.JSONException
- When the persist is invalid.
-
getItemsByIdMap
public static Map<String,XItem> getItemsByIdMap(com.alibaba.fastjson.JSONObject persist) throws com.alibaba.fastjson.JSONException
- Throws:
com.alibaba.fastjson.JSONException
-
getItemsMap
public static HashMap<String,XItem> getItemsMap(com.alibaba.fastjson.JSONObject persist) throws com.alibaba.fastjson.JSONException
- Throws:
com.alibaba.fastjson.JSONException
-
getLabel
public static String getLabel(XItem xItem, Locale locale)
Returns the label of the given item in the given locale.- Parameters:
xItem
- Item for which to get the label.locale
- Locale in which to get the label.- Returns:
- The label of the given item in the given locale.
-
getMaxFileSize
public static Long getMaxFileSize(XItem xItem)
Returns the maximum file size for the given item. If no maximum file size is set, null is returned, indicating that there is no maximum file size.- Parameters:
xItem
- Item for which to get the maximum file size.- Returns:
- The maximum file size for the given item or null if no maximum file size is set.
-
getMaxRepetitions
public static int getMaxRepetitions(XItem xItem)
Returns the maximum number of repetitions for the given item.- Parameters:
xItem
- Item for which to get the maximum number of repetitions.- Returns:
- The maximum number of repetitions for the given item.
-
getMinRepetitions
public static int getMinRepetitions(XItem xItem)
Returns the minimum number of repetitions for the given item.- Parameters:
xItem
- Item for which to get the minimum number of repetitions.- Returns:
- The minimum number of repetitions for the given item.
-
getXItem
@Deprecated public static XItem getXItem(com.alibaba.fastjson.JSONObject jsonObject, IXFormRenderConfig xRenderConfig)
Deprecated.- Parameters:
jsonObject
- JSON object with the properties of the item.xRenderConfig
- Current render configuration of the form.- Returns:
- The item descriptor for the given parameters.
-
getXItem
@Deprecated public static XItem getXItem(com.alibaba.fastjson.JSONObject jsonObject, IXFormRenderConfig xRenderConfig, com.alibaba.fastjson.JSONObject version)
Deprecated.ThexRenderConfig
is not needed. UsegetXItem(JSONObject, JSONObject)
.- Parameters:
jsonObject
- JSON object with the properties of the item.xRenderConfig
- Current render configuration of the form.version
- Version of the form.- Returns:
- The item descriptor for the given parameters.
-
getXItem
public static XItem getXItem(com.alibaba.fastjson.JSONObject jsonObject, com.alibaba.fastjson.JSONObject version)
- Parameters:
jsonObject
- JSON object with the properties of the item.version
- Version of the form.- Returns:
- The item descriptor for the given parameters.
-
-