1 package jodd.servlet.tags.imports; 2 3 import javax.servlet.jsp.JspTagException; 4 import javax.servlet.jsp.tagext.BodyContent; 5 import javax.servlet.jsp.tagext.BodyTagSupport; 6 7 12 public class ImportParam extends BodyTagSupport { 13 14 private String name = ""; 15 20 public void setName(String v) { 21 name = v; 22 } 23 28 protected String getName() { 29 return name; 30 } 31 32 33 private String value = ""; 34 39 public void setValue(String v) { 40 value = v; 41 } 42 47 public void setValue(int v) { 48 value = Integer.toString(v); 49 } 50 55 public void setValue(float f) { 56 value = Float.toString(f); 57 } 58 63 public void setValue(double d) { 64 value = Double.toString(d); 65 } 66 71 public void setValue(Object o) { 72 if (o == null) { 73 value = ""; 74 } else { 75 value = o.toString(); 76 } 77 } 78 83 public String getValue() { 84 return value; 85 } 86 87 private String persist = ""; 88 89 94 public void setPersist(String v) { 95 persist = v; 96 } 97 102 public String getPersist() { 103 return persist; 104 } 105 106 107 private Import parent = null; 108 109 private boolean isPersistent = false; 110 111 public int doStartTag() { 112 parent = (Import) findAncestorWithClass(this, Import.class); 113 if (parent == null) { 114 return SKIP_BODY; 115 } 116 if ((persist != null) && (persist.equals("true"))) { 117 isPersistent = true; 118 } 119 if ((value == null) || (value.length() == 0)) { 120 return EVAL_BODY_AGAIN; 121 } else { 122 pageContext.getRequest().setAttribute(name, value); 123 if (isPersistent == false) { 124 parent.addAttributeName(name); 125 } 126 return SKIP_BODY; 127 } 128 } 129 130 131 public int doAfterBody() throws JspTagException {; 132 BodyContent body = getBodyContent(); 133 String bodyValue = body.getString(); 134 pageContext.getRequest().setAttribute(name, bodyValue); 135 if (isPersistent == false) { 136 parent.addAttributeName(name); 137 } 138 return SKIP_BODY; 139 } 140 141 public int doEndTag() { 142 return EVAL_PAGE; 143 } 144 145 } 146 147 | Popular Tags |