org.opencms.jsp.util
Class CmsJspContentAccessValueWrapper

java.lang.Object
  extended by org.opencms.jsp.util.CmsJspContentAccessValueWrapper

public final class CmsJspContentAccessValueWrapper
extends java.lang.Object

Allows direct access to XML content values, with possible iteration of sub-nodes.

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

Since:
7.0.2
Version:
$Revision: 1.14 $
Author:
Alexander Kandzior
See Also:
CmsJspContentAccessBean, CmsJspTagContentAccess

Nested Class Summary
 class CmsJspContentAccessValueWrapper.CmsHasValueTransformer
          Provides a Map with Booleans that indicate if a nested sub value (xpath) for the current value is available in the XML content.
 class CmsJspContentAccessValueWrapper.CmsValueListTransformer
          Provides a Map which lets the user access nested sub value Lists from the current value, the input is assumed to be a String that represents an xpath in the XML content.
 class CmsJspContentAccessValueWrapper.CmsValueTransformer
          Provides a Map which lets the user a nested sub value from the current value, the input is assumed to be a String that represents an xpath in the XML content.
 class CmsJspContentAccessValueWrapper.CmsXmlValueTransformer
          Provides a Map which lets the user directly access sub-nodes of the XML represented by the current value, the input is assumed to be a String that represents an xpath in the XML content.
 
Field Summary
protected static CmsJspContentAccessValueWrapper NULL_VALUE_WRAPPER
          Constant for the null (non existing) value.
 
Method Summary
protected  java.lang.String createPath(java.lang.Object input)
          Returns the path to the XML content based on the current element path.
static CmsJspContentAccessValueWrapper createWrapper(CmsObject cms, I_CmsXmlContentValue value)
          Factory method to create a new XML content value wrapper.
 boolean equals(java.lang.Object obj)
           
 boolean getExists()
          Returns true in case this value actually exists in the XML content it was requested from.
 java.util.Map getHasValue()
          Returns a lazy initialized Map that provides Booleans that indicate if a nested sub value (xpath) for the current value is available in the XML content.
 int getIndex()
          Returns the node index of the XML content value in the source XML document, starting with 0.
 boolean getIsEmpty()
          Returns true in case the value is empty, that is either null or an empty String.
 boolean getIsEmptyOrWhitespaceOnly()
          Returns true in case the value is empty or whitespace only, that is either null or String that contains only whitespace chars.
 java.util.Locale getLocale()
          Returns the Locale of the current XML content value.
 java.lang.String getPath()
          Returns the path to the current XML content value.
 CmsJspContentAccessValueWrapper getResolve()
          Short form of getResolveMacros().
 CmsJspContentAccessValueWrapper getResolveMacros()
          Turn on macro resolving for the wrapped value.
 java.lang.String getStringValue()
          Returns the String value of the wrapped content value.
 java.util.Map getValue()
          Returns a lazy initialized Map that provides the nested sub values for the current value from the XML content.
 java.util.Map getValueList()
          Returns a lazy initialized Map that provides the Lists of nested sub values for the current value from the XML content.
 java.util.Map getXmlText()
          Returns a lazy initialized Map that provides direct access to the XML element for the current value from the XML content.
 int hashCode()
           
 CmsObject obtainCmsObject()
          Returns the wrapped OpenCms user context.
 I_CmsXmlContentValue obtainContentValue()
          Returns the wrapped content value.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

NULL_VALUE_WRAPPER

protected static final CmsJspContentAccessValueWrapper NULL_VALUE_WRAPPER
Constant for the null (non existing) value.

Method Detail

createWrapper

public static CmsJspContentAccessValueWrapper createWrapper(CmsObject cms,
                                                            I_CmsXmlContentValue value)
Factory method to create a new XML content value wrapper.

In case either parameter is null, the NULL_VALUE_WRAPPER is returned.

Parameters:
cms - the current users OpenCms context
value - the value to warp
Returns:
a new content value wrapper instance, or null if any parameter is null

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object
See Also:
Object.equals(java.lang.Object)

getExists

public boolean getExists()
Returns true in case this value actually exists in the XML content it was requested from.

Usage example on a JSP with the JSTL:

 <cms:contentload ... >
     <cms:contentaccess var="content" />
     <c:if test="${content.value['Link'].exists}" >
         The content has a "Link" value! 
     </c:if>
 </cms:contentload>

Returns:
true in case this value actually exists in the XML content it was requested from

getHasValue

public java.util.Map getHasValue()
Returns a lazy initialized Map that provides Booleans that indicate if a nested sub value (xpath) for the current value is available in the XML content.

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

In case the current value is not a nested XML content value, or the XML content value does not exist, the CmsConstantMap.CONSTANT_BOOLEAN_FALSE_MAP is returned.

Usage example on a JSP with the JSTL:

 <cms:contentload ... >
     <cms:contentaccess var="content" />
     <c:if test="${content.value['Link'].hasValue['Description']}" >
         The content has a "Description" value as sub element to the "Link" value! 
     </c:if>
 </cms:contentload>
Please note that you can also test if a sub-value exists like this:
 <c:if test="${content.value['Link'].value['Description'].exists}" > ... </c:if>

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

getIndex

public int getIndex()
Returns the node index of the XML content value in the source XML document, starting with 0.

In case the XML content value does not exist, -1 is returned.

