Class CmsJspObjectValueWrapper
- java.lang.Object
-
- java.util.AbstractCollection<java.lang.String>
-
- org.opencms.jsp.util.CmsJspObjectValueWrapper
-
- All Implemented Interfaces:
java.lang.Iterable<java.lang.String>,java.util.Collection<java.lang.String>
public final class CmsJspObjectValueWrapper extends java.util.AbstractCollection<java.lang.String>
Provides access to common object types through wrappers.- Since:
- 11.0
-
-
Field Summary
Fields Modifier and Type Field Description protected CmsObjectm_cmsThe wrapped OpenCms user context.protected java.util.Optional<CmsJspLinkWrapper>m_linkObjCached link wrapper - use Optional to distinguish 'uncached' state from 'does not exist'.protected static CmsJspObjectValueWrapperNULL_VALUE_WRAPPERConstant for the null (non existing) value.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static CmsJspObjectValueWrappercreateWrapper(CmsObject cms, java.lang.Object value)Factory method to create a new XML content value wrapper.booleanequals(java.lang.Object obj)CmsObjectgetCmsObject()Returns the current cms context.java.util.Map<java.lang.Object,java.lang.Boolean>getContains()Returns a lazy initialized Map that provides Booleans which indicate if if the wrapped values String representation contains a specific String.booleangetExists()Returnstruein case there was an object wrapped.booleangetIsEmpty()Returnstruein case the object is empty, that is eithernullor an empty String.booleangetIsEmptyOrWhitespaceOnly()Returnstruein case the object is empty or whitespace only, that is eithernullor an empty String.java.util.Map<java.lang.Object,java.lang.Boolean>getIsEqual()Returns a lazy initialized Map that provides Booleans which indicate if an Object is equal to the wrapped object.booleangetIsSet()Returnstruein case the wrapped value exists and is not empty or whitespace only.booleangetIsSetNotNone()Returnstruein case the wrapped value exists, is not empty or whitespace only and is also not equal to the String'none'.java.lang.LonggetMathCeil()Calculates the next largest integer from the wrapped value.java.lang.LonggetMathFloor()Calculates the next smallest integer from the wrapped value.java.lang.LonggetMathRound()Calculates the next integer from the wrapped value by rounding.java.lang.ObjectgetObjectValue()Returns the wrapped object value.java.lang.StringgetStringValue()Deprecated.usegetToString()insteadjava.lang.StringgetStripHtml()Assumes the wrapped value is a String and strips all HTML markup from this String.booleangetToBoolean()Converts the wrapped value to a boolean.CmsJspContainerPageWrappergetToContainerPage()Tries to create a container page wrapper from the wrapped value.java.util.DategetToDate()Converts the wrapped value to a date.java.lang.DoublegetToDouble()Parses the wrapped value to a Double precision float.java.lang.DoublegetToFloat()Parses the wrapped value to a Double precision float.CmsJspImageBeangetToImage()Returns a scaled image bean from the wrapped value.CmsJspInstanceDateBeangetToInstanceDate()Converts a date to an instance date bean.java.lang.LonggetToInteger()Parses the wrapped value to a Long integer.CmsJspLinkWrappergetToLink()Converts the value to a link wrapper.java.lang.StringgetToLinkStr()Returns the substituted link to the wrapped value.java.util.LocalegetToLocale()Converts the wrapped value to a java.util.Locale instance using the locale manager.java.lang.LonggetToLong()Parses the wrapped value to a Long integer.CmsJspResourceWrappergetToResource()Returns the resource this value if pointing to.java.lang.StringgetToString()Returns the wrapped value as a String.java.util.Map<java.lang.Object,java.lang.String>getTrimToSize()Returns a lazy initialized map that provides trimmed to size strings of the wrapped object string value.inthashCode()booleanisEmpty()Supports the use of theemptyoperator in the JSP EL by implementing the Collection interface.booleanisValid(java.util.List<java.lang.String> allowedValues)Compares this value against a list of Strings and returnstruein case the list contains the toString representation of this value, or afalseotherwise.java.util.Iterator<java.lang.String>iterator()Supports the use of theemptyoperator in the JSP EL by implementing the Collection interface.intsize()Supports the use of theemptyoperator in the JSP EL by implementing the Collection interface.static java.lang.StringsubstituteLink(CmsObject cms, java.lang.String target)Returns the substituted link to the given target.java.lang.DoubletoDouble(java.lang.Double def)Parses the wrapped value to a Double precision float, returning the default in case the number can not be parsed.java.lang.DoubletoFloat(java.lang.Double def)Parses the wrapped value to a Double precision float, returning the default in case the number can not be parsed.java.lang.LongtoInteger(java.lang.Long def)Parses the wrapped value to a Long integer, returning the default in case the number can not be parsed.java.lang.LongtoLong(java.lang.Long def)Parses the wrapped value to a Long integer, returning the default in case the number can not be parsed.java.lang.StringtoString()org.opencms.jsp.util.A_CmsJspValueWrapperuseDefault(java.lang.Object defaultValue)Returns a value wrapper for the provided default in case this value is empty.org.opencms.jsp.util.A_CmsJspValueWrappervalidate(java.util.List<java.lang.String> allowedValues)Compares this value against a list of Strings and returns this value in case the list contains the toString representation of this value, or aNULL_VALUE_WRAPPERotherwise.org.opencms.jsp.util.A_CmsJspValueWrappervalidate(java.util.List<java.lang.String> allowedValues, java.lang.Object defaultValue)Checks this value against a list of Strings and returns this value in case the list contains the toString representation of this value, or aCmsJspObjectValueWrapperbased on the given default object otherwise.-
Methods inherited from class java.util.AbstractCollection
add, addAll, clear, contains, containsAll, remove, removeAll, retainAll, toArray, toArray
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
-
-
-
Field Detail
-
NULL_VALUE_WRAPPER
protected static final CmsJspObjectValueWrapper NULL_VALUE_WRAPPER
Constant for the null (non existing) value.
-
m_cms
protected CmsObject m_cms
The wrapped OpenCms user context.
-
m_linkObj
protected java.util.Optional<CmsJspLinkWrapper> m_linkObj
Cached link wrapper - use Optional to distinguish 'uncached' state from 'does not exist'.
-
-
Method Detail
-
createWrapper
public static CmsJspObjectValueWrapper createWrapper(CmsObject cms, java.lang.Object value)
Factory method to create a new XML content value wrapper.In case either parameter is
null, theNULL_VALUE_WRAPPERis returned.- Parameters:
cms- the current users OpenCms contextvalue- the object to warp- Returns:
- a new content value wrapper instance, or
nullif any parameter isnull
-
getExists
public boolean getExists()
Returnstruein case there was an object wrapped.- Returns:
truein case there was an object wrapped
-
getIsEmpty
public boolean getIsEmpty()
Returnstruein case the object is empty, that is eithernullor an empty String.In case the object does not exist,
trueis returned.- Returns:
truein case the object is empty
-
getIsEmptyOrWhitespaceOnly
public boolean getIsEmptyOrWhitespaceOnly()
Returnstruein case the object is empty or whitespace only, that is eithernullor an empty String.In case the object does not exist,
trueis returned.- Returns:
truein case the object is empty
-
getObjectValue
public java.lang.Object getObjectValue()
Returns the wrapped object value.- Returns:
- the wrapped object value
-
getToDate
public java.util.Date getToDate()
Converts the wrapped value to a date. Keeps it as date, if it already is one.- Returns:
- the date
- See Also:
A_CmsJspValueWrapper.getToDate()
-
getToResource
public CmsJspResourceWrapper getToResource()
Returns the resource this value if pointing to.It is assumed the value holds a valid resource UIR in the OpenCms VFS. In case the value cannot be converted to a resource, an error is logged but no exception is thrown.
- Returns:
- the resource this value if pointing to
- See Also:
A_CmsJspValueWrapper.getToResource()
-
hashCode
public int hashCode()
- Specified by:
hashCodein interfacejava.util.Collection<java.lang.String>- See Also:
Object.hashCode()
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.util.AbstractCollection<java.lang.String>- See Also:
Object.toString()
-
substituteLink
public static java.lang.String substituteLink(CmsObject cms, java.lang.String target)
Returns the substituted link to the given target.- Parameters:
cms- the cms contexttarget- the link target- Returns:
- the substituted link
-
equals
public boolean equals(java.lang.Object obj)
- Specified by:
equalsin interfacejava.util.Collection<java.lang.String>- Overrides:
equalsin classjava.lang.Object- See Also:
Object.equals(java.lang.Object)
-
getCmsObject
public CmsObject getCmsObject()
Returns the current cms context.- Returns:
- the cms context
-
getContains
public java.util.Map<java.lang.Object,java.lang.Boolean> getContains()
Returns a lazy initialized Map that provides Booleans which indicate if if the wrapped values String representation contains a specific String.The Object parameter is transformed to it's String representation to perform this check.
- Returns:
- a lazy initialized Map that provides Booleans which indicate if if the wrapped values String representation contains a specific String
-
getIsEqual
public java.util.Map<java.lang.Object,java.lang.Boolean> getIsEqual()
Returns a lazy initialized Map that provides Booleans which indicate if an Object is equal to the wrapped object.- Returns:
- a lazy initialized Map that provides Booleans which indicate if an Object is equal to the wrapped object
-
getIsSet
public boolean getIsSet()
Returnstruein case the wrapped value exists and is not empty or whitespace only.- Returns:
truein case the wrapped value exists and is not empty or whitespace only
-
getIsSetNotNone
public boolean getIsSetNotNone()
Returnstruein case the wrapped value exists, is not empty or whitespace only and is also not equal to the String'none'.- Returns:
truein case the wrapped value exists, is not empty or whitespace only and is also not equal to the String'none'
-
getMathCeil
public java.lang.Long getMathCeil()
Calculates the next largest integer from the wrapped value.Note that the result is an Object of type
Long, so in case the wrapped value can not be converted to a number,nullis returned. This means you can check for anemptyresult in the EL.- Returns:
- the next largest integer for the wrapped value
-
getMathFloor
public java.lang.Long getMathFloor()
Calculates the next smallest integer from the wrapped value.Note that the result is an Object of type
Long, so in case the wrapped value can not be converted to a number,nullis returned. This means you can check for anemptyresult in the EL.- Returns:
- the next smallest integer for the wrapped value
-
getMathRound
public java.lang.Long getMathRound()
Calculates the next integer from the wrapped value by rounding.Note that the result is an Object of type
Long, so in case the wrapped value can not be converted to a number,nullis returned. This means you can check for anemptyresult in the EL.- Returns:
- the next integer for the wrapped value calculated by rounding
-
getStringValue
@Deprecated public java.lang.String getStringValue()
Deprecated.usegetToString()insteadReturns the String value for the wrapped content value.This will return the empty String
""whengetExists()returnsfalse.
- Returns:
- the String value of the wrapped content value
-
getStripHtml
public java.lang.String getStripHtml()
Assumes the wrapped value is a String and strips all HTML markup from this String.- Returns:
- the wrapped value with all HTML stripped.
-
getToBoolean
public boolean getToBoolean()
Converts the wrapped value to a boolean.- Returns:
- the boolean value
-
getToContainerPage
public CmsJspContainerPageWrapper getToContainerPage()
Tries to create a container page wrapper from the wrapped value.- Returns:
- the container page wrapper or null if none could be created
-
getToDouble
public java.lang.Double getToDouble()
Parses the wrapped value to a Double precision float.Note that the result is an Object of type
Double, so in case the wrapped value can not be converted to a number,nullis returned. This means you can check for anemptyresult in the EL.- Returns:
- the Double precision float value
-
getToFloat
public java.lang.Double getToFloat()
Parses the wrapped value to a Double precision float.Note that the result is an Object of type
Double, so in case the wrapped value can not be converted to a number,nullis returned. This means you can check for anemptyresult in the EL.- Returns:
- the Double precision float value
-
getToImage
public CmsJspImageBean getToImage()
Returns a scaled image bean from the wrapped value.In case the value does not point to an image resource,
nullis returned.- Returns:
- the scaled image bean
-
getToInstanceDate
public CmsJspInstanceDateBean getToInstanceDate()
Converts a date to an instance date bean.- Returns:
- the instance date bean.
-
getToInteger
public java.lang.Long getToInteger()
Parses the wrapped value to a Long integer.Note that the result is an Object of type
Long, so in case the wrapped value can not be converted to a number,nullis returned. This means you can check for anemptyresult in the EL.- Returns:
- the Long integer value
- See Also:
getToLong()
-
getToLink
public CmsJspLinkWrapper getToLink()
Converts the value to a link wrapper.- Returns:
- the link wrapper
-
getToLinkStr
public java.lang.String getToLinkStr()
Returns the substituted link to the wrapped value.In case no link can be substituted from the wrapped value, an empty String
""is returned.- Returns:
- the substituted link
-
getToLocale
public java.util.Locale getToLocale()
Converts the wrapped value to a java.util.Locale instance using the locale manager.- Returns:
- the locale instance for the wrapped value
-
getToLong
public java.lang.Long getToLong()
Parses the wrapped value to a Long integer.Note that the result is an Object of type
Long, so in case the wrapped value can not be converted to a number,nullis returned. This means you can check for anemptyresult in the EL.- Returns:
- the Long integer value
- See Also:
getToInteger()
-
getToString
public java.lang.String getToString()
Returns the wrapped value as a String.This will always be at least an empty String
"", nevernull.- Returns:
- the wrapped value as a String
-
getTrimToSize
public java.util.Map<java.lang.Object,java.lang.String> getTrimToSize()
Returns a lazy initialized map that provides trimmed to size strings of the wrapped object string value. The size being the integer value of the key object.- Returns:
- a map that provides trimmed to size strings of the wrapped object string value
-
isEmpty
public boolean isEmpty()
Supports the use of theemptyoperator in the JSP EL by implementing the Collection interface.- Specified by:
isEmptyin interfacejava.util.Collection<java.lang.String>- Overrides:
isEmptyin classjava.util.AbstractCollection<java.lang.String>- Returns:
- the value from
getIsEmptyOrWhitespaceOnly()which is the inverse ofgetIsSet(). - See Also:
AbstractCollection.isEmpty(),getIsEmptyOrWhitespaceOnly(),getIsSet()
-
isValid
public boolean isValid(java.util.List<java.lang.String> allowedValues)
Compares this value against a list of Strings and returnstruein case the list contains the toString representation of this value, or afalseotherwise.- Parameters:
allowedValues- the list of allowed String values- Returns:
- returns
truein case the list contains the toString representation of this value, or afalseotherwise - See Also:
validate(List),validate(List, Object)
-
iterator
public java.util.Iterator<java.lang.String> iterator()
Supports the use of theemptyoperator in the JSP EL by implementing the Collection interface.- Specified by:
iteratorin interfacejava.util.Collection<java.lang.String>- Specified by:
iteratorin interfacejava.lang.Iterable<java.lang.String>- Specified by:
iteratorin classjava.util.AbstractCollection<java.lang.String>- Returns:
- an empty Iterator in case
AbstractCollection.isEmpty()istrue, otherwise an Iterator that will return the String value of this wrapper exactly once. - See Also:
AbstractCollection.size()
-
size
public int size()
Supports the use of theemptyoperator in the JSP EL by implementing the Collection interface.- Specified by:
sizein interfacejava.util.Collection<java.lang.String>- Specified by:
sizein classjava.util.AbstractCollection<java.lang.String>- Returns:
- always returns 0.
- See Also:
AbstractCollection.size()
-
toDouble
public java.lang.Double toDouble(java.lang.Double def)
Parses the wrapped value to a Double precision float, returning the default in case the number can not be parsed.- Parameters:
def- the default in case the wrapped value can not be converted to a number- Returns:
- a Double precision float value
- See Also:
toFloat(Double)
-
toFloat
public java.lang.Double toFloat(java.lang.Double def)
Parses the wrapped value to a Double precision float, returning the default in case the number can not be parsed.- Parameters:
def- the default in case the wrapped value can not be converted to a number- Returns:
- a Double precision float value
- See Also:
toDouble(Double)
-
toInteger
public java.lang.Long toInteger(java.lang.Long def)
Parses the wrapped value to a Long integer, returning the default in case the number can not be parsed.- Parameters:
def- the default in case the wrapped value can not be converted to a number- Returns:
- a Long integer value
- See Also:
toLong(Long)
-
toLong
public java.lang.Long toLong(java.lang.Long def)
Parses the wrapped value to a Long integer, returning the default in case the number can not be parsed.- Parameters:
def- the default in case the wrapped value can not be converted to a number- Returns:
- a Long integer value
- See Also:
toInteger(Long)
-
useDefault
public org.opencms.jsp.util.A_CmsJspValueWrapper useDefault(java.lang.Object defaultValue)
Returns a value wrapper for the provided default in case this value is empty.If this value is empty, the object returned will be of type
CmsJspObjectValueWrapper. This means you can only use simple "get me the value as type X" operations on the result safely.- Parameters:
defaultValue- the object to generate the default value from- Returns:
- a value wrapper for the provided default in case this value is empty.
- See Also:
createWrapper(CmsObject, Object)
-
validate
public org.opencms.jsp.util.A_CmsJspValueWrapper validate(java.util.List<java.lang.String> allowedValues)
Compares this value against a list of Strings and returns this value in case the list contains the toString representation of this value, or aNULL_VALUE_WRAPPERotherwise.- Parameters:
allowedValues- the list of allowed String values- Returns:
- returns this value in case the list contains the toString representation of this value,
or a
NULL_VALUE_WRAPPERotherwise - See Also:
validate(List, Object),isValid(List)
-
validate
public org.opencms.jsp.util.A_CmsJspValueWrapper validate(java.util.List<java.lang.String> allowedValues, java.lang.Object defaultValue)Checks this value against a list of Strings and returns this value in case the list contains the toString representation of this value, or aCmsJspObjectValueWrapperbased on the given default object otherwise.- Parameters:
allowedValues- the list of allowed String valuesdefaultValue- the object to generate the default value from- Returns:
- returns this value in case the list contains the toString representation of this value,
or a
CmsJspObjectValueWrapperbased on the given default object otherwise - See Also:
validate(List),isValid(List),useDefault(Object)
-
-