Class CmsJspContentAccessBean

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

public class CmsJspContentAccessBean extends Object
Allows access to the individual elements of an XML content, usually used inside a loop of a <cms:contentload> tag.

The implementation is optimized for performance and uses lazy initializing of the requested values as much as possible.

Since:
7.0.2
See Also:
  • Field Details

  • Constructor Details

  • Method Details

    • createImageDndAttr

      protected static String createImageDndAttr(CmsUUID structureId, String imagePath, String locale)
      Generates the HTML attribute "data-imagednd" that enables the ADE image drag and drop feature.

      Parameters:
      structureId - the structure ID of the XML document to insert the image
      locale - the locale to generate the image in
      imagePath - the XML path to the image source node.
      Returns:
      the HTML attribute "data-imagednd" that enables the ADE image drag and drop feature
    • getAttachmentLocales

      Gets the list of locales for which there are attachments.

      Returns:
      the list of locales for which there are attachments
    • getAttachments

      Gets an attachment bean, trying to automatically find the right locale for the current page.

      Returns:
      the attachments bean for the current page's locale
      Throws:
      CmsException - if something goes wrong
    • getAttachmentsForLocale

      Gets a lazy map which maps locales to attachment beans for that locale.

      Returns:
      the lazy map
    • getCmsObject

      Returns the OpenCms user context this bean was initialized with.

      Returns:
      the OpenCms user context this bean was initialized with
    • getFile

      public CmsFile getFile()
      Returns the raw VFS file object the content accessed by this bean was created from.

      This can be used to access information from the raw file on a JSP.

      Usage example on a JSP with the JSTL:

       <cms:contentload ... >
           <cms:contentaccess var="content" />
           Root path of the resource: ${content.file.rootPath}
       </cms:contentload>
      Returns:
      the raw VFS file object the content accessed by this bean was created from
    • getFileLink

      public String getFileLink()
      Returns the substituted link to the content file.

      Use for detail page links.

      Returns:
      the substituted link
    • getFilename

      public String getFilename()
      Returns the site path of the current resource, that is the result of CmsObject.getSitePath(CmsResource) with the resource obtained by getFile().

      Usage example on a JSP with the JSTL:

       <cms:contentload ... >
           <cms:contentaccess var="content" />
           Site path of the resource: "${content.filename}";
       </cms:contentload>
      Returns:
      the site path of the current resource
      See Also:
    • getHasLocale

      Returns a lazy initialized Map that provides Booleans that indicate if a specified Locale is available in the XML content.

      The provided Map key is assumed to be a String that represents a Locale.

      Usage example on a JSP with the JSTL:

       <cms:contentload ... >
           <cms:contentaccess var="content" />
           <c:if test="${content.hasLocale['de']}" >
               The content has a "de" Locale!
           </c:if>
       </cms:contentload>
      Returns:
      a lazy initialized Map that provides Booleans that indicate if a specified Locale is available in the XML content
    • getHasLocaleValue

      Returns a lazy initialized Map that provides a Map that provides Booleans that indicate if a value (xpath) is available in the XML content in the selected locale.

      The first provided Map key is assumed to be a String that represents the Locale, the second provided Map key is assumed to be a String that represents the xpath to the value.

      Usage example on a JSP with the JSTL:

       <cms:contentload ... >
           <cms:contentaccess var="content" />
           <c:if test="${content.hasLocaleValue['de']['Title']}" >
               The content has a "Title" value in the "de" Locale!
           </c:if>
       </cms:contentload>
      Please note that you can also test if a locale value exists like this:
       <c:if test="${content.value['de']['Title'].exists}" > ... </c:if>
      Returns:
      a lazy initialized Map that provides a Map that provides Booleans that indicate if a value (xpath) is available in the XML content in the selected locale
      See Also:
    • getHasValue

      Returns a lazy initialized Map that provides Booleans that indicate if a value (xpath) is available in the XML content in the current locale.

      The provided Map key is assumed to be a String that represents the xpath to the value.

      Usage example on a JSP with the JSTL:

       <cms:contentload ... >
           <cms:contentaccess var="content" />
           <c:if test="${content.hasValue['Title']}" >
               The content has a "Title" value in the current locale!
           </c:if>
       </cms:contentload>
      Please note that you can also test if a value exists like this:
       <c:if test="${content.value['Title'].exists}" > ... </c:if>
      Returns:
      a lazy initialized Map that provides Booleans that indicate if a value (xpath) is available in the XML content in the current locale
      See Also:
    • getId

      public CmsUUID getId()
      Returns the structure ID of the current resource, that is the ID of the resource obtained by getFile().

      Usage example on a JSP with the JSTL:

       <cms:contentload ... >
           <cms:contentaccess var="content" />
           Site path of the resource: "${content.id}";
       </cms:contentload>
      Returns:
      the structure ID of the current resource
      See Also:
    • getImageDnd

      Gets the lazy imageDnd map.

      Returns:
      the lazy imageDnd map
    • getIsEditable

      public boolean getIsEditable()
      Returns true in case the current user is allowed to edit the XML content.

      If the check is performed from the online project, the user context is internally switched to an offline project. So this may return true even if the user is currently in the online project. "Allowed to edit" here requires "read" and "write" permission for the VFS resource the XML content was created from. It also requires that the VFS resource is not locked by another user. Moreover, the user must be able to access at least one "offline" project.

      Intended for quick checks to for example show / hide edit buttons for user generated content.

      Returns:
      true in case the current user is allowed to edit the XML content
    • getJson

      Gets the JSON for the current locale.
      Returns:
      the JSON for the current locale
    • getLocale

      public Locale getLocale()
      Returns the Locale this bean is using for content access, this may be a default fall back Locale.

      Returns:
      the Locale this bean is using for content access, this may be a default fall back Locale
    • getLocaleJson

      Gets a lazy map from locales (can be provided as strings or java.util.Locale) to the (default) JSON representation of an XML content.
      Returns:
      the lazy map from locales to JSON strings
    • getLocaleNames

      Returns a lazy initialized Map that provides a List with all available elements paths (Strings) used in this document in the selected locale.

      The provided Map key is assumed to be a String that represents the Locale.

      Usage example on a JSP with the JSTL:

       <cms:contentload ... >
           <cms:contentaccess var="content" />
           <c:forEach items="${content.localeNames['de']}" var="elem">
               <c:out value="${elem}" />
           </c:forEach>
       </cms:contentload>
      Returns:
      a lazy initialized Map that provides a Map that provides values from the XML content in the selected locale
      See Also:
    • getLocaleRdfa

      Returns the map of RDFA maps by locale.

      Returns:
      the map of RDFA maps by locale
    • getLocaleSubValueList

      Returns a lazy initialized Map that provides a Map that provides Lists of direct sub values from the XML content in the selected locale.

      The first provided Map key is assumed to be a String that represents the Locale, the second provided Map key is assumed to be a String that represents the xpath to the value.

      Usage example on a JSP with the JSTL:

       <cms:contentload ... >
           <cms:contentaccess var="content" />
           <c:forEach var="item" items="${content.localeSubValueList['de']['Items']}">
               ${item}
           </c:forEach>
       </cms:contentload>
      Returns:
      a lazy initialized Map that provides a Map that provides Lists of direct sub values from the XML content in the selected locale
      See Also:
    • getLocaleValue

      Returns a lazy initialized Map that provides a Map that provides values from the XML content in the selected locale.

      The first provided Map key is assumed to be a String that represents the Locale, the second provided Map key is assumed to be a String that represents the xpath to the value.

      Usage example on a JSP with the JSTL:

       <cms:contentload ... >
           <cms:contentaccess var="content" />
           The Title in Locale "de": ${content.localeValue['de']['Title']}
       </cms:contentload>
      Returns:
      a lazy initialized Map that provides a Map that provides values from the XML content in the selected locale
      See Also:
    • getLocaleValueList

      Returns a lazy initialized Map that provides a Map that provides Lists of values from the XML content in the selected locale.

      The first provided Map key is assumed to be a String that represents the Locale, the second provided Map key is assumed to be a String that represents the xpath to the value.

      Usage example on a JSP with the JSTL:

       <cms:contentload ... >
           <cms:contentaccess var="content" />
           <c:forEach var="teaser" items="${content.localeValueList['de']['Teaser']}">
               ${teaser}
           </c:forEach>
       </cms:contentload>
      Returns:
      a lazy initialized Map that provides a Map that provides Lists of values from the XML content in the selected locale
      See Also:
    • getNames

      public List<String> getNames()
      Returns a list with all available elements paths (Strings) used in this document in the current locale.

      Usage example on a JSP with the JSTL:

       <cms:contentload ... >
           <cms:contentaccess var="content" />
           <c:forEach items="${content.names}" var="elem">
               <c:out value="${elem}" />
           </c:forEach>
       </cms:contentload>
      Returns:
      a list with all available elements paths (Strings) used in this document in the current locale
      See Also:
    • getPrintStructure

      Prints the XPaths of the available content values into an HTML ul list.

      Returns:
      the HTML list of XPaths
    • getRawContent

      Returns the raw XML content object that is accessed by this bean.

      Returns:
      the raw XML content object that is accessed by this bean
    • getRdfa

      public Map<String,String> getRdfa()
      Returns RDFA by value name map.

      Returns:
      RDFA by value name map
    • getReadCategories

      Reads and returns the categories assigned to the content's VFS resource.
      Returns:
      the categories assigned to the content's VFS resource.
    • getResource

      Returns the (wrapped) content resource for the content accessed by this bean.

      Returns:
      the (wrapped) content resource for the content accessed by this bean
    • getSubValueList

      Returns a lazy initialized Map that provides Lists of direct sub values of the given value from the XML content in the current locale.

      The provided Map key is assumed to be a String that represents the xpath to the value. Use this method in case you want to iterate over a List of sub values from the XML content.

      Usage example on a JSP with the JSTL:

       <cms:contentload ... >
           <cms:contentaccess var="content" />
           <c:forEach var="teaser" items="${content.subValueList['Items']}">
               ${item}
           </c:forEach>
       </cms:contentload>
      Returns:
      a lazy initialized Map that provides Lists of values from the XML content in the current locale
      See Also:
    • getTypeName

      public String getTypeName()
      Returns the resource type name.

      Returns:
      the resource type name
    • getValue

      Returns a lazy initialized Map that provides values from the XML content in the current locale.

      The provided Map key is assumed to be a String that represents the xpath to the value.

      Usage example on a JSP with the JSTL:

       <cms:contentload ... >
           <cms:contentaccess var="content" />
           The Title: ${content.value['Title']}
       </cms:contentload>
      Returns:
      a lazy initialized Map that provides values from the XML content in the current locale
      See Also:
    • getValueList

      Returns a lazy initialized Map that provides Lists of values from the XML content in the current locale.

      The provided Map key is assumed to be a String that represents the xpath to the value. Use this method in case you want to iterate over a List of values form the XML content.

      Usage example on a JSP with the JSTL:

       <cms:contentload ... >
           <cms:contentaccess var="content" />
           <c:forEach var="teaser" items="${content.valueList['Teaser']}">
               ${teaser}
           </c:forEach>
       </cms:contentload>
      Returns:
      a lazy initialized Map that provides Lists of values from the XML content in the current locale
      See Also:
    • getVfs

      Returns an instance of a VFS access bean, initialized with the OpenCms user context this bean was created with.

      Returns:
      an instance of a VFS access bean, initialized with the OpenCms user context this bean was created with
    • getWrap

      Deprecated.
      use getResource() instead
      Returns the (wrapped) content resource for the content accessed by this bean.

      Returns:
      the (wrapped) content resource for the content accessed by this bean
    • init

      public void init(CmsObject cms, Locale locale, I_CmsXmlDocument content, CmsResource resource)
      Initialize this instance.

      Parameters:
      cms - the OpenCms context of the current user
      locale - the Locale to use when accessing the content
      content - the XML content to access
      resource - the resource to create the content from