Class AbstractXmlContentImporter
java.lang.Object
org.ametys.runtime.plugin.component.AbstractLogEnabled
org.ametys.plugins.contentio.in.AbstractContentImporter
org.ametys.plugins.contentio.in.xml.AbstractXmlContentImporter
- All Implemented Interfaces:
ContentImporter
,XmlContentImporter
,LogEnabled
,Prioritizable
,Configurable
,Serviceable
- Direct Known Subclasses:
DefaultXmlContentImporter
public abstract class AbstractXmlContentImporter
extends AbstractContentImporter
implements XmlContentImporter
Abstract
XmlContentImporter
class which provides base XML importer configuration and logic.-
Nested Class Summary
Modifier and TypeClassDescriptionprotected static class
Configurable XML prefix resolver.Nested classes/interfaces inherited from class org.ametys.plugins.contentio.in.AbstractContentImporter
AbstractContentImporter.ContentReference
-
Field Summary
Modifier and TypeFieldDescriptionprotected DOMParser
A DOM parser.protected ServiceManager
The service manager.protected PrefixResolver
The prefix resolver.protected SourceResolver
The source resolver.protected XPathProcessor
The XPath processor.protected String
The configured XML transformation stylesheet.protected XSLTProcessor
The runtime XSLT processor.protected TransformerHandler
The XSL transformer handler.Fields inherited from class org.ametys.plugins.contentio.in.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
-
Method Summary
Modifier and TypeMethodDescriptionvoid
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
(Element element, String name, String defaultValue) Get an element attribute value (trimmed).protected String
getAttributeValue
(Element element, String name, String defaultValue, boolean trim) Get a node's attribute value, optionally trimmed.protected PrefixResolver
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.importContents
(InputStream is, Map<String, Object> params) Import the contents from the file.importContents
(Document document, Map<String, Object> params) Import the contents from the XML DOMDocument
.protected void
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.in.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, restoreContentReferences, setReferenceMetadatas, setRepeaterSize
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.runtime.plugin.component.Prioritizable
getPriority
Methods inherited from interface org.ametys.plugins.contentio.in.xml.XmlContentImporter
supports
-
Field Details
-
_manager
The service manager. -
_srcResolver
The source resolver. -
_domParser
A DOM parser. -
_xPathProcessor
The XPath processor. -
_xsltProcessor
The runtime XSLT processor. -
_prefixResolver
The prefix resolver. -
_xslTransformerHandler
The XSL transformer handler. -
_xsl
The configured XML transformation stylesheet.
-
-
Constructor Details
-
AbstractXmlContentImporter
public AbstractXmlContentImporter()
-
-
Method Details
-
service
- Specified by:
service
in interfaceServiceable
- Overrides:
service
in classAbstractContentImporter
- Throws:
ServiceException
-
configure
- Specified by:
configure
in interfaceConfigurable
- Overrides:
configure
in classAbstractContentImporter
- Throws:
ConfigurationException
-
configureXml
Configure XML-specific properties.- Parameters:
configuration
- the XML configuration.- Throws:
ConfigurationException
- if an error occurs.
-
configureContentCreation
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
Configure the namespace to use.- Parameters:
configuration
- the namespaces configuration, can be null.- Throws:
ConfigurationException
- if an error occurs.
-
getPrefixResolver
Get the prefix resolver.- Returns:
- the prefix resolver.
-
supports
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
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 IOExceptionImport 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
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
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
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
Get an element attribute value (trimmed).- Parameters:
element
- theElement
, 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
Get a node's attribute value, optionally trimmed.- Parameters:
element
- theElement
, 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.
-