geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From genspr...@apache.org
Subject svn commit: r1033345 - /geronimo/external/trunk/tomcat-parent-7.0.0/jasper/src/main/java/org/apache/jasper/util/UniqueAttributesImpl.java
Date Wed, 10 Nov 2010 04:26:38 GMT
Author: genspring
Date: Wed Nov 10 04:26:38 2010
New Revision: 1033345

URL: http://svn.apache.org/viewvc?rev=1033345&view=rev
Log:
https://issues.apache.org/bugzilla/show_bug.cgi?id=49297, Fix the spec broken code in related
code of this bug.

Modified:
    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/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=1033345&r1=1033344&r2=1033345&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
Wed Nov 10 04:26:38 2010
@@ -16,8 +16,8 @@
  */
 package org.apache.jasper.util;
 
-import java.util.HashSet;
-import java.util.Set;
+import java.util.HashMap;
+import java.util.Map;
 
 import org.apache.jasper.compiler.Localizer;
 import org.xml.sax.Attributes;
@@ -29,54 +29,106 @@ import org.xml.sax.helpers.AttributesImp
  */
 public class UniqueAttributesImpl extends AttributesImpl {
 
-    private Set<String> qNames = new HashSet<String>();
+    private Map<String,String> attributes = new HashMap<String,String>();
 
     @Override
     public void clear() {
-        qNames.clear();
+        attributes.clear();
         super.clear();
     }
 
     @Override
     public void setAttributes(Attributes atts) {
+        
         for (int i = 0; i < atts.getLength(); i++) {
-            if (!qNames.add(atts.getQName(i))) {
-                handleDuplicate(atts.getQName(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);
             }
+            
         }
+        
         super.setAttributes(atts);
     }
 
     @Override
     public void addAttribute(String uri, String localName, String qName,
             String type, String value) {
-        if (qNames.add(qName)) {
-            super.addAttribute(uri, localName, qName, type, 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 on how to handle multiple pageEncoding attributes.
+                
+            } else if (!attributes.get(qName).equals(value)) {
+
+                handleDuplicate(qName);
+            } 
+
         } else {
-            handleDuplicate(qName);
+            attributes.put(qName, value);
+            super.addAttribute(uri, localName, qName, type, value);
         }
+       
     }
 
     @Override
     public void setAttribute(int index, String uri, String localName,
             String qName, String type, String value) {
-        qNames.remove(super.getQName(index));
-        if (qNames.add(qName)) {
-            super.setAttribute(index, uri, localName, qName, type, value);
-        } else {
-            handleDuplicate(qName);
-        }
+        
+        attributes.remove(super.getQName(index));
+        attributes.put(qName, value);
+        super.setAttribute(index, uri, localName, qName, type, value);
+
     }
 
     @Override
     public void removeAttribute(int index) {
-        qNames.remove(super.getQName(index));
+        attributes.remove(super.getQName(index));
         super.removeAttribute(index);
     }
 
     @Override
     public void setQName(int index, String qName) {
-        qNames.remove(super.getQName(index));
+        attributes.remove(super.getQName(index));
         super.setQName(index, qName);
     }
 



Mime
View raw message