public class CmsImageLoader extends CmsDumpLoader implements 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
.
Modifier and Type | Field and 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.
|
RESOURCE_LOADER_ID
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_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_OU_ID, KEY_OU_NAME, KEY_PROJECTID, KEY_PUBLISHID, KEY_PUBLISHLIST, 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_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
PARAMETER_ELEMENT
ADD_PARAMETER_METHOD, INIT_CONFIGURATION_METHOD
Constructor and Description |
---|
CmsImageLoader()
Creates a new image loader.
|
Modifier and Type | Method and 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 return
null since this loader does not
need to be configured. |
static java.lang.String |
getDownScaleParams()
Returns the image down scale parameters,
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 re-scale 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 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.
|
canSendLastModifiedHeader, dump, export, getResourceLoaderInfo, isStaticExportEnabled, isStaticExportProcessable, isUsableForTemplates, isUsingUriWhenLoadingTemplate, service
public static final java.lang.String CONFIGURATION_DOWNSCALE
public static final java.lang.String CONFIGURATION_IMAGE_FOLDER
public static final java.lang.String CONFIGURATION_MAX_BLUR_SIZE
public static final java.lang.String CONFIGURATION_MAX_SCALE_SIZE
public static final java.lang.String CONFIGURATION_SCALING_ENABLED
public static final java.lang.String IMAGE_REPOSITORY_DEFAULT
public static final java.lang.String PARAM_CLEAR_IMAGES_CACHE
public static final int RESOURCE_LOADER_ID_IMAGE_LOADER
protected static final org.apache.commons.logging.Log LOG
protected static java.lang.String m_downScaleParams
protected static boolean m_enabled
protected static int m_maxBlurSize
protected static CmsVfsNameBasedDiskCache m_vfsDiskCache
protected java.lang.String m_imageRepositoryFolder
protected int m_maxScaleSize
public CmsImageLoader()
public static java.lang.String getDownScaleParams()
CONFIGURATION_DOWNSCALE
configuration option.
If no down scale parameters have been set in the configuration, this will return null
.
public static java.lang.String getImageRepositoryPath()
CONFIGURATION_IMAGE_FOLDER
configuration option.public static int getMaxBlurSize()
CONFIGURATION_MAX_BLUR_SIZE
configuration option.The default is 2500 * 2500 pixel.
public static boolean isEnabled()
true
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 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 capabilities in OpenCms are disabled by default.
true
if the image scaling and processing capabilities for the
OpenCms VFS images have been enabledpublic void addConfigurationParameter(java.lang.String paramName, java.lang.String paramValue)
I_CmsConfigurationParameterHandler
addConfigurationParameter
in interface I_CmsConfigurationParameterHandler
addConfigurationParameter
in class CmsDumpLoader
paramName
- the name of the parameterparamValue
- the value for the parameterI_CmsConfigurationParameterHandler.addConfigurationParameter(java.lang.String, java.lang.String)
public void cmsEvent(CmsEvent event)
I_CmsEventListener
cmsEvent
in interface I_CmsEventListener
event
- CmsEvent that has occurredI_CmsEventListener.cmsEvent(org.opencms.main.CmsEvent)
public void destroy()
CmsDumpLoader
destroy
in interface I_CmsResourceLoader
destroy
in class CmsDumpLoader
I_CmsResourceLoader.destroy()
public CmsParameterConfiguration getConfiguration()
CmsDumpLoader
null
since this loader does not
need to be configured.getConfiguration
in interface I_CmsConfigurationParameterHandler
getConfiguration
in class CmsDumpLoader
null
if the class does not need any parametersI_CmsConfigurationParameterHandler.getConfiguration()
public int getLoaderId()
I_CmsResourceLoader
getLoaderId
in interface I_CmsResourceLoader
getLoaderId
in class CmsDumpLoader
I_CmsResourceLoader.getLoaderId()
public void initConfiguration()
I_CmsConfigurationParameterHandler
initConfiguration
in interface I_CmsConfigurationParameterHandler
initConfiguration
in class CmsDumpLoader
I_CmsConfigurationParameterHandler.initConfiguration()
public void load(CmsObject cms, CmsResource resource, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res) throws java.io.IOException, CmsException
I_CmsResourceLoader
load
in interface I_CmsResourceLoader
load
in class CmsDumpLoader
cms
- the initialized CmsObject which provides user permissionsresource
- the requested OpenCms VFS resourcereq
- the servlet requestres
- the servlet responsejava.io.IOException
- might be thrown by the servlet environmentCmsException
- in case of errors accessing OpenCms functionsI_CmsResourceLoader.load(org.opencms.file.CmsObject, org.opencms.file.CmsResource, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
protected CmsFile getScaledImage(CmsObject cms, CmsResource resource, CmsImageScaler scaler) throws java.io.IOException, CmsException
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.
cms
- the current users OpenCms contextresource
- the base VFS resource for the imagescaler
- the configured image scalerjava.io.IOException
- in case of errors accessing the disk based cacheCmsException
- in case of errors accessing the OpenCms VFS