Skip to content

Package: BodyContent

BodyContent

nameinstructionbranchcomplexitylinemethod
BodyContent(JspWriter)
M: 8 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
clearBody()
M: 10 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
flush()
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getEnclosingWriter()
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 jakarta.servlet.jsp.JspWriter;
22: import java.io.Reader;
23: import java.io.Writer;
24: import java.io.IOException;
25:
26: /**
27: * An encapsulation of the evaluation of the body of an action so it is available to a tag handler. BodyContent is a
28: * subclass of JspWriter.
29: *
30: * <p>
31: * Note that the content of BodyContent is the result of evaluation, so it will not contain actions and the like, but
32: * the result of their invocation.
33: *
34: * <p>
35: * BodyContent has methods to convert its contents into a String, to read its contents, and to clear the contents.
36: *
37: * <p>
38: * The buffer size of a BodyContent object is unbounded. A BodyContent object cannot be in autoFlush mode. It is not
39: * possible to invoke flush on a BodyContent object, as there is no backing stream.
40: *
41: * <p>
42: * Instances of BodyContent are created by invoking the pushBody and popBody methods of the PageContext class. A
43: * BodyContent is enclosed within another JspWriter (maybe another BodyContent object) following the structure of their
44: * associated actions.
45: *
46: * <p>
47: * A BodyContent is made available to a BodyTag through a setBodyContent() call. The tag handler can use the object
48: * until after the call to doEndTag().
49: */
50: public abstract class BodyContent extends JspWriter {
51:
52: /**
53: * Protected constructor.
54: *
55: * Unbounded buffer, no autoflushing.
56: *
57: * @param e the enclosing JspWriter
58: */
59: protected BodyContent(JspWriter e) {
60: super(UNBOUNDED_BUFFER, false);
61: this.enclosingWriter = e;
62: }
63:
64: /**
65: * Redefined flush() so it is not legal.
66: *
67: * <p>
68: * It is not valid to flush a BodyContent because there is no backing stream behind it.
69: *
70: * @throws IOException always thrown
71: */
72: @Override
73: public void flush() throws IOException {
74: throw new IOException("Illegal to flush within a custom tag");
75: }
76:
77: /**
78: * Clear the body without throwing any exceptions.
79: */
80: public void clearBody() {
81: try {
82: this.clear();
83: } catch (IOException ex) {
84: // TODO -- clean this one up.
85: throw new Error("internal error!;");
86: }
87: }
88:
89: /**
90: * Return the value of this BodyContent as a Reader.
91: *
92: * @return the value of this BodyContent as a Reader
93: */
94: public abstract Reader getReader();
95:
96: /**
97: * Return the value of the BodyContent as a String.
98: *
99: * @return the value of the BodyContent as a String
100: */
101: public abstract String getString();
102:
103: /**
104: * Write the contents of this BodyContent into a Writer. Subclasses may optimize common invocation patterns.
105: *
106: * @param out The writer into which to place the contents of this body evaluation
107: * @throws IOException if an I/O error occurred while writing the contents of this BodyContent to the given Writer
108: */
109: public abstract void writeOut(Writer out) throws IOException;
110:
111: /**
112: * Get the enclosing JspWriter.
113: *
114: * @return the enclosing JspWriter passed at construction time
115: */
116: public JspWriter getEnclosingWriter() {
117: return enclosingWriter;
118: }
119:
120: // private fields
121:
122: private JspWriter enclosingWriter;
123: }