Author: markt Date: Mon Aug 30 22:32:08 2010 New Revision: 991011 URL: http://svn.apache.org/viewvc?rev=991011&view=rev Log: Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=49799 The new omit< attribute for <jsp:attribute .../> elements now supports the use of expressions and expression language.
Added: tomcat/trunk/test/webapp-3.0/bug49799.jsp (with props) Modified: tomcat/trunk/java/org/apache/jasper/compiler/Generator.java tomcat/trunk/java/org/apache/jasper/compiler/Node.java tomcat/trunk/java/org/apache/jasper/compiler/Validator.java tomcat/trunk/test/org/apache/jasper/compiler/TestGenerator.java tomcat/trunk/webapps/docs/changelog.xml Modified: tomcat/trunk/java/org/apache/jasper/compiler/Generator.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/jasper/compiler/Generator.java?rev=991011&r1=991010&r2=991011&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/jasper/compiler/Generator.java (original) +++ tomcat/trunk/java/org/apache/jasper/compiler/Generator.java Mon Aug 30 22:32:08 2010 @@ -1861,20 +1861,30 @@ class Generator { 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 Modified: tomcat/trunk/java/org/apache/jasper/compiler/Node.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/jasper/compiler/Node.java?rev=991011&r1=991010&r2=991011&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/jasper/compiler/Node.java (original) +++ tomcat/trunk/java/org/apache/jasper/compiler/Node.java Mon Aug 30 22:32:08 2010 @@ -1866,7 +1866,7 @@ abstract class Node implements TagConsta // 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; @@ -1890,10 +1890,6 @@ abstract class Node implements TagConsta // (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) { @@ -1933,7 +1929,11 @@ abstract class Node implements TagConsta return trim; } - public boolean isOmit() { + public void setOmit(JspAttribute omit) { + this.omit = omit; + } + + public JspAttribute getOmit() { return omit; } Modified: tomcat/trunk/java/org/apache/jasper/compiler/Validator.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/jasper/compiler/Validator.java?rev=991011&r1=991010&r2=991011&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/jasper/compiler/Validator.java (original) +++ tomcat/trunk/java/org/apache/jasper/compiler/Validator.java Mon Aug 30 22:32:08 2010 @@ -685,6 +685,8 @@ class Validator { @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); } Modified: tomcat/trunk/test/org/apache/jasper/compiler/TestGenerator.java URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/jasper/compiler/TestGenerator.java?rev=991011&r1=991010&r2=991011&view=diff ============================================================================== --- tomcat/trunk/test/org/apache/jasper/compiler/TestGenerator.java (original) +++ tomcat/trunk/test/org/apache/jasper/compiler/TestGenerator.java Mon Aug 30 22:32:08 2010 @@ -20,6 +20,9 @@ package org.apache.jasper.compiler; 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; @@ -211,7 +214,40 @@ public class TestGenerator extends Tomca 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); Added: tomcat/trunk/test/webapp-3.0/bug49799.jsp URL: http://svn.apache.org/viewvc/tomcat/trunk/test/webapp-3.0/bug49799.jsp?rev=991011&view=auto ============================================================================== --- tomcat/trunk/test/webapp-3.0/bug49799.jsp (added) +++ tomcat/trunk/test/webapp-3.0/bug49799.jsp Mon Aug 30 22:32:08 2010 @@ -0,0 +1,40 @@ +<%-- + 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 Propchange: tomcat/trunk/test/webapp-3.0/bug49799.jsp ------------------------------------------------------------------------------ svn:eol-style = native Modified: tomcat/trunk/webapps/docs/changelog.xml URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=991011&r1=991010&r2=991011&view=diff ============================================================================== --- tomcat/trunk/webapps/docs/changelog.xml (original) +++ tomcat/trunk/webapps/docs/changelog.xml Mon Aug 30 22:32:08 2010 @@ -119,6 +119,11 @@ 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"> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org