【Java开源代码栏目提醒】:网学会员--在 Java开源代码编辑为广大网友搜集整理了:JspRuntimeLibrary.java绩等信息,祝愿广大网友取得需要的信息,参考学习。
/*
* $Header: /cvsroot/jetty/Jetty3/src/org/apache/jasper/runtime/JspRuntimeLibrary.java,v 1.2 2000/12/13 14:15:02 gregwilkins Exp $
* $Revision: 1.2 $
* $Date: 2000/12/13 14:15:02 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact
JspRuntimeLibrary.java为[网学网-网友上传,谢谢支持]。.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.jasper.runtime;
import java.io.IOException;
import java.util.Enumeration;
import java.lang.reflect.Method;
import java.io.Writer;
import java.io.Reader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.beans.PropertyDescriptor;
import java.beans.IndexedPropertyDescriptor;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.apache.jasper.JasperException;
import org.apache.jasper.Constants;
/**
* Bunch of util methods that are used by code generated for useBean,
* getProperty and setProperty.
*
* The __begin, __end stuff is there so that the JSP engine can
* actually parse this file and inline them if people don't want
* runtime dependencies on this class. However, I'm not sure if that
* works so well right now. It got forgotten at some point. -akv
*
* @author Mandar Raje
*/
public class JspRuntimeLibrary {
// __begin convertMethod
public static Object convert(String s, Class t) throws JasperException {
try {
if (s == null) {
if (t.equals(Boolean.class) || t.equals(Boolean.TYPE))
s = "false";
else
return null;
}
if ( t.equals(Boolean.class) || t.equals(Boolean.TYPE) ) {
if (s.equalsIgnoreCase("on") || s.equalsIgnoreCase("true"))
s = "true";
else
s = "false";
return new Boolean(s);
} else if ( t.equals(Byte.class) || t.equals(Byte.TYPE) ) {
return new Byte(s);
} else if (t.equals(Character.class) || t.equals(Character.TYPE)) {
return s.length() > 0 ? new Character(s.charAt(0)) : null;
} else if ( t.equals(Short.class) || t.equals(Short.TYPE) ) {
return new Short(s);
} else if ( t.equals(Integer.class) || t.equals(Integer.TYPE) ) {
return new Integer(s);
} else if ( t.equals(Float.class) || t.equals(Float.TYPE) ) {
return new Float(s);
} else if ( t.equals(Long.class) || t.equals(Long.TYPE) ) {
return new Long(s);
} else if ( t.equals(Double.class) || t.equals(Double.TYPE) ) {
return new Double(s);
} else if ( t.equals(String.class) ) {
return s;
} else if ( t.equals(java.io.File.class) ) {
return new java.io.File(s);
}
} catch (Exception ex) {
throw new JasperException (ex);
}
return s;
}
// __end convertMethod
// __begin introspectMethod
public static void introspect(Object bean, ServletRequest request)
throws JasperException
{
Enumeration e = request.getParameterNames();
while ( e.hasMoreElements() ) {
String name = (String) e.nextElement();
String value = request.getParameter(name);
introspecthelper(bean, name, value, request, name, true);
}
}
// __end introspectMethod
// __begin introspecthelperMethod
public static void introspecthelper(Object bean, String prop,
String value, ServletRequest request,
String param, boolean ignoreMethodNF)
throws JasperException
{
java.lang.reflect.Method method = null;
Class type = null;
try {
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();
type = pd[i].getPropertyType();
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();
String[] values = request.getParameterValues(param);
//XXX Please check.
if(values == null) return;
if(t.equals(String.class)) {
method.invoke(bean, new Object[] { values });
} else {
Object tmpval = null;
createTypedArray (bean, method, values, t);
}
} else {
if(value == null || (param != null && value.equals(""))) return;
Object oval = convert(value, type);
if ( oval != null )
method.invoke(bean, new Object[] { oval });
}
}
} catch (Excepti
上一篇:
JspReader.java
下一篇:
让我掉下眼泪的