001: package com.mockrunner.test.web;
002:
003: import java.io.IOException;
004:
005: import javax.servlet.jsp.JspException;
006: import javax.servlet.jsp.JspWriter;
007: import javax.servlet.jsp.PageContext;
008: import javax.servlet.jsp.tagext.BodyTagSupport;
009: import javax.servlet.jsp.tagext.TagSupport;
010:
011: public class TestBodyTag extends BodyTagSupport {
012: private String testString;
013: private Integer testInteger;
014: private double testDouble;
015: private PageContext context;
016: private JspWriter bufferedOut;
017: private boolean releaseCalled = false;
018: private boolean releaseLastCall = false;
019: private int doStartTagReturnValue = TagSupport.EVAL_BODY_INCLUDE;
020: private int doEndTagReturnValue = TagSupport.EVAL_PAGE;
021: private int doAfterBodyReturnValue = TagSupport.SKIP_BODY;
022: private boolean doStartTagCalled = false;
023: private boolean doEndTagCalled = false;
024: private boolean doAfterBodyCalled = false;
025: private boolean doInitBodyCalled = false;
026:
027: public void setDoAfterBodyReturnValue(int doAfterBodyReturnValue) {
028: this .doAfterBodyReturnValue = doAfterBodyReturnValue;
029: }
030:
031: public void setDoEndTagReturnValue(int doEndTagReturnValue) {
032: this .doEndTagReturnValue = doEndTagReturnValue;
033: }
034:
035: public void setDoStartTagReturnValue(int doStartTagReturnValue) {
036: this .doStartTagReturnValue = doStartTagReturnValue;
037: }
038:
039: public int doStartTag() throws JspException {
040: doStartTagCalled = true;
041: try {
042: pageContext.getOut().print("TestBodyTag");
043: } catch (IOException exc) {
044: throw new RuntimeException(exc.getMessage());
045: }
046: return doStartTagReturnValue;
047: }
048:
049: public void doInitBody() throws JspException {
050: doInitBodyCalled = true;
051: bufferedOut = pageContext.getOut();
052: }
053:
054: public int doAfterBody() throws JspException {
055: doAfterBodyCalled = true;
056: int returnValue = doAfterBodyReturnValue;
057: if (BodyTagSupport.EVAL_BODY_AGAIN == doAfterBodyReturnValue) {
058: doAfterBodyReturnValue = BodyTagSupport.SKIP_BODY;
059: }
060: return returnValue;
061: }
062:
063: public int doEndTag() throws JspException {
064: doEndTagCalled = true;
065: return doEndTagReturnValue;
066: }
067:
068: public double getTestDouble() {
069: return testDouble;
070: }
071:
072: public Integer getTestInteger() {
073: return testInteger;
074: }
075:
076: public String getTestString() {
077: return testString;
078: }
079:
080: public void setTestDouble(double testDouble) {
081: this .testDouble = testDouble;
082: }
083:
084: public void setTestInteger(Integer testInteger) {
085: this .testInteger = testInteger;
086: }
087:
088: public void setTestString(String testString) {
089: this .testString = testString;
090: }
091:
092: public void setPageContext(PageContext context) {
093: super .setPageContext(context);
094: this .context = context;
095: }
096:
097: public PageContext getPageContext() {
098: return context;
099: }
100:
101: public JspWriter getBufferedOut() {
102: return bufferedOut;
103: }
104:
105: public void release() {
106: if (wasDoStartTagCalled() && wasDoEndTagCalled()) {
107: releaseLastCall = true;
108: }
109: releaseCalled = true;
110: }
111:
112: public boolean wasReleaseCalled() {
113: return releaseCalled;
114: }
115:
116: public boolean wasReleaseCallLastMethodCall() {
117: return releaseLastCall;
118: }
119:
120: public boolean wasDoInitBodyCalled() {
121: return doInitBodyCalled;
122: }
123:
124: public boolean wasDoAfterBodyCalled() {
125: return doAfterBodyCalled;
126: }
127:
128: public boolean wasDoEndTagCalled() {
129: return doEndTagCalled;
130: }
131:
132: public boolean wasDoStartTagCalled() {
133: return doStartTagCalled;
134: }
135: }
|