Package org.opencms.loader
Class CmsDefaultTemplateContextProvider
java.lang.Object
org.opencms.loader.CmsDefaultTemplateContextProvider
- All Implemented Interfaces:
I_CmsTemplateContextProvider
public class CmsDefaultTemplateContextProvider
extends Object
implements I_CmsTemplateContextProvider
Example implementation of a template context provider for deciding between a desktop template and a mobile template.
The template JSP paths are read from a VFS file "/system/config/templatecontexts.json"
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
JSON attribute name.static final String
JSON attribute name.static final String
JSON attribute name.static final String
JSON attribute name.static final String
JSON attribute name.static final String
The name for the configuration parameter which points to the template contexts configuration file. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionGets a map of all template contexts, with the template context names as keys.Returns the absolute VFS path where the configuration property file is stored.getEditorStyleSheet
(CmsObject cms, String editedResourcePath) Returns the style sheet to be used for the editor.Gets the name of the cookie which should be used for overriding the template context.getTemplateContext
(CmsObject cms, javax.servlet.http.HttpServletRequest request, CmsResource resource) Determines the template context from the current CMS context, request, and resource.void
initialize
(CmsObject cms, String config) Initializes the context provider using a CMS object.readCommonProperty
(CmsObject cms, String propertyName, String fallbackValue) Gets the value which should be used instead of a property which was read from the template resource.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.opencms.loader.I_CmsTemplateContextProvider
getDefaultLabel, getFunctionsForGallery, getMenuLabel, getMenuPosition, getTemplateCompatibility, isHiddenContext, isIgnoreTemplateContextsSetting, shouldShowContextMenuOption, shouldShowElementTemplateContextSelection
-
Field Details
-
A_HEIGHT
JSON attribute name.- See Also:
-
A_NICE_NAME
JSON attribute name.- See Also:
-
A_PATH
JSON attribute name.- See Also:
-
A_VARIANTS
JSON attribute name.- See Also:
-
A_WIDTH
JSON attribute name.- See Also:
-
PARAM_CONFIGURATION
The name for the configuration parameter which points to the template contexts configuration file.- See Also:
-
-
Constructor Details
-
CmsDefaultTemplateContextProvider
public CmsDefaultTemplateContextProvider()Default constructor.
-
-
Method Details
-
getAllContexts
Description copied from interface:I_CmsTemplateContextProvider
Gets a map of all template contexts, with the template context names as keys.- Specified by:
getAllContexts
in interfaceI_CmsTemplateContextProvider
- Returns:
- the map of template context providers
- See Also:
-
getConfigurationPropertyPath
Returns the absolute VFS path where the configuration property file is stored.- Returns:
- the absolute VFS path where the configuration property file is stored
-
getEditorStyleSheet
Description copied from interface:I_CmsTemplateContextProvider
Returns the style sheet to be used for the editor.- Specified by:
getEditorStyleSheet
in interfaceI_CmsTemplateContextProvider
- Parameters:
cms
- the current CMS contexteditedResourcePath
- the path of the edited resource- Returns:
- the path of the style sheet to be used for the resource
- See Also:
-
getOverrideCookieName
Description copied from interface:I_CmsTemplateContextProvider
Gets the name of the cookie which should be used for overriding the template context.- Specified by:
getOverrideCookieName
in interfaceI_CmsTemplateContextProvider
- Returns:
- the name of the cookie used for overriding the template context
- See Also:
-
getTemplateContext
public CmsTemplateContext getTemplateContext(CmsObject cms, javax.servlet.http.HttpServletRequest request, CmsResource resource) Description copied from interface:I_CmsTemplateContextProvider
Determines the template context from the current CMS context, request, and resource.- Specified by:
getTemplateContext
in interfaceI_CmsTemplateContextProvider
- Parameters:
cms
- the CMS contextrequest
- the current requestresource
- the resource being rendered- Returns:
- the current template context
- See Also:
-
initialize
Description copied from interface:I_CmsTemplateContextProvider
Initializes the context provider using a CMS object.Initialization always happens in the Online project.
- Specified by:
initialize
in interfaceI_CmsTemplateContextProvider
- Parameters:
cms
- the current CMS contextconfig
- the template context provider configuration- See Also:
-
readCommonProperty
public String readCommonProperty(CmsObject cms, String propertyName, String fallbackValue) throws CmsException Description copied from interface:I_CmsTemplateContextProvider
Gets the value which should be used instead of a property which was read from the template resource.This is needed because before template context providers, it was common to store template-specific configuration in a property on the template JSP. Since template context providers make the result ambiguous, this method is intended as a replacement.
- Specified by:
readCommonProperty
in interfaceI_CmsTemplateContextProvider
- Parameters:
cms
- the CMS context to usepropertyName
- the name of the propertyfallbackValue
- the value to return if no value is found or an error occurs- Returns:
- the common property value
- Throws:
CmsException
- if something goes wrong- See Also:
-