Class AbstractContentImporter

java.lang.Object
org.ametys.runtime.plugin.component.AbstractLogEnabled
org.ametys.plugins.contentio.in.AbstractContentImporter
All Implemented Interfaces:
ContentImporter, LogEnabled, Prioritizable, Configurable, Serviceable
Direct Known Subclasses:
AbstractXmlContentImporter

Abstract ContentImporter class which provides base importer configuration and logic.<br> Configuration options: <ul> <li>Importer priority</li> <li>Allowed extensions, without leading dot and comma-separated</li> <li>Content types and mixins of the created contents</li> <li>Language of the created contents</li> <li>Content workflow name and creation action ID</li> </ul><br> Example configuration handled by the configure method: <pre> <extension point="org.ametys.plugins.contentio.ContentImporterExtensionPoint" id="my.content.importer" class="..."> <priority>500</priority> <extensions>ext,ext2</extensions> <content-creation> <content-types>My.ContentType.1,My.ContentType.2</content-types> <mixins>My.Mixin.1,My.Mixin.2</mixins> <language>en</language> <workflow name="content" createActionId="1" editActionId="2"/> </content-creation> </extension> </pre>
  • Field Details

  • Constructor Details

  • Method Details

    • service

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

      public void configure(Configuration configuration) throws ConfigurationException
      Specified by:
      configure in interface Configurable
      Throws:
      ConfigurationException
    • configureExtensions

      protected void configureExtensions(Configuration configuration) throws ConfigurationException
      Configure the allowed extensions.
      Parameters:
      configuration - the extension configuration.
      Throws:
      ConfigurationException - if an error occurs.
    • configureContentCreation

      protected void configureContentCreation(Configuration configuration) throws ConfigurationException
      Configure the content creation parameters.
      Parameters:
      configuration - the content creation configuration.
      Throws:
      ConfigurationException - if an error occurs.
    • configureWorkflow

      protected void configureWorkflow(Configuration configuration) throws ConfigurationException
      Configure the content workflow.
      Parameters:
      configuration - the content creation configuration.
      Throws:
      ConfigurationException - if an error occurs.
    • getPriority

      public int getPriority()
      Description copied from interface: Prioritizable
      Get the priority for the component. On components using Prioritizable interface, each implementation define the order. In most cases, less is the number, more prior is the component.
      Specified by:
      getPriority in interface Prioritizable
      Returns:
      the priority
    • getDefaultExtensions

      Get the default allowed extensions.
      Returns:
      the default allowed extensions, without leading dots. Cannot be null.
    • isExtensionValid

      protected boolean isExtensionValid(String name) throws IOException
      Test if the given filename has a supported extension.
      Parameters:
      name - the name, can't be null.
      Returns:
      true if the extension is supported, false otherwise.
      Throws:
      IOException - if an error occurs.
    • getContentTypes

      protected String[] getContentTypes(Map<String,Object> params)
      The content types of a created content.
      Parameters:
      params - the import parameters.
      Returns:
      the content types of a created content.
    • getMixins

      protected String[] getMixins(Map<String,Object> params)
      The mixins of a created content.
      Parameters:
      params - the import parameters.
      Returns:
      The mixins of a created content.
    • getLanguage

      protected String getLanguage(Map<String,Object> params)
      The language of a created content.
      Parameters:
      params - the import parameters.
      Returns:
      The language of a created content.
    • getWorkflowName

      protected String getWorkflowName(Map<String,Object> params)
      The workflow name of a created content.
      Parameters:
      params - the import parameters.
      Returns:
      The workflow name of a created content.
    • getInitialActionId

      protected int getInitialActionId(Map<String,Object> params)
      The workflow creation action ID of a created content.
      Parameters:
      params - the import parameters.
      Returns:
      The workflow creation action ID of a created content.
    • getEditActionId

      protected int getEditActionId(Map<String,Object> params)
      The workflow action ID used to edit a content.
      Parameters:
      params - the import parameters.
      Returns:
      The workflow action ID used to edit a content.
    • getContentIdMap

      Get the map used to store the mapping from "local" ID (defined in the import file) to the AmetysObject ID of the contents, when actually imported.
      Parameters:
      params - the import parameters.
      Returns:
      the content "local to repository" ID map.
    • getContentRefMap

      Get the map used to store the content references. The Map is shaped like: referencing content -> local metadata path -> content references.
      Parameters:
      params - the import parameters.
      Returns:
      the content reference map.
    • addContentReference

      protected void addContentReference(Content content, String metadataPath, AbstractContentImporter.ContentReference reference, Map<String,Object> params)
      Add a content reference to the map.
      Parameters:
      content - The referencing content.
      metadataPath - The path of the metadata which holds the content references.
      reference - The content reference.
      params - The import parameters.
    • addContentReference

      protected void addContentReference(Map<Content,Map<String,Object>> contentRefMap, Content content, String metadataPath, AbstractContentImporter.ContentReference reference)
      Add a content reference to the map.
      Parameters:
      contentRefMap - The content reference map.
      content - The referencing content.
      metadataPath - The path of the metadata which holds the content references.
      reference - The content reference.
    • addContentReferences

      protected void addContentReferences(Map<Content,Map<String,Object>> contentRefMap, Content content, String metadataPath, List<AbstractContentImporter.ContentReference> references)
      Add content references to the map.
      Parameters:
      contentRefMap - The content reference map.
      content - The referencing content.
      metadataPath - The path of the metadata which holds the content references.
      references - the content reference list.
    • getContentRepeaterSizeMap

      Get the map used to store the repeater sizes. The Map is shaped like: referencing content -> local metadata path -> content references.
      Parameters:
      params - the import parameters.
      Returns:
      the content reference map.
    • setRepeaterSize

      protected void setRepeaterSize(Content content, String metadataPath, int repeaterSize, Map<String,Object> params)
      Set a repeater size in the map (needed to execute the edit content function).
      Parameters:
      content - The content containing the repeater.
      metadataPath - The repeater metadata path.
      repeaterSize - The repeater size.
      params - The import parameters.
    • createContent

      protected Content createContent(String title, Map<String,Object> params) throws com.opensymphony.workflow.WorkflowException
      Create a content.
      Parameters:
      title - the content title.
      params - the import parameters.
      Returns:
      the created content.
      Throws:
      com.opensymphony.workflow.WorkflowException - if an error occurs.
    • createContent

      protected Content createContent(String title, String[] contentTypes, String[] mixins, String language, Map<String,Object> params) throws com.opensymphony.workflow.WorkflowException
      Create a content.
      Parameters:
      title - the content title.
      contentTypes - the content types.
      mixins - the content mixins.
      language - the content language.
      params - the import parameters.
      Returns:
      the created content.
      Throws:
      com.opensymphony.workflow.WorkflowException - if an error occurs.
    • createContent

      protected Content createContent(String title, String[] contentTypes, String[] mixins, String language, String workflowName, int initialActionId, Map<String,Object> params) throws com.opensymphony.workflow.WorkflowException
      Create a content.
      Parameters:
      title - the content title.
      contentTypes - the content types.
      mixins - the content mixins.
      language - the content language.
      workflowName - the content workflow name.
      initialActionId - the content create action ID.
      params - the import parameters.
      Returns:
      the created content.
      Throws:
      com.opensymphony.workflow.WorkflowException - if an error occurs.
    • restoreContentReferences

      protected void restoreContentReferences(Map<String,Object> params)
      Restore content references.
      Parameters:
      params - The import parameters.
    • setReferenceMetadatas

      protected void setReferenceMetadatas(Map<String,Object> contentReferences, Map<String,Object> values, Map<String,Integer> repeaters, Map<String,Object> params)
      Fill the value map with the content references.
      Parameters:
      contentReferences - The list of content references indexed by metadata path.
      values - The value map passed to the EditContentFunction class.
      repeaters - The repeater sizes for this content.
      params - The import parameters.
    • getReferencedContentId

      Get the content ID from a content reference.
      Parameters:
      contentRef - The content reference.
      params - The import parameters.
      Returns:
      the content ID if it was found, or null otherwise.
    • getContentFromProperties

      protected Content getContentFromProperties(Map<String,String> propertyValues)
      Search a content from a map of its metadata values.
      Parameters:
      propertyValues - The metadata values.
      Returns:
      The Content if found, null otherwise.