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