Class CmsImageLoader
- All Implemented Interfaces:
I_CmsConfigurationParameterHandler
,I_CmsResourceLoader
,I_CmsEventListener
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 the CmsImageScaler.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
Modifier and TypeFieldDescriptionstatic final String
The configuration parameter for the OpenCms XML configuration to set the image down scale operation.static final String
The configuration parameter for the OpenCms XML configuration to set the image cache repository.static final String
The configuration parameter for the OpenCms XML configuration to set the maximum image blur size.static final String
The configuration parameter for the OpenCms XML configuration to set the maximum image scale size.static final String
The configuration parameter for the OpenCms XML configuration to enable the image scaling.static final String
Default name for the image cache repository.protected static final org.apache.commons.logging.Log
The log object for this class.protected static String
The (optional) image down scale parameters for image write operations.protected static boolean
Indicates if image scaling is active.protected String
The name of the configured image cache repository.protected static int
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
The maximum image size (width or height) to allow when up scaling an image using request parameters.protected static CmsVfsNameBasedDiskCache
The disk cache to use for saving scaled image versions.static final String
Clear event parameter.static final int
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
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addConfigurationParameter
(String paramName, String paramValue) Adds a configuration parameter to this parameter configurable class instance.void
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.Will always returnnull
since this loader does not need to be configured.static String
Returns the image down scale parameters, which is set with theCONFIGURATION_DOWNSCALE
configuration option.static String
Returns the path of the image cache repository folder in the RFS, which is set with theCONFIGURATION_IMAGE_FOLDER
configuration option.int
Returns the id of the ResourceLoader.static int
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
Initializes a configuration after all parameters have been added.static boolean
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 Details
-
CONFIGURATION_DOWNSCALE
The configuration parameter for the OpenCms XML configuration to set the image down scale operation.- See Also:
-
CONFIGURATION_IMAGE_FOLDER
The configuration parameter for the OpenCms XML configuration to set the image cache repository.- See Also:
-
CONFIGURATION_MAX_BLUR_SIZE
The configuration parameter for the OpenCms XML configuration to set the maximum image blur size.- See Also:
-
CONFIGURATION_MAX_SCALE_SIZE
The configuration parameter for the OpenCms XML configuration to set the maximum image scale size.- See Also:
-
CONFIGURATION_SCALING_ENABLED
The configuration parameter for the OpenCms XML configuration to enable the image scaling.- See Also:
-
IMAGE_REPOSITORY_DEFAULT
Default name for the image cache repository.- See Also:
-
PARAM_CLEAR_IMAGES_CACHE
Clear event parameter.- See Also:
-
RESOURCE_LOADER_ID_IMAGE_LOADER
The id of this loader.- See Also:
-
LOG
The log object for this class. -
m_downScaleParams
The (optional) image down scale parameters for image write operations. -
m_enabled
Indicates if image scaling is active. -
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
The disk cache to use for saving scaled image versions. -
m_imageRepositoryFolder
The name of the configured image cache repository. -
m_maxScaleSize
The maximum image size (width or height) to allow when up scaling an image using request parameters.
-
-
Constructor Details
-
CmsImageLoader
public CmsImageLoader()Creates a new image loader.
-
-
Method Details
-
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
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
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
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
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:
-
cmsEvent
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:
-
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:
-
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:
-
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:
-
getScaledImage
protected CmsFile getScaledImage(CmsObject cms, CmsResource resource, CmsImageScaler scaler) throws 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:
IOException
- in case of errors accessing the disk based cacheCmsException
- in case of errors accessing the OpenCms VFS
-
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:
-
load
public void load(CmsObject cms, CmsResource resource, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res) throws 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:
IOException
- might be thrown by the servlet environmentCmsException
- in case of errors accessing OpenCms functions- See Also:
-