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

      • getFunctionDetailLink

        public static java.lang.String getFunctionDetailLink​(CmsObject cms,
                                                             java.lang.String prefix,
                                                             java.lang.String functionName,
                                                             boolean fullLink)
        Gets the link to a function detail page.
        Parameters:
        cms - the CMS context
        prefix - the function detail prefix
        functionName - the function name
        fullLink - true if links should be generated with server prefix
        Returns:
        the link
      • getFunctionDetailLinkExact

        public static java.lang.String getFunctionDetailLinkExact​(CmsObject cms,
                                                                  java.lang.String functionName)
        Gets the link to a function detail page.

        This just returns null if no function detail page is defined, it does not use the default detail page as a fallback.

        Parameters:
        cms - the CMS context
        functionName - the function name
        Returns:
        the link
      • 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
      • decrypt

        public java.lang.String decrypt​(java.lang.String text)
        Uses the default text encryption method to decrypt an encrypted string.
        Parameters:
        text - the encrypted stirng
        Returns:
        the decrypted string
      • 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
      • encrypt

        public java.lang.String encrypt​(java.lang.String text)
        Uses the default text encryption to encrypt an input text.
        Parameters:
        text - the input text
        Returns:
        the encrypted text
      • exists

        public boolean exists​(java.lang.String path)
        Checks if the resource with the given path exists.
        Parameters:
        path - a path
        Returns:
        true if the resource exists
      • 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.
      • getBinaryUploadFolder

        public java.lang.String getBinaryUploadFolder​(CmsJspContentAccessBean content)
        Finds the folder to use for binary uploads, based on the list configuration given as an argument or the current sitemap configuration.
        Parameters:
        content - the list configuration content
        Returns:
        the binary upload folder
      • getBundleEditorLink

        public java.lang.String getBundleEditorLink​(java.lang.String messageKey)
        Generates a link to the bundle editor to edit the provided message key. The back link for the editor is the current uri. If the bundle for the key could not be found, null is returned.
        Parameters:
        messageKey - the message key to open the bundle editor for.
        Returns:
        a link to the bundle editor for editing the provided key, or null if the bundle for the key could not be found.
      • getBundleEditorLink

        public java.lang.String getBundleEditorLink​(java.lang.String messageKey,
                                                    java.lang.String backLinkAnchor)
        Generates a link to the bundle editor to edit the provided message key. The back link for the editor is the current uri with the provided backLinkAnchor added as anchor.. If the bundle for the key could not be found, null is returned.
        Parameters:
        messageKey - the message key to open the bundle editor for.
        backLinkAnchor - the anchor id to add to the backlink to the page. If null no anchor is added to the backlink.
        Returns:
        a link to the bundle editor for editing the provided key, or null if the bundle for the key could not be found.
      • getBundleEditorLink

        public java.lang.String getBundleEditorLink​(java.lang.String messageKey,
                                                    java.lang.String backLinkAnchor,
                                                    java.lang.String backLinkParams)
        Generates a link to the bundle editor to edit the provided message key. The back link for the editor is the current uri with the provided backLinkAnchor added as anchor. If the bundle resource for the key could not be found, null is returned.
        Parameters:
        messageKey - the message key to open the bundle editor for.
        backLinkAnchor - the anchor id to add to the backlink to the page. If null no anchor is added to the backlink.
        backLinkParams - request parameters to add to the backlink without leading '?', e.g. "param1=a¶m2=b".
        Returns:
        a link to the bundle editor for editing the provided key, or null if the bundle for the key could not be found.
      • getBundleEditorLink

        public java.lang.String getBundleEditorLink​(java.lang.String messageKey,
                                                    java.lang.String backLinkAnchor,
                                                    java.lang.String backLinkParams,
                                                    java.lang.String bundleName)
        Generates a link to the bundle editor to edit the provided message key. The back link for the editor is the current uri with the provided backLinkAnchor added as anchor. If the bundle resource for the key could not be found, null is returned.
        Parameters:
        messageKey - the message key to open the bundle editor for.
        backLinkAnchor - the anchor id to add to the backlink to the page. If null no anchor is added to the backlink.
        backLinkParams - request parameters to add to the backlink without leading '?', e.g. "param1=a¶m2=b".
        bundleName - the name of the bundle to search the key in. If null the bundle is detected automatically.
        Returns:
        a link to the bundle editor for editing the provided key, or null if the bundle for the key could not be found.
      • getBundleRootPath

        public java.lang.String getBundleRootPath​(java.lang.String messageKey)
        Gets the root path for the VFS-based message bundle containing the given message key.

        If no VFS-based message bundle contains the given key, null is returned. If multiple message bundles contain it, one of them is arbitrarily chosen (but a warning is logged).

        Note: This uses the online (published) state of message bundles, so if you have unpublished bundle changes, they will not be reflected in the result.

        Parameters:
        messageKey - the message key
        Returns:
        the root path of the bundle containing the message key
      • getContainer

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

        Returns:
        the container the currently rendered element is part of
      • getContainerTypeInfo

        public CmsContainerTypeInfoWrapper getContainerTypeInfo​(java.lang.String containerType)
        Gets information about a given container type.
        Parameters:
        containerType - the container type
        Returns:
        the bean with the information about the container type
      • getControllerCms

        public CmsObject getControllerCms()
        Gets the CmsObject from the current Flex controller.
        Returns:
        the CmsObject from the current Flex controller
      • 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()
      • getFormatterInfo

        public CmsFormatterInfoWrapper getFormatterInfo​(java.lang.String formatterKey)
        Gets the formatter info wrapper for the given formatter key.
        Parameters:
        formatterKey - a formatter key
        Returns:
        the formatter information for the formatter key, or null if no formatter was found
      • getFormatterInfoForContainer

        public java.util.List<CmsFormatterInfoWrappergetFormatterInfoForContainer​(java.lang.String containerType)
        Gets the formatter bean for active formatters with a given container type.
        Parameters:
        containerType - the container type
        Returns:
        the wrapped formatters
      • getFormatterInfoForDisplay

        public java.util.List<CmsFormatterInfoWrappergetFormatterInfoForDisplay​(java.lang.String displayType)
        Gets the formatter beans for active formatters with a given display type.
        Parameters:
        displayType - the display type
        Returns:
        the wrapped formatters
      • 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()
      • getFunctionDetailPageExact

        public java.util.Map<java.lang.String,​java.lang.String> getFunctionDetailPageExact()
        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()
      • getIsDetailPage

        public boolean getIsDetailPage()
        Returns true if the current page is a detail page.

        Returns:
        true if the current page is a detail page
      • getIsEditMode

        public boolean getIsEditMode()
        Returns true if the current request is direct edit enabled.

        Online-, history-requests, previews and temporary files will not be editable.

        Returns:
        true if the current request is 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 true if the current project is the online project.

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

        public boolean getIsPreviewMode()
        Returns true if the current request is in direct edit preview mode.

        This is the case if the request is not in edit mode and in the online project.

        Returns:
        true if the current request is in direct edit preview mode
      • 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
      • getPluginGroups

        public java.util.Set<java.lang.String> getPluginGroups()
        Gets the set of plugin group names.
        Returns:
        the set of plugin group names
      • getPlugins

        public java.util.Map<java.lang.String,​java.util.List<CmsTemplatePluginWrapper>> getPlugins()
        Gets the map of plugins by group.
        Returns:
        the map of active plugins by group
      • 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
      • getReadAttributeOrProperty

        public java.util.Map<java.lang.String,​java.util.Map<java.lang.String,​CmsJspObjectValueWrapper>> getReadAttributeOrProperty()
        Lazily reads the given attribute from the current sitemap or a property of the same name from the given resource.

        Usage example: ${cms.readAttributeOrProperty['/index.html']['attr']}

        Returns:
        a lazy loading map for accessing attributes / properties
      • 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
      • getRequest

        public javax.servlet.ServletRequest getRequest()
        Gets the stored request.
        Returns:
        the stored request
      • getResourceTypeInfo

        public CmsResourceTypeInfoWrapper getResourceTypeInfo​(java.lang.String typeName)
        Gets information about a specific resource type for use in JSPs.

        If no type with the given name exists, null is returned.

        Parameters:
        typeName - the type name
        Returns:
        the bean representing the resource type
      • getSchemaInfo

        public CmsSchemaInfo getSchemaInfo​(java.lang.String typeOrXsd)
                                    throws CmsException
        Gets the schema information bean for the given type or XSD.
        Parameters:
        typeOrXsd - either the name of a resource type, or the VFS path to an XSD schema
        Returns:
        the schema information bean
        Throws:
        CmsException - if something goes wrong
      • 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
      • isForceDisableEditMode

        public boolean isForceDisableEditMode()
        Checks if the flag that forces edit mode to be disabled is set.
        Returns:
        true if the flag that disables edit mode is set
      • isLinkToDifferentSite

        public boolean isLinkToDifferentSite​(java.lang.String link)
        Checks if the link is a link to a path in a different OpenCms site from the current one.
        Parameters:
        link - the link to check
        Returns:
        true if the link is a link to different subsite
      • isLinkToDifferentSubSite

        public boolean isLinkToDifferentSubSite​(java.lang.String link)
        Checks if the link is a link to a path in a different OpenCms subsite from the current one.

        For detail links, this checks the subsite of the detail page, not the subsite of the detail content.

        Parameters:
        link - the link to check
        Returns:
        true if the link is a link to different site
      • 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
      • link

        public CmsJspLinkWrapper link​(java.lang.String path)
        Gets the link wrapper for the given path.
        Parameters:
        path - the path
        Returns:
        the link wrapper
      • readResource

        public CmsJspResourceWrapper readResource​(java.lang.String str)
        Gets the resource wrapper for a given path or id.
        Parameters:
        str - a path or structure id
        Returns:
        the wrapper for the resource with the given path or id
      • readXml

        public CmsJspContentAccessBean readXml​(java.lang.String str)
        Reads an XML content and returns it as a content access bean
        Parameters:
        str - path or id
        Returns:
        the content access bean for the content with the given path or id
      • renderContainer

        public java.lang.String renderContainer​(CmsJspContainerPageWrapper page,
                                                java.lang.String name)
        Renders the elements of container in a container page wrapper as HTML (without a surrounding element).
        Parameters:
        page - the page wrapper
        name - the name or name prefix of the container
        Returns:
        the rendered HTML
      • 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
      • setEditorCssPath

        public java.lang.String setEditorCssPath​(java.lang.String path)
        In edit mode, creates a meta tag that tells the form-based content editor to use the stylesheet with the given path as a default.

        Does nothing outside of edit mode.

        Parameters:
        path - the site path of a style sheet
        Returns:
        the meta tag
      • setElement

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

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

        public void setForceDisableEditMode​(boolean forceDisableEditMode)
        Enables / disables the flag that forces edit mode to be disabled.
        Parameters:
        forceDisableEditMode - the new value for the flag
      • setPage

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

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

        public CmsJspResourceWrapper toResource​(java.lang.Object obj)
        Converts the given object to a resource wrapper and returns it, or returns null if the conversion fails
        Parameters:
        obj - the object to convert
        Returns:
        the resource wrapper
      • 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
      • uri

        public java.lang.String uri()
        Gets the path of either the detail content (if this is a detail request) or the current page if it's not a detail request.
        Returns:
        the URI of the page or detail content
      • wrap

        public java.lang.Object wrap​(java.lang.Object obj)
        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.

        Parameters:
        obj - the object to wrap
        Returns:
        an EL access wrapper map for the given object
      • 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
      • wrapFormatters

        protected java.util.List<CmsFormatterInfoWrapperwrapFormatters​(java.util.Collection<? extends I_CmsFormatterBean> formatters)
        Wraps a list of formatter beans for use in JSPs.
        Parameters:
        formatters - the formatters to wrap
        Returns:
        the wrapped formatters