public abstract class AbstractContentImporter extends AbstractLogEnabled implements ContentImporter, Serviceable, Configurable
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>Modifier and Type | Class and Description |
---|---|
class |
AbstractContentImporter.ContentReference
Class representing a reference to a content in an import file.
|
Modifier and Type | Field and Description |
---|---|
protected static String |
_CONTENT_ID_MAP_KEY
Map used to store the mapping from "local" ID to content ID, when actually imported.
|
protected static String |
_CONTENT_LINK_MAP_KEY
Map used to store the content references, indexed by content and metadata path.
|
protected static String |
_CONTENT_REPEATER_SIZE_MAP
Map used to store the content repeater sizes.
|
protected String[] |
_contentTypes
The imported contents' types.
|
protected ContentWorkflowHelper |
_contentWorkflowHelper
The content workflow helper.
|
protected int |
_editActionId
The importer contents' edition action ID.
|
protected Set<String> |
_extensions
The allowed extensions.
|
protected int |
_initialActionId
The importer contents' initial action ID.
|
protected String |
_language
The importer contents' language.
|
protected String[] |
_mixins
The imported contents' mixins.
|
protected int |
_priority
The importer priority.
|
protected AmetysObjectResolver |
_resolver
The AmetysObject resolver.
|
protected String |
_workflowName
The importer contents' workflow name.
|
protected static int |
DEFAULT_PRIORITY
The default importer priority.
|
Constructor and Description |
---|
AbstractContentImporter() |
Modifier and Type | Method and Description |
---|---|
protected void |
addContentReference(Content content,
String metadataPath,
AbstractContentImporter.ContentReference reference,
Map<String,Object> params)
Add a content reference to the map.
|
protected void |
addContentReference(Map<Content,Map<String,Object>> contentRefMap,
Content content,
String metadataPath,
AbstractContentImporter.ContentReference reference)
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,
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,
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 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 parentContentId,
String parentContentMetadataPath,
Map<String,Object> params)
Create a content.
|
protected Content |
getContentFromProperties(Map<String,String> propertyValues)
Search a content from a map of its metadata values.
|
protected Map<String,String> |
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.
|
protected Map<Content,Map<String,Object>> |
getContentRefMap(Map<String,Object> params)
Get the map used to store the content references.
|
protected Map<Content,Map<String,Integer>> |
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> |
getDefaultExtensions()
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[] |
getMixins(Map<String,Object> params)
The mixins of a created content.
|
int |
getPriority()
Get the importer priority.
|
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 Date |
parseDate(String value)
Parse a String value as a Date.
Allowed formats: yyyy-MM-dd yyyy-MM-dd'T'HH:mm:ss.SSSZZ |
protected Date |
parseDate(String value,
boolean throwException)
Parse a String value as a Date.
Allowed formats: yyyy-MM-dd yyyy-MM-dd'T'HH:mm:ss.SSSZZ |
protected void |
restoreContentReferences(Map<String,Object> params)
Restore content references.
|
void |
service(ServiceManager manager) |
protected void |
setBinaryMetadata(ModifiableCompositeMetadata meta,
String name,
MetadataDefinition metaDef,
String value)
Set a file metadata.
|
protected void |
setBooleanMetadata(ModifiableCompositeMetadata meta,
String name,
MetadataDefinition metaDef,
String[] values)
Set a boolean metadata.
|
protected void |
setDateMetadata(ModifiableCompositeMetadata meta,
String name,
MetadataDefinition metaDef,
String[] values)
Set a date or datetime metadata.
|
protected void |
setDoubleMetadata(ModifiableCompositeMetadata meta,
String name,
MetadataDefinition metaDef,
String[] values)
Set a double metadata.
|
protected void |
setGeocodeMetadata(ModifiableCompositeMetadata meta,
String name,
MetadataDefinition metaDef,
double latitude,
double longitude)
Set a geocode metadata.
|
protected void |
setGeocodeMetadata(ModifiableCompositeMetadata meta,
String name,
MetadataDefinition metaDef,
String latitude,
String longitude)
Set a geocode metadata.
|
protected void |
setLongMetadata(ModifiableCompositeMetadata meta,
String name,
MetadataDefinition metaDef,
String[] values)
Set a long metadata.
|
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 |
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).
|
protected void |
setRichText(ModifiableCompositeMetadata meta,
String name,
InputStream data)
Set a RichText metadata.
|
protected void |
setStringMetadata(ModifiableCompositeMetadata meta,
String name,
MetadataDefinition metaDef,
String[] values)
Set a string metadata.
|
getLogger, setLogger
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
importContents, supports
protected static final int DEFAULT_PRIORITY
protected static final String _CONTENT_ID_MAP_KEY
protected static final String _CONTENT_LINK_MAP_KEY
protected static final String _CONTENT_REPEATER_SIZE_MAP
protected AmetysObjectResolver _resolver
protected ContentWorkflowHelper _contentWorkflowHelper
protected int _priority
protected Set<String> _extensions
protected String[] _contentTypes
protected String _workflowName
protected int _initialActionId
protected int _editActionId
public AbstractContentImporter()
public void service(ServiceManager manager) throws ServiceException
service
in interface Serviceable
ServiceException
public void configure(Configuration configuration) throws ConfigurationException
configure
in interface Configurable
ConfigurationException
protected void configureExtensions(Configuration configuration) throws ConfigurationException
configuration
- the extension configuration.ConfigurationException
- if an error occurs.protected void configureContentCreation(Configuration configuration) throws ConfigurationException
configuration
- the content creation configuration.ConfigurationException
- if an error occurs.protected void configureWorkflow(Configuration configuration) throws ConfigurationException
configuration
- the content creation configuration.ConfigurationException
- if an error occurs.public int getPriority()
ContentImporter
getPriority
in interface ContentImporter
protected Collection<String> getDefaultExtensions()
protected boolean isExtensionValid(String name) throws IOException
name
- the name, can't be null.IOException
- if an error occurs.protected String[] getContentTypes(Map<String,Object> params)
params
- the import parameters.protected String[] getMixins(Map<String,Object> params)
params
- the import parameters.protected String getLanguage(Map<String,Object> params)
params
- the import parameters.protected String getWorkflowName(Map<String,Object> params)
params
- the import parameters.protected int getInitialActionId(Map<String,Object> params)
params
- the import parameters.protected int getEditActionId(Map<String,Object> params)
params
- the import parameters.protected Map<String,String> getContentIdMap(Map<String,Object> params)
params
- the import parameters.protected Map<Content,Map<String,Object>> getContentRefMap(Map<String,Object> params)
params
- the import parameters.protected void addContentReference(Content content, String metadataPath, AbstractContentImporter.ContentReference reference, Map<String,Object> params)
content
- The referencing content.metadataPath
- The path of the metadata which holds the content references.reference
- The content reference.params
- The import parameters.protected void addContentReference(Map<Content,Map<String,Object>> contentRefMap, Content content, String metadataPath, AbstractContentImporter.ContentReference reference)
contentRefMap
- The content reference map.content
- The referencing content.metadataPath
- The path of the metadata which holds the content references.reference
- The content reference.protected void addContentReferences(Map<Content,Map<String,Object>> contentRefMap, Content content, String metadataPath, List<AbstractContentImporter.ContentReference> references)
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.protected Map<Content,Map<String,Integer>> getContentRepeaterSizeMap(Map<String,Object> params)
params
- the import parameters.protected void setRepeaterSize(Content content, String metadataPath, int repeaterSize, Map<String,Object> params)
content
- The content containing the repeater.metadataPath
- The repeater metadata path.repeaterSize
- The repeater size.params
- The import parameters.protected Content createContent(String title, Map<String,Object> params) throws com.opensymphony.workflow.WorkflowException
title
- the content title.params
- the import parameters.com.opensymphony.workflow.WorkflowException
- if an error occurs.protected Content createContent(String title, String[] contentTypes, String[] mixins, String language, Map<String,Object> params) throws com.opensymphony.workflow.WorkflowException
title
- the content title.contentTypes
- the content types.mixins
- the content mixins.language
- the content language.params
- the import parameters.com.opensymphony.workflow.WorkflowException
- if an error occurs.protected Content createContent(String title, String[] contentTypes, String[] mixins, String language, String parentContentId, String parentContentMetadataPath, Map<String,Object> params) throws com.opensymphony.workflow.WorkflowException
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.com.opensymphony.workflow.WorkflowException
- if an error occurs.protected Content createContent(String title, String[] contentTypes, String[] mixins, String language, String workflowName, int initialActionId, Map<String,Object> params) throws com.opensymphony.workflow.WorkflowException
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.com.opensymphony.workflow.WorkflowException
- if an error occurs.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
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.com.opensymphony.workflow.WorkflowException
- if an error occurs.protected void setStringMetadata(ModifiableCompositeMetadata meta, String name, MetadataDefinition metaDef, String[] values)
meta
- the metadata holder.name
- the metadata name.metaDef
- the metadata definition.values
- the metadata values.protected void setBooleanMetadata(ModifiableCompositeMetadata meta, String name, MetadataDefinition metaDef, String[] values)
meta
- the metadata holder.name
- the metadata name.metaDef
- the metadata definition.values
- the metadata values.protected void setLongMetadata(ModifiableCompositeMetadata meta, String name, MetadataDefinition metaDef, String[] values)
meta
- the metadata holder.name
- the metadata name.metaDef
- the metadata definition.values
- the metadata values.protected void setDoubleMetadata(ModifiableCompositeMetadata meta, String name, MetadataDefinition metaDef, String[] values)
meta
- the metadata holder.name
- the metadata name.metaDef
- the metadata definition.values
- the metadata values.protected void setDateMetadata(ModifiableCompositeMetadata meta, String name, MetadataDefinition metaDef, String[] values)
meta
- the metadata holder.name
- the metadata name.metaDef
- the metadata definition.values
- the metadata values.protected Date parseDate(String value)
value
- the String value.null
if the value can't be parsed.protected Date parseDate(String value, boolean throwException)
value
- the String value.throwException
- true to throw an exception if the value can't be parsed, false to return null.null
if the value can't be parsed and throwException is false.protected void setGeocodeMetadata(ModifiableCompositeMetadata meta, String name, MetadataDefinition metaDef, String latitude, String longitude)
meta
- the metadata holder.name
- the metadata name.metaDef
- the metadata definition.latitude
- the geocode latitude as a String.longitude
- the geocode longitude as a String.protected void setGeocodeMetadata(ModifiableCompositeMetadata meta, String name, MetadataDefinition metaDef, double latitude, double longitude)
meta
- the metadata holder.name
- the metadata name.metaDef
- the metadata definition.latitude
- the geocode latitude.longitude
- the geocode longitude.protected void setBinaryMetadata(ModifiableCompositeMetadata meta, String name, MetadataDefinition metaDef, String value) throws IOException
meta
- the metadata holder.name
- the metadata name.metaDef
- the metadata definitionvalue
- the valueIOException
- if an exception occurs when manipulating filesprotected void setRichText(ModifiableCompositeMetadata meta, String name, InputStream data)
meta
- the metadata holder.name
- the metadata name.data
- an input stream on the rich text content.protected void restoreContentReferences(Map<String,Object> params)
params
- The import parameters.protected void setReferenceMetadatas(Map<String,Object> contentReferences, Map<String,Object> values, Map<String,Integer> repeaters, Map<String,Object> params)
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.protected String getReferencedContentId(AbstractContentImporter.ContentReference contentRef, Map<String,Object> params)
contentRef
- The content reference.params
- The import parameters.protected Content getContentFromProperties(Map<String,String> propertyValues)
propertyValues
- The metadata values.