Skip to content

Package: JspFragment

JspFragment

nameinstructionbranchcomplexitylinemethod
JspFragment()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*
2: * Copyright (c) 1997, 2020 Oracle and/or its affiliates and others.
3: * All rights reserved.
4: * Copyright 2004 The Apache Software Foundation
5: *
6: * Licensed under the Apache License, Version 2.0 (the "License");
7: * you may not use this file except in compliance with the License.
8: * 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, software
13: * distributed under the License is distributed on an "AS IS" BASIS,
14: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15: * See the License for the specific language governing permissions and
16: * limitations under the License.
17: */
18:
19: package jakarta.servlet.jsp.tagext;
20:
21: import java.io.IOException;
22: import java.io.Writer;
23: import jakarta.servlet.jsp.JspContext;
24: import jakarta.servlet.jsp.JspException;
25:
26: /**
27: * Encapsulates a portion of JSP code in an object that can be invoked as many times as needed. JSP Fragments are
28: * defined using JSP syntax as the body of a tag for an invocation to a SimpleTag handler, or as the body of a
29: * <jsp:attribute> standard action specifying the value of an attribute that is declared as a fragment, or to be
30: * of type JspFragment in the TLD.
31: * <p>
32: * The definition of the JSP fragment must only contain template text and JSP action elements. In other words, it must
33: * not contain scriptlets or scriptlet expressions. At translation time, the container generates an implementation of
34: * the JspFragment abstract class capable of executing the defined fragment.
35: * <p>
36: * A tag handler can invoke the fragment zero or more times, or pass it along to other tags, before returning. To
37: * communicate values to/from a JSP fragment, tag handlers store/retrieve values in the JspContext associated with the
38: * fragment.
39: * <p>
40: * Note that tag library developers and page authors should not generate JspFragment implementations manually.
41: * <p>
42: * <i>Implementation Note</i>: It is not necessary to generate a separate class for each fragment. One possible
43: * implementation is to generate a single helper class for each page that implements JspFragment. Upon construction, a
44: * discriminator can be passed to select which fragment that instance will execute.
45: *
46: * @since JSP 2.0
47: */
48: public abstract class JspFragment {
49:
50: /**
51: * Executes the fragment and directs all output to the given Writer, or the JspWriter returned by the getOut()
52: * method of the JspContext associated with the fragment if out is null.
53: *
54: * @param out The Writer to output the fragment to, or null if output should be sent to JspContext.getOut().
55: * @throws jakarta.servlet.jsp.JspException Thrown if an error occured while invoking this fragment.
56: * @throws jakarta.servlet.jsp.SkipPageException Thrown if the page that (either directly or indirectly) invoked the
57: * tag handler that invoked this fragment is to cease evaluation. The container must throw this exception if
58: * a Classic Tag Handler returned Tag.SKIP_PAGE or if a Simple Tag Handler threw SkipPageException.
59: * @throws java.io.IOException If there was an error writing to the stream.
60: */
61: public abstract void invoke(Writer out) throws JspException, IOException;
62:
63: /**
64: * Returns the JspContext that is bound to this JspFragment.
65: *
66: * @return The JspContext used by this fragment at invocation time.
67: */
68: public abstract JspContext getJspContext();
69:
70: }