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