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
AbstractXmlContentImporterclass which provides base XML importer configuration and logic.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classAbstractXmlContentImporter.DefaultPrefixResolverConfigurable XML prefix resolver.-
Nested classes/interfaces inherited from class org.ametys.plugins.contentio.in.AbstractContentImporter
AbstractContentImporter.ContentReference
-
-
Field Summary
Fields Modifier and Type Field Description protected DOMParser_domParserA DOM parser.protected ServiceManager_managerThe service manager.protected PrefixResolver_prefixResolverThe prefix resolver.protected SourceResolver_srcResolverThe source resolver.protected XPathProcessor_xPathProcessorThe XPath processor.protected String_xslThe configured XML transformation stylesheet.protected XSLTProcessor_xsltProcessorThe runtime XSLT processor.protected TransformerHandler_xslTransformerHandlerThe 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 Constructor Description AbstractXmlContentImporter()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidconfigure(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 PrefixResolvergetPrefixResolver()Get 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.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 voidinitializeXslTransformerHandler()Initialize 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, 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 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:
servicein interfaceServiceable- Overrides:
servicein classAbstractContentImporter- Throws:
ServiceException
-
configure
public void configure(Configuration configuration) throws ConfigurationException
- Specified by:
configurein interfaceConfigurable- Overrides:
configurein 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:AbstractContentImporterConfigure the content creation parameters.- Overrides:
configureContentCreationin 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: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
public Set<String> importContents(InputStream is, Map<String,Object> params) throws IOException
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 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(Element element, String name, String defaultValue)
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
protected String getAttributeValue(Element element, String name, String defaultValue, boolean trim)
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.
-
-