📄 jspruntimelibrary.java
字号:
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) {
throw new JasperException(ex);
}
if (!ignoreMethodNF && (method == null)) {
if (type == null) {
throw new JasperException(
Localizer.getMessage("jsp.error.beans.noproperty",
prop,
bean.getClass().getName()));
} else {
throw new JasperException(
Localizer.getMessage("jsp.error.beans.nomethod.setproperty",
prop,
type.getName(),
bean.getClass().getName()));
}
}
}
// __end introspecthelperMethod
//-------------------------------------------------------------------
// functions to convert builtin Java data types to string.
//-------------------------------------------------------------------
// __begin toStringMethod
public static String toString(Object o) {
return String.valueOf(o);
}
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", ex);
}
}
/**
* 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 encoded 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 == '%') {
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(
Localizer.getMessage("jsp.error.beans.nullbean"));
}
Object value = null;
try {
Method method = getReadMethod(o.getClass(), prop);
value = method.invoke(o, (Object[]) null);
} catch (Exception ex) {
throw new JasperException (ex);
}
return value;
}
// __end lookupReadMethodMethod
// handles <jsp:setProperty> with EL expression for 'value' attribute
/** Use proprietaryEvaluate
public static void handleSetPropertyExpression(Object bean,
String prop, String expression, PageContext pageContext,
VariableResolver variableResolver, FunctionMapper functionMapper )
throws JasperException
{
try {
Method method = getWriteMethod(bean.getClass(), prop);
method.invoke(bean, new Object[] {
pageContext.getExpressionEvaluator().evaluate(
expression,
method.getParameterTypes()[0],
variableResolver,
functionMapper,
null )
});
} catch (Exception ex) {
throw new JasperException(ex);
}
}
**/
public static void handleSetPropertyExpression(Object bean,
String prop, String expression, PageContext pageContext,
ProtectedFunctionMapper functionMapper )
throws JasperException
{
try {
Method method = getWriteMethod(bean.getClass(), prop);
method.invoke(bean, new Object[] {
PageContextImpl.proprietaryEvaluate(
expression,
method.getParameterTypes()[0],
pageContext,
functionMapper,
false )
});
} catch (Exception ex) {
throw new JasperException(ex);
}
}
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);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -