Class JspUtil
java.lang.Object
org.apache.jasper.compiler.JspUtil
This class has all the utility method(s).
Ideally should move all the bean containers here.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intprivate static final Stringprivate static final Stringprivate static javax.el.ExpressionFactoryprivate static final String[]private static final String(package private) static Manifestprivate static final Stringprivate static final Stringprivate static intprivate static final String -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanConvert a String value to 'boolean'.static voidcheckAttributes(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 voidcheckScope(String scope, Node n, ErrorDispatcher err) Checks to see if the given scope is valid.static Objectstatic StringcoerceToBoolean(String s, boolean isNamedAttribute) static StringcoerceToByte(String s, boolean isNamedAttribute) static StringcoerceToChar(String s, boolean isNamedAttribute) static StringcoerceToCharacter(String s, boolean isNamedAttribute) static StringcoerceToDouble(String s, boolean isNamedAttribute) static StringcoerceToEnum(String s, String enumClass, boolean isNamedAttribute) static StringcoerceToFloat(String s, boolean isNamedAttribute) static StringcoerceToInt(String s, boolean isNamedAttribute) static StringcoerceToInteger(String s, boolean isNamedAttribute) static StringcoerceToLong(String s, boolean isNamedAttribute) static StringcoerceToPrimitiveBoolean(String s, boolean isNamedAttribute) static StringcoerceToPrimitiveByte(String s, boolean isNamedAttribute) static StringcoerceToPrimitiveDouble(String s, boolean isNamedAttribute) static StringcoerceToPrimitiveFloat(String s, boolean isNamedAttribute) static StringcoerceToPrimitiveLong(String s, boolean isNamedAttribute) static StringcoerceToPrimitiveShort(String s, boolean isNamedAttribute) static StringcoerceToShort(String s, boolean isNamedAttribute) static StringescapeQueryString(String unescString) static char[]escapeQuotes(char[] chars) static StringEscape the 5 entities defined by XML.expandClassPath(List<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 StringCompute the canonical name from a Class instance.static Stringprivate static javax.el.ExpressionFactorystatic StringgetExprInXml(String expression) Takes a potential expression and converts it into XML formstatic InputStreamgetInputStream(String fname, JarFile jarFile, JspCompilationContext ctxt, ErrorDispatcher err) (package private) static InputStreamReadergetReader(String fname, String encoding, JarFile jarFile, JspCompilationContext ctxt, ErrorDispatcher err) static StringgetTagHandlerClassName(String path, ErrorDispatcher err) Gets the fully-qualified class name of the tag handler corresponding to the given tag file path.static StringinterpreterCall(boolean isTagFile, String expression, Class expectedType, String fnmapvar, String expectedDeferredType, String expectedReturnType, String[] expectedParamTypes) Produces a String representing a call to the EL interpreter.static booleanisExpression(String token, boolean isXml) Checks if the token is a runtime expression.static booleanisJavaKeyword(String key) Test whether the argument is a Java keywordstatic final StringmakeJavaIdentifier(String identifier) Converts the given identifier to a legal Java identifierstatic final StringmakeJavaPackage(String path) Converts the given path to a Java package or fully-qualified class namestatic final StringmakeXmlJavaIdentifier(String name) Converts the given Xml name to a legal Java identifier.static final StringmangleChar(char ch) Mangle the specified character to create a legal Java class name.static StringGenerates a new temporary variable name.static char[]removeQuotes(char[] chars) static StringReplaces any occurrences of the character replace with the string with.static voidResets the temporary variable name.private static final String[]Splits a string into it's components.static Class<?> toClass(String type, ClassLoader loader) Returns the Class object associated with the class or interface with the given string name.static StringtoJavaSourceType(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 voidvalidateExpressions(Mark where, String expressions, javax.el.FunctionMapper functionMapper, ErrorDispatcher err) Validates the syntax of all EL expressions within the given string.
-
Field Details
-
WEB_INF_TAGS
- See Also:
-
META_INF_TAGS
- See Also:
-
OPEN_EXPR
- See Also:
-
CLOSE_EXPR
- See Also:
-
OPEN_EXPR_XML
- See Also:
-
CLOSE_EXPR_XML
- See Also:
-
tempSequenceNumber
private static int tempSequenceNumber -
expFactory
private static javax.el.ExpressionFactory expFactory -
javaKeywords
-
CHUNKSIZE
public static final int CHUNKSIZE- See Also:
-
manifestMap
-
nullManifest
-
-
Constructor Details
-
JspUtil
public JspUtil()
-
-
Method Details
-
removeQuotes
public static char[] removeQuotes(char[] chars) -
escapeQuotes
public static char[] escapeQuotes(char[] chars) -
isExpression
Checks if the token is a runtime expression. In standard JSP syntax, a runtime expression starts with 'invalid input: '<'%' 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
-
getExprInXml
-
checkScope
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(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
-
escapeXml
-
replace
-
booleanValue
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
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:
ClassNotFoundException
-
interpreterCall
public static String interpreterCall(boolean isTagFile, String expression, Class expectedType, String fnmapvar, String expectedDeferredType, String expectedReturnType, 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, 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
-
resetTemporaryVariableName
public static void resetTemporaryVariableName()Resets the temporary variable name. (not thread-safe) -
nextTemporaryVariableName
Generates a new temporary variable name. (not thread-safe) -
coerceToPrimitiveBoolean
-
coerceToBoolean
-
coerceToPrimitiveByte
-
coerceToByte
-
coerceToChar
-
coerceToCharacter
-
coerceToPrimitiveDouble
-
coerceToDouble
-
coerceToPrimitiveFloat
-
coerceToFloat
-
coerceToInt
-
coerceToInteger
-
coerceToPrimitiveShort
-
coerceToShort
-
coerceToPrimitiveLong
-
coerceToLong
-
coerceToEnum
-
getInputStream
public static InputStream getInputStream(String fname, JarFile jarFile, JspCompilationContext ctxt, ErrorDispatcher err) throws JasperException, IOException - Throws:
JasperExceptionIOException
-
getTagHandlerClassName
public static String getTagHandlerClassName(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
-
split
-
makeJavaIdentifier
-
mangleChar
Mangle the specified character to create a legal Java class name. -
isJavaKeyword
Test whether the argument is a Java keyword -
makeXmlJavaIdentifier
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 InputStreamReader getReader(String fname, String encoding, JarFile jarFile, JspCompilationContext ctxt, ErrorDispatcher err) throws JasperException, IOException - Throws:
JasperExceptionIOException
-
toJavaSourceType
-
getCanonicalName
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
-