📄 jspruntimelibrary.java
字号:
new PrivilegedIntrospectEncodingHelper(
bean,
prop,
value,
request,
param,
ignoreMethodNF,
sourceEncoding,
targetEncoding);
AccessController.doPrivileged(dp);
} catch (PrivilegedActionException pe) {
Exception e = pe.getException();
throw (JasperException) e;
}
} else {
internalIntrospecthelper(
bean,
prop,
value,
request,
param,
ignoreMethodNF,
sourceEncoding,
targetEncoding);
}
}
/**
* Bean 属性设置的实现(可转换字符集编码版本).
*
* @param bean
* @param prop 属性名称
* @param value
* @param request
* @param param 表单参数名称
* @param ignoreMethodNF
* @param sourceEncoding ServeltRequest 的源字符编码名称(如果为空, 则默认为 ISO8859-1)
* @param targetEncoding 目标字符集(可实现中文化处理, 则此参数应该为 "GB2312" 或者 "GBK")
*
* @throws JasperException
*/
private static void internalIntrospecthelper(
Object bean,
String prop,
String value,
ServletRequest request,
String param,
boolean ignoreMethodNF,
String sourceEncoding,
String targetEncoding
)
throws JasperException {
java.lang.reflect.Method method = null;
Class type = null;
Class propertyEditorClass = null;
try {
// 从 Bean 中解析属性信息并查找相关的 write 方法
java.beans.BeanInfo info =
java.beans.Introspector.getBeanInfo(bean.getClass());
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();// write 方法
type = pd[i].getPropertyType();// 属性类型
propertyEditorClass = pd[i].getPropertyEditorClass();// 属性编辑器类型
break;
}
}
}
if (method != null) {
if (type.isArray()) {
if (request == null) {
throw new JasperException(
Constants
.getString(
"jsp.error.beans.setproperty.noindexset",
new Object[] {
}));
};
Class t = type.getComponentType();
// 从 servlet 读取参数(此处应该加入字符集处理机制)
String[] values = request.getParameterValues(param);
//XXX Please check.
if (values == null) {
return;
} else {
// TODO: 字符集转换 - Added by BeanSoft Studio on 2004-04-06
if(sourceEncoding != null && targetEncoding != null
&& targetEncoding.length() > 0) {
for(int i = 0; i < values.length; i++) {
values[i] = new String(values[i].getBytes(
sourceEncoding), targetEncoding);
}
}
}
if (t.equals(String.class)) {
method.invoke(bean, new Object[] { values });
} else {
Object tmpval = null;
createTypedArray(
prop,
bean,
method,
values,
t,
propertyEditorClass);
}
} else {
if (value == null || (param != null && value.equals("")))
return;
// 进行类型转换
Object oval =
convert(prop, value, type, propertyEditorClass);
// 转换失败不赋值
if (oval != null)
method.invoke(bean, new Object[] { oval });
}
}
} catch (Exception ex) {
ex.printStackTrace();
throw new JasperException(ex);
}
if (!ignoreMethodNF && (method == null)) {
if (type == null) {
throw new JasperException(
Constants.getString(
"jsp.error.beans.noproperty",
new Object[] { prop, bean.getClass().getName()}));
} else {
throw new JasperException(
Constants.getString(
"jsp.error.beans.nomethod.setproperty",
new Object[] { prop, bean.getClass().getName()}));
}
}
}
// __end introspecthelperMethod
//-------------------------------------------------------------------
// functions to convert builtin Java data types to string.
//-------------------------------------------------------------------
// __begin toStringMethod
public static String toString(Object o) {
return (o == null) ? "" : o.toString();
}
public static String toString(byte b) {
return new Byte(b).toString();
}
public static String toString(boolean b) {
return new Boolean(b).toString();
}
public static String toString(short s) {
return new Short(s).toString();
}
public static String toString(int i) {
return new Integer(i).toString();
}
public static String toString(float f) {
return new Float(f).toString();
}
public static String toString(long l) {
return new Long(l).toString();
}
public static String toString(double d) {
return new Double(d).toString();
}
public static String toString(char c) {
return new Character(c).toString();
}
// __end toStringMethod
/**
* Create a typed array.
* This is a special case where params are passed through
* the request and the property is indexed.
*/
public static void createTypedArray(
String propertyName,
Object bean,
Method method,
String[] values,
Class t,
Class propertyEditorClass)
throws JasperException {
try {
if (propertyEditorClass != null) {
Object[] tmpval = new Integer[values.length];
for (int i = 0; i < values.length; i++) {
tmpval[i] =
getValueFromBeanInfoPropertyEditor(
t,
propertyName,
values[i],
propertyEditorClass);
}
method.invoke(bean, new Object[] { tmpval });
} else if (t.equals(Integer.class)) {
Integer[] tmpval = new Integer[values.length];
for (int i = 0; i < values.length; i++)
tmpval[i] = new Integer(values[i]);
method.invoke(bean, new Object[] { tmpval });
} else if (t.equals(Byte.class)) {
Byte[] tmpval = new Byte[values.length];
for (int i = 0; i < values.length; i++)
tmpval[i] = new Byte(values[i]);
method.invoke(bean, new Object[] { tmpval });
} else if (t.equals(Boolean.class)) {
Boolean[] tmpval = new Boolean[values.length];
for (int i = 0; i < values.length; i++)
tmpval[i] = new Boolean(values[i]);
method.invoke(bean, new Object[] { tmpval });
} else if (t.equals(Short.class)) {
Short[] tmpval = new Short[values.length];
for (int i = 0; i < values.length; i++)
tmpval[i] = new Short(values[i]);
method.invoke(bean, new Object[] { tmpval });
} else if (t.equals(Long.class)) {
Long[] tmpval = new Long[values.length];
for (int i = 0; i < values.length; i++)
tmpval[i] = new Long(values[i]);
method.invoke(bean, new Object[] { tmpval });
} else if (t.equals(Double.class)) {
Double[] tmpval = new Double[values.length];
for (int i = 0; i < values.length; i++)
tmpval[i] = new Double(values[i]);
method.invoke(bean, new Object[] { tmpval });
} else if (t.equals(Float.class)) {
Float[] tmpval = new Float[values.length];
for (int i = 0; i < values.length; i++)
tmpval[i] = new Float(values[i]);
method.invoke(bean, new Object[] { tmpval });
} else if (t.equals(Character.class)) {
Character[] tmpval = new Character[values.length];
for (int i = 0; i < values.length; i++)
tmpval[i] = new Character(values[i].charAt(0));
method.invoke(bean, new Object[] { tmpval });
} else if (t.equals(int.class)) {
int[] tmpval = new int[values.length];
for (int i = 0; i < values.length; i++)
tmpval[i] = Integer.parseInt(values[i]);
method.invoke(bean, new Object[] { tmpval });
} else if (t.equals(byte.class)) {
byte[] tmpval = new byte[values.length];
for (int i = 0; i < values.length; i++)
tmpval[i] = Byte.parseByte(values[i]);
method.invoke(bean, new Object[] { tmpval });
} else if (t.equals(boolean.class)) {
boolean[] tmpval = new boolean[values.length];
for (int i = 0; i < values.length; i++)
tmpval[i] = (Boolean.valueOf(values[i])).booleanValue();
method.invoke(bean, new Object[] { tmpval });
} else if (t.equals(short.class)) {
short[] tmpval = new short[values.length];
for (int i = 0; i < values.length; i++)
tmpval[i] = Short.parseShort(values[i]);
method.invoke(bean, new Object[] { tmpval });
} else if (t.equals(long.class)) {
long[] tmpval = new long[values.length];
for (int i = 0; i < values.length; i++)
tmpval[i] = Long.parseLong(values[i]);
method.invoke(bean, new Object[] { tmpval });
} else if (t.equals(double.class)) {
double[] tmpval = new double[values.length];
for (int i = 0; i < values.length; i++)
tmpval[i] = Double.valueOf(values[i]).doubleValue();
method.invoke(bean, new Object[] { tmpval });
} else if (t.equals(float.class)) {
float[] tmpval = new float[values.length];
for (int i = 0; i < values.length; i++)
tmpval[i] = Float.valueOf(values[i]).floatValue();
method.invoke(bean, new Object[] { tmpval });
} else if (t.equals(char.class)) {
char[] tmpval = new char[values.length];
for (int i = 0; i < values.length; i++)
tmpval[i] = values[i].charAt(0);
method.invoke(bean, new Object[] { tmpval });
} else {
Object[] tmpval = new Integer[values.length];
for (int i = 0; i < values.length; i++) {
tmpval[i] =
getValueFromPropertyEditorManager(
t,
propertyName,
values[i]);
}
method.invoke(bean, new Object[] { tmpval });
}
} catch (Exception ex) {
throw new JasperException("error in invoking method");
}
}
/**
* Escape special shell characters.
* @param unescString The string to shell-escape
* @return The escaped shell string.
*/
public static String escapeQueryString(String unescString) {
if (unescString == null)
return null;
String escString = "";
String shellSpChars = "&;`'\"|*?~<>^()[]{}$\\\n";
for (int index = 0; index < unescString.length(); index++) {
char nextChar = unescString.charAt(index);
if (shellSpChars.indexOf(nextChar) != -1)
escString += "\\";
escString += nextChar;
}
return escString;
}
/**
* Decode an URL formatted string.
* @param s The string to decode.
* @return The decoded string.
*/
public static String decode(String encoded) {
// speedily leave if we're not needed
if (encoded == null)
return null;
if (encoded.indexOf('%') == -1 && encoded.indexOf('+') == -1)
return encoded;
//allocate the buffer - use byte[] to avoid calls to new.
byte holdbuffer[] = new byte[encoded.length()];
char holdchar;
int bufcount = 0;
for (int count = 0; count < encoded.length(); count++) {
char cur = encoded.charAt(count);
if (cur == '%') {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -