1 28 29 package com.caucho.jstl.el; 30 31 import com.caucho.jsp.PageContextImpl; 32 import com.caucho.jstl.ChooseTag; 33 import com.caucho.util.L10N; 34 import com.caucho.xpath.Env; 35 import com.caucho.xpath.Expr; 36 import com.caucho.xpath.XPath; 37 38 import org.w3c.dom.Node ; 39 40 import javax.servlet.jsp.JspException ; 41 import javax.servlet.jsp.tagext.Tag ; 42 import javax.servlet.jsp.tagext.TagSupport ; 43 44 47 public class XmlWhenTag extends TagSupport { 48 private static L10N L = new L10N(XmlWhenTag.class); 49 50 private Expr _select; 51 52 57 public void setSelect(Expr select) 58 { 59 _select = select; 60 } 61 62 65 public int doStartTag() 66 throws JspException 67 { 68 try { 69 Tag parent = getParent(); 70 71 if (! (parent instanceof ChooseTag)) 72 throw new JspException (L.l("x:when tag must be contained in a c:choose tag.")); 73 74 ChooseTag chooseTag = (ChooseTag) parent; 75 76 if (chooseTag.isMatch()) 77 return SKIP_BODY; 78 79 PageContextImpl pageContext = (PageContextImpl) this.pageContext; 80 81 Env env = XPath.createEnv(); 82 env.setVarEnv(pageContext.getVarEnv()); 83 84 Node node = pageContext.getNodeEnv(); 85 86 boolean test = _select.evalBoolean(node, env); 87 88 env.free(); 89 90 if (test) { 91 chooseTag.setMatch(); 92 93 return EVAL_BODY_INCLUDE; 94 } 95 else 96 return SKIP_BODY; 97 } catch (JspException e) { 98 throw e; 99 } catch (Exception e) { 100 throw new JspException (e); 101 } 102 } 103 } 104 | Popular Tags |