Interface I_CmsTemplateContextProvider
- All Known Implementing Classes:
CmsDefaultTemplateContextProvider
,CmsTransformerTemplateProvider
Implementations of this class are used to dynamically determine a template used for rendering a page at runtime, e.g. there could be one template for desktop browsers and another for mobile browsers. It is possible to override the template using a cookie containing the name of the template context which should be used as a value. The cookie name is determined by the template context provider.
-
Method Summary
Modifier and TypeMethodDescriptionGets a map of all template contexts, with the template context names as keys.default String
getDefaultLabel
(Locale locale) Customizes the label for the default template context option.getEditorStyleSheet
(CmsObject cms, String editedResourcePath) Returns the style sheet to be used for the editor.getFunctionsForGallery
(CmsObject cms, String templateContext) Returns a set of structure ids of dynamic functions that are allowed to appear in the gallery dialog search results, or null if the dynamic function results should not be restricted.default String
getMenuLabel
(Locale locale) Gets the label to use for the menu entry in the given locale.default int
Special integer that indicates the position for the template context selection in the context menu.Gets the name of the cookie which should be used for overriding the template context.default String
getTemplateCompatibility
(String templateContextKey) Gets the template compatibility for the given template context key.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.default boolean
isHiddenContext
(String key) Checks if the template context should be hidden in the GUI.default boolean
Checks if the 'templateContexts' setting should be ignored when rendering container elements (i.e.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.default boolean
Checks if the context menu option for switching the template should be shown for the given user context.default boolean
Controls whether template context select options should be shown in the element settings dialog.
-
Method Details
-
getAllContexts
Gets a map of all template contexts, with the template context names as keys.- Returns:
- the map of template context providers
-
getDefaultLabel
Customizes the label for the default template context option.If null is returned, the default label for the default template will be used. If null is returned, a default
- Parameters:
locale
- the locale for i18n- Returns:
- the label for the default template context option
-
getEditorStyleSheet
Returns the style sheet to be used for the editor.- 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
-
getFunctionsForGallery
Returns a set of structure ids of dynamic functions that are allowed to appear in the gallery dialog search results, or null if the dynamic function results should not be restricted.Note: Functions may be excluded from the gallery dialog search results for other reasons even if they appear in the set returned by this method.
- Parameters:
cms
- the current CMS contexttemplateContext
- the current template context key- Returns:
- the set of ids of dynamic functions to allow in the gallery search results, or null if function results shouldn't be restricted
-
getMenuLabel
Gets the label to use for the menu entry in the given locale.If this returns null, the default menu entry label is used.
- Parameters:
locale
- the locale for which we want the menu entry label- Returns:
- the menu entry label
-
getMenuPosition
Special integer that indicates the position for the template context selection in the context menu.Currently can only return 0 or 1.
- Returns:
- the context menu position
-
getOverrideCookieName
Gets the name of the cookie which should be used for overriding the template context.- Returns:
- the name of the cookie used for overriding the template context
-
getTemplateCompatibility
Gets the template compatibility for the given template context key.The template compatibility controls which elements are visible as gallery search results when the template with the given key is active. If the template.compatibility property on a resource is set (possibly inherited from a parent folder), but does not contain the compatibility value returned by this method, it will not show up in gallery search results when the template referenced by templateContextKey is active.
- Parameters:
templateContextKey
- the key for a template context- Returns:
- a template compatibility string (should not contain whitespace or punctuation)
-
getTemplateContext
CmsTemplateContext getTemplateContext(CmsObject cms, javax.servlet.http.HttpServletRequest request, CmsResource resource) Determines the template context from the current CMS context, request, and resource.- Parameters:
cms
- the CMS contextrequest
- the current requestresource
- the resource being rendered- Returns:
- the current template context
-
initialize
Initializes the context provider using a CMS object.Initialization always happens in the Online project.
- Parameters:
cms
- the current CMS contextconfig
- the template context provider configuration
-
isHiddenContext
Checks if the template context should be hidden in the GUI.- Parameters:
key
- the key of a template context- Returns:
- true if the template context should be hidden in the GUI
-
isIgnoreTemplateContextsSetting
Checks if the 'templateContexts' setting should be ignored when rendering container elements (i.e. they will be rendered by default, regardless of the setting value).- Returns:
- true if the templateContexts setting should be ignored by the cms:container tag
-
readCommonProperty
String readCommonProperty(CmsObject cms, String propertyName, String fallbackValue) throws CmsException 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.
- 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
-
shouldShowContextMenuOption
Checks if the context menu option for switching the template should be shown for the given user context.- Parameters:
cms
- the CmsObject to check- Returns:
- true if the context menu option should be visible
-
shouldShowElementTemplateContextSelection
Controls whether template context select options should be shown in the element settings dialog.- Parameters:
cms
- the CmsObject for the current user- Returns:
- true if the template context select options should be shown in the element settings dialog
-