Package org.ametys.plugins.contentio.in
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
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>-
Nested Class Summary
Modifier and TypeClassDescriptionclass
Class representing a reference to a content in an import file. -
Field Summary
Modifier and TypeFieldDescriptionprotected static final String
Map used to store the mapping from "local" ID to content ID, when actually imported.protected static final String
Map used to store the content references, indexed by content and metadata path.protected static final String
Map used to store the content repeater sizes.protected String[]
The imported contents' types.protected ContentWorkflowHelper
The content workflow helper.protected int
The importer contents' edition action ID.The allowed extensions.protected int
The importer contents' initial action ID.protected String
The importer contents' language.protected String[]
The imported contents' mixins.protected int
The importer priority.protected AmetysObjectResolver
The AmetysObject resolver.protected String
The importer contents' workflow name.protected static final int
The default importer priority. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
addContentReference
(Map<Content, Map<String, Object>> contentRefMap, Content content, String metadataPath, AbstractContentImporter.ContentReference reference) Add a content reference to the map.protected void
addContentReference
(Content content, String metadataPath, AbstractContentImporter.ContentReference reference, Map<String, Object> params) Add a content reference to the map.protected void
addContentReferences
(Map<Content, Map<String, Object>> contentRefMap, Content content, String metadataPath, List<AbstractContentImporter.ContentReference> references) Add content references to the map.void
configure
(Configuration configuration) protected void
configureContentCreation
(Configuration configuration) Configure the content creation parameters.protected void
configureExtensions
(Configuration configuration) Configure the allowed extensions.protected void
configureWorkflow
(Configuration configuration) Configure the content workflow.protected Content
createContent
(String title, String[] contentTypes, String[] mixins, String language, String workflowName, int initialActionId, String parentContentId, String parentContentMetadataPath, Map<String, Object> params) Create a content.protected Content
createContent
(String title, String[] contentTypes, String[] mixins, String language, String workflowName, int initialActionId, Map<String, Object> params) Create a content.protected Content
createContent
(String title, String[] contentTypes, String[] mixins, String language, String parentContentId, String parentContentMetadataPath, Map<String, Object> params) Create a content.protected Content
createContent
(String title, String[] contentTypes, String[] mixins, String language, Map<String, Object> params) Create a content.protected Content
createContent
(String title, Map<String, Object> params) Create a content.protected Content
getContentFromProperties
(Map<String, String> propertyValues) Search a content from a map of its metadata values.getContentIdMap
(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.getContentRefMap
(Map<String, Object> params) Get the map used to store the content references.getContentRepeaterSizeMap
(Map<String, Object> params) Get the map used to store the repeater sizes.protected String[]
getContentTypes
(Map<String, Object> params) The content types of a created content.protected Collection<String>
Get the default allowed extensions.protected int
getEditActionId
(Map<String, Object> params) The workflow action ID used to edit a content.protected int
getInitialActionId
(Map<String, Object> params) The workflow creation action ID of a created content.protected String
getLanguage
(Map<String, Object> params) The language of a created content.protected String[]
The mixins of a created content.int
Get the priority for the component.protected String
getReferencedContentId
(AbstractContentImporter.ContentReference contentRef, Map<String, Object> params) Get the content ID from a content reference.protected String
getWorkflowName
(Map<String, Object> params) The workflow name of a created content.protected boolean
isExtensionValid
(String name) Test if the given filename has a supported extension.protected void
restoreContentReferences
(Map<String, Object> params) Restore content references.void
service
(ServiceManager manager) 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.protected void
Set a repeater size in the map (needed to execute the edit content function).Methods inherited from class org.ametys.runtime.plugin.component.AbstractLogEnabled
getLogger, setLogger
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.ametys.plugins.contentio.in.ContentImporter
importContents, supports
-
Field Details
-
DEFAULT_PRIORITY
The default importer priority.- See Also:
-
_CONTENT_ID_MAP_KEY
Map used to store the mapping from "local" ID to content ID, when actually imported. -
_CONTENT_LINK_MAP_KEY
Map used to store the content references, indexed by content and metadata path. -
_CONTENT_REPEATER_SIZE_MAP
Map used to store the content repeater sizes. -
_resolver
The AmetysObject resolver. -
_contentWorkflowHelper
The content workflow helper. -
_priority
The importer priority. -
_extensions
The allowed extensions. -
_contentTypes
The imported contents' types. -
_mixins
The imported contents' mixins. -
_language
The importer contents' language. -
_workflowName
The importer contents' workflow name. -
_initialActionId
The importer contents' initial action ID. -
_editActionId
The importer contents' edition action ID.
-
-
Constructor Details
-
AbstractContentImporter
public AbstractContentImporter()
-
-
Method Details
-
service
- Specified by:
service
in interfaceServiceable
- Throws:
ServiceException
-
configure
- Specified by:
configure
in interfaceConfigurable
- Throws:
ConfigurationException
-
configureExtensions
Configure the allowed extensions.- Parameters:
configuration
- the extension configuration.- Throws:
ConfigurationException
- if an error occurs.
-
configureContentCreation
Configure the content creation parameters.- Parameters:
configuration
- the content creation configuration.- Throws:
ConfigurationException
- if an error occurs.
-
configureWorkflow
Configure the content workflow.- Parameters:
configuration
- the content creation configuration.- Throws:
ConfigurationException
- if an error occurs.
-
getPriority
Description copied from interface:Prioritizable
Get the priority for the component. On components usingPrioritizable
interface, each implementation define the order. In most cases, less is the number, more prior is the component.- Specified by:
getPriority
in interfacePrioritizable
- Returns:
- the priority
-
getDefaultExtensions
Get the default allowed extensions.- Returns:
- the default allowed extensions, without leading dots. Cannot be null.
-
isExtensionValid
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
The content types of a created content.- Parameters:
params
- the import parameters.- Returns:
- the content types of a created content.
-
getMixins
The mixins of a created content.- Parameters:
params
- the import parameters.- Returns:
- The mixins of a created content.
-
getLanguage
The language of a created content.- Parameters:
params
- the import parameters.- Returns:
- The language of a created content.
-
getWorkflowName
The workflow name of a created content.- Parameters:
params
- the import parameters.- Returns:
- The workflow name of a created content.
-
getInitialActionId
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
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.WorkflowExceptionCreate 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.WorkflowExceptionCreate 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.WorkflowExceptionCreate 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.WorkflowExceptionCreate 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.WorkflowExceptionCreate 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.
-
restoreContentReferences
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
protected String getReferencedContentId(AbstractContentImporter.ContentReference contentRef, Map<String, Object> params) 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
Search a content from a map of its metadata values.- Parameters:
propertyValues
- The metadata values.- Returns:
- The Content if found, null otherwise.
-