Skip to content

Package: TagLibraryValidator

TagLibraryValidator

nameinstructionbranchcomplexitylinemethod
TagLibraryValidator()
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%
getInitParameters()
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%
release()
M: 1 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
setInitParameters(Map)
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%
validate(String, String, PageData)
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%

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.util.Map;
22:
23: /**
24: * Translation-time validator class for a JSP page. A validator operates on the XML view associated with the JSP page.
25: *
26: * <p>
27: * The TLD file associates a TagLibraryValidator class and some init arguments with a tag library.
28: *
29: * <p>
30: * The JSP container is reponsible for locating an appropriate instance of the appropriate subclass by
31: *
32: * <ul>
33: * <li>new a fresh instance, or reuse an available one
34: * <li>invoke the setInitParams(Map) method on the instance
35: * </ul>
36: *
37: * once initialized, the validate(String, String, PageData) method will be invoked, where the first two arguments are
38: * the prefix and uri for this tag library in the XML View. The prefix is intended to make it easier to produce an error
39: * message. However, it is not always accurate. In the case where a single URI is mapped to more than one prefix in the
40: * XML view, the prefix of the first URI is provided. Therefore, to provide high quality error messages in cases where
41: * the tag elements themselves are checked, the prefix parameter should be ignored and the actual prefix of the element
42: * should be used instead. TagLibraryValidators should always use the uri to identify elements as beloning to the tag
43: * library, not the prefix.
44: *
45: * <p>
46: * A TagLibraryValidator instance may create auxiliary objects internally to perform the validation (e.g. an XSchema
47: * validator) and may reuse it for all the pages in a given translation run.
48: *
49: * <p>
50: * The JSP container is not guaranteed to serialize invocations of validate() method, and TagLibraryValidators should
51: * perform any synchronization they may require.
52: *
53: * <p>
54: * As of JSP 2.0, a JSP container must provide a jsp:id attribute to provide higher quality validation errors. The
55: * container will track the JSP pages as passed to the container, and will assign to each element a unique "id", which
56: * is passed as the value of the jsp:id attribute. Each XML element in the XML view available will be extended with this
57: * attribute. The TagLibraryValidator can then use the attribute in one or more ValidationMessage objects. The container
58: * then, in turn, can use these values to provide more precise information on the location of an error.
59: *
60: * <p>
61: * The actual prefix of the <code>id</code> attribute may or may not be <code>jsp</code> but it will always map to the
62: * namespace <code>http://java.sun.com/JSP/Page</code>. A TagLibraryValidator implementation must rely on the uri, not
63: * the prefix, of the <code>id</code> attribute.
64: */
65: abstract public class TagLibraryValidator {
66:
67: /**
68: * Sole constructor. (For invocation by subclass constructors, typically implicit.)
69: */
70: public TagLibraryValidator() {
71: }
72:
73: /**
74: * Set the init data in the TLD for this validator. Parameter names are keys, and parameter values are the values.
75: *
76: * @param map A Map describing the init parameters
77: */
78: public void setInitParameters(Map<String, Object> map) {
79: initParameters = map;
80: }
81:
82: /**
83: * Get the init parameters data as an immutable Map. Parameter names are keys, and parameter values are the values.
84: *
85: * @return The init parameters as an immutable map.
86: */
87: public Map<String, Object> getInitParameters() {
88: return initParameters;
89: }
90:
91: /**
92: * Validate a JSP page. This will get invoked once per unique tag library URI in the XML view. This method will
93: * return null if the page is valid; otherwise the method should return an array of ValidationMessage objects. An
94: * array of length zero is also interpreted as no errors.
95: *
96: * @param prefix the first prefix with which the tag library is associated, in the XML view. Note that some tags may
97: * use a different prefix if the namespace is redefined.
98: * @param uri the tag library's unique identifier
99: * @param page the JspData page object
100: * @return A null object, or zero length array if no errors, an array of ValidationMessages otherwise.
101: */
102: public ValidationMessage[] validate(String prefix, String uri, PageData page) {
103: return null;
104: }
105:
106: /**
107: * Release any data kept by this instance for validation purposes.
108: */
109: public void release() {
110: }
111:
112: // Private data
113: private Map<String, Object> initParameters;
114:
115: }