Class CmsJspStandardContextBean

java.lang.Object
org.opencms.jsp.util.CmsJspStandardContextBean

public final class CmsJspStandardContextBean extends 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
  • Field Details

  • Method Details

    • getFunctionDetailLink

      public static String getFunctionDetailLink(CmsObject cms, String prefix, 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 String getFunctionDetailLinkExact(CmsObject cms, 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
    • createCopy

      Returns a copy of this JSP context bean.

      Returns:
      a copy of this JSP context bean
    • decrypt

      public String decrypt(String text)
      Uses the default text encryption method to decrypt an encrypted string.
      Parameters:
      text - the encrypted stirng
      Returns:
      the decrypted string
    • elementCachingHash

      Returns a caching hash specific to the element, it's properties and the current container width.

      Returns:
      the caching hash
    • encrypt

      public String encrypt(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(String path)
      Checks if the resource with the given path exists.
      Parameters:
      path - a path
      Returns:
      true if the resource exists
    • getAvailableLocales

      Returns the locales available for the currently requested URI.
      Returns:
      the locales available for the currently requested URI.
    • getBean

      public Object getBean(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

      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 String getBundleEditorLink(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 String getBundleEditorLink(String messageKey, 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 String getBundleEditorLink(String messageKey, String backLinkAnchor, 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&param2=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 String getBundleEditorLink(String messageKey, String backLinkAnchor, String backLinkParams, List<String> bundleFilters)
      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&param2=b".
      bundleFilters - substrings of names of bundles to be preferred when multiple bundles contain the key.
      Returns:
      a link to the bundle editor for editing the provided key, or null if the bundle for the key could not be found.
    • getBundleEditorLinkForBundle

      public String getBundleEditorLinkForBundle(String messageKey, String backLinkAnchor, String backLinkParams, 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&param2=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 String getBundleRootPath(String messageKey, List<String> bundleFilters)
      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, the name filters are applied in the given order until at least one bundle matches a filter. If multiple bundles match, one of them is arbitrarily chosen (but a warning is logged). If no bundle matches, an arbitrary bundle is chosen (but also 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
      bundleFilters - substrings of names of bundles to be preferred when multiple bundles contain the key.
      Returns:
      the root path of the bundle containing the message key
    • getContainer

      Returns the container the currently rendered element is part of.

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

      Gets information about a given container type.
      Parameters:
      containerType - the container type
      Returns:
      the bean with the information about the container type
    • getControllerCms

      Gets the CmsObject from the current Flex controller.
      Returns:
      the CmsObject from the current Flex controller
    • 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

      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

      Returns the detail content site path, or null if not available.

      Returns:
      the detail content site path
    • getDetailFunctionPage

      Returns the detail function page.

      Returns:
      the detail function page
    • getDetailOnlyPage

      Returns the detail only page.

      Returns:
      the detail only page
    • getElement

      Returns the currently rendered element.

      Returns:
      the currently rendered element
    • 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

      Returns a lazy initialized map of wrapped element resources by container name.

      Returns:
      the lazy map of element resource wrappers
    • 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:
    • getEnableReload

      Alternative method name for getReloadMarker().
      Returns:
      the reload marker
      See Also:
    • getFormatterInfo

      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

      Gets the formatter bean for active formatters with a given container type.
      Parameters:
      containerType - the container type
      Returns:
      the wrapped formatters
    • getFormatterInfoForDisplay

      Gets the formatter beans for active formatters with a given display type.
      Parameters:
      displayType - the display type
      Returns:
      the wrapped formatters
    • getFormatterSettingDefault

      Gets a lazy map which can be used to access element setting defaults for a specific formatter key and setting name.
      Returns:
      the lazy map
    • getFunction

      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.
      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

      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']} /&gt
       
      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:
    • 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']} /&gt
       
      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:
    • getFunctionFormatFromContent

      Returns a lazy map which creates a wrapper object for a dynamic function format when given an XML content as a key.

      Returns:
      a lazy map for accessing function formats for a content
    • 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 Locale getLocale()
      Returns the current locale.

      Returns:
      the current locale
    • getLocaleResource

      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

      Gets the main locale for the current page's locale group.

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

      public Map<String,String> getMeta()
      Returns the meta mappings map.

      Returns:
      the meta mappings
    • getPage

      Returns the currently displayed container page.

      Returns:
      the currently displayed container page
    • getPage

      public CmsContainerPageBean getPage(Object page, 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
    • getPageResource

      Returns the current container page resource.

      Returns:
      the current container page resource
    • getParentContainer

      Returns the parent container to the current container if available.

      Returns:
      the parent container
    • getParentContainers

      Returns the instance id parent container mapping.

      Returns:
      the instance id parent container mapping
    • getParentElement

      Returns the parent element to the current element if available.

      Returns:
      the parent element or null
    • getPluginGroups

      Gets the set of plugin group names.
      Returns:
      the set of plugin group names
    • getPlugins

      Gets the map of plugins by group.
      Returns:
      the map of active plugins by group
    • getPreviewFormatter

      JSP EL accessor method for retrieving the preview formatters.

      Returns:
      a lazy map for accessing preview formatters
    • getReadAllSubCategories

      Reads all sub-categories below the provided category.
      Returns:
      The map from the provided category to it's sub-categories in a CmsJspCategoryAccessBean.
    • 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
    • getReadCategories

      Reads the categories assigned to the currently requested URI.
      Returns:
      the categories assigned to the currently requested URI.
    • getReadCategory

      Transforms the category path of a category to the category.
      Returns:
      a map from root or site path to category.
    • 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.
    • getReadResourceCategories

      Reads the categories assigned to a resource.
      Returns:
      map from the resource path (root path) to the assigned categories
    • 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
    • getRequestContext

      Returns the request context.

      Returns:
      the request context
    • getResourceTypeInfo

      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(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
    • getSitemapConfig

      Gets the wrapper for the sitemap configuration.
      Returns:
      the wrapper object for the sitemap configuration
    • getSitePath

      Transforms root paths to site paths.
      Returns:
      lazy map from root paths to site paths.
      See Also:
    • getSubSitePath

      Returns the subsite path for the currently requested URI.

      Returns:
      the subsite path
    • getSystemInfo

      Returns the system information.

      Returns:
      the system information
    • getTemplate

      Gets a bean containing information about the current template.

      Returns:
      the template information bean
    • getTitle

      public 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

      Get the title and read the Title property according the provided locale.
      Returns:
      The map from locales to the locale specific titles.
    • 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']} /&gt
       
      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:
    • getVfs

      Returns an initialized VFS access bean.

      Returns:
      an initialized VFS access bean
    • getWorkplaceLocale

      Returns the workplace locale from the current user's settings.

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

      public Map<Object,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
    • isDetailPageAvailable

      public boolean isDetailPageAvailable()
      Returns true</code in case a detail page is available for the current element.

      Returns:
      true</code in case a detail page is available for the current element
    • 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(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(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(String path)
      Gets the link wrapper for the given path.
      Parameters:
      path - the path
      Returns:
      the link wrapper
    • readResource

      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

      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

      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
    • setDetailOnlyPage

      public void setDetailOnlyPage(CmsContainerPageBean detailOnlyPage)
      Sets the detail only page.

      Parameters:
      detailOnlyPage - the detail only page to set
    • 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

      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

      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 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 Object wrap(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
    • getCmsObject

      protected CmsObject getCmsObject()
      Accessor for the CmsObject.
      Returns:
      the CmsObject
    • getElementFormatter

      Returns the formatter configuration to the given element.

      Parameters:
      element - the element
      Returns:
      the formatter configuration
    • getLocaleSpecificTitle

      protected String getLocaleSpecificTitle(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
    • getParentElement

      Returns the parent element if available.

      Parameters:
      element - the element
      Returns:
      the parent element or null
    • getSitemapConfigInternal

      Accessor for the sitemap configuration.
      Returns:
      the sitemap configuration
    • readDynamicFunctionBean

      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

      Wraps a list of formatter beans for use in JSPs.
      Parameters:
      formatters - the formatters to wrap
      Returns:
      the wrapped formatters