Class CmsImageLoader
- java.lang.Object
-
- org.opencms.loader.CmsDumpLoader
-
- org.opencms.loader.CmsImageLoader
-
- All Implemented Interfaces:
I_CmsConfigurationParameterHandler
,I_CmsResourceLoader
,I_CmsEventListener
public class CmsImageLoader extends CmsDumpLoader implements I_CmsEventListener
Loader for images from the OpenCms VSF with integrated image scaling and processing capabilities.To scale or process an image, the parameter
has to be appended to the image URI. The value for the parameter needs to be composed from theCmsImageScaler.PARAM_SCALE
SCALE_PARAM
options provided by the constants in the
class.CmsResourceTypeImage
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
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
CONFIGURATION_DOWNSCALE
The configuration parameter for the OpenCms XML configuration to set the image down scale operation.static java.lang.String
CONFIGURATION_IMAGE_FOLDER
The configuration parameter for the OpenCms XML configuration to set the image cache repository.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 static java.lang.String
m_downScaleParams
The (optional) image down scale parameters for image write operations.protected static boolean
m_enabled
Indicates if image scaling is active.protected java.lang.String
m_imageRepositoryFolder
The name of the configured image cache repository.protected static int
m_maxBlurSize
The maximum image size (width * height) to apply image blurring when down scaling (setting this to high may cause "out of memory" errors).protected int
m_maxScaleSize
The maximum image size (width or height) to allow when up scaling an image using request parameters.protected static CmsVfsNameBasedDiskCache
m_vfsDiskCache
The disk cache to use for saving scaled image versions.static java.lang.String
PARAM_CLEAR_IMAGES_CACHE
Clear event parameter.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.configuration.I_CmsConfigurationParameterHandler
ADD_PARAMETER_METHOD, INIT_CONFIGURATION_METHOD
-
Fields inherited from interface org.opencms.main.I_CmsEventListener
EVENT_BEFORE_PUBLISH_PROJECT, EVENT_CLEAR_CACHES, EVENT_CLEAR_OFFLINE_CACHES, EVENT_CLEAR_ONLINE_CACHES, EVENT_CLEAR_PRINCIPAL_CACHES, EVENT_FLEX_CACHE_CLEAR, EVENT_FLEX_PURGE_JSP_REPOSITORY, EVENT_FULLSTATIC_EXPORT, EVENT_GROUP_MODIFIED, EVENT_LOGIN_USER, EVENT_OU_MODIFIED, EVENT_PROJECT_MODIFIED, EVENT_PROPERTY_DEFINITION_CREATED, EVENT_PROPERTY_DEFINITION_MODIFIED, EVENT_PROPERTY_MODIFIED, EVENT_PUBLISH_PROJECT, EVENT_REBUILD_SEARCHINDEXES, EVENT_REINDEX_OFFLINE, EVENT_REINDEX_ONLINE, EVENT_RESOURCE_AND_PROPERTIES_MODIFIED, EVENT_RESOURCE_COPIED, EVENT_RESOURCE_CREATED, EVENT_RESOURCE_DELETED, EVENT_RESOURCE_MODIFIED, EVENT_RESOURCE_MOVED, EVENT_RESOURCES_AND_PROPERTIES_MODIFIED, EVENT_RESOURCES_MODIFIED, EVENT_SITEMAP_CHANGED, EVENT_UPDATE_EXPORTS, EVENT_USER_MODIFIED, KEY_CHANGE, KEY_DBCONTEXT, KEY_GROUP_ID, KEY_GROUP_NAME, KEY_INDEX_NAMES, KEY_IS_ONLINE, KEY_OU_ID, KEY_OU_NAME, KEY_PROJECTID, KEY_PUBLISHID, KEY_PUBLISHLIST, KEY_REINDEX_RELATED, KEY_REPORT, KEY_RESOURCE, KEY_RESOURCES, KEY_SKIPINDEX, KEY_USER_ACTION, KEY_USER_CHANGES, KEY_USER_ID, KEY_USER_NAME, LISTENERS_FOR_ALL_EVENTS, VALUE_CREATE_SIBLING, VALUE_GROUP_MODIFIED_ACTION_CREATE, VALUE_GROUP_MODIFIED_ACTION_DELETE, VALUE_GROUP_MODIFIED_ACTION_WRITE, VALUE_OU_MODIFIED_ACTION_CREATE, VALUE_OU_MODIFIED_ACTION_DELETE, VALUE_USER_MODIFIED_ACTION_ADD_USER_TO_GROUP, VALUE_USER_MODIFIED_ACTION_CREATE_USER, VALUE_USER_MODIFIED_ACTION_DELETE_USER, VALUE_USER_MODIFIED_ACTION_REMOVE_USER_FROM_GROUP, VALUE_USER_MODIFIED_ACTION_RESET_PASSWORD, VALUE_USER_MODIFIED_ACTION_SET_OU, VALUE_USER_MODIFIED_ACTION_WRITE_USER
-
Fields inherited from interface org.opencms.loader.I_CmsResourceLoader
PARAMETER_ELEMENT
-
-
Constructor Summary
Constructors Constructor Description CmsImageLoader()
Creates a new image loader.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addConfigurationParameter(java.lang.String paramName, java.lang.String paramValue)
Adds a configuration parameter to this parameter configurable class instance.void
cmsEvent(CmsEvent event)
Acknowledge the occurrence of the specified event, implement this method to check for CmsEvents in your class.void
destroy()
Destroy this ResourceLoder, this is a NOOP so far.CmsParameterConfiguration
getConfiguration()
Will always returnnull
since this loader does not need to be configured.static java.lang.String
getDownScaleParams()
Returns the image down scale parameters, which is set with theCONFIGURATION_DOWNSCALE
configuration option.static java.lang.String
getImageRepositoryPath()
Returns the path of the image cache repository folder in the RFS, which is set with theCONFIGURATION_IMAGE_FOLDER
configuration option.int
getLoaderId()
Returns the id of the ResourceLoader.static int
getMaxBlurSize()
The maximum blur size for image re-scale operations, which is set with theCONFIGURATION_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()
Returnstrue
if the image scaling and processing capabilities 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 loaded with a I_CmsResourceLoader.-
Methods inherited from class org.opencms.loader.CmsDumpLoader
canSendLastModifiedHeader, dump, export, getResourceLoaderInfo, isStaticExportEnabled, isStaticExportProcessable, isUsableForTemplates, isUsingUriWhenLoadingTemplate, service
-
-
-
-
Field Detail
-
CONFIGURATION_DOWNSCALE
public static final java.lang.String CONFIGURATION_DOWNSCALE
The configuration parameter for the OpenCms XML configuration to set the image down scale 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 repository.- 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
-
PARAM_CLEAR_IMAGES_CACHE
public static final java.lang.String PARAM_CLEAR_IMAGES_CACHE
Clear event parameter.- 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_downScaleParams
protected static java.lang.String m_downScaleParams
The (optional) image down scale parameters for image write operations.
-
m_enabled
protected static boolean m_enabled
Indicates if image scaling is active.
-
m_maxBlurSize
protected static int m_maxBlurSize
The maximum image size (width * height) to apply image blurring when down scaling (setting this to high may cause "out of memory" errors).
-
m_vfsDiskCache
protected static CmsVfsNameBasedDiskCache m_vfsDiskCache
The disk cache to use for saving scaled image versions.
-
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 up scaling 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 down scale parameters, which is set with theCONFIGURATION_DOWNSCALE
configuration option.If no down scale parameters have been set in the configuration, this will return
null
.- Returns:
- the image down scale parameters
-
getImageRepositoryPath
public static java.lang.String getImageRepositoryPath()
Returns the path of the image cache repository folder in the RFS, which is set with theCONFIGURATION_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 re-scale operations, which is set with theCONFIGURATION_MAX_BLUR_SIZE
configuration option.The default is 2500 * 2500 pixel.
- Returns:
- the maximum blur size for image re-scale operations
-
isEnabled
public static boolean isEnabled()
Returnstrue
if the image scaling and processing capabilities 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 valuetrue
in the configuration fileopencms-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 capabilities in OpenCms are disabled by default.
- Returns:
true
if the image scaling and processing capabilities 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 interfaceI_CmsConfigurationParameterHandler
- Overrides:
addConfigurationParameter
in classCmsDumpLoader
- Parameters:
paramName
- the name of the parameterparamValue
- the value for the parameter- See Also:
I_CmsConfigurationParameterHandler.addConfigurationParameter(java.lang.String, java.lang.String)
-
cmsEvent
public void cmsEvent(CmsEvent event)
Description copied from interface:I_CmsEventListener
Acknowledge the occurrence of the specified event, implement this method to check for CmsEvents in your class.- Specified by:
cmsEvent
in interfaceI_CmsEventListener
- Parameters:
event
- CmsEvent that has occurred- See Also:
I_CmsEventListener.cmsEvent(org.opencms.main.CmsEvent)
-
destroy
public void destroy()
Description copied from class:CmsDumpLoader
Destroy this ResourceLoder, this is a NOOP so far.- Specified by:
destroy
in interfaceI_CmsResourceLoader
- Overrides:
destroy
in classCmsDumpLoader
- See Also:
I_CmsResourceLoader.destroy()
-
getConfiguration
public CmsParameterConfiguration getConfiguration()
Description copied from class:CmsDumpLoader
Will always returnnull
since this loader does not need to be configured.- Specified by:
getConfiguration
in interfaceI_CmsConfigurationParameterHandler
- Overrides:
getConfiguration
in classCmsDumpLoader
- Returns:
- the parameters of this configurable class instance,
or
null
if the class does not need any parameters - 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 interfaceI_CmsResourceLoader
- Overrides:
getLoaderId
in classCmsDumpLoader
- Returns:
- the id of the ResourceLoader
- See Also:
I_CmsResourceLoader.getLoaderId()
-
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 contextresource
- the base VFS resource for the imagescaler
- the configured image scaler- Returns:
- a scaled version of the given OpenCms VFS image resource
- Throws:
java.io.IOException
- in case of errors accessing the disk based cacheCmsException
- in case of errors accessing the OpenCms VFS
-
initConfiguration
public void initConfiguration()
Description copied from interface:I_CmsConfigurationParameterHandler
Initializes a configuration after all parameters have been added.- Specified by:
initConfiguration
in interfaceI_CmsConfigurationParameterHandler
- Overrides:
initConfiguration
in classCmsDumpLoader
- 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 loaded with a I_CmsResourceLoader.- Specified by:
load
in interfaceI_CmsResourceLoader
- Overrides:
load
in classCmsDumpLoader
- Parameters:
cms
- the initialized CmsObject which provides user permissionsresource
- the requested OpenCms VFS resourcereq
- the servlet requestres
- the servlet response- Throws:
java.io.IOException
- might be thrown by the servlet environmentCmsException
- in case of errors accessing OpenCms functions- See Also:
I_CmsResourceLoader.load(org.opencms.file.CmsObject, org.opencms.file.CmsResource, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
-
-