Package org.apache.jasper.runtime
Class JspRuntimeLibrary
- java.lang.Object
-
- org.apache.jasper.runtime.JspRuntimeLibrary
-
public class JspRuntimeLibrary extends java.lang.ObjectBunch of util methods that are used by code generated for useBean, getProperty and setProperty.
-
-
Field Summary
Fields Modifier and Type Field Description static booleanGRAALIndicates whether the code is running under GraalVM native image.
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static java.lang.Stringcapitalize(java.lang.String name)Reverse of Introspector.decapitalize.static java.lang.Objectcoerce(java.lang.String s, java.lang.Class<?> target)Coerces a string to the target type.static booleancoerceToBoolean(java.lang.String s)Coerces a string to a boolean value.static bytecoerceToByte(java.lang.String s)Coerces a string to a byte value.static charcoerceToChar(java.lang.String s)Coerces a string to a char value.static doublecoerceToDouble(java.lang.String s)Coerces a string to a double value.static floatcoerceToFloat(java.lang.String s)Coerces a string to a float value.static intcoerceToInt(java.lang.String s)Coerces a string to an int value.static longcoerceToLong(java.lang.String s)Coerces a string to a long value.static shortcoerceToShort(java.lang.String s)Coerces a string to a short value.static java.lang.Objectconvert(java.lang.String propertyName, java.lang.String s, java.lang.Class<?> t, java.lang.Class<?> propertyEditorClass)Converts a string value to the target type, using a property editor if specified.static voidcreateTypedArray(java.lang.String propertyName, java.lang.Object bean, java.lang.reflect.Method method, java.lang.String[] values, java.lang.Class<?> t, java.lang.Class<?> propertyEditorClass)Create a typed array.static java.lang.StringescapeQueryString(java.lang.String unescString)Escape special shell characters.static java.lang.StringgetContextRelativePath(ServletRequest request, java.lang.String relativePath)Convert a possibly relative resource path into a context-relative resource path that starts with a '/'.static java.lang.reflect.MethodgetReadMethod(java.lang.Class<?> beanClass, java.lang.String prop)Gets the read method (getter) for a bean property.static java.lang.ThrowablegetThrowable(ServletRequest request)Returns the value of the jakarta.servlet.error.exception request attribute value, if present, otherwise the value of the jakarta.servlet.jsp.jspException request attribute value.static java.lang.ObjectgetValueFromBeanInfoPropertyEditor(java.lang.Class<?> attrClass, java.lang.String attrName, java.lang.String attrValue, java.lang.Class<?> propertyEditorClass)Gets a value using a bean info property editor.static java.lang.ObjectgetValueFromPropertyEditorManager(java.lang.Class<?> attrClass, java.lang.String attrName, java.lang.String attrValue)Gets a value using the property editor manager.static java.lang.reflect.MethodgetWriteMethod(java.lang.Class<?> beanClass, java.lang.String prop)Gets the write method (setter) for a bean property.static java.lang.ObjecthandleGetProperty(java.lang.Object o, java.lang.String prop)Gets the value of a bean property.static voidhandleSetProperty(java.lang.Object bean, java.lang.String prop, boolean value)Sets a bean property to the given boolean value.static voidhandleSetProperty(java.lang.Object bean, java.lang.String prop, byte value)Sets a bean property to the given byte value.static voidhandleSetProperty(java.lang.Object bean, java.lang.String prop, char value)Sets a bean property to the given char value.static voidhandleSetProperty(java.lang.Object bean, java.lang.String prop, double value)Sets a bean property to the given double value.static voidhandleSetProperty(java.lang.Object bean, java.lang.String prop, float value)Sets a bean property to the given float value.static voidhandleSetProperty(java.lang.Object bean, java.lang.String prop, int value)Sets a bean property to the given int value.static voidhandleSetProperty(java.lang.Object bean, java.lang.String prop, long value)Sets a bean property to the given long value.static voidhandleSetProperty(java.lang.Object bean, java.lang.String prop, short value)Sets a bean property to the given short value.static voidhandleSetProperty(java.lang.Object bean, java.lang.String prop, java.lang.Object value)Sets a bean property to the given value.static voidhandleSetPropertyExpression(java.lang.Object bean, java.lang.String prop, java.lang.String expression, PageContext pageContext, ProtectedFunctionMapper functionMapper)Sets a bean property from an EL expression.static voidinclude(ServletRequest request, ServletResponse response, java.lang.String relativePath, JspWriter out, boolean flush)Perform a RequestDispatcher.include() operation, with optional flushing of the response beforehand.static voidintrospect(java.lang.Object bean, ServletRequest request)Sets bean properties from request parameters.static voidintrospecthelper(java.lang.Object bean, java.lang.String prop, java.lang.String value, ServletRequest request, java.lang.String param, boolean ignoreMethodNF)Sets a single bean property from a string value.static voidnonstandardSetTag(PageContext pageContext, java.lang.String var, java.lang.Object value, int scope)This method parallels the logic ofSetSupport.doEndTag().static voidreleaseTag(Tag tag, InstanceManager instanceManager)Releases a tag and destroys its instance.static voidreleaseTag(Tag tag, InstanceManager instanceManager, boolean reused)Deprecated.static JspWriterstartBufferedBody(PageContext pageContext, BodyTag tag)Starts a buffered body for a tag that supports body content.static java.lang.StringtoString(boolean b)Converts a boolean to its string representation.static java.lang.StringtoString(byte b)Converts a byte to its string representation.static java.lang.StringtoString(char c)Converts a char to its string representation.static java.lang.StringtoString(double d)Converts a double to its string representation.static java.lang.StringtoString(float f)Converts a float to its string representation.static java.lang.StringtoString(int i)Converts an int to its string representation.static java.lang.StringtoString(long l)Converts a long to its string representation.static java.lang.StringtoString(short s)Converts a short to its string representation.static java.lang.StringtoString(java.lang.Object o)Converts an object to its string representation.static java.lang.StringURLEncode(java.lang.String s, java.lang.String enc)URL encodes a string, based on the supplied character encoding.
-
-
-
Method Detail
-
getThrowable
public static java.lang.Throwable getThrowable(ServletRequest request)
Returns the value of the jakarta.servlet.error.exception request attribute value, if present, otherwise the value of the jakarta.servlet.jsp.jspException request attribute value. This method is called at the beginning of the generated servlet code for a JSP error page, when the "exception" implicit scripting language variable is initialized.- Parameters:
request- The Servlet request- Returns:
- the throwable in the error attribute if any
-
coerceToBoolean
public static boolean coerceToBoolean(java.lang.String s)
Coerces a string to a boolean value.- Parameters:
s- The string to coerce- Returns:
- the boolean value, or false if the string is null/empty
-
coerceToByte
public static byte coerceToByte(java.lang.String s)
Coerces a string to a byte value.- Parameters:
s- The string to coerce- Returns:
- the byte value, or 0 if the string is null/empty
-
coerceToChar
public static char coerceToChar(java.lang.String s)
Coerces a string to a char value.- Parameters:
s- The string to coerce- Returns:
- the char value, or 0 if the string is null/empty
-
coerceToDouble
public static double coerceToDouble(java.lang.String s)
Coerces a string to a double value.- Parameters:
s- The string to coerce- Returns:
- the double value, or 0 if the string is null/empty
-
coerceToFloat
public static float coerceToFloat(java.lang.String s)
Coerces a string to a float value.- Parameters:
s- The string to coerce- Returns:
- the float value, or 0 if the string is null/empty
-
coerceToInt
public static int coerceToInt(java.lang.String s)
Coerces a string to an int value.- Parameters:
s- The string to coerce- Returns:
- the int value, or 0 if the string is null/empty
-
coerceToShort
public static short coerceToShort(java.lang.String s)
Coerces a string to a short value.- Parameters:
s- The string to coerce- Returns:
- the short value, or 0 if the string is null/empty
-
coerceToLong
public static long coerceToLong(java.lang.String s)
Coerces a string to a long value.- Parameters:
s- The string to coerce- Returns:
- the long value, or 0 if the string is null/empty
-
coerce
public static java.lang.Object coerce(java.lang.String s, java.lang.Class<?> target)Coerces a string to the target type.- Parameters:
s- The string to coercetarget- The target class- Returns:
- the coerced value
-
convert
public static java.lang.Object convert(java.lang.String propertyName, java.lang.String s, java.lang.Class<?> t, java.lang.Class<?> propertyEditorClass) throws JasperExceptionConverts a string value to the target type, using a property editor if specified.- Parameters:
propertyName- The property names- The string value to convertt- The target classpropertyEditorClass- The property editor class, ornull- Returns:
- the converted value
- Throws:
JasperException- if conversion fails
-
introspect
public static void introspect(java.lang.Object bean, ServletRequest request) throws JasperExceptionSets bean properties from request parameters.- Parameters:
bean- The beanrequest- The servlet request- Throws:
JasperException- if setting a property fails
-
introspecthelper
public static void introspecthelper(java.lang.Object bean, java.lang.String prop, java.lang.String value, ServletRequest request, java.lang.String param, boolean ignoreMethodNF) throws JasperExceptionSets a single bean property from a string value.- Parameters:
bean- The beanprop- The property namevalue- The string valuerequest- The servlet requestparam- The parameter nameignoreMethodNF- Whether to ignore missing methods- Throws:
JasperException- if setting the property fails
-
toString
public static java.lang.String toString(java.lang.Object o)
Converts an object to its string representation.- Parameters:
o- The object- Returns:
- the string representation
-
toString
public static java.lang.String toString(byte b)
Converts a byte to its string representation.- Parameters:
b- The byte value- Returns:
- the string representation
-
toString
public static java.lang.String toString(boolean b)
Converts a boolean to its string representation.- Parameters:
b- The boolean value- Returns:
- the string representation
-
toString
public static java.lang.String toString(short s)
Converts a short to its string representation.- Parameters:
s- The short value- Returns:
- the string representation
-
toString
public static java.lang.String toString(int i)
Converts an int to its string representation.- Parameters:
i- The int value- Returns:
- the string representation
-
toString
public static java.lang.String toString(float f)
Converts a float to its string representation.- Parameters:
f- The float value- Returns:
- the string representation
-
toString
public static java.lang.String toString(long l)
Converts a long to its string representation.- Parameters:
l- The long value- Returns:
- the string representation
-
toString
public static java.lang.String toString(double d)
Converts a double to its string representation.- Parameters:
d- The double value- Returns:
- the string representation
-
toString
public static java.lang.String toString(char c)
Converts a char to its string representation.- Parameters:
c- The char value- Returns:
- the string representation
-
createTypedArray
public static void createTypedArray(java.lang.String propertyName, java.lang.Object bean, java.lang.reflect.Method method, java.lang.String[] values, java.lang.Class<?> t, java.lang.Class<?> propertyEditorClass) throws JasperExceptionCreate a typed array. This is a special case where params are passed through the request and the property is indexed.- Parameters:
propertyName- The property namebean- The beanmethod- The methodvalues- Array valuest- The classpropertyEditorClass- The editor for the property- Throws:
JasperException- An error occurred
-
escapeQueryString
public static java.lang.String escapeQueryString(java.lang.String unescString)
Escape special shell characters.- Parameters:
unescString- The string to shell-escape- Returns:
- The escaped shell string.
-
handleGetProperty
public static java.lang.Object handleGetProperty(java.lang.Object o, java.lang.String prop) throws JasperExceptionGets the value of a bean property.- Parameters:
o- The beanprop- The property name- Returns:
- the property value
- Throws:
JasperException- if getting the property fails
-
handleSetPropertyExpression
public static void handleSetPropertyExpression(java.lang.Object bean, java.lang.String prop, java.lang.String expression, PageContext pageContext, ProtectedFunctionMapper functionMapper) throws JasperExceptionSets a bean property from an EL expression.- Parameters:
bean- The beanprop- The property nameexpression- The EL expressionpageContext- The page contextfunctionMapper- The function mapper- Throws:
JasperException- if setting the property fails
-
handleSetProperty
public static void handleSetProperty(java.lang.Object bean, java.lang.String prop, java.lang.Object value) throws JasperExceptionSets a bean property to the given value.- Parameters:
bean- The beanprop- The property namevalue- The value to set- Throws:
JasperException- if setting the property fails
-
handleSetProperty
public static void handleSetProperty(java.lang.Object bean, java.lang.String prop, int value) throws JasperExceptionSets a bean property to the given int value.- Parameters:
bean- The beanprop- The property namevalue- The value to set- Throws:
JasperException- if setting the property fails
-
handleSetProperty
public static void handleSetProperty(java.lang.Object bean, java.lang.String prop, short value) throws JasperExceptionSets a bean property to the given short value.- Parameters:
bean- The beanprop- The property namevalue- The value to set- Throws:
JasperException- if setting the property fails
-
handleSetProperty
public static void handleSetProperty(java.lang.Object bean, java.lang.String prop, long value) throws JasperExceptionSets a bean property to the given long value.- Parameters:
bean- The beanprop- The property namevalue- The value to set- Throws:
JasperException- if setting the property fails
-
handleSetProperty
public static void handleSetProperty(java.lang.Object bean, java.lang.String prop, double value) throws JasperExceptionSets a bean property to the given double value.- Parameters:
bean- The beanprop- The property namevalue- The value to set- Throws:
JasperException- if setting the property fails
-
handleSetProperty
public static void handleSetProperty(java.lang.Object bean, java.lang.String prop, float value) throws JasperExceptionSets a bean property to the given float value.- Parameters:
bean- The beanprop- The property namevalue- The value to set- Throws:
JasperException- if setting the property fails
-
handleSetProperty
public static void handleSetProperty(java.lang.Object bean, java.lang.String prop, char value) throws JasperExceptionSets a bean property to the given char value.- Parameters:
bean- The beanprop- The property namevalue- The value to set- Throws:
JasperException- if setting the property fails
-
handleSetProperty
public static void handleSetProperty(java.lang.Object bean, java.lang.String prop, byte value) throws JasperExceptionSets a bean property to the given byte value.- Parameters:
bean- The beanprop- The property namevalue- The value to set- Throws:
JasperException- if setting the property fails
-
handleSetProperty
public static void handleSetProperty(java.lang.Object bean, java.lang.String prop, boolean value) throws JasperExceptionSets a bean property to the given boolean value.- Parameters:
bean- The beanprop- The property namevalue- The value to set- Throws:
JasperException- if setting the property fails
-
capitalize
public static java.lang.String capitalize(java.lang.String name)
Reverse of Introspector.decapitalize.- Parameters:
name- The name- Returns:
- the capitalized string
-
getWriteMethod
public static java.lang.reflect.Method getWriteMethod(java.lang.Class<?> beanClass, java.lang.String prop) throws JasperExceptionGets the write method (setter) for a bean property.- Parameters:
beanClass- The bean classprop- The property name- Returns:
- the write method
- Throws:
JasperException- if the property or write method cannot be found
-
getReadMethod
public static java.lang.reflect.Method getReadMethod(java.lang.Class<?> beanClass, java.lang.String prop) throws JasperExceptionGets the read method (getter) for a bean property.- Parameters:
beanClass- The bean classprop- The property name- Returns:
- the read method
- Throws:
JasperException- if the property or read method cannot be found
-
getValueFromBeanInfoPropertyEditor
public static java.lang.Object getValueFromBeanInfoPropertyEditor(java.lang.Class<?> attrClass, java.lang.String attrName, java.lang.String attrValue, java.lang.Class<?> propertyEditorClass) throws JasperExceptionGets a value using a bean info property editor.- Parameters:
attrClass- The attribute classattrName- The attribute nameattrValue- The attribute value as a stringpropertyEditorClass- The property editor class- Returns:
- the converted value
- Throws:
JasperException- if conversion fails
-
getValueFromPropertyEditorManager
public static java.lang.Object getValueFromPropertyEditorManager(java.lang.Class<?> attrClass, java.lang.String attrName, java.lang.String attrValue) throws JasperExceptionGets a value using the property editor manager.- Parameters:
attrClass- The attribute classattrName- The attribute nameattrValue- The attribute value as a string- Returns:
- the converted value
- Throws:
JasperException- if conversion fails
-
getContextRelativePath
public static java.lang.String getContextRelativePath(ServletRequest request, java.lang.String relativePath)
Convert a possibly relative resource path into a context-relative resource path that starts with a '/'.- Parameters:
request- The servlet request we are processingrelativePath- The possibly relative resource path- Returns:
- an absolute path
-
include
public static void include(ServletRequest request, ServletResponse response, java.lang.String relativePath, JspWriter out, boolean flush) throws java.io.IOException, ServletException
Perform a RequestDispatcher.include() operation, with optional flushing of the response beforehand.- Parameters:
request- The servlet request we are processingresponse- The servlet response we are processingrelativePath- The relative path of the resource to be includedout- The Writer to whom we are currently writingflush- Should we flush before the include is processed?- Throws:
java.io.IOException- if thrown by the included servletServletException- if thrown by the included servlet
-
URLEncode
public static java.lang.String URLEncode(java.lang.String s, java.lang.String enc)URL encodes a string, based on the supplied character encoding.- Parameters:
s- The String to be URL encoded.enc- The character encoding- Returns:
- The URL encoded String
-
startBufferedBody
public static JspWriter startBufferedBody(PageContext pageContext, BodyTag tag) throws JspException
Starts a buffered body for a tag that supports body content.- Parameters:
pageContext- The page contexttag- The body tag- Returns:
- the JspWriter for the body content
- Throws:
JspException- if starting the buffered body fails
-
releaseTag
@Deprecated public static void releaseTag(Tag tag, InstanceManager instanceManager, boolean reused)
Deprecated.
-
releaseTag
public static void releaseTag(Tag tag, InstanceManager instanceManager)
Releases a tag and destroys its instance.- Parameters:
tag- The tag to releaseinstanceManager- The instance manager
-
nonstandardSetTag
public static void nonstandardSetTag(PageContext pageContext, java.lang.String var, java.lang.Object value, int scope)
This method parallels the logic ofSetSupport.doEndTag().- Parameters:
pageContext- pageContextvar- name of the variablevalue- value to storescope- scope
-
-