1 6 7 package org.netbeans.test.taglibrary.handlers; 8 9 import java.io.IOException ; 10 import javax.servlet.jsp.JspException ; 11 import javax.servlet.jsp.JspWriter ; 12 import javax.servlet.jsp.tagext.BodyContent ; 13 import javax.servlet.jsp.tagext.BodyTagSupport ; 14 15 20 21 public class SumBodyTagHandler extends BodyTagSupport { 22 23 26 private int x = 0; 27 28 31 private int y = 0; 32 33 34 public SumBodyTagHandler() { 35 super(); 36 } 37 38 46 51 private void otherDoStartTagOperations() { 52 } 70 71 76 private void otherDoEndTagOperations() { 77 } 85 86 93 private void writeTagBodyContent(JspWriter out, BodyContent bodyContent) throws IOException { 94 out.println("<p>"); 99 out.println("Sum of " + x + " and " + y + " is " + (x+y)); 100 out.println("<br/>"); 101 102 bodyContent.writeOut(out); 106 107 out.println("<br/>"); 108 out.println("END of sum"); 109 out.println("</p>"); 110 111 112 bodyContent.clearBody(); 114 } 115 116 125 133 134 public int doStartTag() throws JspException , JspException { 135 otherDoStartTagOperations(); 136 137 if (theBodyShouldBeEvaluated()) { 138 return EVAL_BODY_BUFFERED; 139 } else { 140 return SKIP_BODY; 141 } 142 } 143 144 150 public int doEndTag() throws JspException , JspException { 151 otherDoEndTagOperations(); 152 153 if (shouldEvaluateRestOfPageAfterEndTag()) { 154 return EVAL_PAGE; 155 } else { 156 return SKIP_PAGE; 157 } 158 } 159 160 166 public int doAfterBody() throws JspException { 167 try { 168 BodyContent bodyContent = getBodyContent(); 172 JspWriter out = bodyContent.getEnclosingWriter(); 173 174 writeTagBodyContent(out, bodyContent); 175 } catch (Exception ex) { 176 handleBodyContentException(ex); 177 } 178 179 if (theBodyShouldBeEvaluatedAgain()) { 180 return EVAL_BODY_AGAIN; 181 } else { 182 return SKIP_BODY; 183 } 184 } 185 186 189 private void handleBodyContentException(Exception ex) throws JspException { 190 throw new JspException ("error in NewTag: " + ex); 192 } 193 194 199 private boolean shouldEvaluateRestOfPageAfterEndTag() { 200 return true; 207 } 208 209 215 private boolean theBodyShouldBeEvaluatedAgain() { 216 return false; 224 } 225 226 230 private boolean theBodyShouldBeEvaluated() { 231 232 return true; 238 } 239 240 243 public void setX(int value) { 244 this.x = value; 245 } 246 247 250 public void setY(int value) { 251 this.y = value; 252 } 253 254 } 255 | Popular Tags |