org.opencms.jsp.util
Class CmsJspContentAccessBean

java.lang.Object
  extended by 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:
CmsJspTagContentAccess

Nested Class Summary
 class CmsJspContentAccessBean.CmsHasLocaleTransformer
          Provides Booleans that indicate if a specified locale is available in the XML content, the input is assumed to be a String that represents a Locale.
 class CmsJspContentAccessBean.CmsHasLocaleValueTransformer
          Provides Booleans that indicate if a specified path exists in the XML content, the input is assumed to be a String that represents an xpath in the XML content.
 class CmsJspContentAccessBean.CmsHasValueTransformer
          Provides a Map with Booleans that indicate if a specified path exists in the XML content in the selected Locale, the input is assumed to be a String that represents an xpath in the XML content.
 class CmsJspContentAccessBean.CmsLocaleNamesTransformer
          Provides a Map which lets the user access the list of element names from the selected locale in an XML content, the input is assumed to be a String that represents a Locale.
 class CmsJspContentAccessBean.CmsLocaleSubValueListTransformer
          Provides a Map which lets the user access sub value Lists from the selected locale in an XML content, the input is assumed to be a String that represents a Locale.
 class CmsJspContentAccessBean.CmsLocaleValueListTransformer
          Provides a Map which lets the user access value Lists from the selected locale in an XML content, the input is assumed to be a String that represents a Locale.
 class CmsJspContentAccessBean.CmsLocaleValueTransformer
          Provides a Map which lets the user access a value from the selected locale in an XML content, the input is assumed to be a String that represents a Locale.
 class CmsJspContentAccessBean.CmsSubValueListTransformer
          Provides a Map which lets the user access sub value Lists in an XML content, the input is assumed to be a String that represents an xpath in the XML content.
 class CmsJspContentAccessBean.CmsValueListTransformer
          Provides a Map which lets the user access value Lists in an XML content, the input is assumed to be a String that represents an xpath in the XML content.
 class CmsJspContentAccessBean.CmsValueTransformer
          Provides a Map which lets the user access a value in an XML content, the input is assumed to be a String that represents an xpath in the XML content.
 
Field Summary
protected static Map<String,CmsJspContentAccessValueWrapper> CONSTANT_NULL_VALUE_WRAPPER_MAP
          Constant Map that always returns the CmsJspContentAccessValueWrapper.NULL_VALUE_WRAPPER.
 
Constructor Summary
CmsJspContentAccessBean()
          No argument constructor, required for a JavaBean.
CmsJspContentAccessBean(CmsObject cms, CmsResource resource)
          Creates a content access bean based on a Resource, using the current request context locale.
CmsJspContentAccessBean(CmsObject cms, Locale locale, CmsResource resource)
          Creates a content access bean based on a Resource.
CmsJspContentAccessBean(CmsObject cms, Locale locale, I_CmsXmlDocument content)
          Creates a content access bean based on an XML content object.
 
