org.opencms.loader
Class CmsImageLoader

java.lang.Object
  extended byorg.opencms.loader.CmsDumpLoader
      extended byorg.opencms.loader.CmsImageLoader
All Implemented Interfaces:
I_CmsConfigurationParameterHandler, I_CmsResourceLoader

public class CmsImageLoader
extends CmsDumpLoader

Loader for images from the OpenCms VSF with integrated image scaling and processing capabilites.

To scale or process an image, the parameter CmsImageScaler.PARAM_SCALE has to be appended to the image URI. The value for the parameter needs to be composed from the SCALE_PARAM options provided by the constants in the CmsResourceTypeImage class.

For example, to scale an image to exact 800x600 pixel with center fitting and a background color of grey, the following parameter String can be used: w:800,h:600,t:0,c:c0c0c0.

Since:
6.2.0
Version:
$Revision: 1.8 $
Author:
Alexander Kandzior

Field Summary
static java.lang.String CONFIGURATION_DOWNSCALE
          The configuration parameter for the OpenCms XML configuration to set the image downscale operation.
static java.lang.String CONFIGURATION_IMAGE_FOLDER
          The configuration parameter for the OpenCms XML configuration to set the image cache respository.
static java.lang.String CONFIGURATION_MAX_BLUR_SIZE
          The configuration parameter for the OpenCms XML configuration to set the maximum image blur size.
static java.lang.String CONFIGURATION_MAX_SCALE_SIZE
          The configuration parameter for the OpenCms XML configuration to set the maximum image scale size.
static java.lang.String CONFIGURATION_SCALING_ENABLED
          The configuration parameter for the OpenCms XML configuration to enable the image scaling.
static java.lang.String IMAGE_REPOSITORY_DEFAULT
          Default name for the image cache repository.
protected static org.apache.commons.logging.Log LOG
          The log object for this class.
protected  java.lang.String m_imageRepositoryFolder
          The name of the configured image cache repository.
protected  int m_maxScaleSize
          The maximum image size (width or height) to allow when upscaling an image using request parameters.
static int RESOURCE_LOADER_ID_IMAGE_LOADER
          The id of this loader.
 
Fields inherited from class org.opencms.loader.CmsDumpLoader
RESOURCE_LOADER_ID
 
Fields inherited from interface org.opencms.loader.I_CmsResourceLoader
PARAMETER_ELEMENT
 
Fields inherited from interface org.opencms.configuration.I_CmsConfigurationParameterHandler
ADD_PARAMETER_METHOD, INIT_CONFIGURATION_METHOD
 
Constructor Summary
CmsImageLoader()
          Creates a new image loader.
 
Method Summary
 void addConfigurationParameter(java.lang.String paramName, java.lang.String paramValue)
          Adds a configuration parameter to this parameter configurable class instance.
 void destroy()
          Destroy this ResourceLoder, this is a NOOP so far.
 java.util.Map getConfiguration()
          Will always return null since this loader does not need to be configured.
static java.lang.String getDownScaleParams()
          Returns the image downscale paramerters, which is set with the CONFIGURATION_DOWNSCALE configuration option.
static java.lang.String getImageRepositoryPath()
          Returns the path of the image cache repository folder in the RFS, which is set with the CONFIGURATION_IMAGE_FOLDER configuration option.
 int getLoaderId()
          Returns the id of the ResourceLoader.
static int getMaxBlurSize()
          The maximum blur size for image rescale operations, which is set with the CONFIGURATION_MAX_BLUR_SIZE configuration option.
protected  CmsFile getScaledImage(CmsObject cms, CmsResource resource, CmsImageScaler scaler)
          Returns a scaled version of the given OpenCms VFS image resource.
 void initConfiguration()
          Initializes a configuration after all parameters have been added.
static boolean isEnabled()
          Returns true if the image scaling and processing capablities for the OpenCms VFS images have been enabled, false if not.
 void load(CmsObject cms, CmsResource resource, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)
          Basic top-page processing method for a I_CmsResourceLoader, this method is called if the page is called as a sub-element on a page not already loded with a I_CmsResourceLoader.
 
Methods inherited from class org.opencms.loader.CmsDumpLoader
canSendLastModifiedHeader, dump, export, getResourceLoaderInfo, isStaticExportEnabled, isStaticExportProcessable, isUsableForTemplates, isUsingUriWhenLoadingTemplate, service
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CONFIGURATION_DOWNSCALE

public static final java.lang.String CONFIGURATION_DOWNSCALE
The configuration parameter for the OpenCms XML configuration to set the image downscale operation.

See Also:
Constant Field Values

CONFIGURATION_IMAGE_FOLDER

public static final java.lang.String CONFIGURATION_IMAGE_FOLDER
The configuration parameter for the OpenCms XML configuration to set the image cache respository.

See Also:
Constant Field Values

CONFIGURATION_MAX_BLUR_SIZE

public static final java.lang.String CONFIGURATION_MAX_BLUR_SIZE
The configuration parameter for the OpenCms XML configuration to set the maximum image blur size.

See Also:
Constant Field Values

CONFIGURATION_MAX_SCALE_SIZE

public static final java.lang.String CONFIGURATION_MAX_SCALE_SIZE
The configuration parameter for the OpenCms XML configuration to set the maximum image scale size.

See Also:
Constant Field Values

CONFIGURATION_SCALING_ENABLED

public static final java.lang.String CONFIGURATION_SCALING_ENABLED
The configuration parameter for the OpenCms XML configuration to enable the image scaling.

