Class CmsJspStandardContextBean


  • public final class CmsJspStandardContextBean
    extends java.lang.Object
    Allows convenient access to the most important OpenCms functions on a JSP page, indented to be used from a JSP with the JSTL or EL.

    This bean is available by default in the context of an OpenCms managed JSP.

    Since:
    8.0
    • Method Detail

      • getInstance

        public static CmsJspStandardContextBean getInstance​(javax.servlet.ServletRequest req)
        Creates a new instance of the standard JSP context bean.

        To prevent multiple creations of the bean during a request, the OpenCms request context attributes are used to cache the created VFS access utility bean.

        Parameters:
        req - the current servlet request
        Returns:
        a new instance of the standard JSP context bean
      • elementCachingHash

        public java.lang.String elementCachingHash()
        Returns a caching hash specific to the element, it's properties and the current container width.

        Returns:
        the caching hash
      • getAvailableLocales

        public java.util.List<java.util.Locale> getAvailableLocales()
        Returns the locales available for the currently requested URI.
        Returns:
        the locales available for the currently requested URI.
      • getBean

        public java.lang.Object getBean​(java.lang.String className)
        Helper for easy instantiation and initialization of custom context beans that returns an instance of the class specified via className, with the current context already set.
        Parameters:
        className - name of the class to instantiate. Must be a subclass of A_CmsJspCustomContextBean.
        Returns:
        an instance of the provided class with the current context already set.
      • getContainer

        public CmsContainerBean getContainer()
        Returns the container the currently rendered element is part of.

        Returns:
        the currently the currently rendered element is part of
      • getDetailContent

        public CmsJspResourceWrapper getDetailContent()
        Returns the current detail content, or null if no detail content is requested.

        Returns:
        the current detail content, or null if no detail content is requested.

      • getDetailContentId

        public CmsUUID getDetailContentId()
        Returns the structure id of the current detail content, or null if no detail content is requested.

        Returns:
        the structure id of the current detail content, or null if no detail content is requested.

      • getDetailContentSitePath

        public java.lang.String getDetailContentSitePath()
        Returns the detail content site path, or null if not available.

        Returns:
        the detail content site path
      • getElementBeansInContainers

        public java.util.Map<java.lang.String,​java.util.List<CmsJspStandardContextBean.CmsContainerElementWrapper>> getElementBeansInContainers()
        Returns a lazy initialized map of wrapped container elements beans by container name suffix.

        So in case there is more than one container where the name end with the given suffix, a joined list of container elements beans is returned.

        Returns:
        a lazy initialized map of wrapped container elements beans by container name suffix
        See Also:
        getElementsInContainer()
      • getElementsInContainer

        public java.util.Map<java.lang.String,​java.util.List<CmsJspResourceWrapper>> getElementsInContainer()
        Returns a lazy initialized map of wrapped element resources by container name.

        Returns:
        the lazy map of element resource wrappers
      • getElementsInContainers

        public java.util.Map<java.lang.String,​java.util.List<CmsJspResourceWrapper>> getElementsInContainers()
        Returns a lazy initialized map of wrapped element resources by container name suffix.

        So in case there is more than one container where the name end with the given suffix, a joined list of elements is returned.

        Returns:
        the lazy map of element resource wrappers
        See Also:
        getElementBeansInContainers()
      • getEnableReload

        public java.lang.String getEnableReload()
        Alternative method name for getReloadMarker().
        Returns:
        the reload marker
        See Also:
        getReloadMarker()
      • getFunction

        public java.util.Map<java.lang.String,​CmsDynamicFunctionBeanWrappergetFunction()
        Returns a lazy initialized Map which allows access to the dynamic function beans using the JSP EL.

        When given a key, the returned map will look up the corresponding dynamic function bean in the module configuration.

        Returns:
        a lazy initialized Map which allows access to the dynamic function beans using the JSP EL
      • getFunctionDetail

        @Deprecated
        public java.util.Map<java.lang.String,​java.lang.String> getFunctionDetail()
        Deprecated.
        Deprecated method to access function detail pages using the EL.

        Returns:
        a lazy initialized Map that provides the detail page link as a value when given the name of a (named) dynamic function as a key
      • getFunctionDetailPage

        public java.util.Map<java.lang.String,​java.lang.String> getFunctionDetailPage()
        Returns a lazy initialized Map that provides the detail page link as a value when given the name of a (named) dynamic function as a key.

        The provided Map key is assumed to be a String that represents a named dynamic function.

        Usage example on a JSP with the JSTL:

         <a href=${cms.functionDetailPage['search']} />
         
        Returns:
        a lazy initialized Map that provides the detail page link as a value when given the name of a (named) dynamic function as a key
        See Also:
        getTypeDetailPage()
      • getIsEditMode

        public boolean getIsEditMode()
        Checks if the current request should be direct edit enabled. Online-, history-requests, previews and temporary files will not be editable.

        Returns:
        true if the current request should be direct edit enabled
      • getIsJSONRequest

        public boolean getIsJSONRequest()
        Returns true if the current request is a JSON request.

        Returns:
        true if we are in a JSON request
      • getIsOnlineProject

        public boolean getIsOnlineProject()
        Returns if the current project is the online project.

        Returns:
        true if the current project is the online project
      • getLocale

        public java.util.Locale getLocale()
        Returns the current locale.

        Returns:
        the current locale
      • getLocaleResource

        public java.util.Map<java.lang.String,​CmsJspResourceWrappergetLocaleResource()
        Gets a map providing access to the locale variants of the current page.

        Note that all available locales for the site / subsite are used as keys, not just the ones for which a locale variant actually exists. Usage in JSPs: ${cms.localeResource['de']]

        Returns:
        the map from locale strings to locale variant resources
      • getMainLocale

        public java.util.Locale getMainLocale()
        Gets the main locale for the current page's locale group.

        Returns:
        the main locale for the current page's locale group
      • getMeta

        public java.util.Map<java.lang.String,​java.lang.String> getMeta()
        Returns the meta mappings map.

        Returns:
        the meta mappings
      • getPage

        public CmsContainerPageBean getPage()
        Returns the currently displayed container page.

        Returns:
        the currently displayed container page
      • getPage

        public CmsContainerPageBean getPage​(java.lang.Object page,
                                            java.lang.Object locale)
        Returns the container page bean for the give page and locale.

        Parameters:
        page - the container page resource as id, path or already as resource
        locale - the content locale as locale or string
        Returns:
        the container page bean
      • getParentContainers

        public java.util.Map<java.lang.String,​CmsContainerBeangetParentContainers()
        Returns the instance id parent container mapping.

        Returns:
        the instance id parent container mapping
      • getPreviewFormatter

        public java.util.Map<java.lang.String,​java.lang.String> getPreviewFormatter()
        JSP EL accessor method for retrieving the preview formatters.

        Returns:
        a lazy map for accessing preview formatters
      • getReadCategory

        public java.util.Map<java.lang.String,​CmsCategorygetReadCategory()
        Transforms the category path of a category to the category.
        Returns:
        a map from root or site path to category.
      • getReadPathCategories

        public java.util.Map<java.lang.String,​java.util.List<CmsCategory>> getReadPathCategories()
        Transforms the category path to the list of all categories on that path.

        Example: For path "location/europe/" the list [getReadCategory.get("location/"),getReadCategory.get("location/europe/")] is returned.

        Returns:
        a map from a category path to list of categories on that path.
      • getReloadMarker

        public java.lang.String getReloadMarker()
        Returns a HTML comment string that will cause the container page editor to reload the page if the element or its settings were edited.

        Returns:
        the reload marker
      • getSite

        public CmsSite getSite()
        Returns the current site.

        Returns:
        the current site
      • getSubSitePath

        public java.lang.String getSubSitePath()
        Returns the subsite path for the currently requested URI.

        Returns:
        the subsite path
      • getTitle

        public java.lang.String getTitle()
        Returns the title of a page delivered from OpenCms, usually used for the <title> tag of a HTML page.

        If no title information has been found, the empty String "" is returned.

        Returns:
        the title of the current page
      • getTitleLocale

        public java.util.Map<java.lang.String,​java.lang.String> getTitleLocale()
        Get the title and read the Title property according the provided locale.
        Returns:
        The map from locales to the locale specific titles.
      • getTypeDetailPage

        public java.util.Map<java.lang.String,​java.lang.String> getTypeDetailPage()
        Returns a lazy initialized Map that provides the detail page link as a value when given the name of a resource type as a key.

        The provided Map key is assumed to be the name of a resource type that has a detail page configured.

        Usage example on a JSP with the JSTL:

         <a href=${cms.typeDetailPage['bs-blog']} />
         
        Returns:
        a lazy initialized Map that provides the detail page link as a value when given the name of a resource type as a key
        See Also:
        getFunctionDetailPage()
      • getVfs

        public CmsJspVfsAccessBean getVfs()
        Returns an initialized VFS access bean.

        Returns:
        an initialized VFS access bean
      • getWorkplaceLocale

        public java.util.Locale getWorkplaceLocale()
        Returns the workplace locale from the current user's settings.

        Returns:
        returns the workplace locale from the current user's settings
      • getWrap

        public java.util.Map<java.lang.Object,​java.lang.Object> getWrap()
        Returns an EL access wrapper map for the given object.

        If the object is a CmsResource, then a CmsJspResourceWrapper is returned. Otherwise the object is wrapped in a CmsJspObjectValueWrapper.

        If the object is already is a wrapper, it is returned unchanged.

        Returns:
        an EL access wrapper map for the given object
      • initPage

        public void initPage()
                      throws CmsException
        Initializes the requested container page.

        Throws:
        CmsException - in case reading the requested resource fails
      • isDetailRequest

        public boolean isDetailRequest()
        Returns true if this is a request to a detail resource, false otherwise.

        Same as to check if getDetailContent() is null.

        Returns:
        true if this is a request to a detail resource, false otherwise
      • isDragMode

        public boolean isDragMode()
        Returns if the page is in drag mode.

        Returns:
        if the page is in drag mode
      • isEdited

        public boolean isEdited()
        Returns the flag to indicate if in drag and drop mode.

        Returns:
        true if in drag and drop mode
      • isModelGroupElement

        public boolean isModelGroupElement()
        Returns if the current element is a model group.

        Returns:
        true if the current element is a model group
      • isModelGroupPage

        public boolean isModelGroupPage()
        Returns if the current page is used to manage model groups.

        Returns:
        true if the current page is used to manage model groups
      • setContainer

        public void setContainer​(CmsContainerBean container)
        Sets the container the currently rendered element is part of.

        Parameters:
        container - the container the currently rendered element is part of
      • setDragMode

        public void setDragMode​(boolean isDragMode)
        Sets if the page is in drag mode.

        Parameters:
        isDragMode - if the page is in drag mode
      • setEdited

        public void setEdited​(boolean edited)
        Sets the flag to indicate if in drag and drop mode.

        Parameters:
        edited - true if in drag and drop mode
      • setElement

        public void setElement​(CmsContainerElementBean element)
        Sets the currently rendered element.

        Parameters:
        element - the currently rendered element to set
      • setPage

        public void setPage​(CmsContainerPageBean page)
        Sets the currently displayed container page.

        Parameters:
        page - the currently displayed container page to set
      • updateCmsObject

        public void updateCmsObject​(CmsObject cms)
        Updates the internally stored OpenCms user context.

        Parameters:
        cms - the new OpenCms user context
      • updateRequestData

        public void updateRequestData​(CmsFlexRequest cmsFlexRequest)
        Updates the standard context bean from the request.

        Parameters:
        cmsFlexRequest - the request from which to update the data
      • getLocaleSpecificTitle

        protected java.lang.String getLocaleSpecificTitle​(java.util.Locale locale)
        Returns the title according to the given locale.
        Parameters:
        locale - the locale for which the title should be read.
        Returns:
        the title according to the given locale
      • readDynamicFunctionBean

        protected CmsDynamicFunctionBean readDynamicFunctionBean​(java.lang.String configuredName)
                                                          throws CmsException
        Reads a dynamic function bean, given its name in the module configuration.

        Parameters:
        configuredName - the name of the dynamic function in the module configuration
        Returns:
        the dynamic function bean for the dynamic function configured under that name
        Throws:
        CmsException - if something goes wrong