KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > servlet > jsp > tagext > BodyTagSupport


1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. 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 package javax.servlet.jsp.tagext;
18
19 import javax.servlet.jsp.JspException JavaDoc;
20 import javax.servlet.jsp.JspWriter JavaDoc;
21
22 /**
23  * A base class for defining tag handlers implementing BodyTag.
24  *
25  * <p>
26  * The BodyTagSupport class implements the BodyTag interface and adds
27  * additional convenience methods including getter methods for the
28  * bodyContent property and methods to get at the previous out JspWriter.
29  *
30  * <p>
31  * Many tag handlers will extend BodyTagSupport and only redefine a
32  * few methods.
33  */

34
35 public class BodyTagSupport extends TagSupport JavaDoc implements BodyTag JavaDoc {
36
37     /**
38      * Default constructor, all subclasses are required to only define
39      * a public constructor with the same signature, and to call the
40      * superclass constructor.
41      *
42      * This constructor is called by the code generated by the JSP
43      * translator.
44      */

45
46     public BodyTagSupport() {
47     super();
48     }
49
50     /**
51      * Default processing of the start tag returning EVAL_BODY_BUFFERED.
52      *
53      * @return EVAL_BODY_BUFFERED
54      * @throws JspException if an error occurred while processing this tag
55      * @see BodyTag#doStartTag
56      */

57  
58     public int doStartTag() throws JspException JavaDoc {
59         return EVAL_BODY_BUFFERED;
60     }
61
62
63     /**
64      * Default processing of the end tag returning EVAL_PAGE.
65      *
66      * @return EVAL_PAGE
67      * @throws JspException if an error occurred while processing this tag
68      * @see Tag#doEndTag
69      */

70
71     public int doEndTag() throws JspException JavaDoc {
72     return super.doEndTag();
73     }
74
75
76     // Actions related to body evaluation
77

78     /**
79      * Prepare for evaluation of the body: stash the bodyContent away.
80      *
81      * @param b the BodyContent
82      * @see #doAfterBody
83      * @see #doInitBody()
84      * @see BodyTag#setBodyContent
85      */

86
87     public void setBodyContent(BodyContent JavaDoc b) {
88     this.bodyContent = b;
89     }
90
91
92     /**
93      * Prepare for evaluation of the body just before the first body evaluation:
94      * no action.
95      *
96      * @throws JspException if an error occurred while processing this tag
97      * @see #setBodyContent
98      * @see #doAfterBody
99      * @see BodyTag#doInitBody
100      */

101
102     public void doInitBody() throws JspException JavaDoc {
103     }
104
105
106     /**
107      * After the body evaluation: do not reevaluate and continue with the page.
108      * By default nothing is done with the bodyContent data (if any).
109      *
110      * @return SKIP_BODY
111      * @throws JspException if an error occurred while processing this tag
112      * @see #doInitBody
113      * @see BodyTag#doAfterBody
114      */

115
116     public int doAfterBody() throws JspException JavaDoc {
117     return SKIP_BODY;
118     }
119
120
121     /**
122      * Release state.
123      *
124      * @see Tag#release
125      */

126
127     public void release() {
128     bodyContent = null;
129
130     super.release();
131     }
132
133     /**
134      * Get current bodyContent.
135      *
136      * @return the body content.
137      */

138     
139     public BodyContent JavaDoc getBodyContent() {
140     return bodyContent;
141     }
142
143
144     /**
145      * Get surrounding out JspWriter.
146      *
147      * @return the enclosing JspWriter, from the bodyContent.
148      */

149
150     public JspWriter JavaDoc getPreviousOut() {
151     return bodyContent.getEnclosingWriter();
152     }
153
154     // protected fields
155

156     /**
157      * The current BodyContent for this BodyTag.
158      */

159     protected BodyContent JavaDoc bodyContent;
160 }
161
Popular Tags