Interface I_CmsTemplateContextProvider

  • All Known Implementing Classes:
    CmsDefaultTemplateContextProvider, CmsTransformerTemplateProvider

    public interface I_CmsTemplateContextProvider
    Interface for template context providers.

    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

      All Methods Instance Methods Abstract Methods Default Methods 
      Modifier and Type Method Description
      java.util.Map<java.lang.String,​CmsTemplateContext> getAllContexts()
      Gets a map of all template contexts, with the template context names as keys.
      default java.lang.String getDefaultLabel​(java.util.Locale locale)
      Customizes the label for the default template context option.
      java.lang.String getEditorStyleSheet​(CmsObject cms, java.lang.String editedResourcePath)
      Returns the style sheet to be used for the editor.
      default java.util.Set<CmsUUID> getFunctionsForGallery​(CmsObject cms, java.lang.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 java.lang.String getMenuLabel​(java.util.Locale locale)
      Gets the label to use for the menu entry in the given locale.
      default int getMenuPosition()
      Special integer that indicates the position for the template context selection in the context menu.
      java.lang.String getOverrideCookieName()
      Gets the name of the cookie which should be used for overriding the template context.
      default java.lang.String getTemplateCompatibility​(java.lang.String templateContextKey)
      Gets the template compatibility for the given template context key.
      CmsTemplateContext 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, java.lang.String config)
      Initializes the context provider using a CMS object.
      default boolean isHiddenContext​(java.lang.String key)
      Checks if the template context should be hidden in the GUI.
      default boolean isIgnoreTemplateContextsSetting()
      Checks if the 'templateContexts' setting should be ignored when rendering container elements (i.e.
      java.lang.String readCommonProperty​(CmsObject cms, java.lang.String propertyName, java.lang.String fallbackValue)
      Gets the value which should be used instead of a property which was read from the template resource.
      default boolean shouldShowContextMenuOption​(CmsObject cms)
      Checks if the context menu option for switching the template should be shown for the given user context.
      default boolean shouldShowElementTemplateContextSelection​(CmsObject cms)
      Controls whether template context select options should be shown in the element settings dialog.
    • Method Detail

      • getAllContexts

        java.util.Map<java.lang.String,​CmsTemplateContextgetAllContexts()
        Gets a map of all template contexts, with the template context names as keys.

        Returns:
        the map of template context providers
      • getDefaultLabel

        default java.lang.String getDefaultLabel​(java.util.Locale locale)
        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

        java.lang.String getEditorStyleSheet​(CmsObject cms,
                                             java.lang.String editedResourcePath)
        Returns the style sheet to be used for the editor.

        Parameters:
        cms - the current CMS context
        editedResourcePath - the path of the edited resource
        Returns:
        the path of the style sheet to be used for the resource
      • getFunctionsForGallery

        default java.util.Set<CmsUUIDgetFunctionsForGallery​(CmsObject cms,
                                                              java.lang.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.

        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 context
        templateContext - 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

        default java.lang.String getMenuLabel​(java.util.Locale locale)
        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

        default int 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

        java.lang.String 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

        default java.lang.String getTemplateCompatibility​(java.lang.String templateContextKey)
        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 context
        request - the current request
        resource - the resource being rendered
        Returns:
        the current template context
      • initialize

        void initialize​(CmsObject cms,
                        java.lang.String config)
        Initializes the context provider using a CMS object.

        Initialization always happens in the Online project.

        Parameters:
        cms - the current CMS context
        config - the template context provider configuration
      • isHiddenContext

        default boolean isHiddenContext​(java.lang.String key)
        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

        default boolean 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

        java.lang.String readCommonProperty​(CmsObject cms,
                                            java.lang.String propertyName,
                                            java.lang.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 use
        propertyName - the name of the property
        fallbackValue - 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

        default boolean shouldShowContextMenuOption​(CmsObject cms)
        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

        default boolean shouldShowElementTemplateContextSelection​(CmsObject cms)
        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