Package org.opencms.loader
Class CmsDefaultTemplateContextProvider
- java.lang.Object
-
- org.opencms.loader.CmsDefaultTemplateContextProvider
-
- All Implemented Interfaces:
I_CmsTemplateContextProvider
public class CmsDefaultTemplateContextProvider extends java.lang.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
Fields Modifier and Type Field Description static java.lang.StringA_HEIGHTJSON attribute name.static java.lang.StringA_NICE_NAMEJSON attribute name.static java.lang.StringA_PATHJSON attribute name.static java.lang.StringA_VARIANTSJSON attribute name.static java.lang.StringA_WIDTHJSON attribute name.static java.lang.StringPARAM_CONFIGURATIONThe name for the configuration parameter which points to the template contexts configuration file.
-
Constructor Summary
Constructors Constructor Description CmsDefaultTemplateContextProvider()Default constructor.
-
Method Summary
All Methods Instance Methods Concrete 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.java.lang.StringgetConfigurationPropertyPath()Returns the absolute VFS path where the configuration property file is stored.java.lang.StringgetEditorStyleSheet(CmsObject cms, java.lang.String editedResourcePath)Returns the style sheet to be used for the editor.java.lang.StringgetOverrideCookieName()Gets the name of the cookie which should be used for overriding the template context.CmsTemplateContextgetTemplateContext(CmsObject cms, javax.servlet.http.HttpServletRequest request, CmsResource resource)Determines the template context from the current CMS context, request, and resource.voidinitialize(CmsObject cms, java.lang.String config)Initializes the context provider using a CMS object.java.lang.StringreadCommonProperty(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.-
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, shouldShowContextMenuOption, shouldShowElementTemplateContextSelection
-
-
-
-
Field Detail
-
A_HEIGHT
public static final java.lang.String A_HEIGHT
JSON attribute name.- See Also:
- Constant Field Values
-
A_NICE_NAME
public static final java.lang.String A_NICE_NAME
JSON attribute name.- See Also:
- Constant Field Values
-
A_PATH
public static final java.lang.String A_PATH
JSON attribute name.- See Also:
- Constant Field Values
-
A_VARIANTS
public static final java.lang.String A_VARIANTS
JSON attribute name.- See Also:
- Constant Field Values
-
A_WIDTH
public static final java.lang.String A_WIDTH
JSON attribute name.- See Also:
- Constant Field Values
-
PARAM_CONFIGURATION
public static final java.lang.String PARAM_CONFIGURATION
The name for the configuration parameter which points to the template contexts configuration file.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
CmsDefaultTemplateContextProvider
public CmsDefaultTemplateContextProvider()
Default constructor.
-
-
Method Detail
-
getAllContexts
public java.util.Map<java.lang.String,CmsTemplateContext> getAllContexts()
Description copied from interface:I_CmsTemplateContextProviderGets a map of all template contexts, with the template context names as keys.- Specified by:
getAllContextsin interfaceI_CmsTemplateContextProvider- Returns:
- the map of template context providers
- See Also:
I_CmsTemplateContextProvider.getAllContexts()
-
getConfigurationPropertyPath
public java.lang.String 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
public java.lang.String getEditorStyleSheet(CmsObject cms, java.lang.String editedResourcePath)
Description copied from interface:I_CmsTemplateContextProviderReturns the style sheet to be used for the editor.- Specified by:
getEditorStyleSheetin 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:
I_CmsTemplateContextProvider.getEditorStyleSheet(org.opencms.file.CmsObject, java.lang.String)
-
getOverrideCookieName
public java.lang.String getOverrideCookieName()
Description copied from interface:I_CmsTemplateContextProviderGets the name of the cookie which should be used for overriding the template context.- Specified by:
getOverrideCookieNamein interfaceI_CmsTemplateContextProvider- Returns:
- the name of the cookie used for overriding the template context
- See Also:
I_CmsTemplateContextProvider.getOverrideCookieName()
-
getTemplateContext
public CmsTemplateContext getTemplateContext(CmsObject cms, javax.servlet.http.HttpServletRequest request, CmsResource resource)
Description copied from interface:I_CmsTemplateContextProviderDetermines the template context from the current CMS context, request, and resource.- Specified by:
getTemplateContextin interfaceI_CmsTemplateContextProvider- Parameters:
cms- the CMS contextrequest- the current requestresource- the resource being rendered- Returns:
- the current template context
- See Also:
I_CmsTemplateContextProvider.getTemplateContext(org.opencms.file.CmsObject, javax.servlet.http.HttpServletRequest, org.opencms.file.CmsResource)
-
initialize
public void initialize(CmsObject cms, java.lang.String config)
Description copied from interface:I_CmsTemplateContextProviderInitializes the context provider using a CMS object.Initialization always happens in the Online project.
- Specified by:
initializein interfaceI_CmsTemplateContextProvider- Parameters:
cms- the current CMS contextconfig- the template context provider configuration- See Also:
I_CmsTemplateContextProvider.initialize(org.opencms.file.CmsObject, java.lang.String)
-
readCommonProperty
public java.lang.String readCommonProperty(CmsObject cms, java.lang.String propertyName, java.lang.String fallbackValue) throws CmsException
Description copied from interface:I_CmsTemplateContextProviderGets 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:
readCommonPropertyin 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:
I_CmsTemplateContextProvider.readCommonProperty(org.opencms.file.CmsObject, java.lang.String, java.lang.String)
-
-