Usage example on a JSP with the JSTL:

 <cms:contentload ... >
     <cms:contentaccess var="content" />
     The locale of the Link node: ${content.value['Link'].locale}
 </cms:contentload>

Returns:
the locale of the current XML content value

getIsEmpty

public boolean getIsEmpty()
Returns true in case the value is empty, that is either null or an empty String.

In case the XML content value does not exist, true is returned.

Usage example on a JSP with the JSTL:

 <cms:contentload ... >
     <cms:contentaccess var="content" />
     <c:if test="${content.value['Link'].isEmpty}" >
         The content of the "Link" value is empty. 
     </c:if>
 </cms:contentload>

Returns:
true in case the value is empty

getIsEmptyOrWhitespaceOnly

public boolean getIsEmptyOrWhitespaceOnly()
Returns true in case the value is empty or whitespace only, that is either null or String that contains only whitespace chars.

In case the XML content value does not exist, true is returned.

Usage example on a JSP with the JSTL:

 <cms:contentload ... >
     <cms:contentaccess var="content" />
     <c:if test="${content.value['Link'].isEmptyOrWhitespaceOnly}" >
         The content of the "Link" value is empty or contains only whitespace chars. 
     </c:if>
 </cms:contentload>

Returns:
true in case the value is empty or whitespace only

getLocale

public java.util.Locale getLocale()
Returns the Locale of the current XML content value.

In case the XML content value does not exist, the OpenCms system default Locale is returned.

Usage example on a JSP with the JSTL:

 <cms:contentload ... >
     <cms:contentaccess var="content" />
     The locale of the Link node: ${content.value['Link'].locale}
 </cms:contentload>

Returns:
the locale of the current XML content value

getPath

public java.lang.String getPath()
Returns the path to the current XML content value.

In case the XML content value does not exist, an empty String "" is returned.

Usage example on a JSP with the JSTL:

 <cms:contentload ... >
     <cms:contentaccess var="content" />
     The path to the Link node in the XML: ${content.value['Link'].path}
 </cms:contentload>

Returns:
the path to the current XML content value

getResolve

public CmsJspContentAccessValueWrapper getResolve()
Short form of getResolveMacros().

Returns:
a value wrapper with macro resolving turned on
See Also:
getResolveMacros()

getResolveMacros

public CmsJspContentAccessValueWrapper getResolveMacros()
Turn on macro resolving for the wrapped value.

Macro resolving is turned off by default. When turned on, a macro resolver is initialized with the current OpenCms user context and the URI of the current resource. This means known macros contained in the wrapped value will be resolved when the output String is generated. For example, a %(property.Title) in the value would be replaced with the value of the title property. Macros that can not be resolved will be kept.

Usage example on a JSP with the JSTL:

 <cms:contentload ... >
     <cms:contentaccess var="content" />
     The text with macros resolved: ${content.value['Text'].resolveMacros}
 </cms:contentload>

Returns:
a value wrapper with macro resolving turned on
See Also:
CmsMacroResolver

getStringValue

public java.lang.String getStringValue()
Returns the String value of the wrapped content value.

Note that this will return the empty String "" when getExists() returns false

.

Returns:
the String value of the wrapped content value
See Also:
toString()

getValue

public java.util.Map getValue()
Returns a lazy initialized Map that provides the nested sub values for the current value from the XML content.

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

In case the current value is not a nested XML content value, or the XML content value does not exist, the CmsJspContentAccessBean.CONSTANT_NULL_VALUE_WRAPPER_MAP is returned.

Usage example on a JSP with the JSTL:

 <cms:contentload ... >
     <cms:contentaccess var="content" />
     The Link Description: ${content.value['Link'].value['Description']}
 </cms:contentload>
Please note that this example will only work if the 'Link' element is mandatory in the schema definition of the XML content.

Returns:
a lazy initialized Map that provides a sub value for the current value from the XML content

getValueList

public java.util.Map getValueList()
Returns a lazy initialized Map that provides the Lists of nested sub values for the current value from the XML content.

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

In case the current value is not a nested XML content value, or the XML content value does not exist, the CmsConstantMap.CONSTANT_EMPTY_LIST_MAP is returned.

Usage example on a JSP with the JSTL:

 <cms:contentload ... >
     <cms:contentaccess var="content" />
     <c:forEach var="desc" items="${content.value['Link'].valueList['Description']}">
         ${desc}
     </c:forEach>
 </cms:contentload>

Returns:
a lazy initialized Map that provides a Lists of sub values for the current value from the XML content

getXmlText

public java.util.Map getXmlText()
Returns a lazy initialized Map that provides direct access to the XML element for the current value from the XML content.

Returns:
a lazy initialized Map that provides direct access to the XML element for the current value from the XML content

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object
See Also:
Object.hashCode()

obtainCmsObject

public CmsObject obtainCmsObject()
Returns the wrapped OpenCms user context.

Note that this will return null when getExists() returns false.

Returns:
the wrapped OpenCms user context

obtainContentValue

public I_CmsXmlContentValue obtainContentValue()
Returns the wrapped content value.

Note that this will return null when getExists() returns false

. Method name does not start with "get" to prevent using it in the expression language.

Returns:
the wrapped content value

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object
See Also:
Object.toString(), getStringValue()

createPath

protected java.lang.String createPath(java.lang.Object input)
Returns the path to the XML content based on the current element path.

This is used to create xpath information for sub-elements in the transformers.

Parameters:
input - the additional path that is appended to the current path
Returns:
the path to the XML content based on the current element path