Class CmsImageLoader
- All Implemented Interfaces:
I_CmsConfigurationParameterHandler,I_CmsResourceLoader,I_CmsStaticExportDirectResponseLoader,I_CmsStaticExportStreamLoader,I_CmsStoredContentDirectDeliveryLoader,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_SCALESCALE_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
FieldsModifier and TypeFieldDescriptionstatic final StringControls max number of threads that are allowed to scale images concurrently.static final StringThe configuration parameter for the OpenCms XML configuration to set the image down scale operation.static final StringThe configuration parameter for the OpenCms XML configuration to set the image cache repository.static final StringThe configuration parameter for the OpenCms XML configuration to set the maximum image blur size.static final StringThe configuration parameter for the OpenCms XML configuration to set the maximum image scale size.static final StringThe configuration parameter for the OpenCms XML configuration to enable the image scaling.static final StringDefault name for the image cache repository.protected static final org.apache.commons.logging.LogThe log object for this class.protected static StringThe (optional) image down scale parameters for image write operations.protected static booleanIndicates if image scaling is active.protected static I_CmsImageCacheThe optional external image cache.protected static CmsImageCacheAccessRenewalAsynchronous access-triggered renewal for the configured external image cache.protected StringThe name of the configured image cache repository.protected static StringThe image cache repository path, ornullfor image caches without file system access.protected static intThe maximum image size (width * height) to apply image blurring when down scaling (setting this to high may cause "out of memory" errors).protected intThe maximum image size (width or height) to allow when up scaling an image using request parameters.protected static CmsVfsNameBasedDiskCacheThe disk cache to use for saving scaled image versions.static final StringClear event parameter.static final intThe id of this loader.Fields inherited from class org.opencms.loader.CmsDumpLoader
RESOURCE_LOADER_IDFields inherited from interface org.opencms.configuration.I_CmsConfigurationParameterHandler
ADD_PARAMETER_METHOD, INIT_CONFIGURATION_METHODFields 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_INSTANT_PUBLISH, 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_USERFields inherited from interface org.opencms.loader.I_CmsResourceLoader
PARAMETER_ELEMENT -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddConfigurationParameter(String paramName, String paramValue) Adds a configuration parameter to this parameter configurable class instance.voidAcknowledge the occurrence of the specified event, implement this method to check for CmsEvents in your class.protected voidcreateImageCacheEntry(CmsObject cms, CmsResource resource, CmsImageScaler scaler, String key) Creates an image cache entry without checking whether it already exists.voiddestroy()Destroy this ResourceLoder, this is a NOOP so far.protected StringensureImageCacheEntry(CmsObject cms, CmsResource resource, CmsImageScaler scaler) Ensures that an image cache entry exists in the configured image cache.byte[]export(CmsObject cms, CmsResource resource, jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse res) Static exports the contents of the requested file and it's sub-elements.voidexportTo(CmsObject cms, CmsResource resource, jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse res, OutputStream exportOut) Static exports the contents of the requested resource to an output stream, optionally also to the response.Will always returnnullsince this loader does not need to be configured.static StringReturns the image down scale parameters, which is set with theCONFIGURATION_DOWNSCALEconfiguration option.static I_CmsImageCacheReturns the configured external image cache.protected StringgetImageCacheKey(CmsResource resource, CmsImageScaler scaler) Returns the image cache key for an image/scaler pair.static StringReturns the path of the image cache repository folder in the RFS.intReturns the id of the ResourceLoader.static intThe maximum blur size for image re-scale operations, which is set with theCONFIGURATION_MAX_BLUR_SIZEconfiguration option.protected CmsFilegetScaledImage(CmsObject cms, CmsResource resource, CmsImageScaler scaler) Returns a scaled version of the given OpenCms VFS image resource.getScaledImageFile(CmsObject cms, CmsResource resource, jakarta.servlet.http.HttpServletRequest req) Returns the RFS cache file for the image scaler parameters from the request.protected FilegetScaledImageFile(CmsObject cms, CmsResource resource, CmsImageScaler scaler) Returns the RFS cache file for a scaled version of the given OpenCms VFS image resource.voidInitializes a configuration after all parameters have been added.protected voidInitializes the classic RFS image cache used when no external image cache backend is selected.voidinitializeImageCache(CmsParameterConfiguration propertyConfiguration) Initializes the image cache after the complete OpenCms runtime configuration is available.protected voidinitImageCache(CmsParameterConfiguration propertyConfiguration) Initializes the optional image cache.static booleanReturnstrueif the image scaling and processing capabilities for the OpenCms VFS images have been enabled,falseif not.booleanisStoredContentDirectDeliveryEnabled(CmsObject cms, CmsResource resource, jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse res) Returns if direct delivery of externally stored original content is enabled for the given resource.voidload(CmsObject cms, CmsResource resource, jakarta.servlet.http.HttpServletRequest req, jakarta.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.voidloadCacheFile(CmsResource resource, File file, jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse res) Loads an image cache file to the response.protected voidloadImageCacheEntry(CmsResource resource, String key, jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse res) Loads an image cache entry from the configured storage to the response.booleantryExportDirectResponse(CmsObject cms, CmsResource resource, jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse res) Tries to handle an on-demand static export directly.Methods inherited from class org.opencms.loader.CmsDumpLoader
canSendLastModifiedHeader, deliverStoredContent, dump, exportStoredContentTo, getClientCacheMaxAge, getResourceLoaderInfo, isStaticExportEnabled, isStaticExportProcessable, isUsableForTemplates, isUsingUriWhenLoadingTemplate, prepareResponse, service
-
Field Details
-
CONFIGURATION_CONCURRENCY
Controls max number of threads that are allowed to scale images concurrently.- See Also:
-
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_imageRepositoryPath
The image cache repository path, ornullfor image caches without file system access. -
m_imageCache
The optional external image cache. -
m_imageCacheAccessRenewal
Asynchronous access-triggered renewal for the configured external image cache. -
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_DOWNSCALEconfiguration option.If no down scale parameters have been set in the configuration, this will return
null.- Returns:
- the image down scale parameters
-
getImageCache
Returns the configured external image cache.The classic RFS image cache is not represented by an
I_CmsImageCacheinstance, so this method returnsnullfor it.- Returns:
- the configured external image cache, or
nullfor the classic RFS image cache
-
getImageRepositoryPath
Returns the path of the image cache repository folder in the RFS.For image cache backends without file system access, this returns
null.- Returns:
- the path of the image cache repository folder in the RFS, or
null
-
getMaxBlurSize
The maximum blur size for image re-scale operations, which is set with theCONFIGURATION_MAX_BLUR_SIZEconfiguration option.The default is 2500 * 2500 pixel.
- Returns:
- the maximum blur size for image re-scale operations
-
isEnabled
Returnstrueif the image scaling and processing capabilities for the OpenCms VFS images have been enabled,falseif not.Image scaling is enabled by setting the loader parameter
image.scaling.enabledto the valuetruein 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:
trueif the image scaling and processing capabilities for the OpenCms VFS images have been enabled
-
addConfigurationParameter
Description copied from interface:I_CmsConfigurationParameterHandlerAdds a configuration parameter to this parameter configurable class instance.- Specified by:
addConfigurationParameterin interfaceI_CmsConfigurationParameterHandler- Overrides:
addConfigurationParameterin classCmsDumpLoader- Parameters:
paramName- the name of the parameterparamValue- the value for the parameter- See Also:
-
cmsEvent
Description copied from interface:I_CmsEventListenerAcknowledge the occurrence of the specified event, implement this method to check for CmsEvents in your class.- Specified by:
cmsEventin interfaceI_CmsEventListener- Parameters:
event- CmsEvent that has occurred- See Also:
-
destroy
Description copied from class:CmsDumpLoaderDestroy this ResourceLoder, this is a NOOP so far.- Specified by:
destroyin interfaceI_CmsResourceLoader- Overrides:
destroyin classCmsDumpLoader- See Also:
-
export
public byte[] export(CmsObject cms, CmsResource resource, jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse res) throws IOException, CmsException Description copied from interface:I_CmsResourceLoaderStatic exports the contents of the requested file and it's sub-elements.During static export, the resource content may be written to 2 streams: The export stream, and the http response output stream. Which stream is actually used depends whether the export is in "on demand" or "after publish" mode. In "on demand" mode, the resource needs to be written both to the response stream and to the file stream. In "after publish" mode, it's usually only written to the file stream, but sometimes it's required to write to the response stream as well.
- Specified by:
exportin interfaceI_CmsResourceLoader- Overrides:
exportin classCmsDumpLoader- Parameters:
cms- the initialized CmsObject which provides user permissionsresource- the requested OpenCms VFS resourcereq- the servlet requestres- the servlet response- Returns:
- the contents to export, or
nullif no export is required - Throws:
IOException- might be thrown in the process of including the sub elementCmsException- in case something goes wrong- See Also:
-
exportTo
public void exportTo(CmsObject cms, CmsResource resource, jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse res, OutputStream exportOut) throws IOException, CmsException Description copied from interface:I_CmsStaticExportStreamLoaderStatic exports the contents of the requested resource to an output stream, optionally also to the response.- Specified by:
exportToin interfaceI_CmsStaticExportStreamLoader- Overrides:
exportToin classCmsDumpLoader- Parameters:
cms- the initialized CmsObject which provides user permissionsresource- the requested OpenCms VFS resourcereq- the servlet requestres- the servlet responseexportOut- the export output stream- Throws:
IOException- might be thrown in the process of writing the streamsCmsException- in case something goes wrong- See Also:
-
getConfiguration
Description copied from class:CmsDumpLoaderWill always returnnullsince this loader does not need to be configured.- Specified by:
getConfigurationin interfaceI_CmsConfigurationParameterHandler- Overrides:
getConfigurationin classCmsDumpLoader- Returns:
- the parameters of this configurable class instance,
or
nullif the class does not need any parameters - See Also:
-
getLoaderId
Description copied from interface:I_CmsResourceLoaderReturns the id of the ResourceLoader.- Specified by:
getLoaderIdin interfaceI_CmsResourceLoader- Overrides:
getLoaderIdin classCmsDumpLoader- Returns:
- the id of the ResourceLoader
- See Also:
-
getScaledImageFile
public File getScaledImageFile(CmsObject cms, CmsResource resource, jakarta.servlet.http.HttpServletRequest req) throws IOException, CmsException Returns the RFS cache file for the image scaler parameters from the request.- Parameters:
cms- the current users OpenCms contextresource- the base VFS resource for the imagereq- the current request- Returns:
- the scaled image cache file, or
nullif the request contains no valid scaling parameters - 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_CmsConfigurationParameterHandlerInitializes a configuration after all parameters have been added.- Specified by:
initConfigurationin interfaceI_CmsConfigurationParameterHandler- Overrides:
initConfigurationin classCmsDumpLoader- Throws:
CmsConfigurationException- if something goes wrong- See Also:
-
initializeImageCache
public void initializeImageCache(CmsParameterConfiguration propertyConfiguration) throws CmsConfigurationException Initializes the image cache after the complete OpenCms runtime configuration is available.- Parameters:
propertyConfiguration- the OpenCms properties- Throws:
CmsConfigurationException- if the image cache can not be initialized
-
isStoredContentDirectDeliveryEnabled
public boolean isStoredContentDirectDeliveryEnabled(CmsObject cms, CmsResource resource, jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse res) throws CmsException Description copied from interface:I_CmsStoredContentDirectDeliveryLoaderReturns if direct delivery of externally stored original content is enabled for the given resource.- Specified by:
isStoredContentDirectDeliveryEnabledin interfaceI_CmsStoredContentDirectDeliveryLoader- Overrides:
isStoredContentDirectDeliveryEnabledin classCmsDumpLoader- Parameters:
cms- the CMS contextresource- the resourcereq- the requestres- the response- Returns:
trueif direct stored content delivery may be used- Throws:
CmsException- in case the decision can not be made- See Also:
-
load
public void load(CmsObject cms, CmsResource resource, jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse res) throws IOException, CmsException Description copied from interface:I_CmsResourceLoaderBasic 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:
loadin interfaceI_CmsResourceLoader- Overrides:
loadin 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:
-
loadCacheFile
public void loadCacheFile(CmsResource resource, File file, jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse res) throws IOException Loads an image cache file to the response.- Parameters:
resource- the original resourcefile- the image cache filereq- the current requestres- the current response- Throws:
IOException- in case writing fails
-
tryExportDirectResponse
public boolean tryExportDirectResponse(CmsObject cms, CmsResource resource, jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse res) throws IOException, CmsException Description copied from interface:I_CmsStaticExportDirectResponseLoaderTries to handle an on-demand static export directly.- Specified by:
tryExportDirectResponsein interfaceI_CmsStaticExportDirectResponseLoader- Parameters:
cms- the CMS contextresource- the resource to exportreq- the current requestres- the current response- Returns:
trueif the export response has been handled- Throws:
IOException- in case writing failsCmsException- in case export fails- See Also:
-
createImageCacheEntry
protected void createImageCacheEntry(CmsObject cms, CmsResource resource, CmsImageScaler scaler, String key) throws IOException, CmsException Creates an image cache entry without checking whether it already exists.- Parameters:
cms- the CMS contextresource- the image resourcescaler- the image scalerkey- the image cache key- Throws:
IOException- in case scaling failsCmsException- in case VFS or cache access fails
-
ensureImageCacheEntry
protected String ensureImageCacheEntry(CmsObject cms, CmsResource resource, CmsImageScaler scaler) throws IOException, CmsException Ensures that an image cache entry exists in the configured image cache.- Parameters:
cms- the CMS contextresource- the image resourcescaler- the image scaler- Returns:
- the image cache key
- Throws:
IOException- in case scaling failsCmsException- in case VFS access fails
-
getImageCacheKey
Returns the image cache key for an image/scaler pair.- Parameters:
resource- the image resourcescaler- the image scaler- Returns:
- the image cache key
-
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
-
getScaledImageFile
protected File getScaledImageFile(CmsObject cms, CmsResource resource, CmsImageScaler scaler) throws IOException, CmsException Returns the RFS cache file for a scaled version of the given OpenCms VFS image resource.- Parameters:
cms- the current users OpenCms contextresource- the base VFS resource for the imagescaler- the configured image scaler- Returns:
- the scaled image cache file
- Throws:
IOException- in case of errors accessing the disk based cacheCmsException- in case of errors accessing the OpenCms VFS
-
initDefaultImageCache
Initializes the classic RFS image cache used when no external image cache backend is selected. -
initImageCache
protected void initImageCache(CmsParameterConfiguration propertyConfiguration) throws CmsConfigurationException Initializes the optional image cache.- Throws:
CmsConfigurationException
-
loadImageCacheEntry
protected void loadImageCacheEntry(CmsResource resource, String key, jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse res) throws IOException, CmsException Loads an image cache entry from the configured storage to the response.- Parameters:
resource- the original resourcekey- the image cache keyreq- the requestres- the response- Throws:
IOException- in case writing failsCmsException- in case store access fails
-