Class CmsJspElFunctions

    • Method Summary

      All Methods Static Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      static void addToList​(java.util.List<java.lang.Object> list, java.lang.Object value)
      Extends the given list by adding the provided object.
      static CmsObject convertCmsObject​(java.lang.Object input)
      Returns an OpenCms user context created from an Object.
      static java.util.Date convertDate​(java.lang.Object input)
      Returns a Date created from an Object.
      static java.lang.Double convertDouble​(java.lang.Object input)
      Returns a Double created from an Object.
      static java.util.List<java.lang.Object> convertList​(java.util.List<java.lang.Object> input, java.lang.String attributeName)
      Returns a list of attribute values specified by the attribute name of the items of the given list.
      static java.util.Locale convertLocale​(java.lang.Object input)
      Returns a Locale created from an Object.
      static CmsResource convertRawResource​(CmsObject cms, java.lang.Object input)
      Returns a resource created from an Object.
      static javax.servlet.ServletRequest convertRequest​(java.lang.Object input)
      Tries to convert the given input object into a request.
      static CmsJspResourceWrapper convertResource​(CmsObject cms, java.lang.Object input)
      Returns a resource wrapper created from the input.
      static java.util.List<CmsJspResourceWrapper> convertResourceList​(CmsObject cms, java.util.List<CmsResource> list)
      Returns a list of resource wrappers created from the input list of resources.
      static CmsUUID convertUUID​(java.lang.Object input)
      Returns a CmsUUID created from an Object.
      static java.util.List<java.lang.Object> createList()
      Returns a newly created, empty List object.
      static CmsObject getCmsObject​(java.lang.Object input)
      Returns the current OpenCms user context from the given page context.
      static java.lang.Integer getListSize​(java.util.Collection<java.lang.Object> input)
      Returns the size of the given list.
      static java.lang.String getModuleParam​(java.lang.String name, java.lang.String key)
      Returns a parameter value from the module parameters.
      static java.lang.String getNavigationUri​(java.lang.Object input)
      Deprecated.
      On a JSP use ${cms.requestContext.uri} instead.
      static java.lang.String getRequestLink​(java.lang.String url)
      Returns the link without parameters from a String that is formatted for a GET request.
      static java.lang.String getRequestParam​(java.lang.String url, java.lang.String paramName)
      Returns the value of a parameter from a String that is formatted for a GET request.
      static CmsJspVfsAccessBean getVfsAccessBean​(java.lang.Object input)
      Returns a JSP / EL VFS access bean.
      static boolean isSubSitemap​(CmsResource resource)
      Returns whether the given resource is a sub sitemap folder.
      static boolean isWrapper​(java.lang.Object value)
      Returns whether the given value is an instance of A_CmsJspValueWrapper.
      static java.lang.String jsonGetString​(java.lang.Object maybeJsonString, java.lang.Object key)
      Parses the JSON String and returns the requested value.
      static java.util.Map<java.lang.String,​java.lang.String> jsonToMap​(java.lang.String jsonString)
      Converts a string (which is assumed to contain a JSON object whose values are strings only) to a map, for use in JSPs.
      static java.lang.String lookup​(java.lang.String key, java.lang.String map)
      Looks up the given key from the map that is passed as a String, and returns either the element found or the empty String.
      static java.lang.String lookup​(java.lang.String key, java.lang.String map, java.lang.String defaultValue)
      Looks up the given key from the map that is passed as a String, and returns either the element found or the default value.
      static java.lang.Long mathCeil​(java.lang.Object param)
      Calculates the next largest integer for the given number parameter.
      static java.lang.Long mathFloor​(java.lang.Object param)
      Calculates the next smallest integer for the given number parameter.
      static java.lang.Long mathRound​(java.lang.Object param)
      Calculates the next integer for the given number parameter by rounding.
      static java.lang.Object parseJson​(java.lang.String value)
      Parses JSON object.
      static java.lang.String repairHtml​(java.lang.String input)
      Repairs the given HTML input by adding potentially missing closing tags.
      static java.lang.String stripHtml​(java.lang.Object input)
      Strips all HTML markup from the given input.
      static java.lang.Double toNumber​(java.lang.Object input, java.lang.Object def)
      Converts the given Object to a (Double) number, falling back to a default if this is not possible.
      static java.lang.String trimToSize​(java.lang.String input, int length)
      Returns a substring of the source, which is at most length characters long.
      static boolean validateRegex​(java.lang.String value, java.lang.String regex)
      Validates a value against a regular expression.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • addToList

        public static void addToList​(java.util.List<java.lang.Object> list,
                                     java.lang.Object value)
        Extends the given list by adding the provided object.

        Parameters:
        list - the list to extend
        value - the value to add to the list
      • convertCmsObject

        public static CmsObject convertCmsObject​(java.lang.Object input)
        Returns an OpenCms user context created from an Object.

        • If the input is already a CmsObject, it is casted and returned unchanged.
        • If the input is a ServletRequest, the OpenCms user context is read from the request context.
        • If the input is a PageContext, the OpenCms user context is read from the request of the page context.
        • Otherwise the input is converted to a String which should be a user name, and creation of a OpenCms user context with this name is attempted. Please note that this will only work if the user name is either the "Guest" user or the "Export" user.
        • If no valid OpenCms user context could be created with all of the above, then a new user context for the "Guest" user is created.
        Parameters:
        input - the input to create an OpenCms user context from
        Returns:
        an OpenCms user context created from an Object
      • convertDate

        public static java.util.Date convertDate​(java.lang.Object input)
        Returns a Date created from an Object.

        • The Object is first checked if it is a Date already, if so it is casted and returned unchanged.
        • If not, the input is checked if it is a Long, and if so the Date is created from the Long value.
        • If it's not a Date and not a Long, the Object is transformed to a String and then it's tried to parse a Long out of the String.
        • If this fails, it is tried to parse as a Date using the default date formatting.
        • If this also fails, a new Date is returned that has been initialized with 0.

        Parameters:
        input - the Object to create a Date from
        Returns:
        a Date created from the given Object
      • convertDouble

        public static java.lang.Double convertDouble​(java.lang.Object input)
        Returns a Double created from an Object.

        • If the input already is a Number, this number is returned as Double.
        • If the input is of type A_CmsJspValueWrapper, the wrapper is converted to a Double using A_CmsJspValueWrapper.getToDouble().
        • If the input is a String, it is converted to a Double.
        • Otherwise null is returned.
        Parameters:
        input - the Object to create a Double from
        Returns:
        a Double created from the given Object
      • convertList

        public static java.util.List<java.lang.Object> convertList​(java.util.List<java.lang.Object> input,
                                                                   java.lang.String attributeName)
        Returns a list of attribute values specified by the attribute name of the items of the given list.

        Parameters:
        input - the list of objects to obtain the attribute values from
        attributeName - the name of the attribute to obtain
        Returns:
        a list of attributes specified by the attribute name of the items of the given list
      • convertLocale

        public static java.util.Locale convertLocale​(java.lang.Object input)
        Returns a Locale created from an Object.

        • The Object is first checked if it is a Locale already, if so it is casted and returned.
        • If not, the input is transformed to a String and then a Locale lookup with this String is done.
        • If the locale lookup fails, the OpenCms default locale is returned.
        Parameters:
        input - the Object to create a Locale from
        Returns:
        a Locale created from the given Object
      • convertRawResource

        public static CmsResource convertRawResource​(CmsObject cms,
                                                     java.lang.Object input)
                                              throws CmsException
        Returns a resource created from an Object.

        • If the input is already a CmsResource, it is casted to the resource and returned unchanged.
        • If the input is a String, the given OpenCms context is used to read a resource with this name from the VFS.
        • If the input is a CmsUUID, the given OpenCms context is used to read a resource with this UUID from the VFS.
        • Otherwise the input is converted to a String, and then the given OpenCms context is used to read a resource with this name from the VFS.
        Parameters:
        cms - the current OpenCms user context
        input - the input to create a resource from
        Returns:
        a resource created from the given Object
        Throws:
        CmsException - in case of errors accessing the OpenCms VFS for reading the resource
      • convertRequest

        public static javax.servlet.ServletRequest convertRequest​(java.lang.Object input)
        Tries to convert the given input object into a request.

        This is only possible if the input object is already a request or if it is a page context.

        If everything else, this method returns null.

        Parameters:
        input - the input object to convert to a request
        Returns:
        a request object, or null
      • convertResourceList

        public static java.util.List<CmsJspResourceWrapperconvertResourceList​(CmsObject cms,
                                                                                java.util.List<CmsResource> list)
        Returns a list of resource wrappers created from the input list of resources.
        Parameters:
        cms - the current OpenCms user context
        list - the list to create the resource wrapper list from
        Returns:
        the list of wrapped resources.
      • convertUUID

        public static CmsUUID convertUUID​(java.lang.Object input)
        Returns a CmsUUID created from an Object.

        • The Object is first checked if it is a CmsUUID already, if so it is casted and returned.
        • If not, the input is transformed to a byte[] and a new CmsUUID is created with this byte[].
        • Otherwise the input is casted to a String and a new CmsUUID is created with this String.
        Parameters:
        input - the Object to create a CmsUUID from
        Returns:
        a CmsUUID created from the given Object
      • createList

        public static java.util.List<java.lang.Object> createList()
        Returns a newly created, empty List object.

        There is no way to create an empty list using standard JSTL methods, hence this function.

        Returns:
        a newly created, empty List object
      • getCmsObject

        public static CmsObject getCmsObject​(java.lang.Object input)
        Returns the current OpenCms user context from the given page context.

        Parameters:
        input - the input to create a CmsObject from
        Returns:
        the current OpenCms user context from the given page context
      • getListSize

        public static java.lang.Integer getListSize​(java.util.Collection<java.lang.Object> input)
        Returns the size of the given list.

        Parameters:
        input - the list of objects to obtain the size from
        Returns:
        the size of the given list
      • getModuleParam

        public static java.lang.String getModuleParam​(java.lang.String name,
                                                      java.lang.String key)
        Returns a parameter value from the module parameters.

        Parameters:
        name - the name of the module
        key - the parameter to return the value for
        Returns:
        the parameter value from the module parameters, or null if the parameter is not set
      • getNavigationUri

        @Deprecated
        public static java.lang.String getNavigationUri​(java.lang.Object input)
        Deprecated.
        On a JSP use ${cms.requestContext.uri} instead.
        Returns the current request URI.

        For OpenCms 10.5, this is the same as using ${cms.requestContext.uri} on a JSP.

        Parameters:
        input - the request convertible object to get the navigation URI from
        Returns:
        the current navigation URI
      • getRequestLink

        public static java.lang.String getRequestLink​(java.lang.String url)
        Returns the link without parameters from a String that is formatted for a GET request.

        Parameters:
        url - the URL to remove the parameters from
        Returns:
        the link without parameters
      • getRequestParam

        public static java.lang.String getRequestParam​(java.lang.String url,
                                                       java.lang.String paramName)
        Returns the value of a parameter from a String that is formatted for a GET request.

        Parameters:
        url - the URL to get the parameter value from
        paramName - the request parameter name
        Returns:
        the value of the parameter
      • getVfsAccessBean

        public static CmsJspVfsAccessBean getVfsAccessBean​(java.lang.Object input)
        Returns a JSP / EL VFS access bean.

        Parameters:
        input - the Object to create a CmsObject from
        Returns:
        a JSP / EL VFS access bean
      • isSubSitemap

        public static boolean isSubSitemap​(CmsResource resource)
        Returns whether the given resource is a sub sitemap folder.

        Parameters:
        resource - the resource to check
        Returns:
        true if the given resource is a sub sitemap folder
      • isWrapper

        public static boolean isWrapper​(java.lang.Object value)
        Returns whether the given value is an instance of A_CmsJspValueWrapper.

        Parameters:
        value - the value object to check
        Returns:
        true if the given value is an instance of A_CmsJspValueWrapper
      • jsonGetString

        public static java.lang.String jsonGetString​(java.lang.Object maybeJsonString,
                                                     java.lang.Object key)
        Parses the JSON String and returns the requested value.

        Parameters:
        maybeJsonString - the JSON string
        key - the key
        Returns:
        the json value string
      • jsonToMap

        public static java.util.Map<java.lang.String,​java.lang.String> jsonToMap​(java.lang.String jsonString)
        Converts a string (which is assumed to contain a JSON object whose values are strings only) to a map, for use in JSPs.

        If the input can't be interpreted as JSON, an empty map is returned.

        Parameters:
        jsonString - the JSON string
        Returns:
        the map with the keys/values from the JSON
      • lookup

        public static java.lang.String lookup​(java.lang.String key,
                                              java.lang.String map)
        Looks up the given key from the map that is passed as a String, and returns either the element found or the empty String.

        The map String must have the form "key1:value1|key2:value2" etc.

        Parameters:
        key - the key to look up
        map - the map represented as a String
        Returns:
        the element found in the map with the given key, or the empty String
      • lookup

        public static java.lang.String lookup​(java.lang.String key,
                                              java.lang.String map,
                                              java.lang.String defaultValue)
        Looks up the given key from the map that is passed as a String, and returns either the element found or the default value.

        The map String must have the form "key1:value1|key2:value2" etc.

        Parameters:
        key - the key to look up
        map - the map represented as a String
        defaultValue - the default value
        Returns:
        the element found in the map with the given key, or the default value
      • mathCeil

        public static java.lang.Long mathCeil​(java.lang.Object param)
        Calculates the next largest integer for the given number parameter.

        Note that the result is an Object of type Long, so in case the parameter can not be converted to a number, null is returned.

        Parameters:
        param - an Object that will be converted to a number
        Returns:
        the next largest integer for the given number parameter
      • mathFloor

        public static java.lang.Long mathFloor​(java.lang.Object param)
        Calculates the next smallest integer for the given number parameter.

        Note that the result is an Object of type Long, so in case the parameter can not be converted to a number, null is returned.

        Parameters:
        param - an Object that will be converted to a number
        Returns:
        the next smallest integer for the given number parameter
      • mathRound

        public static java.lang.Long mathRound​(java.lang.Object param)
        Calculates the next integer for the given number parameter by rounding.

        Note that the result is an Object of type Long, so in case the parameter can not be converted to a number, null is returned.

        Parameters:
        param - an Object that will be converted to a number
        Returns:
        the next integer for the given number parameter calculated by rounding
      • parseJson

        public static java.lang.Object parseJson​(java.lang.String value)
        Parses JSON object.
        Parameters:
        value -
        Returns:
      • repairHtml

        public static java.lang.String repairHtml​(java.lang.String input)
        Repairs the given HTML input by adding potentially missing closing tags.

        Parameters:
        input - the HTML input
        Returns:
        the repaired HTML or an empty string in case of errors
      • stripHtml

        public static java.lang.String stripHtml​(java.lang.Object input)
        Strips all HTML markup from the given input.

        • In case the input is an instance of CmsJspContentAccessValueWrapper, an optimized method is used for the HTML stripping.
        • Otherwise the input is converted to a String and this String is stripped.
        Parameters:
        input - the input to Strip from HTML
        Returns:
        the given input with all HTML stripped.
      • toNumber

        public static java.lang.Double toNumber​(java.lang.Object input,
                                                java.lang.Object def)
        Converts the given Object to a (Double) number, falling back to a default if this is not possible.

        In case even the default can not be converted to a number, -1.0 is returned.

        Parameters:
        input - the Object to convert to a (Double) number
        def - the fall back default value in case the conversion is not possible
        Returns:
        the given Object converted to a (Double) number
      • trimToSize

        public static java.lang.String trimToSize​(java.lang.String input,
                                                  int length)
        Returns a substring of the source, which is at most length characters long.

        If a char is cut, " ..." is appended to the result.

        Parameters:
        input - the string to trim
        length - the maximum length of the string to be returned
        Returns:
        a substring of the source, which is at most length characters long
        See Also:
        CmsStringUtil.trimToSize(String, int, String)
      • validateRegex

        public static boolean validateRegex​(java.lang.String value,
                                            java.lang.String regex)
        Validates a value against a regular expression.

        Parameters:
        value - the value
        regex - the regex
        Returns:
        true if the value satisfies the validation