001 /* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 */ 019 020 // 021 // This source code implements specifications defined by the Java 022 // Community Process. In order to remain compliant with the specification 023 // DO NOT add / change / or delete method signatures! 024 // 025 026 package javax.servlet.jsp.tagext; 027 028 import java.io.IOException; 029 import java.io.Writer; 030 import javax.servlet.jsp.*; 031 032 /** 033 * Encapsulates a portion of JSP code in an object that 034 * can be invoked as many times as needed. JSP Fragments are defined 035 * using JSP syntax as the body of a tag for an invocation to a SimpleTag 036 * handler, or as the body of a <jsp:attribute> standard action 037 * specifying the value of an attribute that is declared as a fragment, 038 * or to be of type JspFragment in the TLD. 039 * <p> 040 * The definition of the JSP fragment must only contain template 041 * text and JSP action elements. In other words, it must not contain 042 * scriptlets or scriptlet expressions. At translation time, the 043 * container generates an implementation of the JspFragment abstract class 044 * capable of executing the defined fragment. 045 * <p> 046 * A tag handler can invoke the fragment zero or more times, or 047 * pass it along to other tags, before returning. To communicate values 048 * to/from a JSP fragment, tag handlers store/retrieve values in 049 * the JspContext associated with the fragment. 050 * <p> 051 * Note that tag library developers and page authors should not generate 052 * JspFragment implementations manually. 053 * <p> 054 * <i>Implementation Note</i>: It is not necessary to generate a 055 * separate class for each fragment. One possible implementation is 056 * to generate a single helper class for each page that implements 057 * JspFragment. Upon construction, a discriminator can be passed to 058 * select which fragment that instance will execute. 059 * 060 * @since 2.0 061 */ 062 public abstract class JspFragment { 063 064 /** 065 * Executes the fragment and directs all output to the given Writer, 066 * or the JspWriter returned by the getOut() method of the JspContext 067 * associated with the fragment if out is null. 068 * 069 * @param out The Writer to output the fragment to, or null if 070 * output should be sent to JspContext.getOut(). 071 * @throws javax.servlet.jsp.JspException Thrown if an error occured 072 * while invoking this fragment. 073 * @throws javax.servlet.jsp.SkipPageException Thrown if the page 074 * that (either directly or indirectly) invoked the tag handler that 075 * invoked this fragment is to cease evaluation. The container 076 * must throw this exception if a Classic Tag Handler returned 077 * Tag.SKIP_PAGE or if a Simple Tag Handler threw SkipPageException. 078 * @throws java.io.IOException If there was an error writing to the 079 * stream. 080 */ 081 public abstract void invoke( Writer out ) 082 throws JspException, IOException; 083 084 /** 085 * Returns the JspContext that is bound to this JspFragment. 086 * 087 * @return The JspContext used by this fragment at invocation time. 088 */ 089 public abstract JspContext getJspContext(); 090 091 }