magoffin.matt.ma2.image
Class BaseImageMediaHandler

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

public abstract class BaseImageMediaHandler
extends AbstractMediaHandler

Base implementation of MediaMetadata for image media types.

The DEFAULT_ORIENTATION_90_CLOCKWISE_VALUE, DEFAULT_ORIENTATION_90_COUNTER_CLOCKWISE_VALUE, and DEFAULT_ORIENTATION_180_VALUE constants are set to 8, 6, and 3 to work with EXIF camera orientation values by default.

Version:
$Revision: 177 $ $Date: 2008-12-29 09:45:55 +1300 (Mon, 29 Dec 2008) $
Author:
matt.magoffin

Field Summary
static java.lang.String DEFAULT_ORIENTATION_180_VALUE
          The default value for the orientation180 property.
static java.lang.String DEFAULT_ORIENTATION_90_CLOCKWISE_VALUE
          The default value for the orientationClockwiseValue property.
static java.lang.String DEFAULT_ORIENTATION_90_COUNTER_CLOCKWISE_VALUE
          The default value for the orientationCounterClockwiseValue property.
static java.lang.String DEFAULT_ORIENTATION_METADATA_KEY
          The default value for the orientationMetadataKey property.
static java.lang.Integer ROTATE_180
          The rotation degrees for 180 degrees.
static java.lang.Integer ROTATE_90_CCW
          The rotation degrees for 90 degrees counter-clockwise.
static java.lang.Integer ROTATE_90_CW
          The rotation degrees for 90 degrees clockwise.
 
Fields inherited from class magoffin.matt.ma2.support.AbstractMediaHandler
log, METADATA_PARAMETER_KEY
 
Constructor Summary
BaseImageMediaHandler(java.lang.String mime)
          Construct with a MIME type.
 
Method Summary
 java.lang.String getOrientation180Value()
           
 java.lang.String getOrientation90ClockwiseValue()
           
 java.lang.String getOrientation90CounterClockwiseValue()
           
 java.lang.String getOrientationMetadataKey()
           
protected  MediaMetadata handleMetadata(MediaRequest request, org.springframework.core.io.Resource mediaResource, MediaItem item)
          Extract metadata from a resource and replace item metadata with all extracted data.
protected  boolean needToRotate(MediaItem item, MediaRequest request)
          Check if rotation needs to be performed for a given media item based on the orientation metadata available in the media item.
 void setOrientation180Value(java.lang.String orientation180Value)
           
 void setOrientation90ClockwiseValue(java.lang.String orientation90ClockwiseValue)
           
 void setOrientation90CounterClockwiseValue(java.lang.String orientation90CounterClockwiseValue)
           
 void setOrientationMetadataKey(java.lang.String orientationMetadataKey)
           
 
Methods inherited from class magoffin.matt.ma2.support.AbstractMediaHandler
applyEffects, createMetadataList, defaultHandleRequestOriginal, getDomainObjectFactory, getEffect, 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
 
Methods inherited from interface magoffin.matt.ma2.MediaHandler
createNewMediaItem, handleMediaRequest
 

Field Detail

ROTATE_90_CW

public static final java.lang.Integer ROTATE_90_CW
The rotation degrees for 90 degrees clockwise.


ROTATE_90_CCW

public static final java.lang.Integer ROTATE_90_CCW
The rotation degrees for 90 degrees counter-clockwise.


ROTATE_180

public static final java.lang.Integer ROTATE_180
The rotation degrees for 180 degrees.


DEFAULT_ORIENTATION_METADATA_KEY

public static final java.lang.String DEFAULT_ORIENTATION_METADATA_KEY
The default value for the orientationMetadataKey property.

See Also:
Constant Field Values

DEFAULT_ORIENTATION_90_COUNTER_CLOCKWISE_VALUE

public static final java.lang.String DEFAULT_ORIENTATION_90_COUNTER_CLOCKWISE_VALUE
The default value for the orientationCounterClockwiseValue property.


DEFAULT_ORIENTATION_90_CLOCKWISE_VALUE

