Class ContentTypesHelper

    • Method Detail

      • _createCaches

        protected void _createCaches()
        Creates the caches
      • isInstanceOf

        public boolean isInstanceOf​(Content content,
                                    String cTypeId)
        Determines if a content is a instance of given content type id
        Parameters:
        content - The content
        cTypeId - The id of content type or mixin
        Returns:
        true if the content is an instance of content type
      • getCommonAncestors

        public Set<StringgetCommonAncestors​(Collection<String> contentTypeIds)
        Get the identifiers of the content types common ancestors
        Parameters:
        contentTypeIds - The identifiers of the content types to compare
        Returns:
        The identifiers of common ancestors
      • removeAncestors

        protected Set<StringremoveAncestors​(Set<String> contentTypes)
        Remove all content types in the set that are ancestors of other content types in the set.
        Parameters:
        contentTypes - a Set of content type IDs.
        Returns:
        a Set of content type IDs without ancestors.
      • getAncestors

        public Set<StringgetAncestors​(String contentTypeId)
        Get all ancestors for the given content type
        Parameters:
        contentTypeId - The content type id to test
        Returns:
        A non-null set of all ancestors. Does not contains the contentTypeId itself.
        Throws:
        IllegalArgumentException - if the content type does not exist.
      • getSupertypeIds

        public Pair<String[],​String[]> getSupertypeIds​(String contentTypeId)
        Get super type's ids for the given content type The first entry contains super content types, the second one contains super mixin types
        Parameters:
        contentTypeId - The content type id to test
        Returns:
        An array of super type's ids.
        Throws:
        IllegalArgumentException - if the content type does not exist.
      • getPluginName

        public String getPluginName​(String contentTypeId)
        Get plugin name for the given content type
        Parameters:
        contentTypeId - The content type id to test
        Returns:
        the plugin name
        Throws:
        IllegalArgumentException - if the content type does not exist.
      • buildReverseHierarchies

        public List<Set<String>> buildReverseHierarchies​(String contentTypeId)
        Builds the reverse hierarchies of ancestors of a content type
        Parameters:
        contentTypeId - The content type's id
        Returns:
        the reverse hierarchies with ancestors
      • getViews

        public Map<String,​ViewgetViews​(String[] contentTypeIds,
                                               String[] mixinIds)
        Get all views resulting of the concatenation of views of given content types and mixins.
        Parameters:
        contentTypeIds - the identifiers of the content types
        mixinIds - the identifiers of the mixins
        Returns:
        The views
      • getViews

        public Map<String,​ViewgetViews​(String[] contentTypeIds,
                                               String[] mixinIds,
                                               Set<String> viewNamesToAvoid)
        Get all views resulting of the concatenation of views of given content types and mixins.
        Parameters:
        contentTypeIds - the identifiers of the content types
        mixinIds - the identifiers of the mixins
        viewNamesToAvoid - names of views that should not be managed
        Returns:
        The views
      • getView

        public View getView​(String viewName,
                            String[] contentTypeIds,
                            String[] mixinIds)
        Get the view for view resulting of the concatenation of views of the given content types and mixins.
        Parameters:
        viewName - the name of the view to retrieve
        contentTypeIds - the identifiers of the content types
        mixinIds - the identifiers of the mixins
        Returns:
        The view or null if none matches.
      • getViewWithFallback

        public View getViewWithFallback​(String viewName,
                                        String fallbackViewName,
                                        Content content)
        Get the view for view resulting for a given content
        Parameters:
        viewName - the name of the view to retrieve. If null or empty, fallback view will be used.
        fallbackViewName - the name of the view to retrieve if the initial was not found. If null or empty, "main" view view will be used as fallback view.
        content - the content
        Returns:
        The view or null if none matches.
      • getViewWithFallback

        public View getViewWithFallback​(String viewName,
                                        String fallbackViewName,
                                        String[] contentTypeIds,
                                        String[] mixinIds)
        Get the view for view resulting of the concatenation of views of the given content types and mixins.
        Parameters:
        viewName - the name of the view to retrieve. If null or empty, fallback view will be used.
        fallbackViewName - the name of the view to retrieve if the initial was not found. If null or empty, "main" view view will be used as fallback view.
        contentTypeIds - the identifiers of the content types
        mixinIds - the identifiers of the mixins
        Returns:
        The view or null if none matches.
      • getViewAsJSON

        public Map<String,​ObjectgetViewAsJSON​(String contentTypeId,
                                                      String viewName,
                                                      boolean isEdition)
                                               throws ProcessingException
        Converts the view with the given name in a JSON Map
        Parameters:
        contentTypeId - the content type identifier
        viewName - the name of the view to convert
        isEdition - true if the JSON result is used for edition purposes (configure a form panel, ...) false otherwise
        Returns:
        the view as a JSON Map
        Throws:
        ProcessingException - if an error occurs when converting the view
      • getTitleViewAsJSON

        public Map<String,​ObjectgetTitleViewAsJSON​(String contentTypeId,
                                                           boolean isEdition)
                                                    throws ProcessingException
        Converts the title view in a JSON Map
        Parameters:
        contentTypeId - the content type identifier
        isEdition - true if the JSON result is used for edition purposes (configure a form panel, ...) false otherwise
        Returns:
        the view as a JSON Map
        Throws:
        ProcessingException - if an error occurs when converting the view
      • joinViews

        public View joinViews​(List<View> views)
        Creates a view that is a jointure between all the given views
        Parameters:
        views - the views to join
        Returns:
        the joined view
      • getMetadataSetsForView

        @Deprecated
        public Map<String,​MetadataSetgetMetadataSetsForView​(String[] cTypes,
                                                                    String[] mixins,
                                                                    boolean includeInternal)
        Deprecated.
        Get all metadata sets for view resulting of the concatenation of metadata sets of given content types and mixins.
        Parameters:
        cTypes - The id of content types
        mixins - The id of mixins
        includeInternal - true True to include internal metadata sets
        Returns:
        The metadata sets
      • getMetadataSetsForEdition

        @Deprecated
        public Map<String,​MetadataSetgetMetadataSetsForEdition​(String[] cTypes,
                                                                       String[] mixins,
                                                                       boolean includeInternal)
        Deprecated.
        Get all metadata sets for edition resulting of the concatenation of metadata sets of given content types and mixins.
        Parameters:
        cTypes - The id of content types
        mixins - The id of mixins
        includeInternal - true True to include internal metadata sets
        Returns:
        The metadata sets
      • getMetadataSetForView

        @Deprecated
        public MetadataSet getMetadataSetForView​(String metadataSetName,
                                                 String[] cTypes,
                                                 String[] mixins)
        Deprecated.
        Get the metadata set for view resulting of the concatenation of metadata sets of given content types and mixins.
        Parameters:
        metadataSetName - the name of metadata set to retrieve
        cTypes - The id of content types
        mixins - The id of mixins
        Returns:
        The list of metadata set names.
      • getViewsInfo

        public List<Map<String,​Object>> getViewsInfo​(String contentTypeId,
                                                           boolean includeInternals)
        Get the views of a content type
        Parameters:
        contentTypeId - the content type id
        includeInternals - Set to true to include internal views.
        Returns:
        the views' info
      • getIndexingModel

        public IndexingModel getIndexingModel​(Content content)
        Get the indexing model resulting of the concatenation of indexing models of given content types and mixins.
        Parameters:
        content - The content.
        Returns:
        The indexing model
      • getIndexingModel

        public IndexingModel getIndexingModel​(String[] cTypes,
                                              String[] mixins)
        Get the indexing model resulting of the concatenation of indexing models of given content types and mixins.
        Parameters:
        cTypes - The id of content types
        mixins - The id of mixins
        Returns:
        The indexing model
      • getModelItemsPaths

        public Map<String,​List<ModelItem>> getModelItemsPaths​(Set<String> paths,
                                                                    Content content)
        Retrieve the list of successive model items represented by the given paths, indexed by path.
        Parameters:
        paths - paths of the model items to retrieve. These paths are relative to the given containers. No matter if they are definition or data paths (with repeater entry positions)
        content - the content
        Returns:
        the list of successive model items, indexed by path
        Throws:
        IllegalArgumentException - if one of the given paths is null or empty
        UndefinedItemPathException - if there is no item defined at one of the given paths in given item containers
      • getModelItemsPaths

        public Map<String,​List<ModelItem>> getModelItemsPaths​(Set<String> paths,
                                                                    ContentType contentType)
        Retrieve the list of successive model items represented by the given paths, indexed by path.
        Parameters:
        paths - paths of the model items to retrieve. These paths are relative to the given containers. No matter if they are definition or data paths (with repeater entry positions)
        contentType - the content type
        Returns:
        the list of successive model items, indexed by path
        Throws:
        IllegalArgumentException - if one of the given paths is null or empty
        UndefinedItemPathException - if there is no item defined at one of the given paths in given item containers
      • getModelItemPath

        public List<ModelItemgetModelItemPath​(String path,
                                                ContentType contentType)
        Retrieve the list of successive model items represented by the given path.
        Parameters:
        path - path of the model items to retrieve. This path is relative to the given containers. No matter if it is a definition or data path (with repeater entry positions)
        contentType - the content type
        Returns:
        the list of successive model items
        Throws:
        IllegalArgumentException - if the given path is null or empty
        UndefinedItemPathException - if there is no item defined at the given path in given item containers
      • isCompatibleContentType

        public boolean isCompatibleContentType​(Content content,
                                               String cTypeId)
        Determines if the given content type can be added to content
        Parameters:
        content - The content
        cTypeId - The id of content type
        Returns:
        true if the content type is compatible with content
      • getCommonModelItems

        public Map<String,​ModelItemgetCommonModelItems​(Collection<String> contentTypeIds,
                                                               String viewName)
        Retrieves the common model items for a list of content types
        Parameters:
        contentTypeIds - The list of content types to consider
        viewName - The view name to list model items
        Returns:
        The map of model items. Key are the model item's path in the content type
      • _populateModelItemsAccumulator

        protected void _populateModelItemsAccumulator​(Map<String,​ModelItem> internalAcc,
                                                      ViewItemContainer viewItemContainer,
                                                      String prefix)
        Populates the accumulator with the model items
        Parameters:
        internalAcc - the accumulator of model items
        viewItemContainer - the view item container of the content
        prefix - the view item accessor path prefix
      • getContentTypesInformations

        public Set<Map<String,​Object>> getContentTypesInformations​(List<String> contentTypeIds,
                                                                         boolean withRight)
        Get the content types information as JSON
        Parameters:
        contentTypeIds - the list of content type ids
        withRight - true to add rights to results
        Returns:
        the list of content types information as JSON
      • getContentTypesList

        public Map<String,​ObjectgetContentTypesList​(List<String> ids,
                                                            boolean inherited,
                                                            boolean checkRights,
                                                            boolean includePrivate,
                                                            boolean includeMixins,
                                                            boolean includeAbstract)
        Get information on content types.
        Parameters:
        ids - The id of content types to retrieve
        inherited - If true, the sub-types will be also returned.
        checkRights - If true, only content types allowed for creation will be returned
        includePrivate - 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.
        Returns:
        A Map with retrieved, unknown, not-allowed and private content types
      • hasRight

        public boolean hasRight​(String contentTypeId)
        Test if the current user has the right needed by the content type to create a content.
        Parameters:
        contentTypeId - The content type id
        Returns:
        true if the user has the right needed, false otherwise.
      • _hasRight

        protected boolean _hasRight​(ContentType contentType)
        Test if the current user has the right needed by the content type to create a content.
        Parameters:
        contentType - The content type
        Returns:
        true if the user has the right needed, false otherwise.
      • getContentTypeIdForRendering

        public String getContentTypeIdForRendering​(Content content)
        Get the id of content type to use for rendering
        Parameters:
        content - The content
        Returns:
        the id of dynamic or standard content type
      • getDynamicContentTypeId

        public String getDynamicContentTypeId​(String[] contentTypes,
                                              String[] mixinTypes)
        Get the id of the dynamic content type matching to given ones
        Parameters:
        contentTypes - The content types
        mixinTypes - The mixins
        Returns:
        the id of dynamic content type or null if no dynamic content type was found
      • getContentTypePluginForRendering

        public String getContentTypePluginForRendering​(Content content)
        Get the plugin name of content type to use for rendering
        Parameters:
        content - The content
        Returns:
        the plugin name of dynamic or standard content type
      • getDynamicContentTypePlugin

        public String getDynamicContentTypePlugin​(String[] contentTypes,
                                                  String[] mixinTypes)
        Get the plugin name of the dynamic content type matching to given ones
        Parameters:
        contentTypes - The content types
        mixinTypes - The mixins
        Returns:
        the plugin name of dynamic content type or null if no dynamic content type was found
      • getIconGlyph

        public String getIconGlyph​(Content content)
        Retrieves the CSS class to use as glyph icon of the content
        Parameters:
        content - The content
        Returns:
        the glyph
      • getIconDecorator

        public String getIconDecorator​(Content content)
        Retrieves the CSS class to use as decorator above the main icon
        Parameters:
        content - The content
        Returns:
        the decorator CSS class name
      • getSmallIcon

        public String getSmallIcon​(Content content)
        Retrieves the URL of the icon without the context path.
        Parameters:
        content - The content
        Returns:
        the icon URL for the small image 16x16.
      • getMediumIcon

        public String getMediumIcon​(Content content)
        Retrieves the URL of the icon without the context path.
        Parameters:
        content - The content
        Returns:
        the icon URL for the medium image 32x32.
      • getLargeIcon

        public String getLargeIcon​(Content content)
        Retrieves the URL of the icon without the context path.
        Parameters:
        content - The content
        Returns:
        the icon URL for the large image 48x48.
      • getFirstContentType

        public ContentType getFirstContentType​(Content content)
        Get the content type which determines the content icons and rendering
        Parameters:
        content - The content
        Returns:
        The main content type
      • isArchivedContentType

        public boolean isArchivedContentType​(String cTypeId)
        Determines if the content type is an archived content type
        Parameters:
        cTypeId - The id of content type
        Returns:
        true if the content type is an org.ametys.cms.ArchivedContent