1 16 17 package org.apache.taglibs.standard.tag.common.xml; 18 19 import java.util.List ; 20 21 import javax.servlet.jsp.JspException ; 22 import javax.servlet.jsp.PageContext ; 23 import javax.servlet.jsp.tagext.TagSupport ; 24 25 import org.apache.taglibs.standard.tag.common.core.Util; 26 27 32 public class SetTag extends TagSupport { 33 34 37 private String select; private String var; private int scope; 41 44 49 public SetTag() { 50 super(); 51 init(); 52 } 53 54 private void init() { 56 var = null; 57 select = null; 58 scope = PageContext.PAGE_SCOPE; 59 } 60 61 62 65 public int doStartTag() throws JspException { 67 XPathUtil xu = new XPathUtil(pageContext); 69 List result = 70 xu.selectNodes(XPathUtil.getContext(this), select); 71 Object ret = result; 72 73 if (result.size() == 1) { 75 Object o = result.get(0); 76 if (o instanceof String || o instanceof Boolean 77 || o instanceof Number ) 78 ret = o; 79 } 80 81 pageContext.setAttribute(var, ret, scope); 83 return SKIP_BODY; 84 } 85 86 public void release() { 88 super.release(); 89 init(); 90 } 91 92 93 96 public void setSelect(String select) { 97 this.select = select; 98 } 99 100 public void setVar(String var) { 101 this.var = var; 102 } 103 104 public void setScope(String scope) { 105 this.scope = Util.getScope(scope); 106 } 107 } 108 | Popular Tags |