1 28 29 package com.caucho.jstl.el; 30 31 import com.caucho.el.Expr; 32 import com.caucho.jsp.PageContextImpl; 33 import com.caucho.jstl.NameValueTag; 34 import com.caucho.util.L10N; 35 36 import javax.el.ELContext; 37 import javax.el.ELException; 38 import javax.servlet.jsp.JspException ; 39 import javax.servlet.jsp.tagext.BodyTagSupport ; 40 41 44 public class XmlParamTag extends BodyTagSupport { 45 private static L10N L = new L10N(XmlParamTag.class); 46 47 private Expr _nameExpr; 48 private Expr _valueExpr; 49 50 55 public void setName(Expr name) 56 { 57 _nameExpr = name; 58 } 59 60 65 public void setValue(Expr value) 66 { 67 _valueExpr = value; 68 } 69 70 73 public int doStartTag() 74 throws JspException 75 { 76 try { 77 if (_valueExpr == null) 78 return EVAL_BODY_BUFFERED; 79 80 PageContextImpl pageContext = (PageContextImpl) this.pageContext; 81 ELContext env = pageContext.getELContext(); 82 83 String name = _nameExpr.evalString(env); 84 String value = _valueExpr.evalString(env); 85 86 Object parent = getParent(); 87 if (! (parent instanceof NameValueTag)) 88 throw new JspException (L.l("x:param requires x:transform.")); 89 90 NameValueTag tag = (NameValueTag) parent; 91 92 tag.addParam(name, value); 93 94 return SKIP_BODY; 95 } catch (ELException e) { 96 throw new JspException (e); 97 } 98 } 99 100 103 public int doEndTag() 104 throws JspException 105 { 106 try { 107 if (_valueExpr != null) 108 return EVAL_PAGE; 109 110 String value; 111 112 if (this.bodyContent != null) 113 value = this.bodyContent.getString().trim(); 114 else 115 value = ""; 116 117 PageContextImpl pageContext = (PageContextImpl) this.pageContext; 118 119 String name = _nameExpr.evalString(pageContext.getELContext()); 120 121 Object parent = getParent(); 122 if (! (parent instanceof NameValueTag)) 123 throw new JspException (L.l("c:param requires c:url or c:import parent.")); 124 125 NameValueTag tag = (NameValueTag) parent; 126 127 tag.addParam(name, value); 128 129 return EVAL_PAGE; 130 } catch (ELException e) { 131 throw new JspException (e); 132 } 133 } 134 } 135 | Popular Tags |