Package org.ametys.cms.data.type
Class AbstractContentElementType
- java.lang.Object
-
- org.ametys.runtime.plugin.component.AbstractLogEnabled
-
- org.ametys.core.model.type.AbstractModelItemType
-
- org.ametys.core.model.type.AbstractElementType<ContentValue>
-
- org.ametys.cms.data.type.AbstractContentElementType
-
- All Implemented Interfaces:
ElementType<ContentValue>
,ModelItemType
,LogEnabled
,PluginAware
,Component
,Serviceable
- Direct Known Subclasses:
ContentRepositoryElementType
public abstract class AbstractContentElementType extends AbstractElementType<ContentValue>
Abstract class for content type of elements
-
-
Field Summary
Fields Modifier and Type Field Description protected ContentTypesHelper
_contentTypesHelper
Helper for content typesprotected AmetysObjectResolver
_resolver
Ametys object resolver-
Fields inherited from class org.ametys.core.model.type.AbstractElementType
_jsonUtils
-
-
Constructor Summary
Constructors Constructor Description AbstractContentElementType()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected boolean
_isMultiple(Object value)
Checks if the given value is considered as multiple for this element typeprotected boolean
_isSingle(Object value)
Checks if the given value is considered as single for this element typeprotected ContentValue
_singleValueFromXML(Element element, Optional<Object> additionalData)
Retrieves a single typed value from the given DOM nodeprotected boolean
_useJSONForEdition()
Determine if the JSON format has to be used in edition mode for this element typeprotected Object
_valueToJSON(Object value, DataContext context, BiFunction<String,DataContext,Object> singleStringToJSONFunction, BiFunction<Content,DataContext,Object> singleContentToJSONFunction, BiFunction<ContentValue,DataContext,Object> singleContentValueToJSONFunction)
Convert the value into a JSON object using the given functionsprotected void
_valueToSAX(ContentHandler contentHandler, String tagName, Object value, Optional<ViewItem> viewItem, DataContext context, AttributesImpl attributes)
Generates SAX events for the given valueContentValue
convertValue(Object value)
Try to convert the given value, that is not of the managed typeObject
fromJSONForClient(Object json, DataContext context)
Convert the given client side JSON object to the types valueboolean
isCompatible(Object value)
Checks if the value is compatible with the element typeboolean
isSimple()
Determines if this type is simple or not.void
service(ServiceManager manager)
String
toString(ContentValue value)
Cast a typed value to a StringObject
valueToJSONForClient(Object value, DataContext context)
Convert the value into a JSON object to use client sideObject
valueToJSONForEdition(Object value, DataContext context)
Convert the value into a JSON object to use in edition mode-
Methods inherited from class org.ametys.core.model.type.AbstractElementType
_compareMultipleValues, _compareSingleValues, _getValueAttributes, _isValueFromXMLMultiple, _singleValueToJSON, _singleValueToJSONForEdition, _singleValueToSAX, _valueToJSON, _valueToSAX, _valueToSAXForEdition, castValue, compareValues, getManagedClass, getManagedClassArray, parseConfiguration, valueFromXML, valueToSAX, valueToSAXForEdition
-
Methods inherited from class org.ametys.core.model.type.AbstractModelItemType
_getContextAttributes, getId, setPluginInfo
-
Methods inherited from class org.ametys.runtime.plugin.component.AbstractLogEnabled
getLogger, setLogger
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.ametys.runtime.model.type.ModelItemType
getId, valueToSAX
-
Methods inherited from interface org.ametys.runtime.plugin.component.PluginAware
setPluginInfo
-
-
-
-
Field Detail
-
_resolver
protected AmetysObjectResolver _resolver
Ametys object resolver
-
_contentTypesHelper
protected ContentTypesHelper _contentTypesHelper
Helper for content types
-
-
Constructor Detail
-
AbstractContentElementType
public AbstractContentElementType()
-
-
Method Detail
-
service
public void service(ServiceManager manager) throws ServiceException
- Specified by:
service
in interfaceServiceable
- Overrides:
service
in classAbstractElementType<ContentValue>
- Throws:
ServiceException
-
convertValue
public ContentValue convertValue(Object value) throws BadItemTypeException
Description copied from class:AbstractElementType
Try to convert the given value, that is not of the managed type- Overrides:
convertValue
in classAbstractElementType<ContentValue>
- Parameters:
value
- the value to convert- Returns:
- the converted value or null if it's not possible.
- Throws:
BadItemTypeException
- if the given value is not compatible with the current type
-
toString
public String toString(ContentValue value)
Description copied from interface:ElementType
Cast a typed value to a String- Specified by:
toString
in interfaceElementType<ContentValue>
- Overrides:
toString
in classAbstractElementType<ContentValue>
- Parameters:
value
- the value to cast- Returns:
- the String representation of the value
-
fromJSONForClient
public Object fromJSONForClient(Object json, DataContext context)
Description copied from interface:ElementType
Convert the given client side JSON object to the types value- Parameters:
json
- the JSON object to convertcontext
- the context of the data to retrieve- Returns:
- the typed value corresponding to the JSON object
-
valueToJSONForClient
public Object valueToJSONForClient(Object value, DataContext context)
Description copied from interface:ElementType
Convert the value into a JSON object to use client side- Specified by:
valueToJSONForClient
in interfaceElementType<ContentValue>
- Overrides:
valueToJSONForClient
in classAbstractElementType<ContentValue>
- Parameters:
value
- the value to convertcontext
- The context of the data to convert. Can not be null.- Returns:
- The value as JSON
-
valueToJSONForEdition
public Object valueToJSONForEdition(Object value, DataContext context)
Description copied from interface:ElementType
Convert the value into a JSON object to use in edition mode- Specified by:
valueToJSONForEdition
in interfaceElementType<ContentValue>
- Overrides:
valueToJSONForEdition
in classAbstractElementType<ContentValue>
- Parameters:
value
- the value to convertcontext
- The context of the data to convert. Can not be null.- Returns:
- The value as JSON
-
_valueToJSON
protected Object _valueToJSON(Object value, DataContext context, BiFunction<String,DataContext,Object> singleStringToJSONFunction, BiFunction<Content,DataContext,Object> singleContentToJSONFunction, BiFunction<ContentValue,DataContext,Object> singleContentValueToJSONFunction)
Convert the value into a JSON object using the given functions- Parameters:
value
- the value to convertcontext
- The context of the data to convertsingleStringToJSONFunction
- the function to apply to each single string to convert it into a JSON objectsingleContentToJSONFunction
- the function to apply to each single content to convert it into a JSON objectsingleContentValueToJSONFunction
- the function to apply to each single content value to convert it into a JSON object- Returns:
- The value as JSON
-
_singleValueFromXML
protected ContentValue _singleValueFromXML(Element element, Optional<Object> additionalData)
Description copied from class:AbstractElementType
Retrieves a single typed value from the given DOM node- Overrides:
_singleValueFromXML
in classAbstractElementType<ContentValue>
- Parameters:
element
- the DOM element containing the single valueadditionalData
- additional data needed to get the typed value- Returns:
- the value
-
_valueToSAX
protected void _valueToSAX(ContentHandler contentHandler, String tagName, Object value, Optional<ViewItem> viewItem, DataContext context, AttributesImpl attributes) throws SAXException
Description copied from class:AbstractElementType
Generates SAX events for the given value- Overrides:
_valueToSAX
in classAbstractElementType<ContentValue>
- Parameters:
contentHandler
- theContentHandler
that will receive the SAX eventstagName
- the tag name of the SAX event to generate.value
- the value to SAXviewItem
- The optional view item corresponding item that is currently saxed. This view item gives context for the SAX event that will be generated here.context
- The context of the data to SAXattributes
- the attributes for the SAX events to generate- Throws:
SAXException
- if an error occurs during the SAX events generation
-
isCompatible
public boolean isCompatible(Object value)
Description copied from interface:ElementType
Checks if the value is compatible with the element type- Specified by:
isCompatible
in interfaceElementType<ContentValue>
- Overrides:
isCompatible
in classAbstractElementType<ContentValue>
- Parameters:
value
- the value to check- Returns:
true
if the value matches the current type,false
otherwise
-
isSimple
public boolean isSimple()
Description copied from interface:ElementType
Determines if this type is simple or not. A simple element type is a type of elements that can be edited in a grid- Returns:
true
if the type is simple,false
otherwise
-
_useJSONForEdition
protected boolean _useJSONForEdition()
Description copied from class:AbstractElementType
Determine if the JSON format has to be used in edition mode for this element type- Overrides:
_useJSONForEdition
in classAbstractElementType<ContentValue>
- Returns:
true
if the JSON format has to be used,false
otherwise
-
_isMultiple
protected boolean _isMultiple(Object value)
Description copied from class:AbstractElementType
Checks if the given value is considered as multiple for this element type- Overrides:
_isMultiple
in classAbstractElementType<ContentValue>
- Parameters:
value
- the value to check- Returns:
true
if the value is multiple,false
otherwise
-
_isSingle
protected boolean _isSingle(Object value)
Description copied from class:AbstractElementType
Checks if the given value is considered as single for this element type- Overrides:
_isSingle
in classAbstractElementType<ContentValue>
- Parameters:
value
- the value to check- Returns:
true
if the value is single,false
otherwise
-
-