Hashtable<String,String> map = new Hashtable<String,String>();
Node.JspAttribute[] attrs = n.getJspAttributes();
for (int i = 0; attrs != null && i < attrs.length; i++) {
- String attrStr = null;
+ String value = null;
+ String nvp = null;
if (attrs[i].isNamedAttribute()) {
- if (attrs[i].getNamedAttributeNode().isOmit()) {
- // Skip this attribute - JSP.5-7
+ NamedAttribute attr = attrs[i].getNamedAttributeNode();
+ Node.JspAttribute omitAttr = attr.getOmit();
+ String omit = attributeValue(omitAttr, false, boolean.class);
+ if ("true".equals(omit)) {
continue;
}
- attrStr = generateNamedAttributeValue(attrs[i]
- .getNamedAttributeNode());
+ value = generateNamedAttributeValue(
+ attrs[i].getNamedAttributeNode());
+ if ("false".equals(omit)) {
+ nvp = " + \" " + attrs[i].getName() + "=\\\"\" + " +
+ value + " + \"\\\"\"";
+ } else {
+ nvp = " + (Boolean.valueOf(" + omit + ")?\"\":\" " + attrs[i].getName() +
+ "=\\\"\" + " + value + " + \"\\\"\")";
+ }
} else {
- attrStr = attributeValue(attrs[i], false, Object.class);
+ value = attributeValue(attrs[i], false, Object.class);
+ nvp = " + \" " + attrs[i].getName() + "=\\\"\" + " +
+ value + " + \"\\\"\"";
}
- String s = " + \" " + attrs[i].getName() + "=\\\"\" + "
- + attrStr + " + \"\\\"\"";
- map.put(attrs[i].getName(), s);
+ map.put(attrs[i].getName(), nvp);
}
// Write begin tag, using XML-style 'name' attribute as the
// True if this attribute should be omitted from the output if
// used with a <jsp:element>, otherwise false
- private boolean omit = false;
+ private JspAttribute omit;
private ChildInfo childInfo;
// (if null or true, leave default of true)
trim = false;
}
- if ("true".equals(this.getAttributeValue("omit"))) {
- // (if null or false, leave default of false)
- omit = true;
- }
childInfo = new ChildInfo();
name = this.getAttributeValue("name");
if (name != null) {
return trim;
}
- public boolean isOmit() {
+ public void setOmit(JspAttribute omit) {
+ this.omit = omit;
+ }
+
+ public JspAttribute getOmit() {
return omit;
}
@Override
public void visit(Node.NamedAttribute n) throws JasperException {
JspUtil.checkAttributes("Attribute", n, attributeAttrs, err);
+ n.setOmit(getJspAttribute(null, "omit", null, null, n
+ .getAttributeValue("omit"), n, true));
visitBody(n);
}
import java.io.File;
import java.io.IOException;
import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagData;
return time;
}
}
-
+
+ public void testBug49799() throws Exception {
+
+ String[] expected = { "<p style=\"color:red\">00-Red</p>",
+ "<p>01-Not Red</p>",
+ "<p style=\"color:red\">02-Red</p>",
+ "<p>03-Not Red</p>",
+ "<p style=\"color:red\">04-Red</p>",
+ "<p>05-Not Red</p>"};
+
+ Tomcat tomcat = getTomcatInstance();
+
+ File appDir = new File("test/webapp-3.0");
+ tomcat.addWebapp(null, "/test", appDir.getAbsolutePath());
+ tomcat.start();
+
+ ByteChunk res = new ByteChunk();
+ Map<String,List<String>> headers = new HashMap<String,List<String>>();
+
+ getUrl("http://localhost:" + getPort() + "/test/bug49799.jsp", res,
+ headers);
+
+ // Check request completed
+ String result = res.toString();
+ String[] lines = result.split("\n|\r|\r\n");
+ int i = 0;
+ for (String line : lines) {
+ if (line.length() > 0) {
+ assertEquals(expected[i], line);
+ i++;
+ }
+ }
+ }
+
/** Assertion for text printed by tags:echo */
private static void assertEcho(String result, String expected) {
assertTrue(result.indexOf("<p>" + expected + "</p>") > 0);
--- /dev/null
+<%--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+--%>
+<jsp:element name="p">
+ <jsp:attribute name="style" omit="false">color:red</jsp:attribute>
+ <jsp:body>00-Red</jsp:body>
+</jsp:element>
+<jsp:element name="p">
+ <jsp:attribute name="style" omit="true">color:red</jsp:attribute>
+ <jsp:body>01-Not Red</jsp:body>
+</jsp:element>
+<jsp:element name="p">
+ <jsp:attribute name="style" omit="${false}">color:red</jsp:attribute>
+ <jsp:body>02-Red</jsp:body>
+</jsp:element>
+<jsp:element name="p">
+ <jsp:attribute name="style" omit="${true}">color:red</jsp:attribute>
+ <jsp:body>03-Not Red</jsp:body>
+</jsp:element>
+<jsp:element name="p">
+ <jsp:attribute name="style" omit="<%=(1==2)%>">color:red</jsp:attribute>
+ <jsp:body>04-Red</jsp:body>
+</jsp:element>
+<jsp:element name="p">
+ <jsp:attribute name="style" omit="<%=(1==1)%>">color:red</jsp:attribute>
+ <jsp:body>05-Not Red</jsp:body>
+</jsp:element>
\ No newline at end of file
group should not prevent a page from setting some other content type.
(markt)
</fix>
+ <fix>
+ <bug>49799</bug>: The new <code>omit</code> attribute for
+ <code>jsp:attribute</code> elements now supports the use of expressions
+ and expression language. (markt)
+ </fix>
</changelog>
</subsection>
<subsection name="Cluster">