1 16 package org.apache.taglibs.string; 17 18 import java.io.IOException ; 19 import java.io.StringWriter ; 20 21 import javax.servlet.jsp.JspException ; 22 import javax.servlet.jsp.JspWriter ; 23 import javax.servlet.jsp.tagext.BodyTagSupport ; 24 25 39 abstract public class StringTagSupport extends BodyTagSupport { 40 41 42 43 46 private String var; 47 48 51 public StringTagSupport() { 52 initAttributes(); 53 } 54 55 58 public String getVar() { 59 return this.var; 60 } 61 62 65 public void setVar(String var) { 66 this.var = var; 67 } 68 69 74 public int doEndTag() throws JspException { 75 76 80 81 85 String text = ""; 86 if(bodyContent != null) { 87 StringWriter body = new StringWriter (); 88 try { 89 bodyContent.writeOut(body); 90 text = body.toString(); 91 } catch(IOException ioe) { 92 ioe.printStackTrace(); 93 } 94 } 95 96 Object result = evaluateString( text ); 98 if ( result != null && this.var != null ) { 99 pageContext.setAttribute(this.var, result); 100 } else { 101 text = changeString(text); 103 104 111 112 if(this.var == null) { 113 JspWriter writer = pageContext.getOut(); 114 try { 115 writer.print(text); 116 } catch (IOException e) { 117 throw new JspException (e.toString()); 118 } 119 } else { 120 pageContext.setAttribute(this.var, text); 121 } 122 123 } 124 125 return (EVAL_PAGE); 126 } 127 128 137 public Object evaluateString(String str) throws JspException { 138 return null; 139 } 140 141 148 abstract public String changeString(String str) throws JspException ; 149 150 156 public void initAttributes() { 157 this.var = null; 158 } 159 160 } 161 | Popular Tags |