1 52 53 package freemarker.testcase.servlets; 54 55 import java.io.IOException ; 56 import javax.servlet.jsp.JspException ; 57 import javax.servlet.jsp.tagext.BodyTag ; 58 import javax.servlet.jsp.tagext.BodyTagSupport ; 59 import javax.servlet.jsp.tagext.IterationTag ; 60 import javax.servlet.jsp.tagext.Tag ; 61 import javax.servlet.jsp.tagext.TryCatchFinally ; 62 63 67 public class TestTag extends BodyTagSupport implements TryCatchFinally 68 { 69 private boolean throwException; 70 private int repeatCount; 71 72 public void setRepeatCount(int repeatCount) { 73 this.repeatCount = repeatCount; 74 } 75 76 public void setThrowException(boolean throwException) { 77 this.throwException = throwException; 78 } 79 80 public int doStartTag() throws JspException { 81 try { 82 pageContext.getOut().println("doStartTag() called here"); 83 if(throwException) { 84 throw new JspException ("throwException==true"); 85 } 86 return repeatCount == 0 ? Tag.SKIP_BODY : BodyTag.EVAL_BODY_BUFFERED; 87 } 88 catch(IOException e) { 89 throw new JspException (e); 90 } 91 } 92 93 public int doAfterBody() throws JspException { 94 try { 95 getPreviousOut().println("doAfterBody() called here"); 96 getBodyContent().writeOut(getPreviousOut()); 97 getBodyContent().clear(); 98 return --repeatCount == 0 ? Tag.SKIP_BODY : IterationTag.EVAL_BODY_AGAIN; 99 } 100 catch(IOException e) { 101 throw new JspException (e); 102 } 103 } 104 105 public int doEndTag() throws JspException { 106 try { 107 pageContext.getOut().println("doEndTag() called here"); 108 return Tag.EVAL_PAGE; 109 } 110 catch(IOException e) { 111 throw new JspException (e); 112 } 113 } 114 115 public void doCatch(Throwable t) throws Throwable { 116 pageContext.getOut().println("doCatch() called here with " + t.getClass() + ": " + t.getMessage()); 117 } 118 119 public void doFinally() { 120 try { 121 pageContext.getOut().println("doFinally() called here"); 122 } 123 catch(IOException e) { 124 throw new Error (); } 126 } 127 } 128 | Popular Tags |