Class AbstractXmlContentImporter
- java.lang.Object
-
- org.ametys.runtime.plugin.component.AbstractLogEnabled
-
- org.ametys.plugins.contentio.AbstractContentImporter
-
- org.ametys.plugins.contentio.in.xml.AbstractXmlContentImporter
-
- All Implemented Interfaces:
ContentImporter
,XmlContentImporter
,LogEnabled
,Configurable
,Serviceable
- Direct Known Subclasses:
DefaultXmlContentImporter
public abstract class AbstractXmlContentImporter extends AbstractContentImporter implements XmlContentImporter
AbstractXmlContentImporter
class which provides base XML importer configuration and logic.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
AbstractXmlContentImporter.DefaultPrefixResolver
Configurable XML prefix resolver.-
Nested classes/interfaces inherited from class org.ametys.plugins.contentio.AbstractContentImporter
AbstractContentImporter.ContentReference
-
-
Field Summary
Fields Modifier and Type Field Description protected DOMParser
_domParser
A DOM parser.protected ServiceManager
_manager
The service manager.protected PrefixResolver
_prefixResolver
The prefix resolver.protected SourceResolver
_srcResolver
The source resolver.protected XPathProcessor
_xPathProcessor
The XPath processor.protected String
_xsl
The configured XML transformation stylesheet.protected XSLTProcessor
_xsltProcessor
The runtime XSLT processor.protected TransformerHandler
_xslTransformerHandler
The XSL transformer handler.-
Fields inherited from class org.ametys.plugins.contentio.AbstractContentImporter
_CONTENT_ID_MAP_KEY, _CONTENT_LINK_MAP_KEY, _CONTENT_REPEATER_SIZE_MAP, _contentTypes, _contentWorkflowHelper, _editActionId, _extensions, _initialActionId, _language, _mixins, _priority, _resolver, _workflowName, DEFAULT_PRIORITY
-
-
Constructor Summary
Constructors Constructor Description AbstractXmlContentImporter()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
configure(Configuration configuration)
protected void
configureContentCreation(Configuration configuration)
Configure the content creation parameters.protected void
configureNamespaces(Configuration configuration)
Configure the namespace to use.protected void
configureXml(Configuration configuration)
Configure XML-specific properties.protected String
getAttributeValue(Node node, String name, String defaultValue)
Get a node's attribute value (trimmed).protected String
getAttributeValue(Node node, String name, String defaultValue, boolean trim)
Get a node's attribute value, optionally trimmed.protected PrefixResolver
getPrefixResolver()
Get the prefix resolver.protected String
getTextContent(Node node, String defaultValue)
Get a node's text content, without trimming it.protected String
getTextContent(Node node, String defaultValue, boolean trim)
Get a node's text content, optionally trimmed.Set<String>
importContents(InputStream is, Map<String,Object> params)
Import the contents from the file.protected abstract Set<String>
importContents(Document document, Map<String,Object> params)
Import the contents from the XML DOMDocument
.protected void
initializeXslTransformerHandler()
Initialize the transformer from the configured XSL.void
service(ServiceManager serviceManager)
boolean
supports(InputStream is, String name)
Tests if theContentImporter
is able to import the corresponding stream.
Implementing classes should first test the file extension, if possible, and if the name is provided.-
Methods inherited from class org.ametys.plugins.contentio.AbstractContentImporter
addContentReference, addContentReference, addContentReferences, configureExtensions, configureWorkflow, createContent, createContent, createContent, createContent, createContent, getContentFromProperties, getContentIdMap, getContentRefMap, getContentRepeaterSizeMap, getContentTypes, getDefaultExtensions, getEditActionId, getInitialActionId, getLanguage, getMixins, getPriority, getReferencedContentId, getWorkflowName, isExtensionValid, parseDate, parseDate, restoreContentReferences, setBinaryMetadata, setBooleanMetadata, setDateMetadata, setDoubleMetadata, setGeocodeMetadata, setGeocodeMetadata, setLongMetadata, setReferenceMetadatas, setRepeaterSize, setRichText, setStringMetadata
-
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.ContentImporter
getPriority
-
Methods inherited from interface org.ametys.plugins.contentio.in.xml.XmlContentImporter
supports
-
-
-
-
Field Detail
-
_manager
protected ServiceManager _manager
The service manager.
-
_srcResolver
protected SourceResolver _srcResolver
The source resolver.
-
_domParser
protected DOMParser _domParser
A DOM parser.
-
_xPathProcessor
protected XPathProcessor _xPathProcessor
The XPath processor.
-
_xsltProcessor
protected XSLTProcessor _xsltProcessor
The runtime XSLT processor.
-
_prefixResolver
protected PrefixResolver _prefixResolver
The prefix resolver.
-
_xslTransformerHandler
protected TransformerHandler _xslTransformerHandler
The XSL transformer handler.
-
-
Constructor Detail
-
AbstractXmlContentImporter
public AbstractXmlContentImporter()
-
-
Method Detail
-
service
public void service(ServiceManager serviceManager) throws ServiceException
- Specified by:
service
in interfaceServiceable
- Overrides:
service
in classAbstractContentImporter
- Throws:
ServiceException
-
configure
public void configure(Configuration configuration) throws ConfigurationException
- Specified by:
configure
in interfaceConfigurable
- Overrides:
configure
in classAbstractContentImporter
- Throws:
ConfigurationException
-
configureXml
protected void configureXml(Configuration configuration) throws ConfigurationException
Configure XML-specific properties.- Parameters:
configuration
- the XML configuration.- Throws:
ConfigurationException
- if an error occurs.
-
configureContentCreation
protected void configureContentCreation(Configuration configuration) throws ConfigurationException
Description copied from class:AbstractContentImporter
Configure the content creation parameters.- Overrides:
configureContentCreation
in classAbstractContentImporter
- Parameters:
configuration
- the content creation configuration.- Throws:
ConfigurationException
- if an error occurs.
-
configureNamespaces
protected void configureNamespaces(Configuration configuration) throws ConfigurationException
Configure the namespace to use.- Parameters:
configuration
- the namespaces configuration, can be null.- Throws:
ConfigurationException
- if an error occurs.
-
getPrefixResolver
protected PrefixResolver getPrefixResolver()
Get the prefix resolver.- Returns:
- the prefix resolver.
-
supports
public boolean supports(InputStream is, String name) throws IOException
Description copied from interface:ContentImporter
Tests if theContentImporter
is able to import the corresponding stream.
Implementing classes should first test the file extension, if possible, and if the name is provided.- Specified by:
supports
in interfaceContentImporter
- Parameters:
is
- an input stream on the file, cannot be null. The stream is closed by the caller.name
- the file name, can be null.- Returns:
- true if the
ContentImporter
can import the corresponding stream, false otherwise. - Throws:
IOException
- if an error occurs.
-
importContents
public Set<String> importContents(InputStream is, Map<String,Object> params) throws IOException
Description copied from interface:ContentImporter
Import the contents from the file.- Specified by:
importContents
in interfaceContentImporter
- Parameters:
is
- an input stream on the file, cannot be null. The stream is closed by the caller.params
- input or output parameters.- Returns:
- a Set of the imported content IDs.
- Throws:
IOException
- if an error occurs importing the contents.
-
importContents
protected abstract Set<String> importContents(Document document, Map<String,Object> params) throws IOException
Import the contents from the XML DOMDocument
.- Parameters:
document
- the XML Document.params
- the import parameters.- Returns:
- a Set of the imported content IDs.
- Throws:
IOException
- if an error occurs importing the contents.
-
initializeXslTransformerHandler
protected void initializeXslTransformerHandler() throws IOException, XSLTProcessorException
Initialize the transformer from the configured XSL.- Throws:
IOException
- if an errors occurs reading the XSL.XSLTProcessorException
- of an error occurs during the XSL transformer manipulation
-
getTextContent
protected String getTextContent(Node node, String defaultValue)
Get a node's text content, without trimming it.- Parameters:
node
- the node, can be null.defaultValue
- the default value.- Returns:
- the node's text content, or the default value if the given node is null.
-
getTextContent
protected String getTextContent(Node node, String defaultValue, boolean trim)
Get a node's text content, optionally trimmed.- Parameters:
node
- the node, can be null.defaultValue
- the default value.trim
- true to trim the text content, false otherwise.- Returns:
- the node's text content, or the default value if the given node is null.
-
getAttributeValue
protected String getAttributeValue(Node node, String name, String defaultValue)
Get a node's attribute value (trimmed).- Parameters:
node
- the node, can be null.name
- the attribute name.defaultValue
- the default value.- Returns:
- the node's attribute value, or the default value if the given node is null or the attribute doesn't exist.
-
getAttributeValue
protected String getAttributeValue(Node node, String name, String defaultValue, boolean trim)
Get a node's attribute value, optionally trimmed.- Parameters:
node
- the node, can be null.name
- the attribute name.defaultValue
- the default value.trim
- true- Returns:
- the node's attribute value, or the default value if the given node is null or the attribute doesn't exist.
-
-