Class CmsResourceManager
- java.lang.Object
-
- org.opencms.loader.CmsResourceManager
-
public class CmsResourceManager extends java.lang.Object
Collects all available resource loaders, resource types and resource collectors at startup and provides methods to access them during OpenCms runtime.- Since:
- 6.0.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
CmsResourceManager.NamedTemplate
Bean containing a template resource and the name of the template.
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
DEFAULT_TEMPLATE
The path to the default template.static java.lang.String
MIMETYPE_HTML
The MIME type"text/html"
.static java.lang.String
MIMETYPE_TEXT
The MIME type"text/plain"
.
-
Constructor Summary
Constructors Constructor Description CmsResourceManager()
Creates a new instance for the resource manager, will be called by the VFS configuration manager.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description I_CmsResourceCollector
addContentCollector(java.lang.String className, java.lang.String order)
Adds a given content collector class to the type manager.I_CmsHtmlConverter
addHtmlConverter(java.lang.String name, java.lang.String className)
Adds a new HTML converter class to internal list of loaded converter classes.void
addLoader(I_CmsResourceLoader loader)
Adds a new loader to the internal list of loaded loaders.CmsMimeType
addMimeType(java.lang.String extension, java.lang.String type)
Adds a new MIME type from the XML configuration to the internal list of MIME types.CmsRelationType
addRelationType(java.lang.String name, java.lang.String type)
Adds a new relation type from the XML configuration to the list of user defined relation types.void
addResourceType(I_CmsResourceType resourceType)
Adds a new resource type from the XML configuration to the internal list of loaded resource types.java.util.Map<java.lang.String,CmsDefaultSet<java.lang.String>>
getAllowedContextMap(CmsObject cms)
Gets the map of forbidden contexts for resource types.I_CmsResourceCollector
getContentCollector(java.lang.String collectorName)
Returns the configured content collector with the given name, ornull
if no collector with this name is configured.I_CmsResourceType
getDefaultTypeForName(java.lang.String resourcename)
Returns the default resource type for the given resource name, using the configured resource type file extensions.java.util.Map<java.lang.String,java.lang.String>
getExtensionMapping()
Returns the file extensions (suffixes) mappings to resource types.CmsResourceTranslator
getFileTranslator()
Returns the file translator.CmsResourceTranslator
getFolderTranslator()
Returns the folder translator.java.lang.String
getHtmlConverter(java.lang.String name)
Returns the matching HTML converter class name for the specified option name.java.util.List<CmsHtmlConverterOption>
getHtmlConverters()
Returns an unmodifiable List of the configuredCmsHtmlConverterOption
objects.I_CmsResourceLoader
getLoader(int id)
Returns the loader class instance for the given loader id.I_CmsResourceLoader
getLoader(CmsResource resource)
Returns the loader class instance for a given resource.java.util.List<I_CmsResourceLoader>
getLoaders()
Returns the (unmodifiable array) list with all initialized resource loaders.java.lang.String
getMimeType(java.lang.String filename, java.lang.String encoding)
Returns the MIME type for a specified file name.java.lang.String
getMimeType(java.lang.String filename, java.lang.String encoding, java.lang.String defaultMimeType)
Returns the MIME type for a specified file name.java.util.List<CmsMimeType>
getMimeTypes()
Returns an unmodifiable List of the configuredCmsMimeType
objects.I_CmsFileNameGenerator
getNameGenerator()
Returns the name generator for XML content file names.java.util.List<I_CmsResourceCollector>
getRegisteredContentCollectors()
Returns an (unmodifiable) list of class names of all currently registered content collectors (I_CmsResourceCollector
objects).java.util.List<CmsRelationType>
getRelationTypes()
Returns an unmodifiable List of the configuredCmsRelationType
objects.I_CmsResourceType
getResourceType(int typeId)
Returns the initialized resource type instance for the given id.I_CmsResourceType
getResourceType(java.lang.String typeName)
Returns the initialized resource type instance for the given resource type name.I_CmsResourceType
getResourceType(CmsResource resource)
Convenience method to get the initialized resource type instance for the given resource, with a fall back to special "unknown" resource types in case the resource type is not configured.java.util.List<I_CmsResourceType>
getResourceTypes()
Returns the (unmodifiable) list with all initialized resource types.java.util.List<I_CmsResourceType>
getResourceTypesWithUnknown()
Returns the (unmodifiable) list with all initialized resource types including unknown types.I_CmsResourceType
getResTypeUnknownFile()
The configured default type for files when the resource type is missing.I_CmsResourceType
getResTypeUnknownFolder()
The configured default type for folders when the resource type is missing.CmsTemplateLoaderFacade
getTemplateLoaderFacade(CmsObject cms, javax.servlet.http.HttpServletRequest request, CmsResource resource, java.lang.String templateProperty)
Returns a template loader facade for the given file.CmsTemplateLoaderFacade
getTemplateLoaderFacade(CmsObject cms, CmsResource resource, java.lang.String templateProperty)
Returns a template loader facade for the given file.CmsResourceTranslator
getXsdTranslator()
Returns the XSD translator.boolean
hasResourceType(int typeId)
Deprecated.UsehasResourceType(I_CmsResourceType)
orhasResourceType(I_CmsResourceType)
instead.boolean
hasResourceType(java.lang.String typeName)
Checks if an initialized resource type instance for the given resource type name is available.boolean
hasResourceType(I_CmsResourceType type)
Checks if an initialized resource type instance equal to the given resource type is available.void
initConfiguration()
void
initialize(CmsObject cms)
Initializes all additional resource types stored in the modules.void
loadResource(CmsObject cms, CmsResource resource, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)
Loads the requested resource and writes the contents to the response stream.boolean
matchResourceType(java.lang.String name, int id)
Checks if there is a resource type with a given name whose id matches the given id.void
setNameGenerator(I_CmsFileNameGenerator nameGenerator)
Configures the URL name generator for XML contents.void
setTranslators(CmsResourceTranslator folderTranslator, CmsResourceTranslator fileTranslator, CmsResourceTranslator xsdTranslator)
Sets the folder, the file and the XSD translator.void
shutDown()
Shuts down this resource manage instance.
-
-
-
Field Detail
-
DEFAULT_TEMPLATE
public static final java.lang.String DEFAULT_TEMPLATE
The path to the default template.- See Also:
- Constant Field Values
-
MIMETYPE_HTML
public static final java.lang.String MIMETYPE_HTML
The MIME type"text/html"
.- See Also:
- Constant Field Values
-
MIMETYPE_TEXT
public static final java.lang.String MIMETYPE_TEXT
The MIME type"text/plain"
.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
CmsResourceManager
public CmsResourceManager()
Creates a new instance for the resource manager, will be called by the VFS configuration manager.
-
-
Method Detail
-
addContentCollector
public I_CmsResourceCollector addContentCollector(java.lang.String className, java.lang.String order) throws CmsConfigurationException
Adds a given content collector class to the type manager.- Parameters:
className
- the name of the class to addorder
- the order number for this collector- Returns:
- the created content collector instance
- Throws:
CmsConfigurationException
- in case the collector could not be properly initialized
-
addHtmlConverter
public I_CmsHtmlConverter addHtmlConverter(java.lang.String name, java.lang.String className) throws CmsConfigurationException
Adds a new HTML converter class to internal list of loaded converter classes.- Parameters:
name
- the name of the option that should trigger the HTML converter classclassName
- the name of the class to add- Returns:
- the created HTML converter instance
- Throws:
CmsConfigurationException
- in case the HTML converter could not be properly initialized
-
addLoader
public void addLoader(I_CmsResourceLoader loader) throws CmsConfigurationException
Adds a new loader to the internal list of loaded loaders.- Parameters:
loader
- the loader to add- Throws:
CmsConfigurationException
- in case the resource manager configuration is already initialized
-
addMimeType
public CmsMimeType addMimeType(java.lang.String extension, java.lang.String type) throws CmsConfigurationException
Adds a new MIME type from the XML configuration to the internal list of MIME types.- Parameters:
extension
- the MIME type extensiontype
- the MIME type description- Returns:
- the created MIME type instance
- Throws:
CmsConfigurationException
- in case the resource manager configuration is already initialized
-
addRelationType
public CmsRelationType addRelationType(java.lang.String name, java.lang.String type) throws CmsConfigurationException
Adds a new relation type from the XML configuration to the list of user defined relation types.- Parameters:
name
- the name of the relation typetype
- the type of the relation type, weak or strong- Returns:
- the new created relation type instance
- Throws:
CmsConfigurationException
- in case the resource manager configuration is already initialized
-
addResourceType
public void addResourceType(I_CmsResourceType resourceType) throws CmsConfigurationException
Adds a new resource type from the XML configuration to the internal list of loaded resource types.Resource types can also be added from a module.
- Parameters:
resourceType
- the resource type to add- Throws:
CmsConfigurationException
- in case the resource manager configuration is already initialized
-
getAllowedContextMap
public java.util.Map<java.lang.String,CmsDefaultSet<java.lang.String>> getAllowedContextMap(CmsObject cms)
Gets the map of forbidden contexts for resource types.- Parameters:
cms
- the current CMS context- Returns:
- the map from resource types to the forbidden contexts
-
getContentCollector
public I_CmsResourceCollector getContentCollector(java.lang.String collectorName)
Returns the configured content collector with the given name, ornull
if no collector with this name is configured.- Parameters:
collectorName
- the name of the collector to get- Returns:
- the configured content collector with the given name
-
getDefaultTypeForName
public I_CmsResourceType getDefaultTypeForName(java.lang.String resourcename) throws CmsException
Returns the default resource type for the given resource name, using the configured resource type file extensions.In case the given name does not map to a configured resource type,
CmsResourceTypePlain
is returned.This is only required (and should not be used otherwise) when creating a new resource automatically during file upload or synchronization. Only in this case, the file type for the new resource is determined using this method. Otherwise the resource type is always stored as part of the resource, and is not related to the file name.
- Parameters:
resourcename
- the resource name to look up the resource type for- Returns:
- the default resource type for the given resource name
- Throws:
CmsException
- if something goes wrong
-
getExtensionMapping
public java.util.Map<java.lang.String,java.lang.String> getExtensionMapping()
Returns the file extensions (suffixes) mappings to resource types.- Returns:
- a Map with all known file extensions as keys and their resource types as values.
-
getFileTranslator
public CmsResourceTranslator getFileTranslator()
Returns the file translator.- Returns:
- the file translator
-
getFolderTranslator
public CmsResourceTranslator getFolderTranslator()
Returns the folder translator.- Returns:
- the folder translator
-
getHtmlConverter
public java.lang.String getHtmlConverter(java.lang.String name)
Returns the matching HTML converter class name for the specified option name.- Parameters:
name
- the name of the option that should trigger the HTML converter class- Returns:
- the matching HTML converter class name for the specified option name or
null
if no match is found
-
getHtmlConverters
public java.util.List<CmsHtmlConverterOption> getHtmlConverters()
Returns an unmodifiable List of the configuredCmsHtmlConverterOption
objects.- Returns:
- an unmodifiable List of the configured
CmsHtmlConverterOption
objects
-
getLoader
public I_CmsResourceLoader getLoader(CmsResource resource) throws CmsLoaderException
Returns the loader class instance for a given resource.- Parameters:
resource
- the resource- Returns:
- the appropriate loader class instance
- Throws:
CmsLoaderException
- if something goes wrong
-
getLoader
public I_CmsResourceLoader getLoader(int id)
Returns the loader class instance for the given loader id.- Parameters:
id
- the id of the loader to return- Returns:
- the loader class instance for the given loader id
-
getLoaders
public java.util.List<I_CmsResourceLoader> getLoaders()
Returns the (unmodifiable array) list with all initialized resource loaders.- Returns:
- the (unmodifiable array) list with all initialized resource loaders
-
getMimeType
public java.lang.String getMimeType(java.lang.String filename, java.lang.String encoding)
Returns the MIME type for a specified file name.If an encoding parameter that is not
null
is provided, the returned MIME type is extended with a; charset={encoding}
setting.If no MIME type for the given filename can be determined, the default
is used.MIMETYPE_HTML
- Parameters:
filename
- the file name to check the MIME type forencoding
- the default encoding (charset) in case of MIME types is of type "text"- Returns:
- the MIME type for a specified file
-
getMimeType
public java.lang.String getMimeType(java.lang.String filename, java.lang.String encoding, java.lang.String defaultMimeType)
Returns the MIME type for a specified file name.If an encoding parameter that is not
null
is provided, the returned MIME type is extended with a; charset={encoding}
setting.If no MIME type for the given filename can be determined, the provided default is used.
- Parameters:
filename
- the file name to check the MIME type forencoding
- the default encoding (charset) in case of MIME types is of type "text"defaultMimeType
- the default MIME type to use if no matching type for the filename is found- Returns:
- the MIME type for a specified file
-
getMimeTypes
public java.util.List<CmsMimeType> getMimeTypes()
Returns an unmodifiable List of the configuredCmsMimeType
objects.- Returns:
- an unmodifiable List of the configured
CmsMimeType
objects
-
getNameGenerator
public I_CmsFileNameGenerator getNameGenerator()
Returns the name generator for XML content file names.- Returns:
- the name generator for XML content file names.
-
getRegisteredContentCollectors
public java.util.List<I_CmsResourceCollector> getRegisteredContentCollectors()
Returns an (unmodifiable) list of class names of all currently registered content collectors (I_CmsResourceCollector
objects).- Returns:
- an (unmodifiable) list of class names of all currently registered content collectors
(
I_CmsResourceCollector
objects)
-
getRelationTypes
public java.util.List<CmsRelationType> getRelationTypes()
Returns an unmodifiable List of the configuredCmsRelationType
objects.- Returns:
- an unmodifiable List of the configured
CmsRelationType
objects
-
getResourceType
public I_CmsResourceType getResourceType(CmsResource resource)
Convenience method to get the initialized resource type instance for the given resource, with a fall back to special "unknown" resource types in case the resource type is not configured.- Parameters:
resource
- the resource to get the type for- Returns:
- the initialized resource type instance for the given resource
-
getResourceType
public I_CmsResourceType getResourceType(int typeId) throws CmsLoaderException
Returns the initialized resource type instance for the given id.- Parameters:
typeId
- the id of the resource type to get- Returns:
- the initialized resource type instance for the given id
- Throws:
CmsLoaderException
- if no resource type is available for the given id
-
getResourceType
public I_CmsResourceType getResourceType(java.lang.String typeName) throws CmsLoaderException
Returns the initialized resource type instance for the given resource type name.- Parameters:
typeName
- the name of the resource type to get- Returns:
- the initialized resource type instance for the given name
- Throws:
CmsLoaderException
- if no resource type is available for the given name
-
getResourceTypes
public java.util.List<I_CmsResourceType> getResourceTypes()
Returns the (unmodifiable) list with all initialized resource types.- Returns:
- the (unmodifiable) list with all initialized resource types
-
getResourceTypesWithUnknown
public java.util.List<I_CmsResourceType> getResourceTypesWithUnknown()
Returns the (unmodifiable) list with all initialized resource types including unknown types.- Returns:
- the (unmodifiable) list with all initialized resource types including unknown types
-
getResTypeUnknownFile
public I_CmsResourceType getResTypeUnknownFile()
The configured default type for files when the resource type is missing.- Returns:
- the configured default type for files
-
getResTypeUnknownFolder
public I_CmsResourceType getResTypeUnknownFolder()
The configured default type for folders when the resource type is missing.- Returns:
- The configured default type for folders
-
getTemplateLoaderFacade
public CmsTemplateLoaderFacade getTemplateLoaderFacade(CmsObject cms, CmsResource resource, java.lang.String templateProperty) throws CmsException
Returns a template loader facade for the given file.- Parameters:
cms
- the current OpenCms user contextresource
- the requested filetemplateProperty
- the property to read for the template- Returns:
- a resource loader facade for the given file
- Throws:
CmsException
- if something goes wrong
-
getTemplateLoaderFacade
public CmsTemplateLoaderFacade getTemplateLoaderFacade(CmsObject cms, javax.servlet.http.HttpServletRequest request, CmsResource resource, java.lang.String templateProperty) throws CmsException
Returns a template loader facade for the given file.- Parameters:
cms
- the current OpenCms user contextrequest
- the current requestresource
- the requested filetemplateProperty
- the property to read for the template- Returns:
- a resource loader facade for the given file
- Throws:
CmsException
- if something goes wrong
-
getXsdTranslator
public CmsResourceTranslator getXsdTranslator()
Returns the XSD translator.- Returns:
- the XSD translator
-
hasResourceType
public boolean hasResourceType(I_CmsResourceType type)
Checks if an initialized resource type instance equal to the given resource type is available.- Parameters:
type
- the resource type to check- Returns:
true
if such a resource type has been configured,false
otherwise- See Also:
getResourceType(String)
,getResourceType(int)
-
hasResourceType
@Deprecated public boolean hasResourceType(int typeId)
Deprecated.UsehasResourceType(I_CmsResourceType)
orhasResourceType(I_CmsResourceType)
instead. Resource types should always be referenced either by its type class (preferred) or by type name. Use of int based resource type references will be discontinued in a future OpenCms release.Checks if an initialized resource type instance for the given resource type is is available.- Parameters:
typeId
- the id of the resource type to check- Returns:
true
if such a resource type has been configured,false
otherwise- See Also:
getResourceType(int)
-
hasResourceType
public boolean hasResourceType(java.lang.String typeName)
Checks if an initialized resource type instance for the given resource type name is available.- Parameters:
typeName
- the name of the resource type to check- Returns:
true
if such a resource type has been configured,false
otherwise- See Also:
getResourceType(String)
-
initConfiguration
public void initConfiguration() throws CmsConfigurationException
- Throws:
CmsConfigurationException
- in case of duplicate resource types in the configuration- See Also:
I_CmsConfigurationParameterHandler.initConfiguration()
-
initialize
public void initialize(CmsObject cms) throws CmsRoleViolationException, CmsConfigurationException
Initializes all additional resource types stored in the modules.- Parameters:
cms
- an initialized OpenCms user context with "module manager" role permissions- Throws:
CmsRoleViolationException
- in case the provided OpenCms user context did not have "module manager" role permissionsCmsConfigurationException
- in case of duplicate resource types in the configuration
-
loadResource
public void loadResource(CmsObject cms, CmsResource resource, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res) throws javax.servlet.ServletException, java.io.IOException, CmsException
Loads the requested resource and writes the contents to the response stream.- Parameters:
req
- the current HTTP requestres
- the current HTTP responsecms
- the current OpenCms user contextresource
- the requested resource- Throws:
javax.servlet.ServletException
- if something goes wrongjava.io.IOException
- if something goes wrongCmsException
- if something goes wrong
-
matchResourceType
public boolean matchResourceType(java.lang.String name, int id)
Checks if there is a resource type with a given name whose id matches the given id.This will return 'false' if no resource type with the given name is registered.
- Parameters:
name
- a resource type nameid
- a resource type id- Returns:
- true if a matching resource type with the given name and id was found
-
setNameGenerator
public void setNameGenerator(I_CmsFileNameGenerator nameGenerator) throws CmsConfigurationException
Configures the URL name generator for XML contents.- Parameters:
nameGenerator
- the configured name generator class- Throws:
CmsConfigurationException
- if something goes wrong
-
setTranslators
public void setTranslators(CmsResourceTranslator folderTranslator, CmsResourceTranslator fileTranslator, CmsResourceTranslator xsdTranslator)
Sets the folder, the file and the XSD translator.- Parameters:
folderTranslator
- the folder translator to setfileTranslator
- the file translator to setxsdTranslator
- the XSD translator to set
-
shutDown
public void shutDown() throws java.lang.Exception
Shuts down this resource manage instance.- Throws:
java.lang.Exception
- in case of errors during shutdown
-
-