public class ContentTypesHelper extends AbstractLogEnabled implements Component, Serviceable, ThreadSafe, Disposable
ContentType
sModifier and Type | Class and Description |
---|---|
(package private) class |
ContentTypesHelper.ContentTypeComparator |
Modifier and Type | Field and Description |
---|---|
private Map<String,Map<String,MetadataSet>> |
_cacheForEdition |
private Map<String,Map<String,MetadataSet>> |
_cacheForView |
protected ContentTypeExtensionPoint |
_cTypeEP
The content types extension point
|
private DynamicContentTypeDescriptorExtentionPoint |
_dynamicCTDescriptorEP |
protected RightManager |
_rightManager
The rights manager
|
protected RootContentHelper |
_rootContentHelper
Helper for root content
|
private ServiceManager |
_smanager |
protected CurrentUserProvider |
_userProvider
The current user provider
|
static String |
ROLE
The Avalon role
|
Constructor and Description |
---|
ContentTypesHelper() |
Modifier and Type | Method and Description |
---|---|
private void |
_addIfNotPresent(Collection<String> collection,
String value) |
private List<Set<String>> |
_buildReverseHierarchies(String contentTypeId,
Set<String> hierarchy) |
private boolean |
_containsContentType(String[] cTypesId,
String cTypeId) |
private void |
_copyMetadataSetElementsIfNotExist(AbstractMetadataSetElement src,
AbstractMetadataSetElement dest,
AbstractMetadataSetElement reference) |
private Map<String,Object> |
_dispatchContentTypes(boolean checkRights,
boolean includePrivate,
boolean includeMixins,
boolean includeAbstract,
Collection<String> allContentTypesIds) |
private String |
_getCacheIdentifier(String[] contentTypes,
String[] mixins) |
protected ContentTypeExtensionPoint |
_getContentTypeEP()
Lazy lookup of
ContentTypeExtensionPoint |
protected void |
_getMetadataDefinitionsAcc(Map<String,MetadataDefinition> internalAcc,
AbstractMetadataSetElement metadataSetElement,
String prefix,
MetadataDefinitionHolder metaDefHolder)
Populate the accumulator with the metadata definition
|
protected MetadataSet |
_getMetadataSet(ContentType contentType,
String metadataSetName,
boolean isEdition)
Get the metadataset of a content given the parameters
|
protected boolean |
_hasRight(ContentType contentType)
Test if the current user has the right needed by the content type to create a content.
|
List<Set<String>> |
buildReverseHierarchies(String contentTypeId)
Builds the reverse hierarchies of ancestors of a content type
|
boolean |
canRead(Content content,
MetadataDefinition metadataDef)
Determine whether a metadata can be read at this time.
|
boolean |
canWrite(Content content,
MetadataDefinition metadataDef)
Determine whether a metadata can be read at this time.
|
void |
copyMetadataSetElementsIfNotExist(AbstractMetadataSetElement src,
AbstractMetadataSetElement dest)
Copy the elements of metadata set into a metadata set of destination,
only if the elements are not already presents
|
void |
dispose() |
Set<String> |
getAncestors(String contentTypeId)
Get all ancestors for the given content type
|
String |
getCommonAncestor(Collection<String> contentTypes)
Get the id of the content type common ancestor
|
Map<String,MetadataDefinition> |
getCommonMetadataDefinitions(Collection<String> cTypeIds,
String metadataSetName,
boolean isEdition)
Retrieves the common metadata definitions for a list of content types
|
I18nizableText |
getContentTypeCategory(Content content)
Retrieves the category of the content type.
|
I18nizableText |
getContentTypeDefaultTitle(Content content)
Retrieves the default title of the content type.
|
I18nizableText |
getContentTypeDescription(Content content)
Retrieves the description of the content type.
|
String |
getContentTypeIdForRendering(Content content)
Get the id of content type to use for rendering
|
I18nizableText |
getContentTypeLabel(Content content)
Retrieves the label of the content type.
|
String |
getContentTypePluginForRendering(Content content)
Get the plugin name of content type to use for rendering
|
Map<String,Object> |
getContentTypeProperties(ContentType contentType)
Get the content type properties
|
Set<Map<String,Object>> |
getContentTypesInformations()
Get information on content types.
|
Map<String,Object> |
getContentTypesList(List<String> ids,
boolean inherited,
boolean checkRights,
boolean includePrivate,
boolean includeMixins,
boolean includeAbstract)
Get information on content types.
|
ContentType |
getFirstContentType(Content content)
Get the content type which determines the content icons and rendering
|
String |
getIconDecorator(Content content)
Retrieves the CSS class to use as decorator above the main icon
|
String |
getIconGlyph(Content content)
Retrieves the CSS class to use as glyph icon of the content
|
IndexingModel |
getIndexingModel(Content content)
Get the indexing model resulting of the concatenation of indexing models of given content types and mixins.
|
IndexingModel |
getIndexingModel(String[] cTypes,
String[] mixins)
Get the indexing model resulting of the concatenation of indexing models of given content types and mixins.
|
String |
getLargeIcon(Content content)
Retrieves the URL of the icon without the context path.
|
String |
getMediumIcon(Content content)
Retrieves the URL of the icon without the context path.
|
MetadataDefinition |
getMetadataDefinition(String metadataPath,
Content content)
Retrieve the metadata definition represented by the given path.
|
MetadataDefinition |
getMetadataDefinition(String metadataPath,
ContentType initialContentType)
Retrieves a metadata definition from a path.
|
MetadataDefinition |
getMetadataDefinition(String metadataPath,
String[] cTypes,
String[] mixins)
Retrieve the metadata definition represented by the given path.
|
MetadataDefinition |
getMetadataDefinitionByMetadataValuePath(String metadataValuePath,
Content content)
Retrieve the definition of a given content metadata value path.
|
private MetadataDefinition |
getMetadataDefinitionByMetadataValuePath(String metadataValuePath,
MetadataDefinitionHolder metadataDefHolder)
Retrieve the definition of a given content metadata value path.
|
MetadataDefinition |
getMetadataDefinitionByMetadataValuePath(String metadataValuePath,
String[] cTypes,
String[] mixins)
Retrieve the definition of a given content metadata value path.
|
List<MetadataDefinition> |
getMetadataDefinitionPath(String metadataPath,
Content content)
Retrieve the list of successive metadata definitions represented by the given path.
|
List<MetadataDefinition> |
getMetadataDefinitionPath(String metadataPath,
ContentType initialContentType)
Retrieve the list of successive metadata definitions represented by the given path.
|
List<MetadataDefinition> |
getMetadataDefinitionPath(String metadataPath,
String[] cTypes,
String[] mixins)
Retrieve the list of successive metadata definitions represented by the given path.
|
Map<String,MetadataDefinition> |
getMetadataDefinitions(MetadataDefinitionHolder metaDefHolder,
Predicate<MetadataDefinition> predicate)
Get a flat map of MetadataDefinition corresponding to the required predicate (boolean-valued function)
For example, to get all metadata definitions of type CONTENT, we can do:
getMetadataDefinitions(contentType, m -> m.getType() == MetadataType.CONTENT)
|
Map<String,MetadataDefinition> |
getMetadataDefinitions(MetadataSet metadataSet,
Content content)
Get a flat map of MetadataDefinition corresponding to a metadataSet
|
Map<String,MetadataDefinition> |
getMetadataDefinitions(MetadataSet metadataSet,
ContentType initialContentType)
Get a flat map of MetadataDefinition corresponding to a metadataset
|
Map<String,MetadataDefinition> |
getMetadataDefinitions(MetadataSet metadataSet,
String[] cTypes,
String[] mixins)
Get a flat map of MetadataDefinition corresponding to a metadataset
|
Map<String,MetadataDefinition> |
getMetadataDefinitions(Set<String> metadataPaths,
Content content)
Get a flat map of MetadataDefinition corresponding to a set of metadata paths
|
Map<String,MetadataDefinition> |
getMetadataDefinitions(Set<String> metadataPaths,
ContentType initialContentType)
Get a flat map of MetadataDefinition corresponding to a set of metadata paths
|
Map<String,MetadataDefinition> |
getMetadataDefinitions(Set<String> metadataPaths,
String[] cTypes,
String[] mixins)
Get a flat map of MetadataDefinition corresponding to a set of metadata paths
|
Map<String,MetadataDefinition> |
getMetadataDefinitions(String[] cTypes)
Retrieves all definitions of a metadata resulting of the concatenation of
metadata of given content types.
|
Map<String,List<MetadataDefinition>> |
getMetadataDefinitionsPaths(MetadataSet metadataSet,
Content content)
Get a flat map of MetadataDefinition path corresponding to a metadataset
|
Map<String,List<MetadataDefinition>> |
getMetadataDefinitionsPaths(MetadataSet metadataSet,
ContentType initialContentType)
Get a flat map of MetadataDefinition path corresponding to a metadataSet
|
Map<String,List<MetadataDefinition>> |
getMetadataDefinitionsPaths(MetadataSet metadataSet,
String[] cTypes,
String[] mixins)
Get a flat map of MetadataDefinition path corresponding to a metadataset
|
Map<String,List<MetadataDefinition>> |
getMetadataDefinitionsPaths(Set<String> metadataPaths,
Content content)
Get a flat map of MetadataDefinition path corresponding to a set of metadata paths
|
Map<String,List<MetadataDefinition>> |
getMetadataDefinitionsPaths(Set<String> metadataPaths,
ContentType initialContentType)
Get a flat map of MetadataDefinition path corresponding to a set of metadata paths
|
Map<String,List<MetadataDefinition>> |
getMetadataDefinitionsPaths(Set<String> metadataPaths,
String[] cTypes,
String[] mixins)
Get a flat map of MetadataDefinition path corresponding to a set of metadata paths
|
Set<String> |
getMetadataNames(Content content)
Retrieves the root metadata names of a content.
|
Set<String> |
getMetadataNames(String[] cTypes,
String[] mixins)
Retrieves the metadata names resulting of the union of metadata
names of given content types and mixins
|
protected Set<String> |
getMetadataPaths(AbstractMetadataSetElement metadataSet,
String prefix)
Get a flat map of metadatadefinition corresponding to a metadataset of a content
|
Set<String> |
getMetadataPaths(MetadataSet metadataSet)
Get a flat map of MetadataDefinition corresponding to a metadataset of a content
|
MetadataSet |
getMetadataSetForEdition(String metadataSetName,
String[] cTypes,
String[] mixins)
Get the metadata set for edition resulting of the concatenation of
metadata sets of given content types and mixins.
|
MetadataSet |
getMetadataSetForView(String metadataSetName,
String[] cTypes,
String[] mixins)
Get the metadata set for view resulting of the concatenation of metadata
sets of given content types and mixins.
|
Map<String,MetadataSet> |
getMetadataSetsForEdition(String[] cTypes,
String[] mixins,
boolean includeInternal)
Get all metadata sets for edition resulting of the concatenation of
metadata sets of given content types and mixins.
|
Map<String,MetadataSet> |
getMetadataSetsForView(String[] cTypes,
String[] mixins,
boolean includeInternal)
Get all metadata sets for view resulting of the concatenation of metadata
sets of given content types and mixins.
|
List<Map<String,Object>> |
getMetadataSetsInfo(String cTypeId,
boolean edition,
boolean includeInternal)
Get the metadata sets of a content type
|
String |
getSmallIcon(Content content)
Retrieves the URL of the icon without the context path.
|
static MetadataDefinition |
getTitleMetadataDefinition()
Get the metadata definition for the "title" standard metadata.
|
boolean |
isCompatibleContentType(Content content,
String cTypeId)
Determines if the given content type can be added to content
|
boolean |
isInstanceOf(Content content,
String cTypeId)
Determines if a content is a instance of given content type id
|
protected Set<String> |
removeAncestors(Set<String> contentTypes)
Remove all content types in the set that are ancestors of other content types in the set.
|
void |
service(ServiceManager smanager) |
enableLogging, getLogger, setupLogger, setupLogger, setupLogger
protected ContentTypeExtensionPoint _cTypeEP
protected CurrentUserProvider _userProvider
protected RightManager _rightManager
protected RootContentHelper _rootContentHelper
private DynamicContentTypeDescriptorExtentionPoint _dynamicCTDescriptorEP
private Map<String,Map<String,MetadataSet>> _cacheForView
private Map<String,Map<String,MetadataSet>> _cacheForEdition
private ServiceManager _smanager
public ContentTypesHelper()
public void service(ServiceManager smanager) throws ServiceException
service
in interface Serviceable
ServiceException
public void dispose()
dispose
in interface Disposable
protected ContentTypeExtensionPoint _getContentTypeEP()
ContentTypeExtensionPoint
public boolean isInstanceOf(Content content, String cTypeId)
content
- The contentcTypeId
- The id of content type or mixintrue
if the content is an instance of content typeprivate boolean _containsContentType(String[] cTypesId, String cTypeId)
public String getCommonAncestor(Collection<String> contentTypes)
contentTypes
- The content types to comparenull
if not foundprotected Set<String> removeAncestors(Set<String> contentTypes)
contentTypes
- a Set of content type IDs.public Set<String> getAncestors(String contentTypeId)
contentTypeId
- The content type id to testIllegalArgumentException
- if the content type does not exist.public List<Set<String>> buildReverseHierarchies(String contentTypeId)
contentTypeId
- The content type's idprivate List<Set<String>> _buildReverseHierarchies(String contentTypeId, Set<String> hierarchy)
public Set<String> getMetadataNames(Content content)
content
- The content.public Set<String> getMetadataNames(String[] cTypes, String[] mixins)
cTypes
- The id of content typesmixins
- The id of mixinspublic Map<String,MetadataSet> getMetadataSetsForView(String[] cTypes, String[] mixins, boolean includeInternal)
cTypes
- The id of content typesmixins
- The id of mixinsincludeInternal
- true
True to include internal
metadata setspublic Map<String,MetadataSet> getMetadataSetsForEdition(String[] cTypes, String[] mixins, boolean includeInternal)
cTypes
- The id of content typesmixins
- The id of mixinsincludeInternal
- true
True to include internal
metadata setspublic MetadataSet getMetadataSetForView(String metadataSetName, String[] cTypes, String[] mixins)
metadataSetName
- the name of metadata set to retrievecTypes
- The id of content typesmixins
- The id of mixinspublic MetadataSet getMetadataSetForEdition(String metadataSetName, String[] cTypes, String[] mixins)
metadataSetName
- the name of metadata set to retrievecTypes
- The id of content typesmixins
- The id of mixinspublic List<Map<String,Object>> getMetadataSetsInfo(String cTypeId, boolean edition, boolean includeInternal)
cTypeId
- the content type idedition
- Set to true to get edition metadata set. False otherwise.includeInternal
- Set to true to include internal metadata sets.public IndexingModel getIndexingModel(Content content)
content
- The content.public IndexingModel getIndexingModel(String[] cTypes, String[] mixins)
cTypes
- The id of content typesmixins
- The id of mixinspublic void copyMetadataSetElementsIfNotExist(AbstractMetadataSetElement src, AbstractMetadataSetElement dest)
src
- The metadata set to copydest
- The metadata of destinationprivate void _copyMetadataSetElementsIfNotExist(AbstractMetadataSetElement src, AbstractMetadataSetElement dest, AbstractMetadataSetElement reference)
public MetadataDefinition getMetadataDefinitionByMetadataValuePath(String metadataValuePath, Content content)
metadataValuePath
- the metadata value path: it is separated by slashes and repeaters are valued: eg: "mycomposite/myrepeater[3]/mymetadata".content
- the content.null
if not foundpublic MetadataDefinition getMetadataDefinitionByMetadataValuePath(String metadataValuePath, String[] cTypes, String[] mixins)
metadataValuePath
- the metadata value path: it is separated by slashes and repeaters are valued: eg: "mycomposite.myrepeater[3].mymetadata".cTypes
- The id of content typesmixins
- The id of mixinsnull
if not foundprivate MetadataDefinition getMetadataDefinitionByMetadataValuePath(String metadataValuePath, MetadataDefinitionHolder metadataDefHolder)
metadataValuePath
- the metadata value path: it is separated by slashes and repeaters are valued: eg: "mycomposite/myrepeater[3]/mymetadata".metadataDefHolder
- The metadata def holder (such as the content type)null
if not foundpublic Set<String> getMetadataPaths(MetadataSet metadataSet)
metadataSet
- The metadataset to getprotected Set<String> getMetadataPaths(AbstractMetadataSetElement metadataSet, String prefix)
metadataSet
- The metadataset to getprefix
- The metadata path of the parentpublic MetadataDefinition getMetadataDefinition(String metadataPath, Content content)
metadataPath
- the metadata path separated by '/'content
- The content.public Map<String,MetadataDefinition> getMetadataDefinitions(Set<String> metadataPaths, Content content)
metadataPaths
- A set of metadata path to analysecontent
- The content associatedpublic Map<String,MetadataDefinition> getMetadataDefinitions(MetadataSet metadataSet, Content content)
metadataSet
- A metadataSet to analysecontent
- The content associatedpublic List<MetadataDefinition> getMetadataDefinitionPath(String metadataPath, Content content)
metadataPath
- the metadata path separated by '/'content
- The content.public Map<String,List<MetadataDefinition>> getMetadataDefinitionsPaths(Set<String> metadataPaths, Content content)
metadataPaths
- A set of metadata path to analysecontent
- The content associatedpublic Map<String,List<MetadataDefinition>> getMetadataDefinitionsPaths(MetadataSet metadataSet, Content content)
metadataSet
- A metadataset to analysecontent
- The content associatedpublic MetadataDefinition getMetadataDefinition(String metadataPath, String[] cTypes, String[] mixins)
metadataPath
- the metadata path separated by '/'cTypes
- The content types.mixins
- The content mixins types.public Map<String,MetadataDefinition> getMetadataDefinitions(Set<String> metadataPaths, String[] cTypes, String[] mixins)
metadataPaths
- A set of metadata path to analysecTypes
- The content types.mixins
- The content mixins types.public Map<String,MetadataDefinition> getMetadataDefinitions(MetadataSet metadataSet, String[] cTypes, String[] mixins)
metadataSet
- A metadataset to analysecTypes
- The content types.mixins
- The content mixins types.public Map<String,MetadataDefinition> getMetadataDefinitions(MetadataDefinitionHolder metaDefHolder, Predicate<MetadataDefinition> predicate)
metaDefHolder
- The metadata definition holderpredicate
- The predicate (ex. m -> m.getType() == MetadataType.CONTENT)public List<MetadataDefinition> getMetadataDefinitionPath(String metadataPath, String[] cTypes, String[] mixins)
metadataPath
- the metadata path separated by '/'cTypes
- The id of content typesmixins
- The id of mixinsnull
if not foundpublic Map<String,List<MetadataDefinition>> getMetadataDefinitionsPaths(Set<String> metadataPaths, String[] cTypes, String[] mixins)
metadataPaths
- A set of metadata path to analysecTypes
- The id of content typesmixins
- The id of mixinspublic Map<String,List<MetadataDefinition>> getMetadataDefinitionsPaths(MetadataSet metadataSet, String[] cTypes, String[] mixins)
metadataSet
- A metadataset to analysecTypes
- The id of content typesmixins
- The id of mixinspublic MetadataDefinition getMetadataDefinition(String metadataPath, ContentType initialContentType)
metadataPath
- the metadata path separated by '/'initialContentType
- The initial content type to start the searchnull
if not foundpublic Map<String,MetadataDefinition> getMetadataDefinitions(Set<String> metadataPaths, ContentType initialContentType)
metadataPaths
- A set of metadata path to analyseinitialContentType
- The initial content type to start the searchpublic Map<String,MetadataDefinition> getMetadataDefinitions(MetadataSet metadataSet, ContentType initialContentType)
metadataSet
- A metadataset to analyseinitialContentType
- The initial content type to start the searchpublic List<MetadataDefinition> getMetadataDefinitionPath(String metadataPath, ContentType initialContentType)
initialContentType
- The initial content type to start the searchmetadataPath
- the metadata path separated by '/'public Map<String,List<MetadataDefinition>> getMetadataDefinitionsPaths(Set<String> metadataPaths, ContentType initialContentType)
metadataPaths
- A set of metadata path to analyseinitialContentType
- The initial content type to start the searchpublic Map<String,List<MetadataDefinition>> getMetadataDefinitionsPaths(MetadataSet metadataSet, ContentType initialContentType)
metadataSet
- A semetadataSet to analyseinitialContentType
- The initial content type to start the searchpublic boolean isCompatibleContentType(Content content, String cTypeId)
content
- The contentcTypeId
- The id of content typetrue
if the content type is compatible with contentpublic Map<String,MetadataDefinition> getMetadataDefinitions(String[] cTypes) throws ConfigurationException
cTypes
- The id of content typesConfigurationException
- if an error occurredpublic Map<String,MetadataDefinition> getCommonMetadataDefinitions(Collection<String> cTypeIds, String metadataSetName, boolean isEdition)
cTypeIds
- The list of content types to considermetadataSetName
- The metadata set name to list metadataisEdition
- Is the metadata set for edition (or for view)protected void _getMetadataDefinitionsAcc(Map<String,MetadataDefinition> internalAcc, AbstractMetadataSetElement metadataSetElement, String prefix, MetadataDefinitionHolder metaDefHolder)
internalAcc
- the accumulator of metadata definitionmetadataSetElement
- the metadata set of the contentprefix
- the path prefix preceding the names of the metadatametaDefHolder
- the holder of the metadata definitions for the contentprotected MetadataSet _getMetadataSet(ContentType contentType, String metadataSetName, boolean isEdition)
contentType
- The content type to considermetadataSetName
- The metadata set to get (that list the metadata to consider)isEdition
- Is the metadata set for edition (or for view)public Set<Map<String,Object>> getContentTypesInformations()
public Map<String,Object> getContentTypesList(List<String> ids, boolean inherited, boolean checkRights, boolean includePrivate, boolean includeMixins, boolean includeAbstract)
ids
- The id of content types to retrieveinherited
- If true, the sub-types will be also returned.checkRights
- If true, only content types allowed for creation will
be returnedincludePrivate
- If true, the list will include the private content types. By default the list is restricted to the public content types.includeMixins
- If true the list will include the mixins content types.includeAbstract
- If true the list will include the abstract content types.private Map<String,Object> _dispatchContentTypes(boolean checkRights, boolean includePrivate, boolean includeMixins, boolean includeAbstract, Collection<String> allContentTypesIds)
public Map<String,Object> getContentTypeProperties(ContentType contentType)
contentType
- The content typeprotected boolean _hasRight(ContentType contentType)
contentType
- The content typeprivate void _addIfNotPresent(Collection<String> collection, String value)
public boolean canRead(Content content, MetadataDefinition metadataDef)
metadataDef
- the metadata definitioncontent
- The content where metadata is to be read on.true
if the current user is allowed to read the
metadata of this content.AmetysRepositoryException
- if an error occurs while accessing the
content.public boolean canWrite(Content content, MetadataDefinition metadataDef)
metadataDef
- the metadata definitioncontent
- The content where metadata is to be read on.true
if the current user is allowed to read the
metadata of this content.AmetysRepositoryException
- if an error occurs while accessing the
content.public String getContentTypeIdForRendering(Content content)
content
- The contentpublic String getContentTypePluginForRendering(Content content)
content
- The contentpublic I18nizableText getContentTypeLabel(Content content)
content
- The contentpublic I18nizableText getContentTypeDescription(Content content)
content
- The contentpublic I18nizableText getContentTypeDefaultTitle(Content content)
content
- The contentpublic I18nizableText getContentTypeCategory(Content content)
content
- The contentpublic String getIconGlyph(Content content)
content
- The contentpublic String getIconDecorator(Content content)
content
- The contentpublic String getSmallIcon(Content content)
content
- The contentpublic String getMediumIcon(Content content)
content
- The contentpublic String getLargeIcon(Content content)
content
- The contentpublic ContentType getFirstContentType(Content content)
content
- The contentpublic static MetadataDefinition getTitleMetadataDefinition()
private String _getCacheIdentifier(String[] contentTypes, String[] mixins)