Skip to content

Package: TagSupport

TagSupport

nameinstructionbranchcomplexitylinemethod
TagSupport()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
doAfterBody()
M: 2 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
doEndTag()
M: 2 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
doStartTag()
M: 2 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
findAncestorWithClass(Tag, Class)
M: 40 C: 0
0%
M: 16 C: 0
0%
M: 9 C: 0
0%
M: 11 C: 0
0%
M: 1 C: 0
0%
getId()
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%
getParent()
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%
getValue(String)
M: 10 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
getValues()
M: 9 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
release()
M: 16 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%
removeValue(String)
M: 9 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
setId(String)
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
setPageContext(PageContext)
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
setParent(Tag)
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
setValue(String, Object)
M: 15 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 4 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.Serializable;
22: import java.util.Enumeration;
23: import java.util.Hashtable;
24:
25: import jakarta.servlet.jsp.JspException;
26: import jakarta.servlet.jsp.PageContext;
27:
28: /**
29: * A base class for defining new tag handlers implementing Tag.
30: *
31: * <p>
32: * The TagSupport class is a utility class intended to be used as the base class for new tag handlers. The TagSupport
33: * class implements the Tag and IterationTag interfaces and adds additional convenience methods including getter methods
34: * for the properties in Tag. TagSupport has one static method that is included to facilitate coordination among
35: * cooperating tags.
36: *
37: * <p>
38: * Many tag handlers will extend TagSupport and only redefine a few methods.
39: */
40: public class TagSupport implements IterationTag, Serializable {
41:
42: private static final long serialVersionUID = 3749116330508327592L;
43:
44: /**
45: * Find the instance of a given class type that is closest to a given instance. This method uses the getParent
46: * method from the Tag interface. This method is used for coordination among cooperating tags.
47: *
48: * <p>
49: * The current version of the specification only provides one formal way of indicating the observable type of a tag
50: * handler: its tag handler implementation class, described in the tag-class subelement of the tag element. This is
51: * extended in an informal manner by allowing the tag library author to indicate in the description subelement an
52: * observable type. The type should be a subtype of the tag handler implementation class or void. This addititional
53: * constraint can be exploited by a specialized container that knows about that specific tag library, as in the case
54: * of the JSP standard tag library.
55: *
56: * <p>
57: * When a tag library author provides information on the observable type of a tag handler, client programmatic code
58: * should adhere to that constraint. Specifically, the Class passed to findAncestorWithClass should be a subtype of
59: * the observable type.
60: *
61: *
62: * @param from The instance from where to start looking.
63: * @param klass The subclass of Tag or interface to be matched
64: * @return the nearest ancestor that implements the interface or is an instance of the class specified
65: */
66: public static final Tag findAncestorWithClass(Tag from, Class<?> klass) {
67: boolean isInterface = false;
68:
69:• if (from == null || klass == null
70:• || (!Tag.class.isAssignableFrom(klass) && !(isInterface = klass.isInterface()))) {
71: return null;
72: }
73:
74: for (;;) {
75: Tag tag = from.getParent();
76:
77:• if (tag == null) {
78: return null;
79: }
80:
81:• if ((isInterface && klass.isInstance(tag)) || klass.isAssignableFrom(tag.getClass()))
82: return tag;
83: else
84: from = tag;
85: }
86: }
87:
88: /**
89: * Default constructor, all subclasses are required to define only a public constructor with the same signature, and
90: * to call the superclass constructor.
91: *
92: * This constructor is called by the code generated by the JSP translator.
93: */
94: public TagSupport() {
95: }
96:
97: /**
98: * Default processing of the start tag, returning SKIP_BODY.
99: *
100: * @return SKIP_BODY
101: * @throws JspException if an error occurs while processing this tag
102: *
103: * @see Tag#doStartTag()
104: */
105: @Override
106: public int doStartTag() throws JspException {
107: return SKIP_BODY;
108: }
109:
110: /**
111: * Default processing of the end tag returning EVAL_PAGE.
112: *
113: * @return EVAL_PAGE
114: * @throws JspException if an error occurs while processing this tag
115: *
116: * @see Tag#doEndTag()
117: */
118: @Override
119: public int doEndTag() throws JspException {
120: return EVAL_PAGE;
121: }
122:
123: /**
124: * Default processing for a body.
125: *
126: * @return SKIP_BODY
127: * @throws JspException if an error occurs while processing this tag
128: *
129: * @see IterationTag#doAfterBody()
130: */
131: @Override
132: public int doAfterBody() throws JspException {
133: return SKIP_BODY;
134: }
135:
136: // Actions related to body evaluation
137:
138: /**
139: * Release state.
140: *
141: * @see Tag#release()
142: */
143: @Override
144: public void release() {
145: parent = null;
146: id = null;
147:• if (values != null) {
148: values.clear();
149: }
150: values = null;
151: }
152:
153: /**
154: * Set the nesting tag of this tag.
155: *
156: * @param t The parent Tag.
157: * @see Tag#setParent(Tag)
158: */
159: @Override
160: public void setParent(Tag t) {
161: parent = t;
162: }
163:
164: /**
165: * The Tag instance most closely enclosing this tag instance.
166: *
167: * @see Tag#getParent()
168: *
169: * @return the parent tag instance or null
170: */
171: @Override
172: public Tag getParent() {
173: return parent;
174: }
175:
176: /**
177: * Set the id attribute for this tag.
178: *
179: * @param id The String for the id.
180: */
181: public void setId(String id) {
182: this.id = id;
183: }
184:
185: /**
186: * The value of the id attribute of this tag; or null.
187: *
188: * @return the value of the id attribute, or null
189: */
190: public String getId() {
191: return id;
192: }
193:
194: /**
195: * Set the page context.
196: *
197: * @param pageContext The PageContext.
198: * @see Tag#setPageContext
199: */
200: @Override
201: public void setPageContext(PageContext pageContext) {
202: this.pageContext = pageContext;
203: }
204:
205: /**
206: * Associate a value with a String key.
207: *
208: * @param k The key String.
209: * @param o The value to associate.
210: */
211: public void setValue(String k, Object o) {
212:• if (values == null) {
213: values = new Hashtable<>();
214: }
215: values.put(k, o);
216: }
217:
218: /**
219: * Get a the value associated with a key.
220: *
221: * @param k The string key.
222: * @return The value associated with the key, or null.
223: */
224: public Object getValue(String k) {
225:• if (values == null) {
226: return null;
227: } else {
228: return values.get(k);
229: }
230: }
231:
232: /**
233: * Remove a value associated with a key.
234: *
235: * @param k The string key.
236: */
237: public void removeValue(String k) {
238:• if (values != null) {
239: values.remove(k);
240: }
241: }
242:
243: /**
244: * Enumerate the keys for the values kept by this tag handler.
245: *
246: * @return An enumeration of all the keys for the values set, or null or an empty Enumeration if no values have been
247: * set.
248: */
249: public Enumeration<String> getValues() {
250:• if (values == null) {
251: return null;
252: }
253: return values.keys();
254: }
255:
256: // private fields
257:
258: private Tag parent;
259: private Hashtable<String, Object> values;
260: /**
261: * The value of the id attribute of this tag; or null.
262: */
263: protected String id;
264:
265: // protected fields
266:
267: /**
268: * The PageContext.
269: */
270: protected PageContext pageContext;
271: }