Package org.apache.jasper.compiler
Class JspUtil
- java.lang.Object
-
- org.apache.jasper.compiler.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
-
Field Summary
Fields Modifier and Type Field Description static int
CHUNKSIZE
private static java.lang.String
CLOSE_EXPR
private static java.lang.String
CLOSE_EXPR_XML
private static javax.el.ExpressionFactory
expFactory
private static java.lang.String[]
javaKeywords
(package private) static java.util.Map<java.lang.String,java.util.jar.Manifest>
manifestMap
private static java.lang.String
META_INF_TAGS
(package private) static java.util.jar.Manifest
nullManifest
private static java.lang.String
OPEN_EXPR
private static java.lang.String
OPEN_EXPR_XML
private static int
tempSequenceNumber
private static java.lang.String
WEB_INF_TAGS
-
Constructor Summary
Constructors Constructor Description JspUtil()
-
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.Object
coerce(java.lang.Class targetType, java.lang.String value)
static java.lang.String
coerceToBoolean(java.lang.String s, boolean isNamedAttribute)
static java.lang.String
coerceToByte(java.lang.String s, boolean isNamedAttribute)
static java.lang.String
coerceToChar(java.lang.String s, boolean isNamedAttribute)
static java.lang.String
coerceToCharacter(java.lang.String s, boolean isNamedAttribute)
static java.lang.String
coerceToDouble(java.lang.String s, boolean isNamedAttribute)
static java.lang.String
coerceToEnum(java.lang.String s, java.lang.String enumClass, boolean isNamedAttribute)
static java.lang.String
coerceToFloat(java.lang.String s, boolean isNamedAttribute)
static java.lang.String
coerceToInt(java.lang.String s, boolean isNamedAttribute)
static java.lang.String
coerceToInteger(java.lang.String s, boolean isNamedAttribute)
static java.lang.String
coerceToLong(java.lang.String s, boolean isNamedAttribute)
static java.lang.String
coerceToPrimitiveBoolean(java.lang.String s, boolean isNamedAttribute)
static java.lang.String
coerceToPrimitiveByte(java.lang.String s, boolean isNamedAttribute)
static java.lang.String
coerceToPrimitiveDouble(java.lang.String s, boolean isNamedAttribute)
static java.lang.String
coerceToPrimitiveFloat(java.lang.String s, boolean isNamedAttribute)
static java.lang.String
coerceToPrimitiveLong(java.lang.String s, boolean isNamedAttribute)
static java.lang.String
coerceToPrimitiveShort(java.lang.String s, boolean isNamedAttribute)
static java.lang.String
coerceToShort(java.lang.String s, boolean isNamedAttribute)
static java.lang.String
escapeQueryString(java.lang.String unescString)
static char[]
escapeQuotes(char[] chars)
static java.lang.String
escapeXml(java.lang.String s)
Escape the 5 entities defined by XML.static java.util.List<java.lang.String>
expandClassPath(java.util.List<java.lang.String> files)
Given a list of jar files, their manifest attribute Class-path are scanned, and jars specified there are added to the list.static java.lang.String
getCanonicalName(java.lang.Class c)
Compute the canonical name from a Class instance.static java.lang.String
getExpr(java.lang.String expression, boolean isXml)
private static javax.el.ExpressionFactory
getExpressionFactory()
static java.lang.String
getExprInXml(java.lang.String expression)
Takes a potential expression and converts it into XML formstatic java.io.InputStream
getInputStream(java.lang.String fname, java.util.jar.JarFile jarFile, JspCompilationContext ctxt, ErrorDispatcher err)
(package private) static java.io.InputStreamReader
getReader(java.lang.String fname, java.lang.String encoding, java.util.jar.JarFile jarFile, JspCompilationContext ctxt, ErrorDispatcher err)
static java.lang.String
getTagHandlerClassName(java.lang.String path, 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, java.lang.String expectedDeferredType, java.lang.String expectedReturnType, java.lang.String[] expectedParamTypes)
Produces a String representing a call to the EL interpreter.static boolean
isExpression(java.lang.String token, boolean isXml)
Checks if the token is a runtime expression.static boolean
isJavaKeyword(java.lang.String key)
Test whether the argument is a Java keywordstatic java.lang.String
makeJavaIdentifier(java.lang.String identifier)
Converts the given identifier to a legal Java identifierstatic java.lang.String
makeJavaPackage(java.lang.String path)
Converts the given path to a Java package or fully-qualified class namestatic java.lang.String
makeXmlJavaIdentifier(java.lang.String name)
Converts the given Xml name to a legal Java identifier.static java.lang.String
mangleChar(char ch)
Mangle the specified character to create a legal Java class name.static java.lang.String
nextTemporaryVariableName()
Generates a new temporary variable name.static char[]
removeQuotes(char[] chars)
static java.lang.String
replace(java.lang.String name, char replace, java.lang.String with)
Replaces any occurrences of the character replace with the string with.static void
resetTemporaryVariableName()
Resets the temporary variable name.private static java.lang.String[]
split(java.lang.String path, java.lang.String pat)
Splits a string into it's components.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 "[[[", where et, the element type can be one of ZBCDFIJS or L ; It is converted into forms that can be understood by javac. static void
validateExpressions(Mark where, java.lang.String expressions, javax.el.FunctionMapper functionMapper, ErrorDispatcher err)
Validates the syntax of all EL expressions within the given string.
-
-
-
Field Detail
-
WEB_INF_TAGS
private static final java.lang.String WEB_INF_TAGS
- See Also:
- Constant Field Values
-
META_INF_TAGS
private static final java.lang.String META_INF_TAGS
- See Also:
- Constant Field Values
-
OPEN_EXPR
private static final java.lang.String OPEN_EXPR
- See Also:
- Constant Field Values
-
CLOSE_EXPR
private static final java.lang.String CLOSE_EXPR
- See Also:
- Constant Field Values
-
OPEN_EXPR_XML
private static final java.lang.String OPEN_EXPR_XML
- See Also:
- Constant Field Values
-
CLOSE_EXPR_XML
private static final java.lang.String CLOSE_EXPR_XML
- See Also:
- Constant Field Values
-
tempSequenceNumber
private static int tempSequenceNumber
-
expFactory
private static javax.el.ExpressionFactory expFactory
-
javaKeywords
private static final java.lang.String[] javaKeywords
-
CHUNKSIZE
public static final int CHUNKSIZE
- See Also:
- Constant Field Values
-
manifestMap
static java.util.Map<java.lang.String,java.util.jar.Manifest> manifestMap
-
nullManifest
static java.util.jar.Manifest nullManifest
-
-
Method Detail
-
removeQuotes
public static char[] removeQuotes(char[] chars)
-
escapeQuotes
public static char[] escapeQuotes(char[] chars)
-
isExpression
public static boolean isExpression(java.lang.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 return whether the token is a runtime expression or not.
-
getExpr
public static java.lang.String getExpr(java.lang.String expression, boolean isXml)
- Returns:
- the "expression" part of a runtime expression, taking the delimiters out.
-
getExprInXml
public static java.lang.String getExprInXml(java.lang.String expression)
Takes a potential expression and converts it into XML form
-
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 checkedn
- The Node containing the 'scope' attribute whose value is to be checkederr
- 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.- Throws:
JasperException
-
escapeQueryString
public static java.lang.String escapeQueryString(java.lang.String unescString)
-
escapeXml
public static java.lang.String escapeXml(java.lang.String s)
Escape the 5 entities defined by XML.
-
replace
public static java.lang.String replace(java.lang.String name, char replace, java.lang.String with)
Replaces any occurrences of the character replace with the string with.
-
booleanValue
public static boolean booleanValue(java.lang.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 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").
- Throws:
java.lang.ClassNotFoundException
-
interpreterCall
public static java.lang.String interpreterCall(boolean isTagFile, java.lang.String expression, java.lang.Class expectedType, java.lang.String fnmapvar, java.lang.String expectedDeferredType, java.lang.String expectedReturnType, java.lang.String[] expectedParamTypes)
Produces a String representing a call to the EL interpreter.- Parameters:
expression
- a String containing zero or more "${}" expressionsexpectedType
- the expected type of the interpreted resultfnmapvar
- Variable pointing to a function map.- Returns:
- a String representing a call to the EL interpreter.
-
validateExpressions
public static void validateExpressions(Mark where, java.lang.String expressions, javax.el.FunctionMapper functionMapper, ErrorDispatcher err) throws JasperException
Validates the syntax of all EL expressions within the given string.- Parameters:
where
- the approximate location of the expressions in the JSP pageexpressions
- a string containing an EL expressionserr
- an error dispatcher to use- Throws:
JasperException
-
coerce
public static java.lang.Object coerce(java.lang.Class targetType, java.lang.String value) throws javax.el.ELException
- Throws:
javax.el.ELException
-
resetTemporaryVariableName
public static void resetTemporaryVariableName()
Resets the temporary variable name. (not thread-safe)
-
nextTemporaryVariableName
public static java.lang.String nextTemporaryVariableName()
Generates a new temporary variable name. (not thread-safe)
-
coerceToPrimitiveBoolean
public static java.lang.String coerceToPrimitiveBoolean(java.lang.String s, boolean isNamedAttribute)
-
coerceToBoolean
public static java.lang.String coerceToBoolean(java.lang.String s, boolean isNamedAttribute)
-
coerceToPrimitiveByte
public static java.lang.String coerceToPrimitiveByte(java.lang.String s, boolean isNamedAttribute)
-
coerceToByte
public static java.lang.String coerceToByte(java.lang.String s, boolean isNamedAttribute)
-
coerceToChar
public static java.lang.String coerceToChar(java.lang.String s, boolean isNamedAttribute)
-
coerceToCharacter
public static java.lang.String coerceToCharacter(java.lang.String s, boolean isNamedAttribute)
-
coerceToPrimitiveDouble
public static java.lang.String coerceToPrimitiveDouble(java.lang.String s, boolean isNamedAttribute)
-
coerceToDouble
public static java.lang.String coerceToDouble(java.lang.String s, boolean isNamedAttribute)
-
coerceToPrimitiveFloat
public static java.lang.String coerceToPrimitiveFloat(java.lang.String s, boolean isNamedAttribute)
-
coerceToFloat
public static java.lang.String coerceToFloat(java.lang.String s, boolean isNamedAttribute)
-
coerceToInt
public static java.lang.String coerceToInt(java.lang.String s, boolean isNamedAttribute)
-
coerceToInteger
public static java.lang.String coerceToInteger(java.lang.String s, boolean isNamedAttribute)
-
coerceToPrimitiveShort
public static java.lang.String coerceToPrimitiveShort(java.lang.String s, boolean isNamedAttribute)
-
coerceToShort
public static java.lang.String coerceToShort(java.lang.String s, boolean isNamedAttribute)
-
coerceToPrimitiveLong
public static java.lang.String coerceToPrimitiveLong(java.lang.String s, boolean isNamedAttribute)
-
coerceToLong
public static java.lang.String coerceToLong(java.lang.String s, boolean isNamedAttribute)
-
coerceToEnum
public static java.lang.String coerceToEnum(java.lang.String s, java.lang.String enumClass, boolean isNamedAttribute)
-
getInputStream
public static java.io.InputStream getInputStream(java.lang.String fname, java.util.jar.JarFile jarFile, JspCompilationContext ctxt, ErrorDispatcher err) throws JasperException, java.io.IOException
- Throws:
JasperException
java.io.IOException
-
getTagHandlerClassName
public static java.lang.String getTagHandlerClassName(java.lang.String path, 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 patherr
- Error dispatcher- Returns:
- Fully-qualified class name of the tag handler corresponding to the given tag file path
- Throws:
JasperException
-
makeJavaPackage
public static final 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
-
split
private static final java.lang.String[] split(java.lang.String path, java.lang.String pat)
Splits a string into it's components.- Parameters:
path
- String to splitpat
- Pattern to split at- Returns:
- the components of the path
-
makeJavaIdentifier
public static final 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
-
mangleChar
public static final java.lang.String mangleChar(char ch)
Mangle the specified character to create a legal Java class name.
-
isJavaKeyword
public static boolean isJavaKeyword(java.lang.String key)
Test whether the argument is a Java keyword
-
makeXmlJavaIdentifier
public static final java.lang.String makeXmlJavaIdentifier(java.lang.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
-
getReader
static java.io.InputStreamReader getReader(java.lang.String fname, java.lang.String encoding, java.util.jar.JarFile jarFile, JspCompilationContext ctxt, ErrorDispatcher err) throws JasperException, java.io.IOException
- Throws:
JasperException
java.io.IOException
-
toJavaSourceType
public static java.lang.String toJavaSourceType(java.lang.String type)
Class.getName() return arrays in the form "[[[", where et, the element type can be one of ZBCDFIJS or L ; It is converted into forms that can be understood by javac.
-
getCanonicalName
public static java.lang.String getCanonicalName(java.lang.Class c)
Compute the canonical name from a Class instance. Note that a simple replacment 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.
-
getExpressionFactory
private static javax.el.ExpressionFactory getExpressionFactory()
-
expandClassPath
public static java.util.List<java.lang.String> expandClassPath(java.util.List<java.lang.String> files)
Given a list of jar files, their manifest attribute Class-path are scanned, and jars specified there are added to the list. This is carried out recursively. Note: This is needed to work around the JDK bug 6725230.
-
-