cmsjspcontentaccessvaluewrapper.java
来自「找了很久才找到到源代码」· Java 代码 · 共 519 行 · 第 1/2 页
JAVA
519 行
return m_hasValue;
}
/**
* Returns the node index of the XML content value in the source XML document,
* starting with 0.<p>
*
* In case the XML content value does not exist, <code>-1</code> is returned.<p>
*
* Usage example on a JSP with the JSTL:<pre>
* <cms:contentload ... >
* <cms:contentaccess var="content" />
* The locale of the Link node: ${content.value['Link'].locale}
* </cms:contentload></pre>
*
* @return the locale of the current XML content value
*/
public int getIndex() {
if (m_contentValue == null) {
return -1;
}
return m_contentValue.getIndex();
}
/**
* Returns <code>true</code> in case the value is empty, that is either <code>null</code> or an empty String.<p>
*
* In case the XML content value does not exist, <code>true</code> is returned.<p>
*
* Usage example on a JSP with the JSTL:<pre>
* <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></pre>
*
* @return <code>true</code> in case the value is empty
*/
public boolean getIsEmpty() {
if (m_contentValue == null) {
// this is the case for non existing values
return true;
}
if (m_contentValue.isSimpleType()) {
// return values for simple type
return CmsStringUtil.isEmpty(m_contentValue.getStringValue(m_cms));
} else {
// nested types are not empty if they have any children in the XML
return m_contentValue.getElement().elements().size() > 0;
}
}
/**
* Returns <code>true</code> in case the value is empty or whitespace only,
* that is either <code>null</code> or String that contains only whitespace chars.<p>
*
* In case the XML content value does not exist, <code>true</code> is returned.<p>
*
* Usage example on a JSP with the JSTL:<pre>
* <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></pre>
*
* @return <code>true</code> in case the value is empty or whitespace only
*/
public boolean getIsEmptyOrWhitespaceOnly() {
if (m_contentValue == null) {
// this is the case for non existing values
return true;
}
if (m_contentValue.isSimpleType()) {
// return values for simple type
return CmsStringUtil.isEmptyOrWhitespaceOnly(m_contentValue.getStringValue(m_cms));
} else {
// nested types are not empty if they have any children in the XML
return m_contentValue.getElement().elements().size() > 0;
}
}
/**
* Returns the Locale of the current XML content value.<p>
*
* In case the XML content value does not exist, the OpenCms system default Locale is returned.<p>
*
* Usage example on a JSP with the JSTL:<pre>
* <cms:contentload ... >
* <cms:contentaccess var="content" />
* The locale of the Link node: ${content.value['Link'].locale}
* </cms:contentload></pre>
*
* @return the locale of the current XML content value
*/
public Locale getLocale() {
if (m_contentValue == null) {
return CmsLocaleManager.getDefaultLocale();
}
return m_contentValue.getLocale();
}
/**
* Returns the path to the current XML content value.<p>
*
* In case the XML content value does not exist, an empty String <code>""</code> is returned.<p>
*
* Usage example on a JSP with the JSTL:<pre>
* <cms:contentload ... >
* <cms:contentaccess var="content" />
* The path to the Link node in the XML: ${content.value['Link'].path}
* </cms:contentload></pre>
*
* @return the path to the current XML content value
*/
public String getPath() {
if (m_contentValue == null) {
return "";
}
return m_contentValue.getPath();
}
/**
* Returns a lazy initialized Map that provides the nested sub values
* for the current value from the XML content.<p>
*
* The provided Map key is assumed to be a String that represents the relative xpath to the value.<p>
*
* In case the current value is not a nested XML content value, or the XML content value does not exist,
* the {@link CmsJspContentAccessBean#CONSTANT_NULL_VALUE_WRAPPER_MAP} is returned.<p>
*
* Usage example on a JSP with the JSTL:<pre>
* <cms:contentload ... >
* <cms:contentaccess var="content" />
* The Link Description: ${content.value['Link'].value['Description']}
* </cms:contentload></pre>
*
* @return a lazy initialized Map that provides a sub value for the current value from the XML content
*/
public Map getValue() {
if (m_value == null) {
m_value = LazyMap.decorate(new HashMap(), new CmsValueTransformer());
}
return m_value;
}
/**
* Returns a lazy initialized Map that provides the Lists of nested sub values
* for the current value from the XML content.<p>
*
* 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.<p>
*
* In case the current value is not a nested XML content value, or the XML content value does not exist,
* the {@link CmsConstantMap#CONSTANT_EMPTY_LIST_MAP} is returned.<p>
*
* Usage example on a JSP with the JSTL:<pre>
* <cms:contentload ... >
* <cms:contentaccess var="content" />
* <c:forEach var="desc" items="${content.value['Link'].valueList['Description']}">
* ${desc}
* </c:forEach>
* </cms:contentload></pre>
*
* @return a lazy initialized Map that provides a Lists of sub values for the current value from the XML content
*/
public Map getValueList() {
if (m_valueList == null) {
m_valueList = LazyMap.decorate(new HashMap(), new CmsValueListTransformer());
}
return m_valueList;
}
/**
* @see java.lang.Object#hashCode()
*/
public int hashCode() {
if (m_contentValue == null) {
return 0;
}
if (m_hashCode == 0) {
StringBuffer result = new StringBuffer(64);
result.append(m_contentValue.getDocument().getFile().getStructureId().toString());
result.append('/');
result.append(m_contentValue.getLocale());
result.append('/');
result.append(m_contentValue.getPath());
m_hashCode = result.toString().hashCode();
}
return m_hashCode;
}
/**
* Returns the wrapped OpenCms user context.<p>
*
* Note that this will return <code>null</code> when {@link #getExists()} returns <code>false</code>.
*
* @return the wrapped OpenCms user context
*/
public CmsObject obtainCmsObject() {
return m_cms;
}
/**
* Returns the wrapped content value.<p>
*
* Note that this will return <code>null</code> when {@link #getExists()} returns <code>false</code><p>.
*
* Method name does not start with "get" to prevend using it in the expression language.<p>
*
* @return the wrapped content value
*/
public I_CmsXmlContentValue obtainContentValue() {
return m_contentValue;
}
/**
* @see java.lang.Object#toString()
*/
public String toString() {
if (m_contentValue == null) {
// this is the case for non existing values
return "";
}
if (m_contentValue.isSimpleType()) {
// return values for simple type
return m_contentValue.getStringValue(m_cms);
} else {
// nested types should not be called this way by the user
return "";
}
}
/**
* Returns the path to the XML content based on the current element path.<p>
*
* This is used to create xpath information for sub-elements in the transformers.<p>
*
* @param input the additional path that is appended to the current path
*
* @return the path to the XML content based on the current element path
*/
protected String createPath(Object input) {
return CmsXmlUtils.concatXpath(m_contentValue.getPath(), String.valueOf(input));
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?