magoffin.matt.ma2.image.jmagick
Class BaseJMagickMediaHandler

java.lang.Object
  extended by magoffin.matt.ma2.support.AbstractMediaHandler
      extended by magoffin.matt.ma2.image.BaseImageMediaHandler
          extended by magoffin.matt.ma2.image.jmagick.BaseJMagickMediaHandler
All Implemented Interfaces:
MediaHandler
Direct Known Subclasses:
JpegMediaHandler

public abstract class BaseJMagickMediaHandler
extends BaseImageMediaHandler

Base implementation of MediaHandler that uses the JMagick for image processing.

The configurable properties of this class are:

outputDepth
Force the otuput depth to a specific value. Defaults to 8.
jmagickMediaEffectMap
A Map of effect keys to JMagickMediaEffect implementations.

Version:
$Revision: 176 $ $Date: 2008-12-28 14:33:18 +1300 (Sun, 28 Dec 2008) $
Author:
Matt Magoffin (spamsqr@msqr.us)

Field Summary
static int DEFAULT_OUTPUT_DEPTH
          The default value for the outputDepth property.
 
Fields inherited from class magoffin.matt.ma2.image.BaseImageMediaHandler
DEFAULT_ORIENTATION_180_VALUE, DEFAULT_ORIENTATION_90_CLOCKWISE_VALUE, DEFAULT_ORIENTATION_90_COUNTER_CLOCKWISE_VALUE, DEFAULT_ORIENTATION_METADATA_KEY, ROTATE_180, ROTATE_90_CCW, ROTATE_90_CW
 
Fields inherited from class magoffin.matt.ma2.support.AbstractMediaHandler
log, METADATA_PARAMETER_KEY
 
Constructor Summary
BaseJMagickMediaHandler(java.lang.String mime)
          Construct with a MIME type.
 
Method Summary
 MediaItem createNewMediaItem(java.io.File inputFile)
          Basic JMagick implementation of createNewMediaItem.
protected  void defaultHandleRequest(MediaItem item, MediaRequest request, MediaResponse response)
          Default handler for JMagick requests.
protected  void defaultHandleResource(MediaItem item, MediaRequest request, MediaResponse response, org.springframework.core.io.Resource itemResource)
          Default handler for JMagick resource request.
 MediaEffect getEffect(java.lang.String key, java.util.Map<java.lang.String,?> effectParameters)
          Get a MediaEffect instance for a specific key.
 java.util.Map<java.lang.String,JMagickMediaEffect> getJmagickMediaEffectMap()
           
 int getOutputDepth()
           
protected  java.lang.String getResponseMime(MediaItem item, MediaRequest request, org.springframework.core.io.Resource itemResource)
          Get the MIME type to set in the response.
 void handleMediaRequest(MediaItem item, MediaRequest request, MediaResponse response)
          Basic JMagick implementation of handleMediaRequest.
 void setJmagickMediaEffectMap(java.util.Map<java.lang.String,JMagickMediaEffect> jmagickMediaEffectMap)
           
 void setOutputDepth(int outputDepth)
           
protected  void setupBaseItemProperties(MediaItem item, magick.ImageInfo info)
          Setup some basic properties from an ImageReader.
 
Methods inherited from class magoffin.matt.ma2.image.BaseImageMediaHandler
getOrientation180Value, getOrientation90ClockwiseValue, getOrientation90CounterClockwiseValue, getOrientationMetadataKey, handleMetadata, needToRotate, setOrientation180Value, setOrientation90ClockwiseValue, setOrientation90CounterClockwiseValue, setOrientationMetadataKey
 
Methods inherited from class magoffin.matt.ma2.support.AbstractMediaHandler
applyEffects, createMetadataList, defaultHandleRequestOriginal, getDomainObjectFactory, getFileExtension, getMediaBiz, getMediaMetadataInstance, getMime, getNoWatermarkSizes, getPreferredFileExtension, getRequestEffects, getSmetaPropertyMap, getUserBiz, needToAlter, setDomainObjectFactory, setMediaBiz, setMime, setNoWatermarkSizes, setPreferredFileExtension, setSmetaPropertyMap, setUserBiz
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_OUTPUT_DEPTH

