📄 extractpropertyparametertag.java
字号:
/* * $Id: ExtractPropertyParameterTag.java,v 1.5 2001/10/23 21:47:57 gmurray Exp $
* Copyright 2000 Sun Microsystems, Inc. All rights reserved.
* Copyright 2000 Sun Microsystems, Inc. Tous droits r?erv?.
*/
package com.neusoft.taglibs.smart;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
/** * * This class is to be used with the ExtractProperty tag to specfiy parameters on
* the method calls to the respective objects * */
public class ExtractPropertyParameterTag
extends BodyTagSupport {
private String parameter = null;
private String arg = null;
private String id = null;
private String scope = null;
private String type = "java.lang.String";
private String defaultValue = "";
public ExtractPropertyParameterTag() {
super();
}
public void setParameter(String parameter) {
this.parameter = parameter;
}
public void setScope(String scope) {
this.scope = scope;
}
public void setId(String id) {
this.id = id;
}
public void setType(String type) {
this.type = type;
if (type.toLowerCase().equals("string")) {
this.type = "java.lang.String";
}
}
public void setDefault(String defaultValue) {
this.defaultValue = defaultValue;
}
public void setArg(String arg) {
this.arg = arg;
}
public int doStartTag() throws JspTagException {
// add the parameter to the parameter list of the ExtractPropertyTag
ExtractPropertyTag parent = (ExtractPropertyTag) findAncestorWithClass(this,
ExtractPropertyTag.class);
if (parameter == null && arg == null && id == null) {
throw new JspTagException("ExtractPropertyParamterTag: Either an arg, parameter, or (id and scope) must be specified.");
}
if (parameter != null && arg != null) {
throw new JspTagException(
"ExtractPropertyParamterTag: An arg and parameter cannot both be specified.");
}
if (parent == null) {
throw new JspTagException("ExtractPropertyParamterTag: ExtractPropertyParamterTag tag not inside items tag");
}
String theArg = null;
if (parameter != null) {
theArg = pageContext.getRequest().getParameter(parameter);
if (theArg == null) {
theArg = defaultValue;
}
if (defaultValue.equals("null")) {
theArg = null;
}
}
else if (arg != null) {
theArg = arg;
}
else if (id != null) {
// get the parameter from the scope
if (scope == null) {
throw new JspTagException(
"ExtractPropertyParamterTag: A scope must be set with the attribute id");
}
// XXXX make capable of doing more than strings later
if (scope.toLowerCase().equals("request")) {
theArg = (String) pageContext.getRequest().getAttribute(id);
}
else if (scope.toLowerCase().equals("session")) {
theArg = (String) pageContext.getSession().getAttribute(id);
}
else if (scope.toLowerCase().equals("page")) {
theArg = (String) pageContext.getAttribute(id);
}
}
parent.addParameter(theArg, type);
return EVAL_BODY_TAG;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -