org.apache.struts2.jasper.compiler

## Class JspUtil

- java.lang.Object
- - org.apache.struts2.jasper.compiler.JspUtil

-     public class JspUtil
      extends Object

  This class has all the utility method(s). Ideally should move all the bean containers here.
  Author:
    Mandar Raje., Rajiv Mordani., Danno Ferrin, Pierre Delisle, Shawn Bayern, Mark Roth

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `JspUtil.ValidAttribute`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static int` | `CHUNKSIZE`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `JspUtil()`

  - ### Method Summary

    All Methods Static Methods Concrete Methods Deprecated Methods
    Modifier and Type | Method and Description
    --- | ---
    `static boolean` | `booleanValue(String s)` Convert a String value to 'boolean'.
    `static void` | `checkAttributes(String typeOfTag, org.apache.struts2.jasper.compiler.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(String scope, org.apache.struts2.jasper.compiler.Node n, ErrorDispatcher err)` Checks to see if the given scope is valid.
    `static String` | `coerceToBoolean(String s, boolean isNamedAttribute)`
    `static String` | `coerceToByte(String s, boolean isNamedAttribute)`
    `static String` | `coerceToChar(String s, boolean isNamedAttribute)`
    `static String` | `coerceToCharacter(String s, boolean isNamedAttribute)`
    `static String` | `coerceToDouble(String s, boolean isNamedAttribute)`
    `static String` | `coerceToFloat(String s, boolean isNamedAttribute)`
    `static String` | `coerceToInt(String s, boolean isNamedAttribute)`
    `static String` | `coerceToInteger(String s, boolean isNamedAttribute)`
    `static String` | `coerceToLong(String s, boolean isNamedAttribute)`
    `static String` | `coerceToPrimitiveBoolean(String s, boolean isNamedAttribute)`
    `static String` | `coerceToPrimitiveByte(String s, boolean isNamedAttribute)`
    `static String` | `coerceToPrimitiveDouble(String s, boolean isNamedAttribute)`
    `static String` | `coerceToPrimitiveFloat(String s, boolean isNamedAttribute)`
    `static String` | `coerceToPrimitiveLong(String s, boolean isNamedAttribute)`
    `static String` | `coerceToPrimitiveShort(String s, boolean isNamedAttribute)`
    `static String` | `coerceToShort(String s, boolean isNamedAttribute)`
    `static String` | `escapeQueryString(String unescString)`
    `static char[]` | `escapeQuotes(char[] chars)`
    `static String` | `escapeXml(String s)` Escape the 5 entities defined by XML.
    `static String` | `getCanonicalName(Class c)` Compute the canonical name from a Class instance.
    `static String` | `getExpr(String expression, boolean isXml)`
    `static String` | `getExprInXml(String expression)` Takes a potential expression and converts it into XML form
    `static InputStream` | `getInputStream(String fname, JarFile jarFile, JspCompilationContext ctxt, ErrorDispatcher err)`
    `static String` | `getTagHandlerClassName(String path, ErrorDispatcher err)` Deprecated. Use `getTagHandlerClassName(String, String, ErrorDispatcher)` See https://issues.apache.org/bugzilla/show_bug.cgi?id=46471
    `static String` | `getTagHandlerClassName(String path, String urn, ErrorDispatcher err)` Gets the fully-qualified class name of the tag handler corresponding to the given tag file path.
    `static String` | `interpreterCall(boolean isTagFile, String expression, Class expectedType, String fnmapvar, boolean XmlEscape)` Produces a String representing a call to the EL interpreter.
    `static boolean` | `isExpression(String token, boolean isXml)` Checks if the token is a runtime expression.
    `static boolean` | `isJavaKeyword(String key)`
    `static String` | `makeJavaIdentifier(String identifier)` Converts the given identifier to a legal Java identifier
    `static String` | `makeJavaPackage(String path)` Converts the given path to a Java package or fully-qualified class name
    `static String` | `makeXmlJavaIdentifier(String name)` Converts the given Xml name to a legal Java identifier.
    `static String` | `mangleChar(char ch)` Mangle the specified character to create a legal Java class name.
    `static String` | `nextTemporaryVariableName()` Deprecated.
    `static char[]` | `removeQuotes(char[] chars)`
    `static String` | `replace(String name, char replace, String with)` Replaces any occurrences of the character `replace` with the string `with`.
    `static void` | `resetTemporaryVariableName()` Deprecated.
    `static Class` | `toClass(String type, ClassLoader loader)` 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").
    `static String` | `toJavaSourceType(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.
    `static String` | `toJavaSourceTypeFromTld(String type)` Handles taking input from TLDs 'java.lang.Object' -> 'java.lang.Object.class' 'int' -> 'int.class' 'void' -> 'Void.TYPE' 'int[]' -> 'int[].class'
    `static void` | `validateExpressions(org.apache.struts2.jasper.compiler.Mark where, String expressions, Class expectedType, javax.el.FunctionMapper functionMapper, ErrorDispatcher err)` Deprecated. now delegated to the org.apache.el Package

    - ### 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

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### JspUtil

          public JspUtil()

  - ### Method Detail

    - #### removeQuotes

          public static char[] removeQuotes(char[] chars)

    - #### escapeQuotes

          public static char[] escapeQuotes(char[] chars)

    - #### isExpression

          public static boolean isExpression(String token,
                                             boolean isXml)

      Checks if the token is a runtime expression. In standard JSP syntax, a runtime expression starts with '<%' and ends with '%>'. When the JSP document is in XML syntax, a runtime expression starts with '%=' and ends with '%'.
      Parameters:
        `token` - The token to be checked
        `isXml` - is xml syntax
      Returns:
        whether the token is a runtime expression or not.

    - #### getExpr

          public static String getExpr(String expression,
                                       boolean isXml)

      Parameters:
        `expression` - expression string
        `isXml` - is xml
      Returns:
        the "expression" part of a runtime expression, taking the delimiters out.

    - #### getExprInXml

          public static String getExprInXml(String expression)

      Takes a potential expression and converts it into XML form
      Parameters:
        `expression` - expression string
      Returns:
        expressions as xml

    - #### checkScope

          public static void checkScope(String scope,
                                        org.apache.struts2.jasper.compiler.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(String typeOfTag,
                                             org.apache.struts2.jasper.compiler.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` - type of tag
        `n` - node
        `validAttributes` - valid attributes
        `err` - error dispatcher
      Throws:
        `JasperException` - in case of Jasper errors

    - #### escapeQueryString

          public static String escapeQueryString(String unescString)

    - #### escapeXml

          public static String escapeXml(String s)

      Escape the 5 entities defined by XML.
      Parameters:
        `s` - xml string to escape
      Returns:
        escaped xml string

    - #### replace

          public static String replace(String name,
                                       char replace,
                                       String with)

      Replaces any occurrences of the character `replace` with the string `with`.
      Parameters:
        `name` - string
        `replace` - char to replace
        `with` - replace with
      Returns:
        replaced string

    - #### booleanValue

          public static boolean booleanValue(String s)

      Convert a String value to 'boolean'. Besides the standard conversions done by Boolean.valueOf(s).booleanValue(), 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 Class toClass(String type,
                                      ClassLoader loader)
                               throws ClassNotFoundException

      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` - type
        `loader` - class loader
      Returns:
        the `Class` object associated with the class or interface with the given string name.
      Throws:
        `ClassNotFoundException` - if call was not found

    - #### interpreterCall

          public static String interpreterCall(boolean isTagFile,
                                               String expression,
                                               Class expectedType,
                                               String fnmapvar,
                                               boolean XmlEscape)

      Produces a String representing a call to the EL interpreter.
      Parameters:
        `isTagFile` - is a tag file
        `expression` - a String containing zero or more "${}" expressions
        `expectedType` - the expected type of the interpreted result
        `fnmapvar` - Variable pointing to a function map.
        `XmlEscape` - True if the result should do XML escaping
      Returns:
        a String representing a call to the EL interpreter.

    - #### validateExpressions

          public static void validateExpressions(org.apache.struts2.jasper.compiler.Mark where,
                                                 String expressions,
                                                 Class expectedType,
                                                 javax.el.FunctionMapper functionMapper,
                                                 ErrorDispatcher err)
                                          throws JasperException

      Deprecated. now delegated to the org.apache.el Package
      Validates the syntax of all ${} expressions within the given string.
      Parameters:
        `where` - the approximate location of the expressions in the JSP page
        `expressions` - a string containing zero or more "${}" expressions
        `expectedType` - expected class type
        `functionMapper` - function mapper
        `err` - an error dispatcher to use
      Throws:
        `JasperException` - in case of Jasper errors

    - #### resetTemporaryVariableName

          public static void resetTemporaryVariableName()

      Deprecated.
      Resets the temporary variable name. (not thread-safe)

    - #### nextTemporaryVariableName

          public static String nextTemporaryVariableName()

      Deprecated.
      Returns:
        Generates a new temporary variable name. (not thread-safe)

    - #### coerceToPrimitiveBoolean

          public static String coerceToPrimitiveBoolean(String s,
                                                        boolean isNamedAttribute)

    - #### coerceToBoolean

          public static String coerceToBoolean(String s,
                                               boolean isNamedAttribute)

    - #### coerceToPrimitiveByte

          public static String coerceToPrimitiveByte(String s,
                                                     boolean isNamedAttribute)

    - #### coerceToByte

          public static String coerceToByte(String s,
                                            boolean isNamedAttribute)

    - #### coerceToChar

          public static String coerceToChar(String s,
                                            boolean isNamedAttribute)

    - #### coerceToCharacter

          public static String coerceToCharacter(String s,
                                                 boolean isNamedAttribute)

    - #### coerceToPrimitiveDouble

          public static String coerceToPrimitiveDouble(String s,
                                                       boolean isNamedAttribute)

    - #### coerceToDouble

          public static String coerceToDouble(String s,
                                              boolean isNamedAttribute)

    - #### coerceToPrimitiveFloat

          public static String coerceToPrimitiveFloat(String s,
                                                      boolean isNamedAttribute)

    - #### coerceToFloat

          public static String coerceToFloat(String s,
                                             boolean isNamedAttribute)

    - #### coerceToInt

          public static String coerceToInt(String s,
                                           boolean isNamedAttribute)

    - #### coerceToInteger

          public static String coerceToInteger(String s,
                                               boolean isNamedAttribute)

    - #### coerceToPrimitiveShort

          public static String coerceToPrimitiveShort(String s,
                                                      boolean isNamedAttribute)

    - #### coerceToShort

          public static String coerceToShort(String s,
                                             boolean isNamedAttribute)

    - #### coerceToPrimitiveLong

          public static String coerceToPrimitiveLong(String s,
                                                     boolean isNamedAttribute)

    - #### coerceToLong

          public static String coerceToLong(String s,
                                            boolean isNamedAttribute)

    - #### getInputStream

          public static InputStream getInputStream(String fname,
                                                   JarFile jarFile,
                                                   JspCompilationContext ctxt,
                                                   ErrorDispatcher err)
                                            throws JasperException,
                                                   IOException

      Throws:
        `JasperException`
        `IOException`

    - #### getTagHandlerClassName

          public static String getTagHandlerClassName(String path,
                                                      ErrorDispatcher err)
                                               throws JasperException

      Deprecated. Use `getTagHandlerClassName(String, String, ErrorDispatcher)` See https://issues.apache.org/bugzilla/show_bug.cgi?id=46471
      Gets the fully-qualified class name of the tag handler corresponding to the given tag file path.
      Parameters:
        `path` - Tag file path
        `err` - Error dispatcher
      Returns:
        Fully-qualified class name of the tag handler corresponding to the given tag file path
      Throws:
        `JasperException` - in case of Jasper errors

    - #### getTagHandlerClassName

          public static String getTagHandlerClassName(String path,
                                                      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
        `urn` - urn
        `err` - Error dispatcher
      Returns:
        Fully-qualified class name of the tag handler corresponding to the given tag file path
      Throws:
        `JasperException` - in case of Jasper errors

    - #### makeJavaPackage

          public static final String makeJavaPackage(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 final String makeJavaIdentifier(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

    - #### mangleChar

          public static final String mangleChar(char ch)

      Mangle the specified character to create a legal Java class name.
      Parameters:
        `ch` - character
      Returns:
        new string

    - #### isJavaKeyword

          public static boolean isJavaKeyword(String key)

      Parameters:
        `key` - string to check
      Returns:
        Test whether the argument is a Java keyword

    - #### makeXmlJavaIdentifier

          public static final String makeXmlJavaIdentifier(String name)

      Converts the given Xml name to a legal Java identifier. This is slightly more efficient than makeJavaIdentifier in that we only need to worry about '.', '-', and ':' in the string. We also assume that the resultant string is further concatenated with some prefix string so that we don't have to worry about it being a Java key word.
      Parameters:
        `name` - Identifier to convert
      Returns:
        Legal Java identifier corresponding to the given identifier

    - #### toJavaSourceTypeFromTld

          public static String toJavaSourceTypeFromTld(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` - java source type
      Returns:
        type

    - #### toJavaSourceType

          public static String toJavaSourceType(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` - source type
      Returns:
        java source type

    - #### getCanonicalName

          public static String getCanonicalName(Class c)

      Compute the canonical name from a Class instance. Note that a simple replacement of '$' with '.' of a binary name would not work, as '$' is a legal Java Identifier character.
      Parameters:
        `c` - A instance of java.lang.Class
      Returns:
        The canonical name of c.

Copyright © 2000–2026 Apache Software Foundation. All rights reserved.