Method Summary
 CmsObject getCmsObject()
          Returns the OpenCms user context this bean was initialized with.
 CmsFile getFile()
          Returns the raw VFS file object the content accessed by this bean was created from.
 String getFilename()
          Returns the site path of the current resource, that is the result of CmsObject.getSitePath(CmsResource) with the resource obtained by getFile().
 Map<String,Boolean> getHasLocale()
          Returns a lazy initialized Map that provides Booleans that indicate if a specified Locale is available in the XML content.
 Map<String,Map<String,Boolean>> 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.
 Map<String,Boolean> 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.
 CmsUUID getId()
          Returns the structure ID of the current resource, that is the ID of the resource obtained by getFile().
 Locale getLocale()
          Returns the Locale this bean was initialized with.
 Map<String,List<String>> getLocaleNames()
          Returns a lazy initialized Map that provides a List with all available elements paths (Strings) used in this document in the selected locale.
 Map<String,Map<String,List<CmsJspContentAccessValueWrapper>>> 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.
 Map<String,Map<String,CmsJspContentAccessValueWrapper>> getLocaleValue()
          Returns a lazy initialized Map that provides a Map that provides values from the XML content in the selected locale.
 Map<String,Map<String,List<CmsJspContentAccessValueWrapper>>> getLocaleValueList()
          Returns a lazy initialized Map that provides a Map that provides Lists of values from the XML content in the selected locale.
 List<String> getNames()
          Returns a list with all available elements paths (Strings) used in this document in the current locale.
 I_CmsXmlDocument getRawContent()
          Returns the raw XML content object that is accessed by this bean.
 Map<String,List<CmsJspContentAccessValueWrapper>> 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.
 Map<String,CmsJspContentAccessValueWrapper> getValue()
          Returns a lazy initialized Map that provides values from the XML content in the current locale.
 Map<String,List<CmsJspContentAccessValueWrapper>> getValueList()
          Returns a lazy initialized Map that provides Lists of values from the XML content in the current locale.
 CmsJspVfsAccessBean getVfs()
          Returns an instance of a VFS access bean, initialized with the OpenCms user context this bean was created with.
 void init(CmsObject cms, Locale locale, I_CmsXmlDocument content, CmsResource resource)
          Initialize this instance.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CONSTANT_NULL_VALUE_WRAPPER_MAP

protected static final Map<String,CmsJspContentAccessValueWrapper> CONSTANT_NULL_VALUE_WRAPPER_MAP
Constant Map that always returns the CmsJspContentAccessValueWrapper.NULL_VALUE_WRAPPER.

Constructor Detail

CmsJspContentAccessBean

public CmsJspContentAccessBean()
No argument constructor, required for a JavaBean.

You must call init(CmsObject, Locale, I_CmsXmlDocument, CmsResource) and provide the required values when you use this constructor.

See Also:
init(CmsObject, Locale, I_CmsXmlDocument, CmsResource)

CmsJspContentAccessBean

public CmsJspContentAccessBean(CmsObject cms,
                               CmsResource resource)
Creates a content access bean based on a Resource, using the current request context locale.

Parameters:
cms - the OpenCms context of the current user
resource - the resource to create the content from

CmsJspContentAccessBean

public CmsJspContentAccessBean(CmsObject cms,
                               Locale locale,
                               CmsResource resource)
Creates a content access bean based on a Resource.

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

CmsJspContentAccessBean

public CmsJspContentAccessBean(CmsObject cms,
                               Locale locale,
                               I_CmsXmlDocument content)
Creates a content access bean based on an XML content object.

Parameters:
cms - the OpenCms context of the current user
locale - the Locale to use when accessing the content
content - the content to access
Method Detail

getCmsObject

public CmsObject 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

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:
CmsObject.getSitePath(CmsResource)

getHasLocale

public Map<String,Boolean> 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

public Map<String,Map<String,Boolean>> 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()

getHasValue

public Map<String,Boolean> 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:
getHasLocaleValue()

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:
CmsResource.getStructureId()

getLocale

public Locale getLocale()
Returns the Locale this bean was initialized with.

Returns:
the locale this bean was initialized with

getLocaleNames

public Map<String,List<String>> 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:
getNames()

getLocaleSubValueList

public Map<String,Map<String,List<CmsJspContentAccessValueWrapper>>> 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()

getLocaleValue

public Map<String,Map<String,CmsJspContentAccessValueWrapper>> 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:
getValue()

getLocaleValueList

public Map<String,Map<String,List<CmsJspContentAccessValueWrapper>>> 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:
getLocaleValue()

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:
getLocaleNames()

getRawContent

public I_CmsXmlDocument 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

getSubValueList

public Map<String,List<CmsJspContentAccessValueWrapper>> 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:
getLocaleValueList()

getValue

public Map<String,CmsJspContentAccessValueWrapper> 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:
getLocaleValue()

getValueList

public Map<String,List<CmsJspContentAccessValueWrapper>> 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:
getLocaleValueList()

getVfs

public CmsJspVfsAccessBean 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

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