See Also:
Constant Field Values

IMAGE_REPOSITORY_DEFAULT

public static final java.lang.String IMAGE_REPOSITORY_DEFAULT
Default name for the image cache repository.

See Also:
Constant Field Values

RESOURCE_LOADER_ID_IMAGE_LOADER

public static final int RESOURCE_LOADER_ID_IMAGE_LOADER
The id of this loader.

See Also:
Constant Field Values

LOG

protected static final org.apache.commons.logging.Log LOG
The log object for this class.


m_imageRepositoryFolder

protected java.lang.String m_imageRepositoryFolder
The name of the configured image cache repository.


m_maxScaleSize

protected int m_maxScaleSize
The maximum image size (width or height) to allow when upscaling an image using request parameters.

Constructor Detail

CmsImageLoader

public CmsImageLoader()
Creates a new image loader.

Method Detail

getDownScaleParams

public static java.lang.String getDownScaleParams()
Returns the image downscale paramerters, which is set with the CONFIGURATION_DOWNSCALE configuration option.

If no downscale parameters have been set in the configuration, this will return null.

Returns:
the image downscale paramerters

getImageRepositoryPath

public static java.lang.String getImageRepositoryPath()
Returns the path of the image cache repository folder in the RFS, which is set with the CONFIGURATION_IMAGE_FOLDER configuration option.

Returns:
the path of the image cache repository folder in the RFS

getMaxBlurSize

public static int getMaxBlurSize()
The maximum blur size for image rescale operations, which is set with the CONFIGURATION_MAX_BLUR_SIZE configuration option.

The default is 2500 * 2500 pixel.

Returns:
the maximum blur size for image rescale operations

isEnabled

public static boolean isEnabled()
Returns true if the image scaling and processing capablities for the OpenCms VFS images have been enabled, false if not.

Image scaling is enabled by setting the loader parameter image.scaling.enabled to the value true in the configuration file opencms-vfs.xml.

Enabling image processing in OpenCms may require several additional configuration steps on the server running OpenCms, especially in UNIX systems. Here it is often required to have an X window server configured and accessible so that the required Java ImageIO operations work. Therefore the image scaling capablities in OpenCms are disabled by default.

Returns:
true if the image scaling and processing capablities for the OpenCms VFS images have been enabled

addConfigurationParameter

public void addConfigurationParameter(java.lang.String paramName,
                                      java.lang.String paramValue)
Description copied from interface: I_CmsConfigurationParameterHandler
Adds a configuration parameter to this parameter configurable class instance.

Specified by:
addConfigurationParameter in interface I_CmsConfigurationParameterHandler
Overrides:
addConfigurationParameter in class CmsDumpLoader
See Also:
I_CmsConfigurationParameterHandler.addConfigurationParameter(java.lang.String, java.lang.String)

destroy

public void destroy()
Description copied from class: CmsDumpLoader
Destroy this ResourceLoder, this is a NOOP so far.

Specified by:
destroy in interface I_CmsResourceLoader
Overrides:
destroy in class CmsDumpLoader
See Also:
I_CmsResourceLoader.destroy()

getConfiguration

public java.util.Map getConfiguration()
Description copied from class: CmsDumpLoader
Will always return null since this loader does not need to be configured.

Specified by:
getConfiguration in interface I_CmsConfigurationParameterHandler
Overrides:
getConfiguration in class CmsDumpLoader
See Also:
I_CmsConfigurationParameterHandler.getConfiguration()

getLoaderId

public int getLoaderId()
Description copied from interface: I_CmsResourceLoader
Returns the id of the ResourceLoader.

Specified by:
getLoaderId in interface I_CmsResourceLoader
Overrides:
getLoaderId in class CmsDumpLoader
See Also:
I_CmsResourceLoader.getLoaderId()

initConfiguration

public void initConfiguration()
Description copied from interface: I_CmsConfigurationParameterHandler
Initializes a configuration after all parameters have been added.

Specified by:
initConfiguration in interface I_CmsConfigurationParameterHandler
Overrides:
initConfiguration in class CmsDumpLoader
See Also:
I_CmsConfigurationParameterHandler.initConfiguration()

load

public void load(CmsObject cms,
                 CmsResource resource,
                 javax.servlet.http.HttpServletRequest req,
                 javax.servlet.http.HttpServletResponse res)
          throws java.io.IOException,
                 CmsException
Description copied from interface: I_CmsResourceLoader
Basic top-page processing method for a I_CmsResourceLoader, this method is called if the page is called as a sub-element on a page not already loded with a I_CmsResourceLoader.

Specified by:
load in interface I_CmsResourceLoader
Overrides:
load in class CmsDumpLoader
Throws:
java.io.IOException
CmsException
See Also:
I_CmsResourceLoader.load(org.opencms.file.CmsObject, org.opencms.file.CmsResource, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)

getScaledImage

protected CmsFile getScaledImage(CmsObject cms,
                                 CmsResource resource,
                                 CmsImageScaler scaler)
                          throws java.io.IOException,
                                 CmsException
Returns a scaled version of the given OpenCms VFS image resource.

All results are cached in disk. If the scaled version does not exist in the cache, it is created. Unscaled versions of the images are also stored in the cache.

Parameters:
cms - the current users OpenCms context
resource - the base VFS resource for the image
scaler - the configured image scaler
Returns:
a scaled version of the given OpenCms VFS image resource
Throws:
java.io.IOException - in case of errors acessing the disk based cache
CmsException - in case of errors accessing the OpenCms VFS