Package org.opencms.loader
Class CmsTemplateContextManager
java.lang.Object
org.opencms.loader.CmsTemplateContextManager
Manager class for template context providers.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
Request attribute used to set the template context during RPC calls.static final String
A bean containing information about the selected template.static final String
The request attribute in which the template context is stored.static final String
Attribute name which contains the template name for non-dynamically selected templates.static final String
Attribute name for the template resource.static final String
The prefix used in the template property to activate dynamic template selection. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected CmsXmlContentProperty
createTemplateContextsPropertyDefinition
(I_CmsTemplateContextProvider contextProvider, Locale locale) Creates the setting definition for the templateContexts setting.getContextInfoBean
(CmsObject cms, javax.servlet.http.HttpServletRequest request) Creates a bean with information about the current template context, for use in the client-side code.getProviderKey
(I_CmsTemplateContextProvider provider) Gets the key of a cached template provider (consisting of class name and parameters) that can later be used as an argument to getTemplateContextProvider.getTemplateContext
(String providerName, CmsObject cms, javax.servlet.http.HttpServletRequest request, CmsResource resource) Gets the template context to use.getTemplateContextProvider
(String providerName) Retrieves an instance of a template context provider given its name (optionally prefixed by the 'dynamic:' prefix).getTemplateContextProvider
(CmsObject cms, String path) Gets the template context provider for a given path.static boolean
hasPropertyPrefix
(String propertyValue) Checks if the property value starts with the prefix which marks a dynamic template provider.static boolean
isProvider
(String templatePath) Checks if a template property value refers to a template context provider.readPropertyFromTemplate
(CmsObject cms, CmsResource res, String propertyName, String fallbackValue) Utility method which either reads a property from the template used for a specific resource, or from the template context provider used for the resource if available.static String
removePropertyPrefix
(String propertyValue) Removes the prefix which marks a property value as a dynamic template provider.protected Map<String,
CmsDefaultSet<String>> Helper method for getting the forbidden contexts from the resource manager without a try-catch block.boolean
shouldShowType
(String contextKey, String typeName) Helper method to check whether a given type should not be shown in a context.
-
Field Details
-
ATTR_RPC_CONTEXT_OVERRIDE
Request attribute used to set the template context during RPC calls.- See Also:
-
ATTR_TEMPLATE_BEAN
A bean containing information about the selected template.- See Also:
-
ATTR_TEMPLATE_CONTEXT
The request attribute in which the template context is stored.- See Also:
-
ATTR_TEMPLATE_NAME
Attribute name which contains the template name for non-dynamically selected templates.- See Also:
-
ATTR_TEMPLATE_RESOURCE
Attribute name for the template resource.- See Also:
-
DYNAMIC_TEMPLATE_PREFIX
The prefix used in the template property to activate dynamic template selection.- See Also:
-
-
Constructor Details
-
CmsTemplateContextManager
Creates a new instance.- Parameters:
cms
- the CMS context to use
-
-
Method Details
-
hasPropertyPrefix
Checks if the property value starts with the prefix which marks a dynamic template provider.- Parameters:
propertyValue
- the property value to check- Returns:
- true if the value has the format of a dynamic template provider
-
isProvider
Checks if a template property value refers to a template context provider.- Parameters:
templatePath
- the template property value- Returns:
- true if this value refers to a template context provider
-
removePropertyPrefix
Removes the prefix which marks a property value as a dynamic template provider.- Parameters:
propertyValue
- the value from which to remove the prefix- Returns:
- the string with the prefix removed
-
getContextInfoBean
public CmsTemplateContextInfo getContextInfoBean(CmsObject cms, javax.servlet.http.HttpServletRequest request) Creates a bean with information about the current template context, for use in the client-side code.- Parameters:
cms
- the current CMS contextrequest
- the current request- Returns:
- the bean with the template context information
-
getProviderKey
Gets the key of a cached template provider (consisting of class name and parameters) that can later be used as an argument to getTemplateContextProvider.If the provider is not already cached, returns null.
- Parameters:
provider
- the template provider- Returns:
- the cache key
-
getTemplateContext
public CmsTemplateContext getTemplateContext(String providerName, CmsObject cms, javax.servlet.http.HttpServletRequest request, CmsResource resource) Gets the template context to use.- Parameters:
providerName
- the name of the template context providercms
- the current CMS contextrequest
- the current requestresource
- the current resource- Returns:
- the current template context
-
getTemplateContextProvider
public I_CmsTemplateContextProvider getTemplateContextProvider(CmsObject cms, String path) throws CmsException Gets the template context provider for a given path.- Parameters:
cms
- the current CMS contextpath
- the path for which the template context provider should be determined- Returns:
- the template context provider for the given path
- Throws:
CmsException
- if something goes wrong
-
getTemplateContextProvider
Retrieves an instance of a template context provider given its name (optionally prefixed by the 'dynamic:' prefix).- Parameters:
providerName
- the name of the provider- Returns:
- an instance of the provider class
-
readPropertyFromTemplate
public String readPropertyFromTemplate(CmsObject cms, CmsResource res, String propertyName, String fallbackValue) Utility method which either reads a property from the template used for a specific resource, or from the template context provider used for the resource if available.- Parameters:
cms
- the CMS context to useres
- the resource from whose template or template context provider the property should be readpropertyName
- the property namefallbackValue
- the fallback value- Returns:
- the property value
-
shouldShowType
Helper method to check whether a given type should not be shown in a context.- Parameters:
contextKey
- the key of the template contexttypeName
- the type name- Returns:
- true if the context does not prohibit showing the type
-
createTemplateContextsPropertyDefinition
protected CmsXmlContentProperty createTemplateContextsPropertyDefinition(I_CmsTemplateContextProvider contextProvider, Locale locale) Creates the setting definition for the templateContexts setting.- Parameters:
contextProvider
- the context providerlocale
- the current locale- Returns:
- the setting definition
-
safeGetAllowedContextMap
Helper method for getting the forbidden contexts from the resource manager without a try-catch block.- Returns:
- the forbidden context map
-