Class ContentHelper

All Implemented Interfaces:
LogEnabled, Component, Contextualizable, Serviceable

Helper for Content
  • Field Details

    • ROLE

      public static final String ROLE
      The component role.
  • Constructor Details

  • Method Details

    • service

      public void service(ServiceManager smanager) throws ServiceException
      Specified by:
      service in interface Serviceable
      Throws:
      ServiceException
    • contextualize

      public void contextualize(Context context) throws ContextException
      Specified by:
      contextualize in interface Contextualizable
      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 id
      contentTypeId - The content type to add
      actionId - The workflow action id
      Returns:
      The result in a Map
      Throws:
      com.opensymphony.workflow.WorkflowException - if
      AmetysRepositoryException - 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 id
      contentTypeId - The content type to add
      actionId - The workflow action id
      Returns:
      The result in a Map
      Throws:
      com.opensymphony.workflow.WorkflowException - if
      AmetysRepositoryException - 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 id
      mixinId - The mixin type to add
      actionId - The workflow action id
      Returns:
      The result in a Map
      Throws:
      com.opensymphony.workflow.WorkflowException - if
      AmetysRepositoryException - 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 id
      mixinId - The mixin type to add
      actionId - The workflow action id
      Returns:
      The result in a Map
      Throws:
      com.opensymphony.workflow.WorkflowException - if
      AmetysRepositoryException - if an error occurred
    • getContentEditionInformation

      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.
    • getContentAttributeDefinitionsAsJSON

      public Map<String,Object> getContentAttributeDefinitionsAsJSON(String contentId, boolean isEdition) throws ProcessingException
      Converts the content attribute definitions in a JSON Map
      Parameters:
      contentId - the content identifier
      isEdition - true if the JSON result is used for edition purposes (configure a form panel, ...) false otherwise
      Returns:
      the content attribute definitions as a JSON Map
      Throws:
      ProcessingException - if an error occurs when converting the definitions
    • getContentAttributeDefinitionsAsJSON

      public Map<String,Object> getContentAttributeDefinitionsAsJSON(String contentId, List<String> attibutePaths, boolean isEdition) throws ProcessingException
      Converts the given content attribute definitions in a JSON Map
      Parameters:
      contentId - the content identifier
      attibutePaths - the paths of the attribute definitions to convert
      isEdition - true if the JSON result is used for edition purposes (configure a form panel, ...) false otherwise
      Returns:
      the content attribute definitions as a JSON Map
      Throws:
      ProcessingException - if an error occurs when converting the definitions
    • getContentViewAsJSON

      public Map<String,Object> getContentViewAsJSON(String contentId, String viewName, String fallbackViewName, boolean isEdition) throws ProcessingException
      Converts the content view with the given name in a JSON Map
      Parameters:
      contentId - the content identifier
      viewName - the name of the view to convert
      fallbackViewName - the name of the view to convert if the initial was not found. Can be null.
      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
    • getContentTypes

      Retrieves a Collection containing all content types of the given content
      Parameters:
      content - the content
      Returns:
      all content types of the content
    • getContentTypes

      public Collection<ContentType> getContentTypes(Content content, boolean includeMixins)
      Retrieves a Collection containing content types of the given content
      Parameters:
      content - the content
      includeMixins - true to retrieve the mixins the the collection, false otherwise
      Returns:
      content types of the content
    • getUnknownContentTypeIds

      Determines if the given content has some of its types that are unknown (the extension does not exist)
      Parameters:
      content - the content
      Returns:
      true if at least one of the types of the content is unknown, false otherwise
    • getUnknownContentTypeIds

      public List<String> getUnknownContentTypeIds(Content content, boolean checkMixins)
      Determines if the given content has some of its types that are unknown (the extension does not exist)
      Parameters:
      content - the content
      checkMixins - true to check unknown content types in mixin types
      Returns:
      true if at least one of the types of the content is unknown, false otherwise
    • 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
    • isArchivedContent

      public boolean isArchivedContent(Content content)
      Determines if the content is archived
      Parameters:
      content - the content
      Returns:
      true if the content is archived
    • 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 content
      fieldPath - 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 content
      fieldPath - 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
    • 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)
      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 content
      metadataPath - 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)
      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 content
      metadataPath - 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.
      Get 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 content
      metadataPath - 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.
      Get 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 content
      metadataPath - 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

      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)
      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 metadata
      definition - The definition of the first metadata in path
      metadataPath - The path to the metadata, separated by '/'
      locale - The locale to used to resolve localized metadata
      resolveReferences - 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
    • getSimpleMetadataValue

      @Deprecated public Object getSimpleMetadataValue(CompositeMetadata metadataHolder, MetadataDefinition definition, String metadataName, Locale locale, boolean resolveReferences)
      Deprecated.
      Get the typed value(s) of a simple metadata.
      Parameters:
      metadataHolder - The parent composite metadata
      definition - The definition of the first metadata in path
      metadataName - The name of the metadata
      locale - The locale to used to resolve localized metadata
      resolveReferences - true true to resolve references (such as resource or content)
      Returns:
      The typed final value.
    • 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 check
      ignoreContentTypes - The content types to ignore for referencing contents
      includeSubTypes - 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
    • getReferencingContents

      Returns all Contents referencing the given content with their value path
      Parameters:
      content - The content to get references
      Returns:
      the list of pair path / contents
    • getDefaultWorkflowName

      Get the default workflow name for the content. If several workflows are possible, an empty Optional is returned.
      Parameters:
      content - The content
      Returns:
      The default workflow name or Optional.empty() if it cannot be determine