1 /**
2 *
3 * Copyright 2003-2004 The Apache Software Foundation
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18 //
19 // This source code implements specifications defined by the Java
20 // Community Process. In order to remain compliant with the specification
21 // DO NOT add / change / or delete method signatures!
22 //
23
24 package javax.servlet.jsp.tagext;
25
26 import javax.servlet.jsp.JspException;
27 import javax.servlet.jsp.JspWriter;
28
29 /**
30 * A base class for defining tag handlers implementing BodyTag.
31 *
32 * <p>
33 * The BodyTagSupport class implements the BodyTag interface and adds
34 * additional convenience methods including getter methods for the
35 * bodyContent property and methods to get at the previous out JspWriter.
36 *
37 * <p>
38 * Many tag handlers will extend BodyTagSupport and only redefine a
39 * few methods.
40 */
41
42 public class BodyTagSupport extends TagSupport implements BodyTag {
43
44 /**
45 * Default constructor, all subclasses are required to only define
46 * a public constructor with the same signature, and to call the
47 * superclass constructor.
48 *
49 * This constructor is called by the code generated by the JSP
50 * translator.
51 */
52
53 public BodyTagSupport() {
54 super();
55 }
56
57 /**
58 * Default processing of the start tag returning EVAL_BODY_BUFFERED.
59 *
60 * @return EVAL_BODY_BUFFERED
61 * @throws JspException if an error occurred while processing this tag
62 * @see BodyTag#doStartTag
63 */
64
65 public int doStartTag() throws JspException {
66 return EVAL_BODY_BUFFERED;
67 }
68
69
70 /**
71 * Default processing of the end tag returning EVAL_PAGE.
72 *
73 * @return EVAL_PAGE
74 * @throws JspException if an error occurred while processing this tag
75 * @see Tag#doEndTag
76 */
77
78 public int doEndTag() throws JspException {
79 return super.doEndTag();
80 }
81
82
83 // Actions related to body evaluation
84
85 /**
86 * Prepare for evaluation of the body: stash the bodyContent away.
87 *
88 * @param b the BodyContent
89 * @see #doAfterBody
90 * @see #doInitBody()
91 * @see BodyTag#setBodyContent
92 */
93
94 public void setBodyContent(BodyContent b) {
95 this.bodyContent = b;
96 }
97
98
99 /**
100 * Prepare for evaluation of the body just before the first body evaluation:
101 * no action.
102 *
103 * @throws JspException if an error occurred while processing this tag
104 * @see #setBodyContent
105 * @see #doAfterBody
106 * @see BodyTag#doInitBody
107 */
108
109 public void doInitBody() throws JspException {
110 }
111
112
113 /**
114 * After the body evaluation: do not reevaluate and continue with the page.
115 * By default nothing is done with the bodyContent data (if any).
116 *
117 * @return SKIP_BODY
118 * @throws JspException if an error occurred while processing this tag
119 * @see #doInitBody
120 * @see BodyTag#doAfterBody
121 */
122
123 public int doAfterBody() throws JspException {
124 return SKIP_BODY;
125 }
126
127
128 /**
129 * Release state.
130 *
131 * @see Tag#release
132 */
133
134 public void release() {
135 bodyContent = null;
136
137 super.release();
138 }
139
140 /**
141 * Get current bodyContent.
142 *
143 * @return the body _content.
144 */
145
146 public BodyContent getBodyContent() {
147 return bodyContent;
148 }
149
150
151 /**
152 * Get surrounding out JspWriter.
153 *
154 * @return the enclosing JspWriter, from the bodyContent.
155 */
156
157 public JspWriter getPreviousOut() {
158 return bodyContent.getEnclosingWriter();
159 }
160
161 // protected fields
162
163 /**
164 * The current BodyContent for this BodyTag.
165 */
166 protected BodyContent bodyContent;
167 }