Class AbstractContentImporter

  • All Implemented Interfaces:
    ContentImporter, LogEnabled, Prioritizable, Configurable, Serviceable
    Direct Known Subclasses:
    AbstractXmlContentImporter

    public abstract class AbstractContentImporter
    extends AbstractLogEnabled
    implements ContentImporter, Serviceable, Configurable
    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>
    • Method Detail

      • 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

        protected Collection<StringgetDefaultExtensions()
        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

        protected Map<String,​StringgetContentIdMap​(Map<String,​Object> params)
        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

        protected Map<Content,​Map<String,​Object>> getContentRefMap​(Map<String,​Object> params)
        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.
      • getContentRepeaterSizeMap

        protected Map<Content,​Map<String,​Integer>> getContentRepeaterSizeMap​(Map<String,​Object> params)
        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 parentContentId,
                                        String parentContentMetadataPath,
                                        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.
        parentContentId - the parent content ID.
        parentContentMetadataPath - the parent content metadata path.
        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.
      • createContent

        protected Content createContent​(String title,
                                        String[] contentTypes,
                                        String[] mixins,
                                        String language,
                                        String workflowName,
                                        int initialActionId,
                                        String parentContentId,
                                        String parentContentMetadataPath,
                                        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.
        parentContentId - the parent content ID.
        parentContentMetadataPath - the parent content metadata path.
        params - the import parameters.
        Returns:
        the created content.
        Throws:
        com.opensymphony.workflow.WorkflowException - if an error occurs.
      • 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.
      • 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.