1 13 package com.tonbeller.wcf.component; 14 15 import java.util.Map ; 16 17 import javax.servlet.http.HttpServletRequest ; 18 import javax.servlet.jsp.JspException ; 19 import javax.servlet.jsp.JspTagException ; 20 import javax.servlet.jsp.jstl.core.ConditionalTagSupport; 21 22 import org.apache.log4j.Logger; 23 24 import com.tonbeller.wcf.controller.RequestContext; 25 import com.tonbeller.wcf.expr.ExprUtils; 26 27 37 public class RendererParameterTag extends ConditionalTagSupport { 38 private static Logger logger = Logger.getLogger(RendererParameterTag.class); 39 40 String name; 41 String value; 42 String scope; 43 String test; 44 45 public void setTest(String test) { 46 this.test = test; 47 } 48 49 53 public int doStartTag() throws JspException { 54 logger.info("enter"); 55 RequestContext context = RequestContext.instance(); 56 57 String paramName = name; 58 String paramScope = (scope == null ? "request" : scope); 59 Object paramValue; 60 if (ExprUtils.isExpression(value)) 61 paramValue = context.getModelReference(value); 62 else 63 paramValue = value; 64 65 RendererTag rt = (RendererTag) super.findAncestorWithClass(this, RendererTag.class); 66 if (rt != null) { 67 if (paramValue == null) 69 rt.removeParameter(paramName); 70 else 71 rt.addParameter(paramName, paramValue); 72 } else { 73 if (paramValue == null) 75 RendererParameters.removeParameter(context.getRequest(), paramName, paramValue, paramScope); 76 else 77 RendererParameters.setParameter(context.getRequest(), paramName, paramValue, paramScope); 78 } 79 logger.info("leave"); 80 return super.doStartTag(); 81 } 82 83 87 public void setName(String name) { 88 this.name = name; 89 } 90 91 95 public void setValue(String value) { 96 this.value = value; 97 } 98 99 102 public void setScope(String string) { 103 scope = string; 104 } 105 106 protected boolean condition() throws JspTagException { 107 if (test == null) 108 return false; 109 110 boolean b = true; 111 String v = value; 112 if (v != null && v.startsWith("!")) { 113 v = v.substring(1); 114 b = false; 115 } 116 117 HttpServletRequest hsr = (HttpServletRequest ) pageContext.getRequest(); 118 Map map = RendererParameters.getParameterMap(hsr); 119 String x = (String ) map.get(test); 120 if (x == null) 121 return !b; 122 if (v == null) 123 return b; 124 if (v.equals(x)) 125 return b; 126 return !b; 127 } 128 129 } 130 | Popular Tags |