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
Nested ClassesModifier and TypeClassDescriptionprotected static classConfigurable XML prefix resolver.Nested classes/interfaces inherited from class org.ametys.plugins.contentio.in.AbstractContentImporter
AbstractContentImporter.ContentReference -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected DOMParserA DOM parser.protected ServiceManagerThe service manager.protected PrefixResolverThe prefix resolver.protected SourceResolverThe source resolver.protected XPathProcessorThe XPath processor.protected StringThe configured XML transformation stylesheet.protected XSLTProcessorThe runtime XSLT processor.protected TransformerHandlerThe 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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidconfigure(Configuration configuration) protected voidconfigureContentCreation(Configuration configuration) Configure the content creation parameters.protected voidconfigureNamespaces(Configuration configuration) Configure the namespace to use.protected voidconfigureXml(Configuration configuration) Configure XML-specific properties.protected StringgetAttributeValue(Element element, String name, String defaultValue) Get an element attribute value (trimmed).protected StringgetAttributeValue(Element element, String name, String defaultValue, boolean trim) Get a node's attribute value, optionally trimmed.protected PrefixResolverGet the prefix resolver.protected StringgetTextContent(Node node, String defaultValue) Get a node's text content, without trimming it.protected StringgetTextContent(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 voidInitialize the transformer from the configured XSL.voidservice(ServiceManager serviceManager) booleansupports(InputStream is, String name) Tests if theContentImporteris 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, getContentFromProperties, getContentIdMap, getContentRefMap, getContentRepeaterSizeMap, getContentTypes, getDefaultExtensions, getEditActionId, getInitialActionId, getLanguage, getMixins, getPriority, getReferencedContentId, getWorkflowName, isExtensionValid, restoreContentReferences, setReferenceMetadatas, setRepeaterSizeMethods 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.runtime.plugin.component.Prioritizable
getPriorityMethods 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:
servicein interfaceServiceable- Overrides:
servicein classAbstractContentImporter- Throws:
ServiceException
-
configure
- Specified by:
configurein interfaceConfigurable- Overrides:
configurein classAbstractContentImporter- Throws:
ConfigurationException
-
configureXml
Configure XML-specific properties.- Parameters:
configuration- the XML configuration.- Throws:
ConfigurationException- if an error occurs.
-
configureContentCreation
Description copied from class:AbstractContentImporterConfigure the content creation parameters.- Overrides:
configureContentCreationin 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:ContentImporterTests if theContentImporteris able to import the corresponding stream.
Implementing classes should first test the file extension, if possible, and if the name is provided.- Specified by:
supportsin 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
ContentImportercan import the corresponding stream, false otherwise. - Throws:
IOException- if an error occurs.
-
importContents
Description copied from interface:ContentImporterImport the contents from the file.- Specified by:
importContentsin 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.
-