Class XPathMetadataExtracter
- java.lang.Object
-
- org.alfresco.repo.content.metadata.AbstractMappingMetadataExtracter
-
- org.alfresco.repo.content.metadata.xml.XPathMetadataExtracter
-
- All Implemented Interfaces:
javax.xml.namespace.NamespaceContext,ContentWorker,MetadataEmbedder,MetadataExtracter,org.springframework.beans.factory.Aware,org.springframework.beans.factory.BeanNameAware,org.springframework.context.ApplicationContextAware
public class XPathMetadataExtracter extends AbstractMappingMetadataExtracter implements javax.xml.namespace.NamespaceContext
An extracter that pulls values from XML documents using configurable XPath statements. It is not possible to list a default set of mappings - this is down to the configuration only.When an instance of this extracter is configured, XPath statements should be provided to extract all the available metadata. The implementation is sensitive to what is actually requested by the configured mapping and will only perform the queries necessary to fulfill the requirements.
To summarize, there are two configurations required for this class:
-
A mapping of all reasonable document properties to XPath statements.
See
AbstractMappingMetadataExtracter.setMappingProperties(java.util.Properties). - A mapping of document property names to Alfresco repository model QNames. See {@link #setXpathMappingProperties(Properties).}
All values are extracted as text values and therefore all XPath statements must evaluate to a node that can be rendered as text.
- Since:
- 2.1
- Author:
- Derek Hulley
- See Also:
AbstractMappingMetadataExtracter.setMappingProperties(Properties),setXpathMappingProperties(Properties)
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.alfresco.repo.content.metadata.MetadataExtracter
MetadataExtracter.OverwritePolicy
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String[]SUPPORTED_MIMETYPES-
Fields inherited from class org.alfresco.repo.content.metadata.AbstractMappingMetadataExtracter
MEGABYTE_SIZE, NAMESPACE_PROPERTY_PREFIX, PROPERTY_COMPONENT_EMBED, PROPERTY_COMPONENT_EXTRACT, PROPERTY_PREFIX_METADATA
-
-
Constructor Summary
Constructors Constructor Description XPathMetadataExtracter()Default constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.util.Map<java.lang.String,java.io.Serializable>extractRaw(org.alfresco.service.cmr.repository.ContentReader reader)Override to provide the raw extracted metadata values.protected java.util.Map<java.lang.String,java.util.Set<org.alfresco.service.namespace.QName>>getDefaultMapping()It is not possible to have any default mappings, but something has to be returned.java.lang.StringgetNamespaceURI(java.lang.String prefix)java.lang.StringgetPrefix(java.lang.String namespaceURI)java.util.IteratorgetPrefixes(java.lang.String namespaceURI)protected voidinit()Provides a hook point for implementations to perform initialization.protected java.util.Map<java.lang.String,java.io.Serializable>processDocument(org.w3c.dom.Document document)Executes all the necessary XPath statements to extract values.protected voidreadXPathMappingProperties(java.util.Properties xpathMappingProperties)A utility method to convert mapping properties to the Map form.voidsetXpathMappingProperties(java.util.Properties xpathMappingProperties)Set the properties file that maps document properties to the XPath statements necessary to retrieve them.-
Methods inherited from class org.alfresco.repo.content.metadata.AbstractMappingMetadataExtracter
checkIsEmbedSupported, checkIsSupported, embed, embedInternal, extract, extract, extract, filterSystemProperties, getBeanName, getDefaultEmbedMapping, getEmbedMapping, getExecutorService, getLimits, getMapping, getMimetypeService, isEmbeddingSupported, isSupported, makeDate, newRawMap, putRawValue, readEmbedMappingProperties, readEmbedMappingProperties, readGlobalEmbedMappingProperties, readGlobalExtractMappingProperties, readMappingProperties, readMappingProperties, register, setApplicationContext, setBeanName, setDictionaryService, setEmbedMapping, setEmbedMappingProperties, setEnableStringTagging, setExecutorService, setFailOnTypeConversion, setInheritDefaultEmbedMapping, setInheritDefaultMapping, setMapping, setMappingProperties, setMimetypeLimits, setMimetypeService, setOverwritePolicy, setProperties, setRegistry, setSupportedDateFormats, setSupportedEmbedMimetypes, setSupportedMimetypes
-
-
-
-
Method Detail
-
getNamespaceURI
public java.lang.String getNamespaceURI(java.lang.String prefix)
- Specified by:
getNamespaceURIin interfacejavax.xml.namespace.NamespaceContext
-
getPrefix
public java.lang.String getPrefix(java.lang.String namespaceURI)
- Specified by:
getPrefixin interfacejavax.xml.namespace.NamespaceContext
-
getPrefixes
public java.util.Iterator getPrefixes(java.lang.String namespaceURI)
- Specified by:
getPrefixesin interfacejavax.xml.namespace.NamespaceContext
-
setXpathMappingProperties
public void setXpathMappingProperties(java.util.Properties xpathMappingProperties)
Set the properties file that maps document properties to the XPath statements necessary to retrieve them.The Xpath mapping is of the form:
# Namespaces prefixes namespace.prefix.my=http://www....com/alfresco/1.0 # Mapping editor=/my:example-element/@cm:editor title=/my:example-element/text()
-
init
protected void init()
Description copied from class:AbstractMappingMetadataExtracterProvides a hook point for implementations to perform initialization. The base implementation must be invoked or the extracter will fail during extraction. Thedefault mappingswill be requested during initialization.- Overrides:
initin classAbstractMappingMetadataExtracter
-
getDefaultMapping
protected java.util.Map<java.lang.String,java.util.Set<org.alfresco.service.namespace.QName>> getDefaultMapping()
It is not possible to have any default mappings, but something has to be returned.- Overrides:
getDefaultMappingin classAbstractMappingMetadataExtracter- Returns:
- Returns an empty map
- See Also:
AbstractMappingMetadataExtracter.setInheritDefaultMapping(boolean inherit)
-
extractRaw
protected java.util.Map<java.lang.String,java.io.Serializable> extractRaw(org.alfresco.service.cmr.repository.ContentReader reader) throws java.lang.ThrowableDescription copied from class:AbstractMappingMetadataExtracterOverride to provide the raw extracted metadata values. An extracter should extract as many of the available properties as is realistically possible. Even if thedefault mappingdoesn't handle all properties, it is possible for each instance of the extracter to be configured differently and more or less of the properties may be used in different installations.Raw values must not be trimmed or removed for any reason. Null values and empty strings are
- Null: Removed
- Empty String: Passed to the OverwritePolicy
- Non Serializable: Converted to String or fails if that is not possible
Properties extracted and their meanings and types should be thoroughly described in the class-level javadocs of the extracter implementation, for example:
editor: - the document editor --> cm:author title: - the document title --> cm:title user1: - the document summary user2: - the document description --> cm:description user3: - user4: -
- Specified by:
extractRawin classAbstractMappingMetadataExtracter- Parameters:
reader- the document to extract the values from. This stream provided by the reader must be closed if accessed directly.- Returns:
- Returns a map of document property values keyed by property name.
- Throws:
java.lang.Throwable- All exception conditions can be handled.- See Also:
AbstractMappingMetadataExtracter.getDefaultMapping()
-
processDocument
protected java.util.Map<java.lang.String,java.io.Serializable> processDocument(org.w3c.dom.Document document) throws java.lang.ThrowableExecutes all the necessary XPath statements to extract values.- Throws:
java.lang.Throwable
-
readXPathMappingProperties
protected void readXPathMappingProperties(java.util.Properties xpathMappingProperties)
A utility method to convert mapping properties to the Map form.
-
-