1 5 package com.opensymphony.webwork.views.jsp; 6 7 import javax.servlet.jsp.JspException ; 8 import java.util.Map ; 9 10 11 36 public class ParamTag extends WebWorkBodyTagSupport { 37 39 protected String nameAttr; 41 protected String valueAttr; 42 43 45 public void setName(String aName) { 46 nameAttr = aName; 47 } 48 49 public void setValue(String aName) { 50 valueAttr = aName; 51 } 52 53 public int doEndTag() throws JspException { 55 Parametric parametricTag = (Parametric) findAncestorWithClass(this, Parametric.class); 56 57 if (parametricTag != null) { 58 if (valueAttr != null) { 59 if (parametricTag instanceof UnnamedParametric) { 60 ((UnnamedParametric) parametricTag).addParameter(findValue(valueAttr)); 61 } else { 62 String name = findString(nameAttr); 63 64 if (name == null) { 65 throw new JspException ("No name found for following expression: " + nameAttr); 66 } 67 68 Object value = findValue(valueAttr); 69 parametricTag.addParameter(name, value); 70 } 71 } else { 72 String content = null; 73 74 if (!((bodyContent != null) && ((content = bodyContent.getString()).length() != 0))) { 75 content = null; } 77 78 if (parametricTag instanceof UnnamedParametric) { 79 ((UnnamedParametric) parametricTag).addParameter(content); 80 } else { 81 parametricTag.addParameter(findString(nameAttr), content); 82 } 83 } 84 } 85 86 return EVAL_PAGE; 87 } 88 89 91 public interface Parametric { 93 public Map getParameters(); 94 95 public void addParameter(String name, Object value); 96 } 97 98 public interface UnnamedParametric extends Parametric { 99 public void addParameter(Object value); 100 } 101 } 102 | Popular Tags |