public static final int DEFAULT_OUTPUT_DEPTH
The default value for the outputDepth property.

See Also:
Constant Field Values
Constructor Detail

BaseJMagickMediaHandler

public BaseJMagickMediaHandler(java.lang.String mime)
Construct with a MIME type.

Parameters:
mime - the MIME type
Method Detail

getEffect

public MediaEffect getEffect(java.lang.String key,
                             java.util.Map<java.lang.String,?> effectParameters)
Description copied from interface: MediaHandler
Get a MediaEffect instance for a specific key.

Implementaions must define the keys they support, and define the parameters that go with it.

Specified by:
getEffect in interface MediaHandler
Overrides:
getEffect in class AbstractMediaHandler
Parameters:
key - the key of the desired effect
effectParameters - a Map of parameters (optional)
Returns:
a MediaEffect instance

getJmagickMediaEffectMap

public java.util.Map<java.lang.String,JMagickMediaEffect> getJmagickMediaEffectMap()
Returns:
the jmagickMediaEffectMap

setJmagickMediaEffectMap

public void setJmagickMediaEffectMap(java.util.Map<java.lang.String,JMagickMediaEffect> jmagickMediaEffectMap)
Parameters:
jmagickMediaEffectMap - the jmagickMediaEffectMap to set

createNewMediaItem

public MediaItem createNewMediaItem(java.io.File inputFile)
Basic JMagick implementation of createNewMediaItem.

This implementation creates a new MediaItem instance and then calls setupBaseItemProperties(MediaItem, ImageInfo) followed by BaseImageMediaHandler.handleMetadata(MediaRequest, Resource, MediaItem).

Parameters:
inputFile - the file to create the media item from
Returns:
an instance of MediaItem

handleMediaRequest

public void handleMediaRequest(MediaItem item,
                               MediaRequest request,
                               MediaResponse response)
Basic JMagick implementation of handleMediaRequest.

This implementation simply calls defaultHandleRequest(MediaItem, MediaRequest, MediaResponse).

Parameters:
item - the media item to process
request - the request
response - the response

setupBaseItemProperties

protected void setupBaseItemProperties(MediaItem item,
                                       magick.ImageInfo info)
                                throws magick.MagickException
Setup some basic properties from an ImageReader.

This will set up the item's width, height, and MIME type.

Parameters:
item - the MediaItem to setup
info - the JMagick image
Throws:
magick.MagickException - if a JMagick error occurs

defaultHandleRequest

protected void defaultHandleRequest(MediaItem item,
                                    MediaRequest request,
                                    MediaResponse response)
Default handler for JMagick requests.

This implementation gets a Resource via MediaBiz.getMediaItemResource(MediaItem) and passes that to defaultHandleResource(MediaItem, MediaRequest, MediaResponse, Resource).

Parameters:
item - the item
request - the request
response - the response

getResponseMime

protected java.lang.String getResponseMime(MediaItem item,
                                           MediaRequest request,
                                           org.springframework.core.io.Resource itemResource)
Get the MIME type to set in the response.

This implementation merely calls AbstractMediaHandler.getMime() but extending classes may need to override this.

Parameters:
item - the MediaItem being processed
request - the request
itemResource - the item resource being processed
Returns:
MIME

defaultHandleResource

protected void defaultHandleResource(MediaItem item,
                                     MediaRequest request,
                                     MediaResponse response,
                                     org.springframework.core.io.Resource itemResource)
Default handler for JMagick resource request.

This can be used to service MediaHandlerDelegate requests, if extending classes wish to support that API.

Parameters:
item - the item
request - the request
response - the response
itemResource - the media resource being operated on

getOutputDepth

public int getOutputDepth()
Returns:
the outputDepth

setOutputDepth

public void setOutputDepth(int outputDepth)
Parameters:
outputDepth - the outputDepth to set