Class JspUtil


  • public class JspUtil
    extends java.lang.Object
    This class has all the utility method(s). Ideally should move all the bean containers here.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  JspUtil.ValidAttribute
      Represents a valid attribute for a tag.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int CHUNKSIZE
      Default chunk size for reading files.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean booleanValue​(java.lang.String s)
      Convert a String value to 'boolean'.
      static void checkAttributes​(java.lang.String typeOfTag, Node n, JspUtil.ValidAttribute[] validAttributes, ErrorDispatcher err)
      Checks if all mandatory attributes are present and if all attributes present have valid names.
      static void checkScope​(java.lang.String scope, Node n, ErrorDispatcher err)
      Checks to see if the given scope is valid.
      static java.lang.String coerceToBoolean​(java.lang.String s, boolean isNamedAttribute)
      Generates code to coerce a string to a Boolean object.
      static java.lang.String coerceToByte​(java.lang.String s, boolean isNamedAttribute)
      Generates code to coerce a string to a Byte object.
      static java.lang.String coerceToChar​(java.lang.String s, boolean isNamedAttribute)
      Generates code to coerce a string to a primitive char value.
      static java.lang.String coerceToCharacter​(java.lang.String s, boolean isNamedAttribute)
      Generates code to coerce a string to a Character object.
      static java.lang.String coerceToDouble​(java.lang.String s, boolean isNamedAttribute)
      Generates code to coerce a string to a Double object.
      static java.lang.String coerceToFloat​(java.lang.String s, boolean isNamedAttribute)
      Generates code to coerce a string to a Float object.
      static java.lang.String coerceToInt​(java.lang.String s, boolean isNamedAttribute)
      Generates code to coerce a string to a primitive int value.
      static java.lang.String coerceToInteger​(java.lang.String s, boolean isNamedAttribute)
      Generates code to coerce a string to an Integer object.
      static java.lang.String coerceToLong​(java.lang.String s, boolean isNamedAttribute)
      Generates code to coerce a string to a Long object.
      static java.lang.String coerceToPrimitiveBoolean​(java.lang.String s, boolean isNamedAttribute)
      Generates code to coerce a string to a primitive boolean value.
      static java.lang.String coerceToPrimitiveByte​(java.lang.String s, boolean isNamedAttribute)
      Generates code to coerce a string to a primitive byte value.
      static java.lang.String coerceToPrimitiveDouble​(java.lang.String s, boolean isNamedAttribute)
      Generates code to coerce a string to a primitive double value.
      static java.lang.String coerceToPrimitiveFloat​(java.lang.String s, boolean isNamedAttribute)
      Generates code to coerce a string to a primitive float value.
      static java.lang.String coerceToPrimitiveLong​(java.lang.String s, boolean isNamedAttribute)
      Generates code to coerce a string to a primitive long value.
      static java.lang.String coerceToPrimitiveShort​(java.lang.String s, boolean isNamedAttribute)
      Generates code to coerce a string to a primitive short value.
      static java.lang.String coerceToShort​(java.lang.String s, boolean isNamedAttribute)
      Generates code to coerce a string to a Short object.
      static java.lang.String getExprInXml​(java.lang.String expression)
      Takes a potential expression and converts it into XML form.
      static org.xml.sax.InputSource getInputSource​(java.lang.String fname, Jar jar, JspCompilationContext ctxt)
      Gets an input source for the given file name.
      static java.io.BufferedInputStream getInputStream​(java.lang.String fname, Jar jar, JspCompilationContext ctxt)
      Gets an input stream for the given file name.
      static java.lang.String getTagHandlerClassName​(java.lang.String path, java.lang.String packageName, java.lang.String urn, ErrorDispatcher err)
      Gets the fully-qualified class name of the tag handler corresponding to the given tag file path.
      static java.lang.String interpreterCall​(boolean isTagFile, java.lang.String expression, java.lang.Class<?> expectedType, java.lang.String fnmapvar)
      Produces a String representing a call to the EL interpreter.
      static boolean isJavaKeyword​(java.lang.String key)
      Test whether the argument is a Java keyword.
      static java.lang.String makeJavaIdentifier​(java.lang.String identifier)
      Converts the given identifier to a legal Java identifier
      static java.lang.String makeJavaIdentifierForAttribute​(java.lang.String identifier)
      Converts the given identifier to a legal Java identifier to be used for JSP Tag file attribute names.
      static java.lang.String makeJavaPackage​(java.lang.String path)
      Converts the given path to a Java package or fully-qualified class name
      static java.lang.String mangleChar​(char ch)
      Mangle the specified character to create a legal Java class name.
      static java.lang.Class<?> toClass​(java.lang.String type, java.lang.ClassLoader loader)
      Returns the Class object associated with the class or interface with the given string name.
      static java.lang.String toJavaSourceType​(java.lang.String type)
      Class.getName() return arrays in the form "[[[<et>", where et, the element type can be one of ZBCDFIJS or L<classname>;.
      static java.lang.String toJavaSourceTypeFromTld​(java.lang.String type)
      Handles taking input from TLDs 'java.lang.Object' -> 'java.lang.Object.class' 'int' -> 'int.class' 'void' -> 'Void.TYPE' 'int[]' -> 'int[].class'
      • Methods inherited from class java.lang.Object

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

      • CHUNKSIZE

        public static final int CHUNKSIZE
        Default chunk size for reading files.
        See Also:
        Constant Field Values
    • Method Detail

      • getExprInXml

        public static java.lang.String getExprInXml​(java.lang.String expression)
        Takes a potential expression and converts it into XML form.
        Parameters:
        expression - The expression to convert
        Returns:
        XML view
      • checkScope

        public static void checkScope​(java.lang.String scope,
                                      Node n,
                                      ErrorDispatcher err)
                               throws JasperException
        Checks to see if the given scope is valid.
        Parameters:
        scope - The scope to be checked
        n - The Node containing the 'scope' attribute whose value is to be checked
        err - error dispatcher
        Throws:
        JasperException - if scope is not null and different from "page", "request", "session", and "application"
      • checkAttributes

        public static void checkAttributes​(java.lang.String typeOfTag,
                                           Node n,
                                           JspUtil.ValidAttribute[] validAttributes,
                                           ErrorDispatcher err)
                                    throws JasperException
        Checks if all mandatory attributes are present and if all attributes present have valid names. Checks attributes specified as XML-style attributes as well as attributes specified using the jsp:attribute standard action.
        Parameters:
        typeOfTag - The tag type
        n - The corresponding node
        validAttributes - The array with the valid attributes
        err - Dispatcher for errors
        Throws:
        JasperException - An error occurred
      • booleanValue

        public static boolean booleanValue​(java.lang.String s)
        Convert a String value to 'boolean'. Besides the standard conversions done by Boolean.parseBoolean(s), the value "yes" (ignore case) is also converted to 'true'. If 's' is null, then 'false' is returned.
        Parameters:
        s - the string to be converted
        Returns:
        the boolean value associated with the string s
      • toClass

        public static java.lang.Class<?> toClass​(java.lang.String type,
                                                 java.lang.ClassLoader loader)
                                          throws java.lang.ClassNotFoundException
        Returns the Class object associated with the class or interface with the given string name.

        The Class object is determined by passing the given string name to the Class.forName() method, unless the given string name represents a primitive type, in which case it is converted to a Class object by appending ".class" to it (e.g., "int.class").

        Parameters:
        type - The class name, array or primitive type
        loader - The class loader
        Returns:
        the loaded class
        Throws:
        java.lang.ClassNotFoundException - Loading class failed
      • interpreterCall

        public static java.lang.String interpreterCall​(boolean isTagFile,
                                                       java.lang.String expression,
                                                       java.lang.Class<?> expectedType,
                                                       java.lang.String fnmapvar)
        Produces a String representing a call to the EL interpreter.
        Parameters:
        isTagFile - true if the file is a tag file rather than a JSP
        expression - a String containing zero or more "${}" expressions
        expectedType - the expected type of the interpreted result
        fnmapvar - Variable pointing to a function map.
        Returns:
        a String representing a call to the EL interpreter.
      • coerceToPrimitiveBoolean

        public static java.lang.String coerceToPrimitiveBoolean​(java.lang.String s,
                                                                boolean isNamedAttribute)
        Generates code to coerce a string to a primitive boolean value.
        Parameters:
        s - The string expression
        isNamedAttribute - Whether the value comes from a named attribute
        Returns:
        the generated coercion code
      • coerceToBoolean

        public static java.lang.String coerceToBoolean​(java.lang.String s,
                                                       boolean isNamedAttribute)
        Generates code to coerce a string to a Boolean object.
        Parameters:
        s - The string expression
        isNamedAttribute - Whether the value comes from a named attribute
        Returns:
        the generated coercion code
      • coerceToPrimitiveByte

        public static java.lang.String coerceToPrimitiveByte​(java.lang.String s,
                                                             boolean isNamedAttribute)
        Generates code to coerce a string to a primitive byte value.
        Parameters:
        s - The string expression
        isNamedAttribute - Whether the value comes from a named attribute
        Returns:
        the generated coercion code
      • coerceToByte

        public static java.lang.String coerceToByte​(java.lang.String s,
                                                    boolean isNamedAttribute)
        Generates code to coerce a string to a Byte object.
        Parameters:
        s - The string expression
        isNamedAttribute - Whether the value comes from a named attribute
        Returns:
        the generated coercion code
      • coerceToChar

        public static java.lang.String coerceToChar​(java.lang.String s,
                                                    boolean isNamedAttribute)
        Generates code to coerce a string to a primitive char value.
        Parameters:
        s - The string expression
        isNamedAttribute - Whether the value comes from a named attribute
        Returns:
        the generated coercion code
      • coerceToCharacter

        public static java.lang.String coerceToCharacter​(java.lang.String s,
                                                         boolean isNamedAttribute)
        Generates code to coerce a string to a Character object.
        Parameters:
        s - The string expression
        isNamedAttribute - Whether the value comes from a named attribute
        Returns:
        the generated coercion code
      • coerceToPrimitiveDouble

        public static java.lang.String coerceToPrimitiveDouble​(java.lang.String s,
                                                               boolean isNamedAttribute)
        Generates code to coerce a string to a primitive double value.
        Parameters:
        s - The string expression
        isNamedAttribute - Whether the value comes from a named attribute
        Returns:
        the generated coercion code
      • coerceToDouble

        public static java.lang.String coerceToDouble​(java.lang.String s,
                                                      boolean isNamedAttribute)
        Generates code to coerce a string to a Double object.
        Parameters:
        s - The string expression
        isNamedAttribute - Whether the value comes from a named attribute
        Returns:
        the generated coercion code
      • coerceToPrimitiveFloat

        public static java.lang.String coerceToPrimitiveFloat​(java.lang.String s,
                                                              boolean isNamedAttribute)
        Generates code to coerce a string to a primitive float value.
        Parameters:
        s - The string expression
        isNamedAttribute - Whether the value comes from a named attribute
        Returns:
        the generated coercion code
      • coerceToFloat

        public static java.lang.String coerceToFloat​(java.lang.String s,
                                                     boolean isNamedAttribute)
        Generates code to coerce a string to a Float object.
        Parameters:
        s - The string expression
        isNamedAttribute - Whether the value comes from a named attribute
        Returns:
        the generated coercion code
      • coerceToInt

        public static java.lang.String coerceToInt​(java.lang.String s,
                                                   boolean isNamedAttribute)
        Generates code to coerce a string to a primitive int value.
        Parameters:
        s - The string expression
        isNamedAttribute - Whether the value comes from a named attribute
        Returns:
        the generated coercion code
      • coerceToInteger

        public static java.lang.String coerceToInteger​(java.lang.String s,
                                                       boolean isNamedAttribute)
        Generates code to coerce a string to an Integer object.
        Parameters:
        s - The string expression
        isNamedAttribute - Whether the value comes from a named attribute
        Returns:
        the generated coercion code
      • coerceToPrimitiveShort

        public static java.lang.String coerceToPrimitiveShort​(java.lang.String s,
                                                              boolean isNamedAttribute)
        Generates code to coerce a string to a primitive short value.
        Parameters:
        s - The string expression
        isNamedAttribute - Whether the value comes from a named attribute
        Returns:
        the generated coercion code
      • coerceToShort

        public static java.lang.String coerceToShort​(java.lang.String s,
                                                     boolean isNamedAttribute)
        Generates code to coerce a string to a Short object.
        Parameters:
        s - The string expression
        isNamedAttribute - Whether the value comes from a named attribute
        Returns:
        the generated coercion code
      • coerceToPrimitiveLong

        public static java.lang.String coerceToPrimitiveLong​(java.lang.String s,
                                                             boolean isNamedAttribute)
        Generates code to coerce a string to a primitive long value.
        Parameters:
        s - The string expression
        isNamedAttribute - Whether the value comes from a named attribute
        Returns:
        the generated coercion code
      • coerceToLong

        public static java.lang.String coerceToLong​(java.lang.String s,
                                                    boolean isNamedAttribute)
        Generates code to coerce a string to a Long object.
        Parameters:
        s - The string expression
        isNamedAttribute - Whether the value comes from a named attribute
        Returns:
        the generated coercion code
      • getInputStream

        public static java.io.BufferedInputStream getInputStream​(java.lang.String fname,
                                                                 Jar jar,
                                                                 JspCompilationContext ctxt)
                                                          throws java.io.IOException
        Gets an input stream for the given file name.
        Parameters:
        fname - The file name
        jar - The JAR, or null
        ctxt - The compilation context
        Returns:
        the input stream
        Throws:
        java.io.IOException - if an I/O error occurs
      • getInputSource

        public static org.xml.sax.InputSource getInputSource​(java.lang.String fname,
                                                             Jar jar,
                                                             JspCompilationContext ctxt)
                                                      throws java.io.IOException
        Gets an input source for the given file name.
        Parameters:
        fname - The file name
        jar - The JAR, or null
        ctxt - The compilation context
        Returns:
        the input source
        Throws:
        java.io.IOException - if an I/O error occurs
      • getTagHandlerClassName

        public static java.lang.String getTagHandlerClassName​(java.lang.String path,
                                                              java.lang.String packageName,
                                                              java.lang.String urn,
                                                              ErrorDispatcher err)
                                                       throws JasperException
        Gets the fully-qualified class name of the tag handler corresponding to the given tag file path.
        Parameters:
        path - Tag file path
        packageName - The package name
        urn - The tag identifier
        err - Error dispatcher
        Returns:
        Fully-qualified class name of the tag handler corresponding to the given tag file path
        Throws:
        JasperException - Failed to generate a class name for the tag
      • makeJavaPackage

        public static java.lang.String makeJavaPackage​(java.lang.String path)
        Converts the given path to a Java package or fully-qualified class name
        Parameters:
        path - Path to convert
        Returns:
        Java package corresponding to the given path
      • makeJavaIdentifier

        public static java.lang.String makeJavaIdentifier​(java.lang.String identifier)
        Converts the given identifier to a legal Java identifier
        Parameters:
        identifier - Identifier to convert
        Returns:
        Legal Java identifier corresponding to the given identifier
      • makeJavaIdentifierForAttribute

        public static java.lang.String makeJavaIdentifierForAttribute​(java.lang.String identifier)
        Converts the given identifier to a legal Java identifier to be used for JSP Tag file attribute names.
        Parameters:
        identifier - Identifier to convert
        Returns:
        Legal Java identifier corresponding to the given identifier
      • mangleChar

        public static java.lang.String mangleChar​(char ch)
        Mangle the specified character to create a legal Java class name.
        Parameters:
        ch - The character
        Returns:
        the replacement character as a string
      • isJavaKeyword

        public static boolean isJavaKeyword​(java.lang.String key)
        Test whether the argument is a Java keyword.
        Parameters:
        key - The name
        Returns:
        true if the name is a java identifier
      • toJavaSourceTypeFromTld

        public static java.lang.String toJavaSourceTypeFromTld​(java.lang.String type)
        Handles taking input from TLDs 'java.lang.Object' -> 'java.lang.Object.class' 'int' -> 'int.class' 'void' -> 'Void.TYPE' 'int[]' -> 'int[].class'
        Parameters:
        type - The type from the TLD
        Returns:
        the Java type
      • toJavaSourceType

        public static java.lang.String toJavaSourceType​(java.lang.String type)
        Class.getName() return arrays in the form "[[[<et>", where et, the element type can be one of ZBCDFIJS or L<classname>;. It is converted into forms that can be understood by javac.
        Parameters:
        type - the type to convert
        Returns:
        the equivalent type in Java sources