Class TikaPoweredContentTransformer
- java.lang.Object
-
- org.alfresco.repo.content.transform.ContentTransformerHelper
-
- org.alfresco.repo.content.transform.AbstractContentTransformerLimits
-
- org.alfresco.repo.content.transform.AbstractContentTransformer2
-
- org.alfresco.repo.content.transform.TikaPoweredContentTransformer
-
- All Implemented Interfaces:
ContentWorker,ContentTransformer,org.springframework.beans.factory.Aware,org.springframework.beans.factory.BeanNameAware
- Direct Known Subclasses:
ArchiveContentTransformer,MailContentTransformer,PdfBoxContentTransformer,PoiContentTransformer,PoiHssfContentTransformer,PoiOOXMLContentTransformer,TextMiningContentTransformer,TikaAutoContentTransformer,TikaSpringConfiguredContentTransformer
public abstract class TikaPoweredContentTransformer extends AbstractContentTransformer2
Provides helpful services forContentTransformerimplementations which are powered by Apache Tika. To use Tika to transform some content into Text, Html or XML, create an implementation of this / use the Auto Detect transformer. For now, all transformers are registered as regular, rather than explicit transformations. This should allow you to register your own explicit transformers and have them nicely take priority.- Author:
- Nick Burch
-
-
Field Summary
Fields Modifier and Type Field Description protected org.apache.tika.extractor.DocumentSelectordocumentSelectorprotected static java.lang.StringLINE_BREAKWindows carriage return line feed pair.protected java.util.List<java.lang.String>sourceMimeTypesstatic java.lang.StringWRONG_FORMAT_MESSAGE_ID-
Fields inherited from class org.alfresco.repo.content.transform.AbstractContentTransformerLimits
transformerDebug
-
Fields inherited from class org.alfresco.repo.content.transform.ContentTransformerHelper
transformerConfig
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedTikaPoweredContentTransformer(java.lang.String[] sourceMimeTypes)protectedTikaPoweredContentTransformer(java.util.List<java.lang.String> sourceMimeTypes)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected org.apache.tika.parser.ParseContextbuildParseContext(org.apache.tika.metadata.Metadata metadata, java.lang.String targetMimeType, TransformationOptions options)By default returns a ParseContent that does not recursejava.lang.StringgetComments(boolean available)Overridden to supply a comment or String of commented out transformation properties that specify any (hard coded or implied) supported transformations.protected org.xml.sax.ContentHandlergetContentHandler(java.lang.String targetMimeType, java.io.Writer output)Returns an appropriate Tika ContentHandler for the requested content type.protected org.apache.tika.extractor.DocumentSelectorgetDocumentSelector(org.apache.tika.metadata.Metadata metadata, java.lang.String targetMimeType, TransformationOptions options)Gets the document selector, used for determining whether to parse embedded resources, null by default so parse all.protected abstract org.apache.tika.parser.ParsergetParser()Returns the correct Tika Parser to process the document.booleanisTransformableMimetype(java.lang.String sourceMimetype, java.lang.String targetMimetype, TransformationOptions options)Can we do the requested transformation via Tika? We support transforming to HTML, XML or TextvoidsetDocumentSelector(org.apache.tika.extractor.DocumentSelector documentSelector)Sets the document selector, used for determining whether to parse embedded resources.voidtransformInternal(org.alfresco.service.cmr.repository.ContentReader reader, org.alfresco.service.cmr.repository.ContentWriter writer, TransformationOptions options)Method to be implemented by subclasses wishing to make use of the common infrastructural code provided by this class.-
Methods inherited from class org.alfresco.repo.content.transform.AbstractContentTransformer2
checkTransformable, getExecutorService, getRetryTransformOnDifferentMimeType, getStrictMimeTypeCheck, getTransformationTime, getTransformationTime, isTransformationLimitedInternally, recordError, recordTime, recordTime, register, setAdditionalThreadTimout, setExecutorService, setRegisterTransformer, setRegistry, setRetryTransformOnDifferentMimeType, setStrictMimeTypeCheck, setUseTimeoutThread, toString, transform, transform, transform
-
Methods inherited from class org.alfresco.repo.content.transform.AbstractContentTransformerLimits
getLimits, getLimits, getLimits, getMaxPages, getMaxSourceSizeKBytes, getMaxSourceSizeKBytes, getPageLimit, getReadLimitKBytes, getReadLimitTimeMs, getTimeoutMs, isPageLimitSupported, isTransformable, isTransformable, isTransformableSize, setLimits, setMaxPages, setMaxSourceSizeKBytes, setMimetypeLimits, setPageLimit, setPageLimitsSupported, setReaderLimits, setReadLimitKBytes, setReadLimitTimeMs, setTimeoutMs, setTransformerDebug
-
Methods inherited from class org.alfresco.repo.content.transform.ContentTransformerHelper
deprecatedSetter, equals, getBeanName, getCommentsOnlySupports, getExtensionOrAny, getMimetype, getMimetypeService, getName, getSimpleName, hashCode, isExplicitTransformation, isSupportedTransformation, onlySupports, setBeanName, setExplicitTransformations, setMimetypeService, setSupportedTransformations, setTransformerConfig, setUnsupportedTransformations
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.alfresco.repo.content.transform.ContentTransformer
getName, isExplicitTransformation
-
-
-
-
Field Detail
-
sourceMimeTypes
protected java.util.List<java.lang.String> sourceMimeTypes
-
documentSelector
protected org.apache.tika.extractor.DocumentSelector documentSelector
-
LINE_BREAK
protected static final java.lang.String LINE_BREAK
Windows carriage return line feed pair.- See Also:
- Constant Field Values
-
WRONG_FORMAT_MESSAGE_ID
public static final java.lang.String WRONG_FORMAT_MESSAGE_ID
- See Also:
- Constant Field Values
-
-
Method Detail
-
getParser
protected abstract org.apache.tika.parser.Parser getParser()
Returns the correct Tika Parser to process the document. If you don't know which you want, useTikaAutoContentTransformerwhich makes use of the Tika auto-detection.
-
isTransformableMimetype
public boolean isTransformableMimetype(java.lang.String sourceMimetype, java.lang.String targetMimetype, TransformationOptions options)Can we do the requested transformation via Tika? We support transforming to HTML, XML or Text- Specified by:
isTransformableMimetypein interfaceContentTransformer- Overrides:
isTransformableMimetypein classAbstractContentTransformerLimits- Parameters:
sourceMimetype- the source mimetypetargetMimetype- the target mimetypeoptions- the transformation options- Returns:
- boolean true if this content transformer can satify the mimetypes, false otherwise
-
getComments
public java.lang.String getComments(boolean available)
Description copied from class:ContentTransformerHelperOverridden to supply a comment or String of commented out transformation properties that specify any (hard coded or implied) supported transformations. Used when providing a list of properties to an administrators who may be setting other transformation properties, via JMX. Consider overriding if {linkAbstractContentTransformerLimits.isTransformableMimetype(String, String, TransformationOptions)orContentTransformerWorker.isTransformable(String, String, TransformationOptions)have been overridden. SeeContentTransformerHelper.getCommentsOnlySupports(List, List, boolean)which may be used to help construct a comment.- Specified by:
getCommentsin interfaceContentTransformer- Overrides:
getCommentsin classContentTransformerHelper- Parameters:
available- indicates if the transformer has been registered and is available to be selected.falseindicates that the transformer is only available as a component of a complex transformer.- Returns:
- one line per property. The simple transformer name is returned by default as a comment.
-
getContentHandler
protected org.xml.sax.ContentHandler getContentHandler(java.lang.String targetMimeType, java.io.Writer output) throws javax.xml.transform.TransformerConfigurationExceptionReturns an appropriate Tika ContentHandler for the requested content type. Normally you'll let this work as default, but if you need fine-grained control of how the Tika events become text then override and supply your own.- Throws:
javax.xml.transform.TransformerConfigurationException
-
setDocumentSelector
public void setDocumentSelector(org.apache.tika.extractor.DocumentSelector documentSelector)
Sets the document selector, used for determining whether to parse embedded resources.- Parameters:
documentSelector- DocumentSelector
-
getDocumentSelector
protected org.apache.tika.extractor.DocumentSelector getDocumentSelector(org.apache.tika.metadata.Metadata metadata, java.lang.String targetMimeType, TransformationOptions options)Gets the document selector, used for determining whether to parse embedded resources, null by default so parse all.- Parameters:
metadata- MetadatatargetMimeType- Stringoptions- TransformationOptions- Returns:
- the document selector
-
buildParseContext
protected org.apache.tika.parser.ParseContext buildParseContext(org.apache.tika.metadata.Metadata metadata, java.lang.String targetMimeType, TransformationOptions options)By default returns a ParseContent that does not recurse
-
transformInternal
public void transformInternal(org.alfresco.service.cmr.repository.ContentReader reader, org.alfresco.service.cmr.repository.ContentWriter writer, TransformationOptions options) throws java.lang.ExceptionDescription copied from class:AbstractContentTransformer2Method to be implemented by subclasses wishing to make use of the common infrastructural code provided by this class.- Specified by:
transformInternalin classAbstractContentTransformer2- Parameters:
reader- the source of the content to transformwriter- the target to which to write the transformed contentoptions- a map of options to use when performing the transformation. The map will never be null.- Throws:
java.lang.Exception- exceptions will be handled by this class - subclasses can throw anything
-
-