1. /*
  2. * The Apache Software License, Version 1.1
  3. *
  4. * Copyright (c) 1999 The Apache Software Foundation. All rights
  5. * reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. *
  11. * 1. Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. *
  14. * 2. Redistributions in binary form must reproduce the above copyright
  15. * notice, this list of conditions and the following disclaimer in
  16. * the documentation and/or other materials provided with the
  17. * distribution.
  18. *
  19. * 3. The end-user documentation included with the redistribution, if
  20. * any, must include the following acknowlegement:
  21. * "This product includes software developed by the
  22. * Apache Software Foundation (http://www.apache.org/)."
  23. * Alternately, this acknowlegement may appear in the software itself,
  24. * if and wherever such third-party acknowlegements normally appear.
  25. *
  26. * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
  27. * Foundation" must not be used to endorse or promote products derived
  28. * from this software without prior written permission. For written
  29. * permission, please contact apache@apache.org.
  30. *
  31. * 5. Products derived from this software may not be called "Apache"
  32. * nor may "Apache" appear in their names without prior written
  33. * permission of the Apache Group.
  34. *
  35. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  36. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  37. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  38. * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  39. * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  40. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  41. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  42. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  43. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  44. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  45. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  46. * SUCH DAMAGE.
  47. * ====================================================================
  48. *
  49. * This software consists of voluntary contributions made by many
  50. * individuals on behalf of the Apache Software Foundation. For more
  51. * information on the Apache Software Foundation, please see
  52. * <http://www.apache.org/>.
  53. *
  54. */
  55. package javax.servlet.jsp.tagext;
  56. import javax.servlet.jsp.*;
  57. /**
  58. * The BodyTag interface extends IterationTag by defining additional
  59. * methods that let a tag handler manipulate the content of evaluating its body.
  60. *
  61. * <p>
  62. * It is the responsibility of the tag handler to manipulate the body
  63. * content. For example the tag handler may take the body content,
  64. * convert it into a String using the bodyContent.getString
  65. * method and then use it. Or the tag handler may take the body
  66. * content and write it out into its enclosing JspWriter using
  67. * the bodyContent.writeOut method.
  68. *
  69. * <p> A tag handler that implements BodyTag is treated as one that
  70. * implements IterationTag, except that the doStartTag method can
  71. * return SKIP_BODY, EVAL_BODY_INCLUDE or EVAL_BODY_BUFFERED.
  72. *
  73. * <p>
  74. * If EVAL_BODY_INCLUDE is returned, then evaluation happens
  75. * as in IterationTag.
  76. *
  77. * <p>
  78. * If EVAL_BODY_BUFFERED is returned, then a BodyContent object will be
  79. * created (by code generated by the JSP compiler) to capture the body
  80. * evaluation.
  81. * The code generated by the JSP compiler obtains the BodyContent object by
  82. * calling the pushBody method of the current pageContext, which
  83. * additionally has the effect of saving the previous out value.
  84. * The page compiler returns this object by calling the popBody
  85. * method of the PageContext class;
  86. * the call also restores the value of out.
  87. *
  88. * <p>
  89. * The interface provides one new property with a setter method and one
  90. * new action method.
  91. *
  92. * <p><B>Properties</B>
  93. * <p> There is a new property: bodyContent, to contain the BodyContent
  94. * object, where the JSP Page implementation object will place the
  95. * evaluation (and reevaluation, if appropriate) of the body. The setter
  96. * method (setBodyContent) will only be invoked if doStartTag() returns
  97. * EVAL_BODY_BUFFERED.
  98. *
  99. * <p><B>Methods</B>
  100. * <p> In addition to the setter method for the bodyContent property, there
  101. * is a new action methods: doInitBody(), which is invoked right after
  102. * setBodyContent() and before the body evaluation. This method is only
  103. * invoked if doStartTag() returns EVAL_BODY_BUFFERED.
  104. *
  105. * <p><B>Lifecycle</B>
  106. * <p> Lifecycle details are described by the transition diagram below.
  107. * Exceptions that are thrown during the computation of doStartTag(),
  108. * setBodyContent(), doInitBody(), BODY, doAfterBody() interrupt the
  109. * execution sequence and are propagated up the stack, unless the
  110. * tag handler implements the TryCatchFinally interface; see that
  111. * interface for details.
  112. * <p>
  113. * <IMG src="doc-files/BodyTagProtocol.gif"/>
  114. * <p><B>Empty and Non-Empty Action</B>
  115. * <p> If the TagLibraryDescriptor file indicates that the action must
  116. * always have an empty action, by an <body-content> entry of "empty",
  117. * then the doStartTag() method must return SKIP_BODY.
  118. *
  119. * Otherwise, the doStartTag() method may return SKIP_BODY,
  120. * EVAL_BODY_INCLUDE, or EVAL_BODY_BUFFERED.
  121. *
  122. * <p>
  123. * If SKIP_BODY is returned the body is not evaluated, and doEndTag() is
  124. * invoked.
  125. *
  126. * <p>
  127. * If EVAL_BODY_INCLUDE is returned, setBodyContent() is not invoked,
  128. * doInitBody() is not invoked, the body is evaluated and
  129. * "passed through" to the current out, doAfterBody() is invoked
  130. * and then, after zero or more iterations, doEndTag() is invoked.
  131. *
  132. * <p>
  133. * If EVAL_BODY_BUFFERED is returned, setBodyContent() is invoked,
  134. * doInitBody() is invoked, the body is evaluated, doAfterBody() is
  135. * invoked, and then, after zero or more iterations, doEndTag() is invoked.
  136. */
  137. public interface BodyTag extends IterationTag {
  138. /**
  139. * Deprecated constant that has the same value as EVAL_BODY_BUFFERED
  140. * and EVAL_BODY_AGAIN. This name has been marked as deprecated
  141. * to encourage the use of the two different terms, which are much
  142. * more descriptive.
  143. *
  144. * @deprecated As of Java JSP API 1.2, use BodyTag.EVAL_BODY_BUFFERED
  145. * or IterationTag.EVAL_BODY_AGAIN.
  146. */
  147. public final static int EVAL_BODY_TAG = 2;
  148. /**
  149. * Request the creation of new buffer, a BodyContent on which to
  150. * evaluate the body of this tag.
  151. *
  152. * Returned from doStartTag when it implements BodyTag.
  153. * This is an illegal return value for doStartTag when the class
  154. * does not implement BodyTag.
  155. */
  156. public final static int EVAL_BODY_BUFFERED = 2;
  157. /**
  158. * Set the bodyContent property.
  159. * This method is invoked by the JSP page implementation object at
  160. * most once per action invocation.
  161. * This method will be invoked before doInitBody.
  162. * This method will not be invoked for empty tags or for non-empty
  163. * tags whose doStartTag() method returns SKIP_BODY or EVAL_BODY_INCLUDE.
  164. *
  165. * <p>
  166. * When setBodyContent is invoked, the value of the implicit object out
  167. * has already been changed in the pageContext object. The BodyContent
  168. * object passed will have not data on it but may have been reused
  169. * (and cleared) from some previous invocation.
  170. *
  171. * <p>
  172. * The BodyContent object is available and with the appropriate content
  173. * until after the invocation of the doEndTag method, at which case it
  174. * may be reused.
  175. *
  176. * @param b the BodyContent
  177. * @seealso #doInitBody
  178. * @seealso #doAfterBody
  179. */
  180. void setBodyContent(BodyContent b);
  181. /**
  182. * Prepare for evaluation of the body.
  183. * This method is invoked by the JSP page implementation object
  184. * after setBodyContent and before the first time
  185. * the body is to be evaluated.
  186. * This method will not be invoked for empty tags or for non-empty
  187. * tags whose doStartTag() method returns SKIP_BODY or EVAL_BODY_INCLUDE.
  188. *
  189. * <p>
  190. * The JSP container will resynchronize
  191. * any variable values that are indicated as so in TagExtraInfo after the
  192. * invocation of doInitBody().
  193. *
  194. * @throws JspException
  195. * @seealso #doAfterBody
  196. */
  197. void doInitBody() throws JspException;
  198. }