org.alfresco.repo.content.transform
Class AbstractContentTransformer2

java.lang.Object
  extended by org.alfresco.repo.content.transform.ContentTransformerHelper
      extended by org.alfresco.repo.content.transform.AbstractContentTransformer2
All Implemented Interfaces:
ContentWorker, ContentTransformer
Direct Known Subclasses:
AppleIWorksContentTransformer, BinaryPassThroughContentTransformer, ComplexContentTransformer, EMLTransformer, FailoverContentTransformer, HtmlParserContentTransformer, MediaWikiContentTransformer, PdfBoxPdfToImageContentTransformer, PdfToImageContentTransformer, ProxyContentTransformer, StringExtractingContentTransformer, TextToPdfContentTransformer, TikaPoweredContentTransformer

public abstract class AbstractContentTransformer2
extends ContentTransformerHelper
implements ContentTransformer

Provides basic services for ContentTransformer implementations.

This class maintains the performance measures for the transformers as well, making sure that there is an extra penalty for transformers that fail regularly.


Constructor Summary
protected AbstractContentTransformer2()
          All transformers start with an average transformation time of 0.0ms.
 
Method Summary
protected  void checkTransformable(org.alfresco.service.cmr.repository.ContentReader reader, org.alfresco.service.cmr.repository.ContentWriter writer, TransformationOptions options)
          Convenience method to check the transformability of a transformation
 long getTransformationTime()
          Provides an estimate, usually a worst case guess, of how long a transformation will take.
protected  void recordTime(long transformationTime)
          Records and updates the average transformation time for this transformer.
 void register()
          Registers this instance with the registry if it is present.
 void setRegistry(ContentTransformerRegistry registry)
          The registry to auto-register with
 java.lang.String toString()
           
 void transform(org.alfresco.service.cmr.repository.ContentReader reader, org.alfresco.service.cmr.repository.ContentWriter writer)
           
 void transform(org.alfresco.service.cmr.repository.ContentReader reader, org.alfresco.service.cmr.repository.ContentWriter writer, java.util.Map options)
          Transforms the content provided by the reader and source mimetype to the writer and target mimetype.
 void transform(org.alfresco.service.cmr.repository.ContentReader reader, org.alfresco.service.cmr.repository.ContentWriter writer, TransformationOptions options)
          Transforms the content provided by the reader and source mimetype to the writer and target mimetype with the provided transformation options.
protected abstract  void transformInternal(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.ContentTransformerHelper
getMimetype, getMimetypeService, isExplicitTransformation, setExplicitTransformations, setMimetypeService
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.alfresco.repo.content.transform.ContentTransformer
isExplicitTransformation, isTransformable
 

Constructor Detail

AbstractContentTransformer2

protected AbstractContentTransformer2()
All transformers start with an average transformation time of 0.0ms.

Method Detail

setRegistry

public void setRegistry(ContentTransformerRegistry registry)
The registry to auto-register with

Parameters:
registry - the transformer registry

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

register

public void register()
Registers this instance with the registry if it is present.


checkTransformable

protected void checkTransformable(org.alfresco.service.cmr.repository.ContentReader reader,
                                  org.alfresco.service.cmr.repository.ContentWriter writer,
                                  TransformationOptions options)
Convenience method to check the transformability of a transformation

Parameters:
reader - content reader
writer - content writer
options - transformation options
Throws:
org.alfresco.error.AlfrescoRuntimeException - if the the transformation isn't supported

transformInternal

protected abstract void transformInternal(org.alfresco.service.cmr.repository.ContentReader reader,
                                          org.alfresco.service.cmr.repository.ContentWriter writer,
                                          TransformationOptions options)
                                   throws java.lang.Exception
Method to be implemented by subclasses wishing to make use of the common infrastructural code provided by this class.

Parameters:
reader - the source of the content to transform
writer - the target to which to write the transformed content
options - 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

transform

public final void transform(org.alfresco.service.cmr.repository.ContentReader reader,
                            org.alfresco.service.cmr.repository.ContentWriter writer)
                     throws org.alfresco.service.cmr.repository.ContentIOException
Specified by:
transform in interface ContentTransformer
Throws:
org.alfresco.service.cmr.repository.ContentIOException
See Also:
AbstractContentTransformer2.transform(ContentReader, ContentWriter, Map), #transformInternal(ContentReader, ContentWriter, Map)

transform

public final void transform(org.alfresco.service.cmr.repository.ContentReader reader,
                            org.alfresco.service.cmr.repository.ContentWriter writer,
                            TransformationOptions options)
                     throws org.alfresco.service.cmr.repository.ContentIOException
Description copied from interface: ContentTransformer
Transforms the content provided by the reader and source mimetype to the writer and target mimetype with the provided transformation options.

The transformation viability can be determined by an up front call to ContentTransformer.isTransformable(String, String, TransformationOptions).

The source and target mimetypes must be available on the ContentAccessor.getMimetype() methods of both the reader and the writer.

Both reader and writer will be closed after the transformation completes.

The provided options can be null.

Specified by:
transform in interface ContentTransformer
Parameters:
reader - the source of the content
writer - the destination of the transformed content
options - transformation options, these can be null
Throws:
org.alfresco.service.cmr.repository.ContentIOException - if an IO exception occurs
See Also:
ContentTransformer.transform(org.alfresco.service.cmr.repository.ContentReader, org.alfresco.service.cmr.repository.ContentWriter, org.alfresco.service.cmr.repository.TransformationOptions)

transform

public final void transform(org.alfresco.service.cmr.repository.ContentReader reader,
                            org.alfresco.service.cmr.repository.ContentWriter writer,
                            java.util.Map options)
                     throws org.alfresco.service.cmr.repository.ContentIOException
Description copied from interface: ContentTransformer
Transforms the content provided by the reader and source mimetype to the writer and target mimetype.

The transformation viability can be determined by an up front call to #getReliability(String, String).

The source and target mimetypes must be available on the ContentAccessor.getMimetype() methods of both the reader and the writer.

Both reader and writer will be closed after the transformation completes.

Specified by:
transform in interface ContentTransformer
Parameters:
reader - the source of the content
writer - the destination of the transformed content
options - options to pass to the transformer. These are transformer dependent and may be null.
Throws:
org.alfresco.service.cmr.repository.ContentIOException - if an IO exception occurs

getTransformationTime

public long getTransformationTime()
Description copied from interface: ContentTransformer
Provides an estimate, usually a worst case guess, of how long a transformation will take.

This method is used to determine, up front, which of a set of equally reliant transformers will be used for a specific transformation.

Specified by:
getTransformationTime in interface ContentTransformer
Returns:
Returns the calculated running average of the current transformations

recordTime

protected final void recordTime(long transformationTime)
Records and updates the average transformation time for this transformer.

Subclasses should call this after every transformation in order to keep the running average of the transformation times up to date.

This method is thread-safe. The time spent in this method is negligible so the impact will be minor.

Parameters:
transformationTime - the time it took to perform the transformation. The value may be 0.


Copyright © 2005 - 2010 Alfresco Software, Inc. All Rights Reserved.