Package org.ametys.cms.content
Class ContentHelper
- java.lang.Object
-
- org.apache.avalon.framework.logger.AbstractLogEnabled
-
- org.ametys.cms.content.ContentHelper
-
- All Implemented Interfaces:
Component
,Contextualizable
,LogEnabled
,Serviceable
public class ContentHelper extends AbstractLogEnabled implements Component, Serviceable, Contextualizable
Helper forContent
-
-
Field Summary
Fields Modifier and Type Field Description private ContentTypeExtensionPoint
_contentTypeEP
private ContentTypesHelper
_contentTypesHelper
private Context
_context
private CurrentUserProvider
_currentUserProvider
private ObservationManager
_observationManager
private AmetysObjectResolver
_resolver
private SystemPropertyExtensionPoint
_systemPropertyExtensionPoint
private WorkflowProvider
_workflowProvider
static String
ROLE
The component role.
-
Constructor Summary
Constructors Constructor Description ContentHelper()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description private Object
_getBinaryValue(CompositeMetadata metadataHolder, String metadataName)
Deprecated.private Object
_getBooleanValue(CompositeMetadata metadataHolder, String metadataName, MetadataDefinition definition)
Deprecated.private Object
_getCompositeMetadataValue(CompositeMetadata metadataHolder, MetadataDefinition definition, Locale locale, boolean resolveReferences, boolean returnNullValues, String[] pathSegments, String metadataName)
Deprecated.private Object
_getContentMetadataValue(CompositeMetadata metadataHolder, MetadataDefinition definition, Locale defaultLocale, boolean resolveReferences, boolean returnNullValues, String[] pathSegments, String metadataName)
Deprecated.private Object
_getContentValue(CompositeMetadata metadataHolder, String metadataName, MetadataDefinition definition, boolean resolve)
Deprecated.private Object
_getDateValue(CompositeMetadata metadataHolder, String metadataName, MetadataDefinition definition)
Deprecated.private Object
_getDoubleValue(CompositeMetadata metadataHolder, String metadataName, MetadataDefinition definition)
Deprecated.private Object
_getFileValue(CompositeMetadata metadataHolder, String metadataName, MetadataDefinition definition, boolean resolveReference)
Deprecated.private Object
_getGeocodeValue(CompositeMetadata metadataHolder, String metadataName)
Deprecated.private Object
_getLongValue(CompositeMetadata metadataHolder, String metadataName, MetadataDefinition definition)
Deprecated.private Object
_getMultilingualStringValue(CompositeMetadata metadataHolder, String metadataName, Locale locale, boolean resolve)
Deprecated.private Object
_getReferenceValue(CompositeMetadata metadataHolder, String metadataName, MetadataDefinition definition)
Deprecated.private Object
_getResourceValue(CompositeMetadata metadataHolder, String metadataName, MetadataDefinition definition, boolean resolve)
Deprecated.private Object
_getRichTextValue(CompositeMetadata metadataHolder, String metadataName)
Deprecated.private Object
_getStringValue(CompositeMetadata metadataHolder, String metadataName, MetadataDefinition definition)
Deprecated.private Object
_getSystemPropertyValue(Content content, String[] pathSegments, SystemProperty systemProperty)
private Object
_getUserValue(CompositeMetadata metadataHolder, String metadataName, MetadataDefinition definition)
Deprecated.private Map<String,Object>
_setContentType(String contentId, String contentTypeId, int actionId, boolean remove)
private Map<String,Object>
_setMixinType(String contentId, String mixinId, int actionId, boolean remove)
Map<String,Object>
addContentType(String contentId, String contentTypeId, int actionId)
Add a content type to an existing contentMap<String,Object>
addMixinType(String contentId, String mixinId, int actionId)
Add a mixin type to an existing contentvoid
contextualize(Context context)
Map<String,Object>
getContentEditionInformation(String contentId)
Get content edition information.Object
getMetadataValue(Content content, String metadataPath, Locale defaultLocale, boolean resolveReferences)
Deprecated.Object
getMetadataValue(Content content, String metadataPath, Locale defaultLocale, boolean resolveReferences, boolean returnNullValues)
Deprecated.Object
getMetadataValue(CompositeMetadata metadataHolder, MetadataDefinition definition, String metadataPath, Locale locale, boolean resolveReferences, boolean returnNullValues)
Deprecated.List<Object>
getMetadataValues(String contentId, String metadataPath)
Deprecated.UseModelAwareDataHolder.getValue(String)
insteadList<Object>
getMetadataValues(Content content, String metadataPath, Locale defaultLocale, boolean resolveReferences, boolean returnNullValues)
Deprecated.UseModelAwareDataHolder.getValue(String)
insteadList<Pair<String,Content>>
getReferencingContents(Content content)
Returns all Contents referencing the given content with their value pathObject
getSimpleMetadataValue(CompositeMetadata metadataHolder, MetadataDefinition definition, String metadataName, Locale locale, boolean resolveReferences)
Deprecated.UseModelAwareDataHolder.getValue(String)
insteadContent
getTargetContent(Content sourceContent, String fieldPath)
Get the content from which to get the system property.List<Content>
getTargetContents(Content sourceContent, String fieldPath)
Get the contents from which to get the system property.String
getTitle(Content content)
Get the title of a content.<br> If the content is a multilingual content, the title will be retrieved for the current locale if exists, or for default locale 'en' if exists, or for the first found locale.Map<String,String>
getTitleVariants(Content content)
Get the title variants of a multilingual contentObject
getValue(Content content, String fieldPath, Locale defaultLocale, boolean resolveReferences)
Get the typed value(s) of a content at given path.Object
getValue(Content content, String fieldPath, Locale defaultLocale, boolean resolveReferences, boolean returnNullValues)
Get the typed value(s) of a content at given path.boolean
hasIndexingReferences(Content content)
Test if the given content has indexing references, i.e.boolean
hasReferencingContents(Content content, List<String> ignoreContentTypes, boolean includeSubTypes)
Determines if the content has referencing contents other than whose type is in content types to ignore.boolean
isMultilingual(Content content)
Determines if a content is a multilingual contentboolean
isReferenceTable(Content content)
Determines if the content is a reference table content typeboolean
isSimple(Content content)
Determines if the content is a simple content typeMap<String,Object>
removeContentType(String contentId, String contentTypeId, int actionId)
Remove a content type to an existing contentMap<String,Object>
removeMixinType(String contentId, String mixinId, int actionId)
Remove a mixin type to an existing contentvoid
service(ServiceManager smanager)
-
Methods inherited from class org.apache.avalon.framework.logger.AbstractLogEnabled
enableLogging, getLogger, setupLogger, setupLogger, setupLogger
-
-
-
-
Field Detail
-
_resolver
private AmetysObjectResolver _resolver
-
_contentTypesHelper
private ContentTypesHelper _contentTypesHelper
-
_contentTypeEP
private ContentTypeExtensionPoint _contentTypeEP
-
_observationManager
private ObservationManager _observationManager
-
_workflowProvider
private WorkflowProvider _workflowProvider
-
_currentUserProvider
private CurrentUserProvider _currentUserProvider
-
_systemPropertyExtensionPoint
private SystemPropertyExtensionPoint _systemPropertyExtensionPoint
-
-
Constructor Detail
-
ContentHelper
public ContentHelper()
-
-
Method Detail
-
service
public void service(ServiceManager smanager) throws ServiceException
- Specified by:
service
in interfaceServiceable
- Throws:
ServiceException
-
contextualize
public void contextualize(Context context) throws ContextException
- Specified by:
contextualize
in interfaceContextualizable
- Throws:
ContextException
-
addContentType
public Map<String,Object> addContentType(String contentId, String contentTypeId, int actionId) throws AmetysRepositoryException, com.opensymphony.workflow.WorkflowException
Add a content type to an existing content- Parameters:
contentId
- The content idcontentTypeId
- The content type to addactionId
- The workflow action id- Returns:
- The result in a Map
- Throws:
com.opensymphony.workflow.WorkflowException
- ifAmetysRepositoryException
- if an error occurred
-
removeContentType
public Map<String,Object> removeContentType(String contentId, String contentTypeId, int actionId) throws AmetysRepositoryException, com.opensymphony.workflow.WorkflowException
Remove a content type to an existing content- Parameters:
contentId
- The content idcontentTypeId
- The content type to addactionId
- The workflow action id- Returns:
- The result in a Map
- Throws:
com.opensymphony.workflow.WorkflowException
- ifAmetysRepositoryException
- if an error occurred
-
addMixinType
public Map<String,Object> addMixinType(String contentId, String mixinId, int actionId) throws AmetysRepositoryException, com.opensymphony.workflow.WorkflowException
Add a mixin type to an existing content- Parameters:
contentId
- The content idmixinId
- The mixin type to addactionId
- The workflow action id- Returns:
- The result in a Map
- Throws:
com.opensymphony.workflow.WorkflowException
- ifAmetysRepositoryException
- if an error occurred
-
removeMixinType
public Map<String,Object> removeMixinType(String contentId, String mixinId, int actionId) throws AmetysRepositoryException, com.opensymphony.workflow.WorkflowException
Remove a mixin type to an existing content- Parameters:
contentId
- The content idmixinId
- The mixin type to addactionId
- The workflow action id- Returns:
- The result in a Map
- Throws:
com.opensymphony.workflow.WorkflowException
- ifAmetysRepositoryException
- if an error occurred
-
getContentEditionInformation
public Map<String,Object> getContentEditionInformation(String contentId)
Get content edition information.- Parameters:
contentId
- the content ID.- Returns:
- a Map containing content edition information.
-
hasIndexingReferences
public boolean hasIndexingReferences(Content content)
Test if the given content has indexing references, i.e. if modifying it potentially implies reindexing other contents.- Parameters:
content
- the content to test.- Returns:
true
if one of the content types or mixins has indexing references,false
otherwise.
-
_setContentType
private Map<String,Object> _setContentType(String contentId, String contentTypeId, int actionId, boolean remove) throws AmetysRepositoryException, com.opensymphony.workflow.WorkflowException
- Throws:
AmetysRepositoryException
com.opensymphony.workflow.WorkflowException
-
_setMixinType
private Map<String,Object> _setMixinType(String contentId, String mixinId, int actionId, boolean remove) throws AmetysRepositoryException, com.opensymphony.workflow.WorkflowException
- Throws:
AmetysRepositoryException
com.opensymphony.workflow.WorkflowException
-
isReferenceTable
public boolean isReferenceTable(Content content)
Determines if the content is a reference table content type- Parameters:
content
- The content- Returns:
- true if content is a reference table
-
isMultilingual
public boolean isMultilingual(Content content)
Determines if a content is a multilingual content- Parameters:
content
- The content- Returns:
true
if the content is an instance of content type
-
isSimple
public boolean isSimple(Content content)
Determines if the content is a simple content type- Parameters:
content
- The content- Returns:
- true if content is simple
-
getValue
public Object getValue(Content content, String fieldPath, Locale defaultLocale, boolean resolveReferences)
Get the typed value(s) of a content at given path. The path can represent a system property id or a path of a metadata into the content or a metadata on one or more linked contents, such as 'composite/linkedContent/secondContent/composite/metadata'. The returned value is typed.- Parameters:
content
- The contentfieldPath
- The field id or the path to the metadata, separated by '/'defaultLocale
- The default locale to resolve localized values if the content's language is null. Can be null.resolveReferences
-true
true to resolve references (such as resource or content)- Returns:
- The typed final value. If the final field is multiple, or contains into a repeater or multiple 'CONTENT' metadata, the returned value will be a Collection
-
getValue
public Object getValue(Content content, String fieldPath, Locale defaultLocale, boolean resolveReferences, boolean returnNullValues)
Get the typed value(s) of a content at given path. The path can represent a system property id or a path of an attribute into the content or an attribute on one or more linked contents, such as 'composite/linkedContent/secondContent/composite/attribute'. The returned value is typed.- Parameters:
content
- The contentfieldPath
- The field id or the path to the attribute, separated by '/'defaultLocale
- The default locale to resolve localized values if the content's language is null. Can be null.resolveReferences
-true
true to resolve references (such as resource or content)returnNullValues
-true
true to return null values when the attribute does not exists in a repeater or linked content.- Returns:
- The typed final value. If the final field is multiple, or contained into a repeater or multiple 'CONTENT' attribute, the returned value will be a Collection
-
_getSystemPropertyValue
private Object _getSystemPropertyValue(Content content, String[] pathSegments, SystemProperty systemProperty)
-
getTargetContent
public Content getTargetContent(Content sourceContent, String fieldPath)
Get the content from which to get the system property.- Parameters:
sourceContent
- The source content.fieldPath
- The field path- Returns:
- The target content.
-
getTargetContents
public List<Content> getTargetContents(Content sourceContent, String fieldPath)
Get the contents from which to get the system property.- Parameters:
sourceContent
- The source content.fieldPath
- The field path- Returns:
- The target contents.
-
getMetadataValue
@Deprecated public Object getMetadataValue(Content content, String metadataPath, Locale defaultLocale, boolean resolveReferences)
Deprecated.Get the typed metadata value(s) of a content at given path. The path can represent a path of a metadata into the content or a metadata on one or more linked contents, such as 'composite/linkedContent/secondContent/composite/metadata'. The returned value is typed.- Parameters:
content
- The contentmetadataPath
- The path to the metadata, separated by '/'defaultLocale
- The locale to use to sax localized values such as multilingual content or multilingual string. Only to be valued if initial content's language is null, otherwise set this parameter to null.resolveReferences
-true
true to resolve references (such as resource or content)- Returns:
- The typed final value. If the final metadata is multiple, or contains into a repeater or multiple 'CONTENT' metadata, the returned value will be a Collection
-
getMetadataValue
@Deprecated public Object getMetadataValue(Content content, String metadataPath, Locale defaultLocale, boolean resolveReferences, boolean returnNullValues)
Deprecated.Get the typed metadata value(s) of a content at given path. The path can represent a path of a metadata into the content or a metadata on one or more linked contents, such as 'composite/linkedContent/secondContent/composite/metadata'. The returned value is typed.- Parameters:
content
- The contentmetadataPath
- The path to the metadata, separated by '/'defaultLocale
- The locale to use to sax localized values such as multilingual content or multilingual string. Only to be valued if initial content's language is null, otherwise set this parameter to null.resolveReferences
-true
true to resolve references (such as resource or content)returnNullValues
-true
true to return null values when the metadata does not exists in a repeater or linked content.- Returns:
- The typed final value. If the final metadata is multiple, or contains into a repeater or multiple 'CONTENT' metadata, the returned value will be a Collection
-
getMetadataValues
@Deprecated public List<Object> getMetadataValues(String contentId, String metadataPath)
Deprecated.UseModelAwareDataHolder.getValue(String)
insteadGet the typed values of a content at given path. The value is always returned into a collection of object event if the metadata is a single metadata. The path can represent a path of a metadata into the content or a metadata on one or more linked contents, such as 'composite/linkedContent/secondContent/composite/metadata'. The returned value is typed.- Parameters:
contentId
- The ID of the contentmetadataPath
- The Path to the metadata, separated by '/'- Returns:
- The typed final value. If the final metadata is single, the returned value will be a Collection of one element
-
getMetadataValues
@Deprecated public List<Object> getMetadataValues(Content content, String metadataPath, Locale defaultLocale, boolean resolveReferences, boolean returnNullValues)
Deprecated.UseModelAwareDataHolder.getValue(String)
insteadGet the typed values of a content at given path. The value is always returned into a collection of object event if the metadata is a single metadata. The path can represent a path of a metadata into the content or a metadata on one or more linked contents, such as 'composite/linkedContent/secondContent/composite/metadata'. The returned value is typed.- Parameters:
content
- The contentmetadataPath
- The path to the metadata, separated by '/'defaultLocale
- The locale to use to sax localized values such as multilingual content or multilingual string. Only to be valued if initial content's language is null, otherwise set this parameter to null.resolveReferences
-true
true to resolve references (such as resource or content)returnNullValues
-true
true to return null values when the metadata does not exists in a repeater or linked content.- Returns:
- The typed final value. If the final metadata is single, the returned value will be a Collection of one element
-
getTitle
public String getTitle(Content content)
Get the title of a content.<br> If the content is a multilingual content, the title will be retrieved for the current locale if exists, or for default locale 'en' if exists, or for the first found locale.- Parameters:
content
- The content- Returns:
- The title of the content
-
getTitleVariants
public Map<String,String> getTitleVariants(Content content)
Get the title variants of a multilingual content- Parameters:
content
- The multilingual content- Returns:
- the content's title for each locale
- Throws:
IllegalArgumentException
- if the content is not a multilingual content
-
getMetadataValue
@Deprecated public Object getMetadataValue(CompositeMetadata metadataHolder, MetadataDefinition definition, String metadataPath, Locale locale, boolean resolveReferences, boolean returnNullValues)
Deprecated.Get the typed value(s) at given path. The path can represent a path of a metadata in the parent composite metadata or a path of a metadata into a linked content. The returned value is typed.- Parameters:
metadataHolder
- The parent composite metadatadefinition
- The definition of the first metadata in pathmetadataPath
- The path to the metadata, separated by '/'locale
- The locale to used to resolve localized metadataresolveReferences
-true
true to resolve references (such as resource or content)returnNullValues
-true
true to return null values when metadata does not exists.- Returns:
- The typed final value. If the final metadata is multiple, or contains into a repeater or multiple 'CONTENT' metadata, the returned value will be a Collection
-
_getContentMetadataValue
@Deprecated private Object _getContentMetadataValue(CompositeMetadata metadataHolder, MetadataDefinition definition, Locale defaultLocale, boolean resolveReferences, boolean returnNullValues, String[] pathSegments, String metadataName)
Deprecated.
-
_getCompositeMetadataValue
@Deprecated private Object _getCompositeMetadataValue(CompositeMetadata metadataHolder, MetadataDefinition definition, Locale locale, boolean resolveReferences, boolean returnNullValues, String[] pathSegments, String metadataName)
Deprecated.
-
getSimpleMetadataValue
@Deprecated public Object getSimpleMetadataValue(CompositeMetadata metadataHolder, MetadataDefinition definition, String metadataName, Locale locale, boolean resolveReferences)
Deprecated.UseModelAwareDataHolder.getValue(String)
insteadGet the typed value(s) of a simple metadata.- Parameters:
metadataHolder
- The parent composite metadatadefinition
- The definition of the first metadata in pathmetadataName
- The name of the metadatalocale
- The locale to used to resolve localized metadataresolveReferences
-true
true to resolve references (such as resource or content)- Returns:
- The typed final value.
-
_getStringValue
@Deprecated private Object _getStringValue(CompositeMetadata metadataHolder, String metadataName, MetadataDefinition definition)
Deprecated.
-
_getMultilingualStringValue
@Deprecated private Object _getMultilingualStringValue(CompositeMetadata metadataHolder, String metadataName, Locale locale, boolean resolve)
Deprecated.
-
_getContentValue
@Deprecated private Object _getContentValue(CompositeMetadata metadataHolder, String metadataName, MetadataDefinition definition, boolean resolve)
Deprecated.
-
_getUserValue
@Deprecated private Object _getUserValue(CompositeMetadata metadataHolder, String metadataName, MetadataDefinition definition)
Deprecated.
-
_getDateValue
@Deprecated private Object _getDateValue(CompositeMetadata metadataHolder, String metadataName, MetadataDefinition definition)
Deprecated.
-
_getLongValue
@Deprecated private Object _getLongValue(CompositeMetadata metadataHolder, String metadataName, MetadataDefinition definition)
Deprecated.
-
_getDoubleValue
@Deprecated private Object _getDoubleValue(CompositeMetadata metadataHolder, String metadataName, MetadataDefinition definition)
Deprecated.
-
_getBooleanValue
@Deprecated private Object _getBooleanValue(CompositeMetadata metadataHolder, String metadataName, MetadataDefinition definition)
Deprecated.
-
_getRichTextValue
@Deprecated private Object _getRichTextValue(CompositeMetadata metadataHolder, String metadataName)
Deprecated.
-
_getBinaryValue
@Deprecated private Object _getBinaryValue(CompositeMetadata metadataHolder, String metadataName)
Deprecated.
-
_getResourceValue
@Deprecated private Object _getResourceValue(CompositeMetadata metadataHolder, String metadataName, MetadataDefinition definition, boolean resolve)
Deprecated.
-
_getGeocodeValue
@Deprecated private Object _getGeocodeValue(CompositeMetadata metadataHolder, String metadataName)
Deprecated.
-
_getReferenceValue
@Deprecated private Object _getReferenceValue(CompositeMetadata metadataHolder, String metadataName, MetadataDefinition definition)
Deprecated.
-
_getFileValue
@Deprecated private Object _getFileValue(CompositeMetadata metadataHolder, String metadataName, MetadataDefinition definition, boolean resolveReference)
Deprecated.
-
hasReferencingContents
public boolean hasReferencingContents(Content content, List<String> ignoreContentTypes, boolean includeSubTypes)
Determines if the content has referencing contents other than whose type is in content types to ignore.- Parameters:
content
- The content to checkignoreContentTypes
- The content types to ignore for referencing contentsincludeSubTypes
- True if sub content types are take into account in ignore content types- Returns:
true
if there is at least one Content referencing the content
-
-