org.alfresco.repo.content.transform
Class AbstractContentTransformer2

java.lang.Object
  extended by org.alfresco.repo.content.transform.AbstractContentTransformer2
All Implemented Interfaces:
ContentWorker, ContentTransformer
Direct Known Subclasses:
AbstractImageMagickContentTransformer, BinaryPassThroughContentTransformer, ComplexContentTransformer, HtmlParserContentTransformer, MailContentTransformer, MediaWikiContentTransformer, OpenOfficeContentTransformer, PdfBoxContentTransformer, PdfToImageContentTransformer, PDFToSWFContentTransformer, PoiHssfContentTransformer, RuntimeExecutableContentTransformer, StringExtractingContentTransformer, TextMiningContentTransformer, TextToPdfContentTransformer

public abstract class AbstractContentTransformer2
extends java.lang.Object
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(ContentReader reader, ContentWriter writer, TransformationOptions options)
          Convenience method to check the transformability of a transformation
protected  java.lang.String getMimetype(ContentAccessor content)
          Convenience to fetch and check the mimetype for the given content
protected  MimetypeService getMimetypeService()
           
 long getTransformationTime()
          Provides an estimate, usually a worst case guess, of how long a transformation will take.
 boolean isExplicitTransformation(java.lang.String sourceMimetype, java.lang.String targetMimetype, TransformationOptions options)
          Default implementation, override if need to extend logic
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 setExplicitTransformations(java.util.List explicitTransformations)
           
 void setMimetypeService(MimetypeService mimetypeService)
          Helper setter of the mimetype service.
 void setRegistry(ContentTransformerRegistry registry)
          The registry to auto-register with
 java.lang.String toString()
           
 void transform(ContentReader reader, ContentWriter writer)
           
 void transform(ContentReader reader, ContentWriter writer, java.util.Map options)
          Transforms the content provided by the reader and source mimetype to the writer and target mimetype.
 void transform(ContentReader reader, 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(ContentReader reader, 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 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.alfresco.repo.content.transform.ContentTransformer
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

setMimetypeService

public void setMimetypeService(MimetypeService mimetypeService)
Helper setter of the mimetype service. This is not always required.

Parameters:
mimetypeService -

getMimetypeService

protected MimetypeService getMimetypeService()
Returns:
Returns the mimetype helper

setExplicitTransformations

public void setExplicitTransformations(java.util.List explicitTransformations)

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.


getMimetype

protected java.lang.String getMimetype(ContentAccessor content)
Convenience to fetch and check the mimetype for the given content

Parameters:
content - the reader/writer for the content
Returns:
Returns the mimetype for the content
Throws:
org.alfresco.error.AlfrescoRuntimeException - if the content doesn't have a mimetype

checkTransformable

protected void checkTransformable(ContentReader reader,
                                  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(ContentReader reader,
                                          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(ContentReader reader,
                            ContentWriter writer)
                     throws ContentIOException
Specified by:
transform in interface ContentTransformer
Throws:
ContentIOException
See Also:
AbstractContentTransformer2.transform(ContentReader, ContentWriter, Map), #transformInternal(ContentReader, ContentWriter, Map)

transform

public final void transform(ContentReader reader,
                            ContentWriter writer,
                            TransformationOptions options)
                     throws 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:
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(ContentReader reader,
                            ContentWriter writer,
                            java.util.Map options)
                     throws 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:
ContentIOException - if an IO exception occurs

isExplicitTransformation

public boolean isExplicitTransformation(java.lang.String sourceMimetype,
                                        java.lang.String targetMimetype,
                                        TransformationOptions options)
Default implementation, override if need to extend logic

Specified by:
isExplicitTransformation in interface ContentTransformer
Parameters:
sourceMimetype - the source mimetype
targetMimetype - the target mimetype
options - the transformation options
Returns:
boolean true if it is an explicit transformation, flase otherwise
See Also:
ContentTransformer.isExplicitTransformation(java.lang.String, java.lang.String, org.alfresco.service.cmr.repository.TransformationOptions)

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 - 2008 Alfresco Software, Inc. All Rights Reserved.