Return-Path: Delivered-To: apmail-geronimo-scm-archive@www.apache.org Received: (qmail 51757 invoked from network); 13 Nov 2010 01:43:01 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 13 Nov 2010 01:43:01 -0000 Received: (qmail 93274 invoked by uid 500); 13 Nov 2010 01:43:32 -0000 Delivered-To: apmail-geronimo-scm-archive@geronimo.apache.org Received: (qmail 93171 invoked by uid 500); 13 Nov 2010 01:43:32 -0000 Mailing-List: contact scm-help@geronimo.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: dev@geronimo.apache.org List-Id: Delivered-To: mailing list scm@geronimo.apache.org Received: (qmail 93164 invoked by uid 99); 13 Nov 2010 01:43:31 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 13 Nov 2010 01:43:31 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 13 Nov 2010 01:43:29 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 08F7A23888E7; Sat, 13 Nov 2010 01:42:14 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1034622 - in /geronimo/external/trunk/tomcat-parent-7.0.0/jasper/src/main/java/org/apache/jasper: compiler/Parser.java util/UniqueAttributesImpl.java Date: Sat, 13 Nov 2010 01:42:13 -0000 To: scm@geronimo.apache.org From: genspring@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20101113014214.08F7A23888E7@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: genspring Date: Sat Nov 13 01:42:13 2010 New Revision: 1034622 URL: http://svn.apache.org/viewvc?rev=1034622&view=rev Log: pull the acceptted fix for https://issues.apache.org/bugzilla/show_bug.cgi?id=49297 Modified: geronimo/external/trunk/tomcat-parent-7.0.0/jasper/src/main/java/org/apache/jasper/compiler/Parser.java geronimo/external/trunk/tomcat-parent-7.0.0/jasper/src/main/java/org/apache/jasper/util/UniqueAttributesImpl.java Modified: geronimo/external/trunk/tomcat-parent-7.0.0/jasper/src/main/java/org/apache/jasper/compiler/Parser.java URL: http://svn.apache.org/viewvc/geronimo/external/trunk/tomcat-parent-7.0.0/jasper/src/main/java/org/apache/jasper/compiler/Parser.java?rev=1034622&r1=1034621&r2=1034622&view=diff ============================================================================== --- geronimo/external/trunk/tomcat-parent-7.0.0/jasper/src/main/java/org/apache/jasper/compiler/Parser.java (original) +++ geronimo/external/trunk/tomcat-parent-7.0.0/jasper/src/main/java/org/apache/jasper/compiler/Parser.java Sat Nov 13 01:42:13 2010 @@ -150,7 +150,10 @@ class Parser implements TagConstants { * Attributes ::= (S Attribute)* S? */ Attributes parseAttributes() throws JasperException { - UniqueAttributesImpl attrs = new UniqueAttributesImpl(); + return parseAttributes(false); + } + Attributes parseAttributes(boolean pageDirective) throws JasperException { + UniqueAttributesImpl attrs = new UniqueAttributesImpl(pageDirective); reader.skipSpaces(); int ws = 1; @@ -177,7 +180,7 @@ class Parser implements TagConstants { public static Attributes parseAttributes(ParserController pc, JspReader reader) throws JasperException { Parser tmpParser = new Parser(pc, reader, false, false, null); - return tmpParser.parseAttributes(); + return tmpParser.parseAttributes(true); } /** @@ -327,7 +330,7 @@ class Parser implements TagConstants { * Attribute)* */ private void parsePageDirective(Node parent) throws JasperException { - Attributes attrs = parseAttributes(); + Attributes attrs = parseAttributes(true); Node.PageDirective n = new Node.PageDirective(attrs, start, parent); /* Modified: geronimo/external/trunk/tomcat-parent-7.0.0/jasper/src/main/java/org/apache/jasper/util/UniqueAttributesImpl.java URL: http://svn.apache.org/viewvc/geronimo/external/trunk/tomcat-parent-7.0.0/jasper/src/main/java/org/apache/jasper/util/UniqueAttributesImpl.java?rev=1034622&r1=1034621&r2=1034622&view=diff ============================================================================== --- geronimo/external/trunk/tomcat-parent-7.0.0/jasper/src/main/java/org/apache/jasper/util/UniqueAttributesImpl.java (original) +++ geronimo/external/trunk/tomcat-parent-7.0.0/jasper/src/main/java/org/apache/jasper/util/UniqueAttributesImpl.java Sat Nov 13 01:42:13 2010 @@ -16,8 +16,8 @@ */ package org.apache.jasper.util; -import java.util.HashMap; -import java.util.Map; +import java.util.HashSet; +import java.util.Set; import org.apache.jasper.compiler.Localizer; import org.xml.sax.Attributes; @@ -29,110 +29,92 @@ import org.xml.sax.helpers.AttributesImp */ public class UniqueAttributesImpl extends AttributesImpl { - private Map attributes = new HashMap(); + private static final String IMPORT = "import"; + private static final String PAGE_ENCODING = "pageEncoding"; + + private final boolean pageDirective; + private final Set qNames = new HashSet(); + + public UniqueAttributesImpl() { + this.pageDirective = false; + } + + public UniqueAttributesImpl(boolean pageDirective) { + this.pageDirective = pageDirective; + } @Override public void clear() { - attributes.clear(); + qNames.clear(); super.clear(); } @Override public void setAttributes(Attributes atts) { - for (int i = 0; i < atts.getLength(); i++) { - - String qName = atts.getQName(i); - String value = atts.getValue(i); - - /* - * A translation error will occur if the page directive defines duplicate attribute/values within a given - * translation unit, unless the values for the duplicate attributes are identical for all occurrences. The - * import and pageEncoding attributes are exempt from this rule and can appear multiple times. - */ - if (attributes.keySet().contains(qName)) { - - if (qName.equals("import")) { - - StringBuffer sb = new StringBuffer(3); - sb.append(attributes.get(qName)); - sb.append(","); - sb.append(value); - attributes.put(qName, sb.toString()); - - } /*else if (qName.equals("pageEncoding")) { - - // It's not clear in the spec how would we handle multiple pageEncoding attributes. - - } */else if (!attributes.get(qName).equals(value)) { - - handleDuplicate(qName); - } - - } else { - attributes.put(qName, value); + if (!qNames.add(atts.getQName(i))) { + handleDuplicate(atts.getQName(i), atts.getValue(i)); } - } - super.setAttributes(atts); } @Override public void addAttribute(String uri, String localName, String qName, String type, String value) { - - if (attributes.keySet().contains(qName)) { - - if (qName.equals("import")) { - - StringBuffer sb = new StringBuffer(3); - sb.append(attributes.get(qName)); - sb.append(","); - sb.append(value); - attributes.put(qName, sb.toString()); - super.addAttribute(uri, localName, qName, type, sb.toString()); - - } /*else if (qName.equals("pageEncoding")) { - - // It's not clear in the spec how would we handle multiple pageEncoding attributes. - - } */else if (!attributes.get(qName).equals(value)) { - - handleDuplicate(qName); - } - - } else { - attributes.put(qName, value); + if (qNames.add(qName)) { super.addAttribute(uri, localName, qName, type, value); + } else { + handleDuplicate(qName, value); } - } @Override public void setAttribute(int index, String uri, String localName, String qName, String type, String value) { - - attributes.remove(super.getQName(index)); - attributes.put(qName, value); - super.setAttribute(index, uri, localName, qName, type, value); - + qNames.remove(super.getQName(index)); + if (qNames.add(qName)) { + super.setAttribute(index, uri, localName, qName, type, value); + } else { + handleDuplicate(qName, value); + } } @Override public void removeAttribute(int index) { - attributes.remove(super.getQName(index)); + qNames.remove(super.getQName(index)); super.removeAttribute(index); } @Override public void setQName(int index, String qName) { - attributes.remove(super.getQName(index)); + qNames.remove(super.getQName(index)); super.setQName(index, qName); } - private void handleDuplicate(String qName) { + private void handleDuplicate(String qName, String value) { + if (pageDirective) { + if (IMPORT.equalsIgnoreCase(qName)) { + // Always merge imports + int i = super.getIndex(IMPORT); + String v = super.getValue(i); + super.setValue(i, v + "," + value); + return; + } else if (PAGE_ENCODING.equalsIgnoreCase(qName)) { + // Page encoding can only occur once per file so a second + // attribute - even one with a duplicate value - is an error + } else { + // Other attributes can be repeated if and only if the values + // are identical + String v = super.getValue(qName); + if (v.equals(value)) { + return; + } + } + } + + // Ordinary tag attributes can't be repeated, even with identical values throw new IllegalArgumentException( - Localizer.getMessage("jsp.error.duplicateqname", qName)); + Localizer.getMessage("jsp.error.duplicateqname", qName)); } }