public static final java.lang.String DEFAULT_ORIENTATION_90_CLOCKWISE_VALUE
The default value for the orientationClockwiseValue property.


DEFAULT_ORIENTATION_180_VALUE

public static final java.lang.String DEFAULT_ORIENTATION_180_VALUE
The default value for the orientation180 property.

Constructor Detail

BaseImageMediaHandler

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

Parameters:
mime - the MIME
Method Detail

handleMetadata

protected MediaMetadata handleMetadata(MediaRequest request,
                                       org.springframework.core.io.Resource mediaResource,
                                       MediaItem item)
Description copied from class: AbstractMediaHandler
Extract metadata from a resource and replace item metadata with all extracted data.

This method provides a simple way to populate the Metadata list of a newly created MediaItem. It will generate the list of Metadata and then add all of them into the List returned by MediaItem.getMetadata().

This method first calls AbstractMediaHandler.getMediaMetadataInstance(MediaRequest, Resource, MediaItem) to create a new instance of MediaMetadata and then calls MediaMetadata.setMediaResource(Resource).

If MediaMetadata.getCreationDate() returns a non-null value then a new Calendar instance will be created from it and used to set the creationDate property of the MediaItem.

If the MediaMetadata is an instance of EmbeddedImageMetadata then EmbeddedImageMetadata.getEmbeddedImage() will be called, and the width/height of the returned image will be used to set the width/height properties of the MediaItem provided.

Overrides:
handleMetadata in class AbstractMediaHandler
Parameters:
request - the reqeust (may be null)
mediaResource - the media resource to extract the metadata from
item - the item to replace the extracted metadata in
Returns:
the resulting metadata instance

needToRotate

protected boolean needToRotate(MediaItem item,
                               MediaRequest request)
Check if rotation needs to be performed for a given media item based on the orientation metadata available in the media item.

This method looks in the MediaItem.getMetadata() list for a Metadata.getKey() value equal to getOrientationMetadataKey() as configured on this class.

If rotation should be applied, this method will set the MediaEffect.MEDIA_REQUEST_PARAM_ROTATE_DEGREES parameter on the MediaRequest.getParameters() map to the degrees by which the image should be rotated. This is determined by examining the Metadata.getValue() of the found orientation metadata object. If it is equal to getOrientation90ClockwiseValue() then the degrees will be set to ROTATE_90_CW. If the value is equal to getOrientation90CounterClockwiseValue() then the degrees will be set to ROTATE_90_CCW. If the value is equal to getOrientation180Value() then the degrees will be set to ROTATE_180.

Overrides:
needToRotate in class AbstractMediaHandler
Parameters:
item - the item being processed
request - the request the current request
Returns:
boolean if rotation should be applied to the image

getOrientationMetadataKey

public java.lang.String getOrientationMetadataKey()
Returns:
the orientationMetadataKey

setOrientationMetadataKey

public void setOrientationMetadataKey(java.lang.String orientationMetadataKey)
Parameters:
orientationMetadataKey - the orientationMetadataKey to set

getOrientation90CounterClockwiseValue

public java.lang.String getOrientation90CounterClockwiseValue()
Returns:
the orientation90CounterClockwiseValue

setOrientation90CounterClockwiseValue

public void setOrientation90CounterClockwiseValue(java.lang.String orientation90CounterClockwiseValue)
Parameters:
orientation90CounterClockwiseValue - the orientation90CounterClockwiseValue to set

getOrientation90ClockwiseValue

public java.lang.String getOrientation90ClockwiseValue()
Returns:
the orientation90ClockwiseValue

setOrientation90ClockwiseValue

public void setOrientation90ClockwiseValue(java.lang.String orientation90ClockwiseValue)
Parameters:
orientation90ClockwiseValue - the orientation90ClockwiseValue to set

getOrientation180Value

public java.lang.String getOrientation180Value()
Returns:
the orientation180Value

setOrientation180Value

public void setOrientation180Value(java.lang.String orientation180Value)
Parameters:
orientation180Value - the orientation180Value to set