MCPcopy Create free account
hub / github.com/apache/tomcat / checkAttributes

Method checkAttributes

java/org/apache/jasper/compiler/JspUtil.java:115–198  ·  view source on GitHub ↗

Checks if all mandatory attributes are present and if all attributes present have valid names. Checks attributes specified as XML-style attributes as well as attributes specified using the jsp:attribute standard action. @param typeOfTag The tag type @param n The corresponding no

(String typeOfTag, Node n, ValidAttribute[] validAttributes, ErrorDispatcher err)

Source from the content-addressed store, hash-verified

113 * @throws JasperException An error occurred
114 */
115 public static void checkAttributes(String typeOfTag, Node n, ValidAttribute[] validAttributes, ErrorDispatcher err)
116 throws JasperException {
117 Attributes attrs = n.getAttributes();
118 Mark start = n.getStart();
119 boolean valid = true;
120
121 // AttributesImpl.removeAttribute is broken, so we do this...
122 int tempLength = (attrs == null) ? 0 : attrs.getLength();
123 ArrayList<String> temp = new ArrayList<>(tempLength);
124 for (int i = 0; i < tempLength; i++) {
125 @SuppressWarnings("null") // If attrs==null, tempLength == 0
126 String qName = attrs.getQName(i);
127 if ((!qName.equals("xmlns")) && (!qName.startsWith("xmlns:"))) {
128 temp.add(qName);
129 }
130 }
131
132 // Add names of attributes specified using jsp:attribute
133 Node.Nodes tagBody = n.getBody();
134 if (tagBody != null) {
135 int numSubElements = tagBody.size();
136 for (int i = 0; i < numSubElements; i++) {
137 Node node = tagBody.getNode(i);
138 if (node instanceof Node.NamedAttribute) {
139 String attrName = node.getAttributeValue("name");
140 temp.add(attrName);
141 // Check if this value appear in the attribute of the node
142 if (n.getAttributeValue(attrName) != null) {
143 err.jspError(n, "jsp.error.duplicate.name.jspattribute", attrName);
144 }
145 } else {
146 // Nothing can come before jsp:attribute, and only
147 // jsp:body can come after it.
148 break;
149 }
150 }
151 }
152
153 /*
154 * First check to see if all the mandatory attributes are present. If so only then proceed to see if the other
155 * attributes are valid for the particular tag.
156 */
157 String missingAttribute = null;
158
159 for (ValidAttribute validAttribute : validAttributes) {
160 int attrPos;
161 if (validAttribute.mandatory) {
162 attrPos = temp.indexOf(validAttribute.name);
163 if (attrPos != -1) {
164 temp.remove(attrPos);
165 } else {
166 valid = false;
167 missingAttribute = validAttribute.name;
168 break;
169 }
170 }
171 }
172

Callers 3

visitMethod · 0.95
visitMethod · 0.95
visitMethod · 0.95

Calls 14

getAttributeValueMethod · 0.95
getAttributesMethod · 0.65
getLengthMethod · 0.65
equalsMethod · 0.65
addMethod · 0.65
jspErrorMethod · 0.65
removeMethod · 0.65
getStartMethod · 0.45
getQNameMethod · 0.45
startsWithMethod · 0.45
getBodyMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected