001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package javax.servlet.jsp.tagext;
018:
019: import javax.servlet.jsp.JspException;
020: import javax.servlet.jsp.JspWriter;
021:
022: /**
023: * A base class for defining tag handlers implementing BodyTag.
024: *
025: * <p>
026: * The BodyTagSupport class implements the BodyTag interface and adds
027: * additional convenience methods including getter methods for the
028: * bodyContent property and methods to get at the previous out JspWriter.
029: *
030: * <p>
031: * Many tag handlers will extend BodyTagSupport and only redefine a
032: * few methods.
033: */
034:
035: public class BodyTagSupport extends TagSupport implements BodyTag {
036:
037: /**
038: * Default constructor, all subclasses are required to only define
039: * a public constructor with the same signature, and to call the
040: * superclass constructor.
041: *
042: * This constructor is called by the code generated by the JSP
043: * translator.
044: */
045:
046: public BodyTagSupport() {
047: super ();
048: }
049:
050: /**
051: * Default processing of the start tag returning EVAL_BODY_BUFFERED.
052: *
053: * @return EVAL_BODY_BUFFERED
054: * @throws JspException if an error occurred while processing this tag
055: * @see BodyTag#doStartTag
056: */
057:
058: public int doStartTag() throws JspException {
059: return EVAL_BODY_BUFFERED;
060: }
061:
062: /**
063: * Default processing of the end tag returning EVAL_PAGE.
064: *
065: * @return EVAL_PAGE
066: * @throws JspException if an error occurred while processing this tag
067: * @see Tag#doEndTag
068: */
069:
070: public int doEndTag() throws JspException {
071: return super .doEndTag();
072: }
073:
074: // Actions related to body evaluation
075:
076: /**
077: * Prepare for evaluation of the body: stash the bodyContent away.
078: *
079: * @param b the BodyContent
080: * @see #doAfterBody
081: * @see #doInitBody()
082: * @see BodyTag#setBodyContent
083: */
084:
085: public void setBodyContent(BodyContent b) {
086: this .bodyContent = b;
087: }
088:
089: /**
090: * Prepare for evaluation of the body just before the first body evaluation:
091: * no action.
092: *
093: * @throws JspException if an error occurred while processing this tag
094: * @see #setBodyContent
095: * @see #doAfterBody
096: * @see BodyTag#doInitBody
097: */
098:
099: public void doInitBody() throws JspException {
100: }
101:
102: /**
103: * After the body evaluation: do not reevaluate and continue with the page.
104: * By default nothing is done with the bodyContent data (if any).
105: *
106: * @return SKIP_BODY
107: * @throws JspException if an error occurred while processing this tag
108: * @see #doInitBody
109: * @see BodyTag#doAfterBody
110: */
111:
112: public int doAfterBody() throws JspException {
113: return SKIP_BODY;
114: }
115:
116: /**
117: * Release state.
118: *
119: * @see Tag#release
120: */
121:
122: public void release() {
123: bodyContent = null;
124:
125: super .release();
126: }
127:
128: /**
129: * Get current bodyContent.
130: *
131: * @return the body content.
132: */
133:
134: public BodyContent getBodyContent() {
135: return bodyContent;
136: }
137:
138: /**
139: * Get surrounding out JspWriter.
140: *
141: * @return the enclosing JspWriter, from the bodyContent.
142: */
143:
144: public JspWriter getPreviousOut() {
145: return bodyContent.getEnclosingWriter();
146: }
147:
148: // protected fields
149:
150: /**
151: * The current BodyContent for this BodyTag.
152: */
153: protected BodyContent bodyContent;
154: }
|