📄 extractsearchpropertytag.java
字号:
/*
*********************************************************************
* 文件 : $Workfile: ExtractSearchPropertyTag.java $
* 项目 : 腾龙1.2
* 公司 : 沈阳东软软件股份有限公司
* 日期 : $Date: 03-12-10 18:22 $
* 说明 :
**********************************************************************
* 版本历史:
* $Log: /4 开发工作目录/src/com/neusoft/taglibs/smart/ExtractSearchPropertyTag.java $
*
* 1 03-12-10 18:22 Lihg
*
* 1 03-12-10 8:44 Lihg
*********************************************************************
*/
package com.neusoft.taglibs.smart;
import java.lang.reflect.*;
import java.util.*;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
/**
* This class allows you to retrieve a parameter from the request and output it
* to the page This should allow you to avoid expressions for extracting
* parameter info.
*
*@author <a href="mailto:lihg@neusoft.com">李红国</a>
*@created 2003年7月1日
*/
public class ExtractSearchPropertyTag
extends BodyTagSupport {
private String sourceId = null;
private String sourceScope = null;
private String targetScope = null;
private String property = null;
private Object targetObject = null;
private String destinationId = null;
private String paracount = null;
private ArrayList parameters = new ArrayList();
/**
* 构造对象 ExtractSearchPropertyTag
*/
public ExtractSearchPropertyTag() {
super();
}
/**
* 设定ExtractSearchPropertyTag object-id的属性值
*
*@param sourceId 属性 id 的值
*/
public void setId(String sourceId) {
this.sourceId = sourceId;
}
/**
* 设定ExtractSearchPropertyTag object-scope的属性值
*
*@param sourceScope 属性 scope 的值
*/
public void setScope(String sourceScope) {
this.sourceScope = sourceScope.toLowerCase();
}
/**
* 设定ExtractSearchPropertyTag object-destinationId的属性值
*
*@param destinationId 属性 destinationId 的值
*/
public void setDestinationId(String destinationId) {
this.destinationId = destinationId;
}
/**
* 设定ExtractSearchPropertyTag object-destinationScope的属性值
*
*@param targetScope 属性 destinationScope 的值
*/
public void setDestinationScope(String targetScope) {
this.targetScope = targetScope.toLowerCase();
}
/**
* 设定ExtractSearchPropertyTag object-property的属性值
*
*@param property 属性 property 的值
*/
public void setProperty(String property) {
this.property = property;
}
/**
* 设定ExtractSearchPropertyTag object-paracount的属性值
*
*@param paracount 属性 paracount 的值
*/
public void setParacount(String paracount) {
this.paracount = paracount;
}
/**
* 方法描述
*
*@return 描述返回值信息
*@exception JspTagException 异常描述
*/
public int doStartTag() throws JspTagException {
//System.out.println("sdfsdfsdfsdf");
targetObject = null;
if (sourceScope.equals("request")) {
targetObject = pageContext.getRequest().getAttribute(sourceId);
}
else if (sourceScope.equals("session")) {
targetObject = pageContext.getSession().getAttribute(sourceId);
}
else if (sourceScope.equals("page")) {
targetObject = pageContext.getAttribute(sourceId);
}
if (targetObject == null) {
throw new JspTagException("ExtractSearchPropertyTag: Target Item " +
sourceId + " not found in " + sourceScope +
" scope.");
}
return EVAL_BODY_TAG;
}
/**
* 方法描述
*
*@return 描述返回值信息
*@exception JspTagException 异常描述
*/
public int doEndTag() throws JspTagException {
Object extractedObject = getProperty();
if (targetScope.equals("request")) {
pageContext.getRequest().setAttribute(destinationId, extractedObject);
}
else if (targetScope.equals("session")) {
pageContext.getSession().setAttribute(destinationId, extractedObject);
}
else if (targetScope.equals("page")) {
pageContext.setAttribute(destinationId, extractedObject);
}
parameters = null;
sourceId = null;
sourceScope = null;
targetScope = null;
property = null;
targetObject = null;
destinationId = null;
return EVAL_PAGE;
}
/**
* Using the current Object use reflection to obtain the String data from
* the element method the same as a JavaBean would use: <Br>
* <br>
* e.g. a getXXXX method which has no parameters <br>
* The target method is the property attribute
*
*@return 属性 property的值
*@exception JspTagException 异常描述
*/
private Object getProperty() throws JspTagException {
//String targetMethod = property.substring(0,1).toUpperCase() + property.substring(1,property.length());
String targetMethod = property;
Object returnValue = null;
try {
// set arguments if needed
Class[] args = null;
Object[] params = null;
Object[] paralist = null;
ArrayList aparalist = null;
ArrayList sqlnblist = null;
if (parameters == null) {
Class[] tempArgs = {};
args = tempArgs;
Object[] tempParams = {};
params = tempParams;
}
else {
// set the parameters here
args = new Class[parameters.size()];
params = new Object[parameters.size()];
Iterator it = parameters.iterator();
int index = 0;
//System.out.println("paracount="+paracount);
int pcount = 0;
Integer count = new Integer( -1);
Integer start = new Integer( -1);
String sqlname = "";
while (it.hasNext()) {
ParameterItem item = (ParameterItem) it.next();
//System.out.println("-----------------------" + item);
if (item.getName().equals("start")) {
start = new Integer(item.getParameter());
}
else if (item.getName().equals("count")) {
count = new Integer(item.getParameter());
}
else if (item.getName().equals("sql")) {
sqlname = item.getParameter();
}
else {
if (aparalist == null) {
aparalist = new ArrayList();
}
if (item.getType().equals("int")) {
aparalist.add(new Integer(item.getParameter()));
;
}
else if (item.getType().equals("long")) {
aparalist.add(new Long(item.getParameter()));
}
else {
String escapeString = item.getEscapeString();
String parameter = item.getParameter();
if (escapeString != null && parameter.equals(escapeString)) {
if (sqlnblist == null) {
sqlnblist = new ArrayList();
}
sqlnblist.add(item.getSqlnb());
}
else {
aparalist.add(parameter);
}
}
paralist = aparalist.toArray();
}
}
args = new Class[5];
args[1] = Class.forName("[Ljava.lang.Object;");
args[0] = String.class;
args[2] = int.class;
args[3] = int.class;
args[4] = Class.forName("java.util.ArrayList");
params = new Object[5];
params[1] = paralist;
params[0] = sqlname;
params[2] = start;
params[3] = count;
params[4] = sqlnblist;
}
////System.out.println(targetObject.getClass().getName());
//Method[] mm=targetObject.getClass().getMethods();
//for(int i=0;i<mm.length;i++){
//System.out.println("---"+mm[i].getName());
//for(int j=0;j<mm[i].getParameterTypes().length;j++)
// System.out.println(mm[i].getParameterTypes()[j].getName());
//}
//System.out.println(targetObject.getClass());
Method m = targetObject.getClass().getMethod(property, args);
////System.out.printn(m.getName());
if (m == null) {
throw new JspTagException(
"ExtractPropertyTag: There is no method by the name of " +
targetMethod);
}
returnValue = m.invoke(targetObject, params);
}
catch (java.lang.NoSuchMethodException ex) {
ex.printStackTrace();
throw new JspTagException("ExtractPropertyTag: Method for property " +
property + " not found.");
}
catch (java.lang.reflect.InvocationTargetException ex) {
ex.printStackTrace();
throw new JspTagException("ExtractPropertyTag: Error calling method " +
targetMethod + ":" + ex);
}
catch (java.lang.IllegalAccessException ex) {
ex.printStackTrace();
throw new JspTagException("ExtractPropertyTag: Error calling method " +
targetMethod + ":" + ex);
}
catch (java.lang.ClassNotFoundException ex) {
ex.printStackTrace();
throw new JspTagException("ExtractPropertyTag: Error calling method " +
targetMethod + ":" + ex);
}
return returnValue;
}
/**
* 在ExtractSearchPropertyTag object中Adds a feature to the Parameter
* attribute of the
*
*@param name The feature to be added to the Parameter attribute
*@param parameter The feature to be added to the Parameter attribute
*@param type The feature to be added to the Parameter attribute
*@param escapeString The feature to be added to the Parameter attribute
*@param sqlnb The feature to be added to the Parameter attribute
*/
public void addParameter(String name, String parameter, String type,
String escapeString, String sqlnb) {
//System.out.println(name + "=" + parameter + "=" + type + "=" + escapeString +
//"=" + sqlnb);
ParameterItem parameterItem = new ParameterItem(name, parameter, type,
escapeString, sqlnb);
//System.out.println("-----------" + parameters);
if (parameters == null) {
parameters = new ArrayList();
}
parameters.add(parameterItem);
//System.out.println("11111111111111111111111111111");
}
// This class represents a parameter for internal use in this class only
/**
* 类描述
*
*@author <a href="mailto:lihg@neusoft.com">李红国</a>
*@created 2003年7月1日
*/
class ParameterItem {
private String parameter;
private String type;
private String name;
private String escapeString;
private String sqlnb;
/**
* 构造对象 ParameterItem
*
*@param name 参数描述
*@param parameter 参数描述
*@param type 参数描述
*@param escapeString 参数描述
*@param sqlnb 参数描述
*/
ParameterItem(String name, String parameter, String type,
String escapeString, String sqlnb) {
this.name = name;
this.parameter = parameter;
this.type = type;
this.escapeString = escapeString;
this.sqlnb = sqlnb;
}
/**
* 取得 ParameterItem object 的属性parameter
*
*@return 属性 parameter的值
*/
public String getParameter() {
return parameter;
}
/**
* 取得 ParameterItem object 的属性type
*
*@return 属性 type的值
*/
public String getType() {
return type;
}
/**
* 取得 ParameterItem object 的属性name
*
*@return 属性 name的值
*/
public String getName() {
return name;
}
/**
* 取得 ParameterItem object 的属性escapeString
*
*@return 属性 escapeString的值
*/
public String getEscapeString() {
return escapeString;
}
/**
* 取得 ParameterItem object 的属性sqlnb
*
*@return 属性 sqlnb的值
*/
public String getSqlnb() {
return sqlnb;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -