Class AbstractMappingMetadataExtracter
- All Implemented Interfaces:
ContentWorker,MetadataEmbedder,MetadataExtracter,org.springframework.beans.factory.Aware,org.springframework.beans.factory.BeanNameAware,org.springframework.context.ApplicationContextAware
- Direct Known Subclasses:
AsynchronousExtractor,RFC822MetadataExtracter,XmlMetadataExtracter,XPathMetadataExtracter
- Extract ALL available metadata from the document.
- Translate the metadata into system properties.
Migrating an existing extracter to use this class is straightforward:
- Construct the extracter providing a default set of supported mimetypes to this implementation. This can be overwritten with configurations.
- Implement the
extract(org.alfresco.service.cmr.repository.ContentReader, java.util.Map<org.alfresco.service.namespace.QName, java.io.Serializable>)method. This now returns a raw map of extracted values keyed by document-specific property names. The trimPut method has been replaced with an equivalentputRawValue(String, Serializable, Map). - Provide the default mapping of the document-specific properties to system-specific properties as describe by the
getDefaultMapping()method. The simplest is to provide the default mapping in a correlated .properties file. - Document, in the class-level javadoc, all the available properties that are extracted along with their approximate meanings. Add to this, the default mappings.
- Since:
- 2.1
- Author:
- Jesper Steen Møller, Derek Hulley
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.alfresco.repo.content.metadata.MetadataExtracter
MetadataExtracter.OverwritePolicy -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected DictionaryServiceprotected static org.apache.commons.logging.Logstatic final intstatic final Stringstatic final Stringstatic final Stringstatic final String -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedDefault constructor.protectedAbstractMappingMetadataExtracter(Set<String> supportedMimetypes) Constructor that can be used when the list of supported mimetypes is known up front.protectedAbstractMappingMetadataExtracter(Set<String> supportedMimetypes, Set<String> supportedEmbedMimetypes) Constructor that can be used when the list of supported extract and embed mimetypes is known up front. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidcheckIsEmbedSupported(ContentWriter writer) Checks if embedding for the mimetype is supported.protected voidcheckIsSupported(ContentReader reader) Checks if the mimetype is supported.protected Map<QName,Serializable> convertSystemPropertyValues(Map<QName, Serializable> systemProperties) Converts all values according to their dictionary-defined type.final voidembed(Map<QName, Serializable> properties, ContentReader reader, ContentWriter writer) Embeds the given properties into the file specified by the given content writer. *voidembed(NodeRef nodeRef, Map<QName, Serializable> properties, ContentReader reader, ContentWriter writer) Identical toMetadataEmbedder.embed(Map, ContentReader, ContentWriter)but with the addition of theNodeRefbeing acted on.protected voidembedInternal(Map<String, Serializable> metadata, ContentReader reader, ContentWriter writer) Override to embed metadata values.protected voidembedInternal(NodeRef nodeRef, Map<String, Serializable> metadata, ContentReader reader, ContentWriter writer) final Map<QName,Serializable> extract(ContentReader reader, Map<QName, Serializable> destination) Extracts the metadata values from the content provided by the reader and source mimetype to the supplied map.final Map<QName,Serializable> extract(ContentReader reader, MetadataExtracter.OverwritePolicy overwritePolicy, Map<QName, Serializable> destination) Extracts the metadata values from the content provided by the reader and source mimetype to the supplied map.extract(ContentReader reader, MetadataExtracter.OverwritePolicy overwritePolicy, Map<QName, Serializable> destination, Map<String, Set<QName>> mapping) Extracts the metadata from the content provided by the reader and source mimetype to the supplied map.extract(NodeRef nodeRef, ContentReader reader, Map<QName, Serializable> destination) Identical toMetadataExtracter.extract(ContentReader, Map)but with the addition of theNodeRefbeing acted on.extract(NodeRef nodeRef, ContentReader reader, MetadataExtracter.OverwritePolicy overwritePolicy, Map<QName, Serializable> destination) Identical toMetadataExtracter.extract(ContentReader, OverwritePolicy,Map)but with the addition of theNodeRefbeing acted on.extract(NodeRef nodeRef, ContentReader reader, MetadataExtracter.OverwritePolicy overwritePolicy, Map<QName, Serializable> destination, Map<String, Set<QName>> mapping) Identical toMetadataExtracter.extract(ContentReader, OverwritePolicy, Map, Map)but with the addition of theNodeRefbeing acted on.protected abstract Map<String,Serializable> extractRaw(ContentReader reader) Override to provide the raw extracted metadata values.protected Map<String,Serializable> extractRawInThread(NodeRef nodeRef, ContentReader reader, MetadataExtracterLimits limits) protected Map<String,Serializable> extractRawInThread(NodeRef nodeRef, ContentReader reader, MetadataExtracterLimits limits, MetadataExtracter.OverwritePolicy policy) protected voidprotected voidfilterSystemProperties(Map<QName, Serializable> systemProperties, Map<QName, Serializable> targetProperties) Filters the system properties that are going to be applied.This method provides a best guess of what model properties should be embedded in content.This method provides a best guess of where to store the values extracted from the documents.Helper method for derived classes to obtain the embed mappings.protected ExecutorServiceGets theExecutorServiceto be used for timeout-aware extraction.protected MetadataExtracterLimitsGets the metadata extracter limits for the given mimetype.Helper method for derived classes to obtain the mappings that will be applied to raw values.protected MimetypeServiceprotected voidinit()Provides a hook point for implementations to perform initialization.booleanisEmbeddingSupported(String sourceMimetype) Determines if the extracter works against the given mimetype.protected booleanbooleanisSupported(String sourceMimetype) Determines if the extracter works against the given mimetype.protected DateConvert a date String to a Date objectprotected Map<String,Serializable> mapSystemToRaw(Map<QName, Serializable> systemMetadata) protected final Map<String,Serializable> Helper method to fetch a clean map into which raw values can be dumped.protected booleanputRawValue(String key, Serializable value, Map<String, Serializable> destination) Adds a value to the map, conserving null values.readEmbedMappingProperties(String propertiesUrl) A utility method to read embed mapping properties from a resource file and convert to the map form.readEmbedMappingProperties(Properties mappingProperties) A utility method to convert mapping properties to the Map form.A utility method to convert global mapping properties to the Map form.A utility method to convert global properties to the Map form for the given propertyComponent.readMappingProperties(String propertiesUrl) A utility method to read mapping properties from a resource file and convert to the map form.readMappingProperties(Properties mappingProperties) A utility method to convert mapping properties to the Map form.final voidregister()Registers this instance of the extracter with the registry.voidsetApplicationContext(org.springframework.context.ApplicationContext applicationContext) voidsetBeanName(String beanName) voidsetDictionaryService(DictionaryService dictionaryService) voidsetEmbedMapping(Map<QName, Set<String>> embedMapping) Set the embed mapping from document metadata to system metadata.voidsetEmbedMappingProperties(Properties embedMappingProperties) Set the properties that contain the embed mapping from model properties to content file metadata.voidsetEnableStringTagging(boolean enableStringTagging) Whether or not to enable the pass through of simple strings to cm:taggable tagsvoidsetExecutorService(ExecutorService executorService) Sets theExecutorServiceto be used for timeout-aware extraction.voidsetFailOnTypeConversion(boolean failOnTypeConversion) Set whether the extractor should discard metadata that fails to convert to the target type defined in the data dictionary model.voidsetInheritDefaultEmbedMapping(boolean inheritDefaultEmbedMapping) Set if the embed property mappings augment or override the mapping generically provided by the extracter implementation.voidsetInheritDefaultMapping(boolean inheritDefaultMapping) Set if the property mappings augment or override the mapping generically provided by the extracter implementation.voidsetMapping(Map<String, Set<QName>> mapping) Set the mapping from document metadata to system metadata.voidsetMappingProperties(Properties mappingProperties) Set the properties that contain the mapping from document metadata to system metadata.voidsetMimetypeLimits(Map<String, MetadataExtracterLimits> mimetypeLimits) Sets the map of source mimetypes to metadata extracter limits.voidsetMimetypeService(MimetypeService mimetypeService) voidsetOverwritePolicy(MetadataExtracter.OverwritePolicy overwritePolicy) Set the policy to use when existing values are encountered.voidsetProperties(Properties properties) The Alfresco global properties.voidsetRegistry(MetadataExtracterRegistry registry) Set the registry to register with.voidsetSupportedDateFormats(List<String> supportedDateFormats) Set the date formats, over and above theISO8601 format, that will be supported for string to date conversions.voidsetSupportedEmbedMimetypes(Collection<String> supportedEmbedMimetypes) Set the mimetypes that are supported for embedding.voidsetSupportedMimetypes(Collection<String> supportedMimetypes) Set the mimetypes that are supported by the extracter.
-
Field Details
-
NAMESPACE_PROPERTY_PREFIX
- See Also:
-
PROPERTY_PREFIX_METADATA
- See Also:
-
PROPERTY_COMPONENT_EXTRACT
- See Also:
-
PROPERTY_COMPONENT_EMBED
- See Also:
-
MEGABYTE_SIZE
public static final int MEGABYTE_SIZE- See Also:
-
logger
protected static org.apache.commons.logging.Log logger -
dictionaryService
-
-
Constructor Details
-
AbstractMappingMetadataExtracter
protected AbstractMappingMetadataExtracter()Default constructor. If this is called, thenisSupported(String)should be implemented. This is useful when the list of supported mimetypes is not known when the instance is constructed. Alternatively, once the set becomes known, callsetSupportedMimetypes(Collection). -
AbstractMappingMetadataExtracter
Constructor that can be used when the list of supported mimetypes is known up front.- Parameters:
supportedMimetypes- the set of mimetypes supported by default
-
AbstractMappingMetadataExtracter
protected AbstractMappingMetadataExtracter(Set<String> supportedMimetypes, Set<String> supportedEmbedMimetypes) Constructor that can be used when the list of supported extract and embed mimetypes is known up front.- Parameters:
supportedMimetypes- the set of mimetypes supported for extraction by defaultsupportedEmbedMimetypes- the set of mimetypes supported for embedding by default
-
-
Method Details
-
setRegistry
Set the registry to register with. If this is not set, then the default initialization will not auto-register the extracter for general use. It can still be used directly.- Parameters:
registry- a metadata extracter registry
-
setMimetypeService
- Parameters:
mimetypeService- the mimetype service. Set this if required.
-
getMimetypeService
- Returns:
- Returns the mimetype helper
-
setDictionaryService
- Parameters:
dictionaryService- the dictionary service to determine which data conversions are necessary
-
getSupportedMimetypes
-
setSupportedMimetypes
Set the mimetypes that are supported by the extracter. -
setSupportedEmbedMimetypes
Set the mimetypes that are supported for embedding. -
isSupported
Determines if the extracter works against the given mimetype.- Specified by:
isSupportedin interfaceMetadataExtracter- Parameters:
sourceMimetype- the document mimetype- Returns:
- Returns true if the mimetype is supported, otherwise false.
- See Also:
-
isEmbeddingSupported
Determines if the extracter works against the given mimetype.- Specified by:
isEmbeddingSupportedin interfaceMetadataEmbedder- Parameters:
sourceMimetype- the document mimetype- Returns:
- Returns true if the mimetype is supported, otherwise false.
- See Also:
-
isEnabled
-
setOverwritePolicy
Set the policy to use when existing values are encountered. Depending on how the extractor is called, this may not be relevant, i.e an empty map of existing properties may be passed in by the client code, which may follow its own overwrite strategy.- Parameters:
overwritePolicy- the policy to apply when there are existing system properties
-
setFailOnTypeConversion
public void setFailOnTypeConversion(boolean failOnTypeConversion) Set whether the extractor should discard metadata that fails to convert to the target type defined in the data dictionary model. This is true by default i.e. if the data extracted is not compatible with the target model then the extraction will fail. If this is false then any extracted data that fails to convert will be discarded.- Parameters:
failOnTypeConversion- false to discard properties that can't get converted to the dictionary-defined type, or true (default) to fail the extraction if the type doesn't convert
-
setSupportedDateFormats
Set the date formats, over and above theISO8601 format, that will be supported for string to date conversions. The supported syntax is described by the SimpleDateFormat Javadocs.- Parameters:
supportedDateFormats- a list of supported date formats.
-
setInheritDefaultMapping
public void setInheritDefaultMapping(boolean inheritDefaultMapping) Set if the property mappings augment or override the mapping generically provided by the extracter implementation. The default is false, i.e. any mapping set completely replaces thedefault mappings.Note that even when set to true an individual property mapping entry replaces the entry provided by the extracter implementation.
- Parameters:
inheritDefaultMapping- true to add the configured mapping to the list of default mappings.- See Also:
-
setBeanName
- Specified by:
setBeanNamein interfaceorg.springframework.beans.factory.BeanNameAware
-
getBeanName
-
setApplicationContext
public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext) - Specified by:
setApplicationContextin interfaceorg.springframework.context.ApplicationContextAware
-
setProperties
The Alfresco global properties. -
setEnableStringTagging
public void setEnableStringTagging(boolean enableStringTagging) Whether or not to enable the pass through of simple strings to cm:taggable tags- Parameters:
enableStringTagging- true find or create tags for each string mapped to cm:taggable. false (default) ignore mapping strings to tags.
-
setInheritDefaultEmbedMapping
public void setInheritDefaultEmbedMapping(boolean inheritDefaultEmbedMapping) Set if the embed property mappings augment or override the mapping generically provided by the extracter implementation. The default is false, i.e. any mapping set completely replaces thedefault mappings.Note that even when set to true an individual property mapping entry replaces the entry provided by the extracter implementation.
- Parameters:
inheritDefaultEmbedMapping- true to add the configured embed mapping to the list of default embed mappings.- See Also:
-
setMimetypeLimits
Sets the map of source mimetypes to metadata extracter limits. -
getExecutorService
Gets theExecutorServiceto be used for timeout-aware extraction.If no
ExecutorServicehas been defined a default ofExecutors.newCachedThreadPool()is used duringinit().- Returns:
- the defined or default
ExecutorService
-
setExecutorService
Sets theExecutorServiceto be used for timeout-aware extraction.- Parameters:
executorService- theExecutorServicefor timeouts
-
setMapping
Set the mapping from document metadata to system metadata. It is possible to direct an extracted document property to several system properties. The conversion between the document property types and the system property types will be done by thedefault converter.- Parameters:
mapping- a mapping from document metadata to system metadata
-
setEmbedMapping
Set the embed mapping from document metadata to system metadata. It is possible to direct an model properties to several content file metadata keys. The conversion between the model property types and the content file metadata keys types will be done by thedefault converter.- Parameters:
embedMapping- an embed mapping from model properties to content file metadata keys
-
setMappingProperties
Set the properties that contain the mapping from document metadata to system metadata. This is an alternative to thesetMapping(Map)method. Any mappings already present will be cleared out. The property mapping is of the form:# Namespaces prefixes namespace.prefix.cm=http://www.alfresco.org/model/content/1.0 namespace.prefix.my=http://www....com/alfresco/1.0 # Mapping editor=cm:author, my:editor title=cm:title user1=cm:summary user2=cm:description
The mapping can therefore be from a single document property onto several system properties.- Parameters:
mappingProperties- the properties that map document properties to system properties
-
setEmbedMappingProperties
Set the properties that contain the embed mapping from model properties to content file metadata. This is an alternative to thesetEmbedMapping(Map)method. Any mappings already present will be cleared out. The property mapping is of the form:# Namespaces prefixes namespace.prefix.cm=http://www.alfresco.org/model/content/1.0 namespace.prefix.my=http://www....com/alfresco/1.0 # Mapping cm\:author=editor cm\:title=title cm\:summary=user1 cm\:description=description,user2
The embed mapping can therefore be from a model property onto several content file metadata properties.- Parameters:
embedMappingProperties- the properties that map model properties to content file metadata properties
-
getMapping
Helper method for derived classes to obtain the mappings that will be applied to raw values. This should be called after initialization in order to guarantee the complete map is given.Normally, the list of properties that can be extracted from a document is fixed and well-known - in that case, just extract everything. But Some implementations may have an extra, indeterminate set of values available for extraction. If the extraction of these runtime parameters is expensive, then the keys provided by the return value can be used to extract values from the documents. The metadata extraction becomes fully configuration-driven, i.e. declaring further mappings will result in more values being extracted from the documents.
Most extractors will not be using this method.
-
getEmbedMapping
Helper method for derived classes to obtain the embed mappings. This should be called after initialization in order to guarantee the complete map is given.Normally, the list of properties that can be embedded in a document is fixed and well-known.. But some implementations may have an extra, indeterminate set of values available for embedding. If the embedding of these runtime parameters is expensive, then the keys provided by the return value can be used to embed values in the documents. The metadata embedding becomes fully configuration-driven, i.e. declaring further mappings will result in more values being embedded in the documents.
-
readMappingProperties
A utility method to read mapping properties from a resource file and convert to the map form.- Parameters:
propertiesUrl- A standard Properties file URL location- See Also:
-
readGlobalExtractMappingProperties
A utility method to convert global properties to the Map form for the given propertyComponent.Mappings can be specified using the same method defined for normal mapping properties files but with a prefix of
metadata.extracter, the extracter bean name, and the extract component. For example: metadata.extracter.TikaAuto.extract.namespace.prefix.my=http://DummyMappingMetadataExtracter metadata.extracter.TikaAuto.extract.namespace.prefix.cm=http://www.alfresco.org/model/content/1.0 metadata.extracter.TikaAuto.extract.dc\:description=cm:description, my:customDescription -
readMappingProperties
A utility method to convert mapping properties to the Map form.- See Also:
-
readEmbedMappingProperties
A utility method to read embed mapping properties from a resource file and convert to the map form.- Parameters:
propertiesUrl- A standard Properties file URL location- See Also:
-
readGlobalEmbedMappingProperties
A utility method to convert global mapping properties to the Map form.Different from readGlobalExtractMappingProperties in that keys are the Alfresco QNames and values are file metadata properties.
Mappings can be specified using the same method defined for normal embed mapping properties files but with a prefix of
metadata.extracter, the extracter bean name, and the embed component. For example: metadata.extracter.TikaAuto.embed.namespace.prefix.cm=http://www.alfresco.org/model/content/1.0 metadata.extracter.TikaAuto.embed.cm\:description=description- See Also:
-
readEmbedMappingProperties
A utility method to convert mapping properties to the Map form.Different from readMappingProperties in that keys are the Alfresco QNames and values are file metadata properties.
- See Also:
-
register
public final void register()Registers this instance of the extracter with the registry. This will call theinit()method and then register if the registry is available.- See Also:
-
init
protected void init()Provides 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. -
checkIsSupported
Checks if the mimetype is supported.- Parameters:
reader- the reader to check- Throws:
org.alfresco.error.AlfrescoRuntimeException- if the mimetype is not supported
-
checkIsEmbedSupported
Checks if embedding for the mimetype is supported.- Parameters:
writer- the writer to check- Throws:
org.alfresco.error.AlfrescoRuntimeException- if embedding for the mimetype is not supported
-
extract
public final Map<QName,Serializable> extract(ContentReader reader, Map<QName, Serializable> destination) Extracts the metadata values from the content provided by the reader and source mimetype to the supplied map. The internal mapping andoverwrite policybetween document metadata and system metadata will be used.The extraction viability can be determined by an up front call to
MetadataExtracter.isSupported(String).The source mimetype must be available on the
ContentAccessor.getMimetype()method of the reader.- Specified by:
extractin interfaceMetadataExtracter- Parameters:
reader- the source of the contentdestination- the map of properties to populate (essentially a return value)- Returns:
- Returns a map of all properties on the destination map that were added or modified. If the return map is empty, then no properties were modified.
- See Also:
-
extract
public final Map<QName,Serializable> extract(ContentReader reader, MetadataExtracter.OverwritePolicy overwritePolicy, Map<QName, Serializable> destination) Extracts the metadata values from the content provided by the reader and source mimetype to the supplied map.The extraction viability can be determined by an up front call to
MetadataExtracter.isSupported(String).The source mimetype must be available on the
ContentAccessor.getMimetype()method of the reader.- Specified by:
extractin interfaceMetadataExtracter- Parameters:
reader- the source of the contentoverwritePolicy- the policy stipulating how the system properties must be overwritten if presentdestination- the map of properties to populate (essentially a return value)- Returns:
- Returns a map of all properties on the destination map that were added or modified. If the return map is empty, then no properties were modified.
- See Also:
-
extract
public Map<QName,Serializable> extract(ContentReader reader, MetadataExtracter.OverwritePolicy overwritePolicy, Map<QName, Serializable> destination, Map<String, Set<QName>> mapping) Extracts the metadata from the content provided by the reader and source mimetype to the supplied map. The mapping from document metadata to system metadata is explicitly provided. Theoverwrite policyis also explictly set.The extraction viability can be determined by an up front call to
MetadataExtracter.isSupported(String).The source mimetype must be available on the
ContentAccessor.getMimetype()method of the reader.- Specified by:
extractin interfaceMetadataExtracter- Parameters:
reader- the source of the contentoverwritePolicy- the policy stipulating how the system properties must be overwritten if presentdestination- the map of properties to populate (essentially a return value)mapping- a mapping of document-specific properties to system properties.- Returns:
- Returns a map of all properties on the destination map that were added or modified. If the return map is empty, then no properties were modified.
- See Also:
-
extract
public Map<QName,Serializable> extract(NodeRef nodeRef, ContentReader reader, Map<QName, Serializable> destination) Identical toMetadataExtracter.extract(ContentReader, Map)but with the addition of theNodeRefbeing acted on. By default, the method without theNodeRefis called.- Specified by:
extractin interfaceMetadataExtracter- Parameters:
nodeRef- the node being acted on.reader- the source of the contentdestination- the map of properties to populate (essentially a return value)- Returns:
- Returns a map of all properties on the destination map that were added or modified. If the return map is empty, then no properties were modified.
-
extract
public Map<QName,Serializable> extract(NodeRef nodeRef, ContentReader reader, MetadataExtracter.OverwritePolicy overwritePolicy, Map<QName, Serializable> destination) Identical toMetadataExtracter.extract(ContentReader, OverwritePolicy,Map)but with the addition of theNodeRefbeing acted on. By default, the method without theNodeRefis called.- Specified by:
extractin interfaceMetadataExtracter- Parameters:
nodeRef- the node being acted on.reader- the source of the contentdestination- the map of properties to populate (essentially a return value)- Returns:
- Returns a map of all properties on the destination map that were added or modified. If the return map is empty, then no properties were modified.
-
extract
public Map<QName,Serializable> extract(NodeRef nodeRef, ContentReader reader, MetadataExtracter.OverwritePolicy overwritePolicy, Map<QName, Serializable> destination, Map<String, Set<QName>> mapping) Identical toMetadataExtracter.extract(ContentReader, OverwritePolicy, Map, Map)but with the addition of theNodeRefbeing acted on. By default, the method without theNodeRefis called.- Specified by:
extractin interfaceMetadataExtracter- Parameters:
nodeRef- the node being acted on.reader- the source of the contentoverwritePolicy- the policy stipulating how the system properties must be overwritten if presentdestination- the map of properties to populate (essentially a return value)mapping- a mapping of document-specific properties to system properties.- Returns:
- Returns a map of all properties on the destination map that were added or modified. If the return map is empty, then no properties were modified.
-
embed
public final void embed(Map<QName, Serializable> properties, ContentReader reader, ContentWriter writer) Embeds the given properties into the file specified by the given content writer. *The embedding viability can be determined by an up front call to
MetadataEmbedder.isEmbeddingSupported(String).The source mimetype must be available on the
ContentAccessor.getMimetype()method of the writer.- Specified by:
embedin interfaceMetadataEmbedder- Parameters:
properties- the model properties to embedreader- the reader for the original source content filewriter- the writer for the content after metadata has been embedded
-
embed
public void embed(NodeRef nodeRef, Map<QName, Serializable> properties, ContentReader reader, ContentWriter writer) Identical toMetadataEmbedder.embed(Map, ContentReader, ContentWriter)but with the addition of theNodeRefbeing acted on. By default, the method without theNodeRefis called.- Specified by:
embedin interfaceMetadataEmbedder- Parameters:
nodeRef- the node being acted on.properties- the model properties to embedreader- the reader for the original source content filewriter- the writer for the content after metadata has been embedded
-
mapSystemToRaw
- Parameters:
systemMetadata- Metadata keyed by system properties- Returns:
- Returns the metadata keyed by the content file metadata properties
-
filterSystemProperties
protected void filterSystemProperties(Map<QName, Serializable> systemProperties, Map<QName, Serializable> targetProperties) Filters the system properties that are going to be applied. Gives the metadata extracter an opportunity to remove properties that may not be appropriate in a given context.- Parameters:
systemProperties- map of system properties to be appliedtargetProperties- map of target properties, may be used to provide to the context requried
-
convertSystemPropertyValues
protected Map<QName,Serializable> convertSystemPropertyValues(Map<QName, Serializable> systemProperties) Converts all values according to their dictionary-defined type. This uses thefailOnTypeConversion flagto determine how failures are handled i.e. if values fail to convert, the process may discard the property.- Parameters:
systemProperties- the values keyed to system property names- Returns:
- Returns a modified map of properties that have been converted.
-
makeDate
Convert a date String to a Date object -
putRawValue
Adds a value to the map, conserving null values. Values are converted to null if:- it is an empty string value after trimming
- it is an empty collection
- it is an empty array
- Parameters:
key- the destination keyvalue- the serializable valuedestination- the map to put values into- Returns:
- Returns true if set, otherwise false
-
newRawMap
Helper method to fetch a clean map into which raw values can be dumped.- Returns:
- Returns an empty map
-
getDefaultMapping
This method provides a best guess of where to store the values extracted from the documents. The list of properties mapped by default need not include all properties extracted from the document; just the obvious set of mappings need be supplied. Implementations must either provide the default mapping properties in the expected location or override the method to provide the default mapping.The default implementation looks for the default mapping file in the location given by the class name and .properties. If the extracter's class is x.y.z.MyExtracter then the default properties will be picked up at classpath:/alfresco/metadata/MyExtracter.properties. The previous location of classpath:/x/y/z/MyExtracter.properties is still supported but may be removed in a future release. Inner classes are supported, but the '$' in the class name is replaced with '-', so default properties for x.y.z.MyStuff$MyExtracter will be located using classpath:/alfresco/metadata/MyStuff-MyExtracter.properties.
The default mapping implementation should include thorough Javadocs so that the system administrators can accurately determine how to best enhance or override the default mapping.
If the default mapping is declared in a properties file other than the one named after the class, then the
readMappingProperties(String)method can be used to quickly generate the return value:
The map can also be created in code either statically or during the call.{ return readMappingProperties(DEFAULT_MAPPING); }- Returns:
- Returns the default, static mapping. It may not be null.
- See Also:
-
getDefaultEmbedMapping
This method provides a best guess of what model properties should be embedded in content. The list of properties mapped by default need not include all properties to be embedded in the document; just the obvious set of mappings need be supplied. Implementations must either provide the default mapping properties in the expected location or override the method to provide the default mapping.The default implementation looks for the default mapping file in the location given by the class name and .embed.properties. If the extracter's class is x.y.z.MyExtracter then the default properties will be picked up at classpath:/x/y/z/MyExtracter.embed.properties. Inner classes are supported, but the '$' in the class name is replaced with '-', so default properties for x.y.z.MyStuff$MyExtracter will be located using x.y.z.MyStuff-MyExtracter.embed.properties.
The default mapping implementation should include thorough Javadocs so that the system administrators can accurately determine how to best enhance or override the default mapping.
If the default mapping is declared in a properties file other than the one named after the class, then the
readEmbedMappingProperties(String)method can be used to quickly generate the return value:
The map can also be created in code either statically or during the call.protected Map<<String, Set> getDefaultMapping() { return readEmbedMappingProperties(DEFAULT_MAPPING); } If no embed mapping properties file is found a reverse of the extract mapping in
getDefaultMapping()will be assumed with the first QName in each value used as the key for this mapping and a last win approach for duplicates.- Returns:
- Returns the default, static embed mapping. It may not be null.
- See Also:
-
getLimits
Gets the metadata extracter limits for the given mimetype.A specific match for the given mimetype is tried first and if none is found a wildcard of "*" is tried, if still not found defaults value will be used
- Parameters:
mimetype- String- Returns:
- the found limits or default values
-
extractRawInThread
protected Map<String,Serializable> extractRawInThread(NodeRef nodeRef, ContentReader reader, MetadataExtracterLimits limits, MetadataExtracter.OverwritePolicy policy) throws Throwable - Throws:
Throwable
-
extractRawInThread
protected Map<String,Serializable> extractRawInThread(NodeRef nodeRef, ContentReader reader, MetadataExtracterLimits limits) throws Throwable - Throws:
Throwable
-
extractRawThreadFinished
protected void extractRawThreadFinished() -
extractRaw
Override 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: -
- 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:
Throwable- All exception conditions can be handled.- See Also:
-
embedInternal
protected void embedInternal(NodeRef nodeRef, Map<String, Serializable> metadata, ContentReader reader, ContentWriter writer) throws Throwable- Throws:
Throwable
-
embedInternal
protected void embedInternal(Map<String, Serializable> metadata, ContentReader reader, ContentWriter writer) throws ThrowableOverride to embed metadata values. An extracter should embed 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.- Parameters:
metadata- the metadata keys and values to embed in the content filereader- the reader for the original document. This stream provided by the reader must be closed if accessed directly.writer- the writer for the document to embed the values in. This stream provided by the writer must be closed if accessed directly.- Throws:
Throwable- All exception conditions can be handled.- See Also:
-