📄 jspruntimelibrary.java
字号:
holdbuffer[bufcount++] =
(byte) Integer.parseInt(
encoded.substring(count + 1, count + 3),
16);
if (count + 2 >= encoded.length())
count = encoded.length();
else
count += 2;
} else if (cur == '+') {
holdbuffer[bufcount++] = (byte) ' ';
} else {
holdbuffer[bufcount++] = (byte) cur;
}
}
// REVISIT -- remedy for Deprecated warning.
//return new String(holdbuffer,0,0,bufcount);
return new String(holdbuffer, 0, bufcount);
}
// __begin lookupReadMethodMethod
public static Object handleGetProperty(Object o, String prop)
throws JasperException {
if (o == null) {
throw new JasperException(
Constants
.getString("jsp.error.beans.nullbean", new Object[] {
}));
}
Object value = null;
try {
java.lang.reflect.Method method = getReadMethod(o.getClass(), prop);
value = method.invoke(o, null);
} catch (Exception ex) {
throw new JasperException(ex);
}
return value;
}
// __end lookupReadMethodMethod
public static void handleSetProperty(
Object bean,
String prop,
Object value)
throws JasperException {
try {
Method method = getWriteMethod(bean.getClass(), prop);
method.invoke(bean, new Object[] { value });
} catch (Exception ex) {
throw new JasperException(ex);
}
}
public static void handleSetProperty(Object bean, String prop, int value)
throws JasperException {
try {
Method method = getWriteMethod(bean.getClass(), prop);
method.invoke(bean, new Object[] { new Integer(value)});
} catch (Exception ex) {
throw new JasperException(ex);
}
}
public static void handleSetProperty(Object bean, String prop, short value)
throws JasperException {
try {
Method method = getWriteMethod(bean.getClass(), prop);
method.invoke(bean, new Object[] { new Short(value)});
} catch (Exception ex) {
throw new JasperException(ex);
}
}
public static void handleSetProperty(Object bean, String prop, long value)
throws JasperException {
try {
Method method = getWriteMethod(bean.getClass(), prop);
method.invoke(bean, new Object[] { new Long(value)});
} catch (Exception ex) {
throw new JasperException(ex);
}
}
public static void handleSetProperty(
Object bean,
String prop,
double value)
throws JasperException {
try {
Method method = getWriteMethod(bean.getClass(), prop);
method.invoke(bean, new Object[] { new Double(value)});
} catch (Exception ex) {
throw new JasperException(ex);
}
}
public static void handleSetProperty(Object bean, String prop, float value)
throws JasperException {
try {
Method method = getWriteMethod(bean.getClass(), prop);
method.invoke(bean, new Object[] { new Float(value)});
} catch (Exception ex) {
throw new JasperException(ex);
}
}
public static void handleSetProperty(Object bean, String prop, char value)
throws JasperException {
try {
Method method = getWriteMethod(bean.getClass(), prop);
method.invoke(bean, new Object[] { new Character(value)});
} catch (Exception ex) {
throw new JasperException(ex);
}
}
public static void handleSetProperty(Object bean, String prop, byte value)
throws JasperException {
try {
Method method = getWriteMethod(bean.getClass(), prop);
method.invoke(bean, new Object[] { new Byte(value)});
} catch (Exception ex) {
throw new JasperException(ex);
}
}
public static void handleSetProperty(
Object bean,
String prop,
boolean value)
throws JasperException {
try {
Method method = getWriteMethod(bean.getClass(), prop);
method.invoke(bean, new Object[] { new Boolean(value)});
} catch (Exception ex) {
throw new JasperException(ex);
}
}
public static java.lang.reflect.Method getWriteMethod(
Class beanClass,
String prop)
throws JasperException {
java.lang.reflect.Method method = null;
Class type = null;
try {
java.beans.BeanInfo info =
java.beans.Introspector.getBeanInfo(beanClass);
if (info != null) {
java.beans.PropertyDescriptor pd[] =
info.getPropertyDescriptors();
for (int i = 0; i < pd.length; i++) {
if (pd[i].getName().equals(prop)) {
method = pd[i].getWriteMethod();
type = pd[i].getPropertyType();
break;
}
}
} else {
// just in case introspection silently fails.
throw new JasperException(
Constants.getString(
"jsp.error.beans.nobeaninfo",
new Object[] { beanClass.getName()}));
}
} catch (Exception ex) {
throw new JasperException(ex);
}
if (method == null) {
if (type == null) {
throw new JasperException(
Constants.getString(
"jsp.error.beans.noproperty",
new Object[] { prop, beanClass.getName()}));
} else {
throw new JasperException(
Constants.getString(
"jsp.error.beans.nomethod.setproperty",
new Object[] { prop, beanClass.getName()}));
}
}
return method;
}
public static java.lang.reflect.Method getReadMethod(
Class beanClass,
String prop)
throws JasperException {
java.lang.reflect.Method method = null;
Class type = null;
try {
java.beans.BeanInfo info =
java.beans.Introspector.getBeanInfo(beanClass);
if (info != null) {
java.beans.PropertyDescriptor pd[] =
info.getPropertyDescriptors();
for (int i = 0; i < pd.length; i++) {
if (pd[i].getName().equals(prop)) {
method = pd[i].getReadMethod();
type = pd[i].getPropertyType();
break;
}
}
} else {
// just in case introspection silently fails.
throw new JasperException(
Constants.getString(
"jsp.error.beans.nobeaninfo",
new Object[] { beanClass.getName()}));
}
} catch (Exception ex) {
throw new JasperException(ex);
}
if (method == null) {
if (type == null) {
throw new JasperException(
Constants.getString(
"jsp.error.beans.noproperty",
new Object[] { prop, beanClass.getName()}));
} else {
throw new JasperException(
Constants.getString(
"jsp.error.beans.nomethod",
new Object[] { prop, beanClass.getName()}));
}
}
return method;
}
//*********************************************************************
// PropertyEditor Support
public static Object getValueFromBeanInfoPropertyEditor(
Class attrClass,
String attrName,
String attrValue,
Class propertyEditorClass)
throws JasperException {
try {
PropertyEditor pe =
(PropertyEditor) propertyEditorClass.newInstance();
pe.setAsText(attrValue);
return pe.getValue();
} catch (Exception ex) {
throw new JasperException(
"Unable to convert string '"
+ attrValue
+ "' to class "
+ attrClass.getName()
+ " for attribute "
+ attrName
+ ": "
+ ex);
}
}
public static Object getValueFromPropertyEditorManager(
Class attrClass,
String attrName,
String attrValue)
throws JasperException {
try {
PropertyEditor propEditor =
PropertyEditorManager.findEditor(attrClass);
if (propEditor != null) {
propEditor.setAsText(attrValue);
return propEditor.getValue();
} else {
throw new IllegalArgumentException("Property Editor not registered with the PropertyEditorManager");
}
} catch (IllegalArgumentException ex) {
throw new JasperException(
"Unable to convert string '"
+ attrValue
+ "' to class "
+ attrClass.getName()
+ " for attribute "
+ attrName
+ ": "
+ ex);
}
}
// ************************************************************************
// General Purpose Runtime Methods
// ************************************************************************
/**
* Convert a possibly relative resource path into a context-relative
* resource path that starts with a '/'.
*
* @param request The servlet request we are processing
* @param relativePath The possibly relative resource path
*/
public static String getContextRelativePath(
ServletRequest request,
String relativePath) {
if (relativePath.startsWith("/"))
return (relativePath);
if (!(request instanceof HttpServletRequest))
return (relativePath);
HttpServletRequest hrequest = (HttpServletRequest) request;
String uri =
(String) request.getAttribute("javax.servlet.include.servlet_path");
if (uri == null)
uri = hrequest.getServletPath();
return (uri.substring(0, uri.lastIndexOf('/')) + '/' + relativePath);
}
/**
* Perform a RequestDispatcher.include() operation, with optional flushing
* of the response beforehand.
*
* @param request The servlet request we are processing
* @param response The servlet response we are processing
* @param relativePath The relative path of the resource to be included
* @param out The JspWriter to whom we are currently writing
* @param flush Should we flush before the include is processed?
*
* @exception IOException if thrown by the included servlet
* @exception ServletException if thrown by the included servlet
*/
public static void include(
HttpServletRequest request,
HttpServletResponse response,
String relativePath,
JspWriter out,
boolean flush)
throws IOException, ServletException {
if (flush && !(out instanceof BodyContent))
out.flush();
// FIXME - It is tempting to use request.getRequestDispatcher() to
// resolve a relative path directly, but Catalina currently does not
// take into account whether the caller is inside a RequestDispatcher
// include or not. Whether Catalina *should* take that into account
// is a spec issue currently under review. In the mean time,
// replicate Jasper's previous behavior
String resourcePath = getContextRelativePath(request, relativePath);
RequestDispatcher rd = request.getRequestDispatcher(resourcePath);
rd.include(request, new ServletResponseWrapperInclude(response, out));
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -