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
Nested ClassesModifier and TypeClassDescriptionclassClass representing a reference to a content in an import file. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final StringMap used to store the mapping from "local" ID to content ID, when actually imported.protected static final StringMap used to store the content references, indexed by content and metadata path.protected static final StringMap used to store the content repeater sizes.protected String[]The imported contents' types.protected ContentWorkflowHelperThe content workflow helper.protected intThe importer contents' edition action ID.The allowed extensions.protected intThe importer contents' initial action ID.protected StringThe importer contents' language.protected String[]The imported contents' mixins.protected intThe importer priority.protected AmetysObjectResolverThe AmetysObject resolver.protected StringThe importer contents' workflow name.protected static final intThe default importer priority. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddContentReference(Map<Content, Map<String, Object>> contentRefMap, Content content, String metadataPath, AbstractContentImporter.ContentReference reference) Add a content reference to the map.protected voidaddContentReference(Content content, String metadataPath, AbstractContentImporter.ContentReference reference, Map<String, Object> params) Add a content reference to the map.protected voidaddContentReferences(Map<Content, Map<String, Object>> contentRefMap, Content content, String metadataPath, List<AbstractContentImporter.ContentReference> references) Add content references to the map.voidconfigure(Configuration configuration) protected voidconfigureContentCreation(Configuration configuration) Configure the content creation parameters.protected voidconfigureExtensions(Configuration configuration) Configure the allowed extensions.protected voidconfigureWorkflow(Configuration configuration) Configure the content workflow.protected ContentcreateContent(String title, String[] contentTypes, String[] mixins, String language, String workflowName, int initialActionId, Map<String, Object> params) Create a content.protected ContentcreateContent(String title, String[] contentTypes, String[] mixins, String language, Map<String, Object> params) Create a content.protected ContentcreateContent(String title, Map<String, Object> params) Create a content.protected ContentgetContentFromProperties(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 intgetEditActionId(Map<String, Object> params) The workflow action ID used to edit a content.protected intgetInitialActionId(Map<String, Object> params) The workflow creation action ID of a created content.protected StringgetLanguage(Map<String, Object> params) The language of a created content.protected String[]The mixins of a created content.intGet the priority for the component.protected StringgetReferencedContentId(AbstractContentImporter.ContentReference contentRef, Map<String, Object> params) Get the content ID from a content reference.protected StringgetWorkflowName(Map<String, Object> params) The workflow name of a created content.protected booleanisExtensionValid(String name) Test if the given filename has a supported extension.protected voidrestoreContentReferences(Map<String, Object> params) Restore content references.voidservice(ServiceManager manager) protected voidsetReferenceMetadatas(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 voidSet a repeater size in the map (needed to execute the edit content function).Methods inherited from class org.ametys.runtime.plugin.component.AbstractLogEnabled
getLogger, setLoggerMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods 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:
servicein interfaceServiceable- Throws:
ServiceException
-
configure
- Specified by:
configurein 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:PrioritizableGet the priority for the component. On components usingPrioritizableinterface, each implementation define the order. In most cases, less is the number, more prior is the component.- Specified by:
getPriorityin 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 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.
-
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.
-