Lines 16-23
Link Here
|
16 |
*/ |
16 |
*/ |
17 |
package org.apache.jasper.util; |
17 |
package org.apache.jasper.util; |
18 |
|
18 |
|
19 |
import java.util.HashSet; |
19 |
import java.util.HashMap; |
20 |
import java.util.Set; |
20 |
import java.util.Map; |
21 |
|
21 |
|
22 |
import org.apache.jasper.compiler.Localizer; |
22 |
import org.apache.jasper.compiler.Localizer; |
23 |
import org.xml.sax.Attributes; |
23 |
import org.xml.sax.Attributes; |
Lines 29-82
import org.xml.sax.helpers.AttributesImpl;
Link Here
|
29 |
*/ |
29 |
*/ |
30 |
public class UniqueAttributesImpl extends AttributesImpl { |
30 |
public class UniqueAttributesImpl extends AttributesImpl { |
31 |
|
31 |
|
32 |
private Set<String> qNames = new HashSet<String>(); |
32 |
private Map<String,String> attributes = new HashMap<String,String>(); |
33 |
|
33 |
|
34 |
@Override |
34 |
@Override |
35 |
public void clear() { |
35 |
public void clear() { |
36 |
qNames.clear(); |
36 |
attributes.clear(); |
37 |
super.clear(); |
37 |
super.clear(); |
38 |
} |
38 |
} |
39 |
|
39 |
|
40 |
@Override |
40 |
@Override |
41 |
public void setAttributes(Attributes atts) { |
41 |
public void setAttributes(Attributes atts) { |
|
|
42 |
|
42 |
for (int i = 0; i < atts.getLength(); i++) { |
43 |
for (int i = 0; i < atts.getLength(); i++) { |
43 |
if (!qNames.add(atts.getQName(i))) { |
44 |
|
44 |
handleDuplicate(atts.getQName(i)); |
45 |
String qName = atts.getQName(i); |
|
|
46 |
String value = atts.getValue(i); |
47 |
|
48 |
/* |
49 |
* A translation error will occur if the page directive defines duplicate attribute/values within a given |
50 |
* translation unit, unless the values for the duplicate attributes are identical for all occurrences. The |
51 |
* import and pageEncoding attributes are exempt from this rule and can appear multiple times. |
52 |
*/ |
53 |
if (attributes.keySet().contains(qName)) { |
54 |
|
55 |
/* if (qName.equals("import")) { |
56 |
|
57 |
StringBuffer sb = new StringBuffer(3); |
58 |
sb.append(attributes.get(qName)); |
59 |
sb.append(","); |
60 |
sb.append(value); |
61 |
attributes.put(qName, sb.toString()); |
62 |
|
63 |
} else*/ |
64 |
if (qName.equals("pageEncoding")) { |
65 |
|
66 |
// It's not clear in the spec how would we handle multiple pageEncoding attributes. |
67 |
|
68 |
} else if (!attributes.get(qName).equals(value)) { |
69 |
|
70 |
handleDuplicate(qName); |
71 |
} |
72 |
|
73 |
} else { |
74 |
attributes.put(qName, value); |
45 |
} |
75 |
} |
|
|
76 |
|
46 |
} |
77 |
} |
|
|
78 |
|
47 |
super.setAttributes(atts); |
79 |
super.setAttributes(atts); |
48 |
} |
80 |
} |
49 |
|
81 |
|
50 |
@Override |
82 |
@Override |
51 |
public void addAttribute(String uri, String localName, String qName, |
83 |
public void addAttribute(String uri, String localName, String qName, |
52 |
String type, String value) { |
84 |
String type, String value) { |
53 |
if (qNames.add(qName)) { |
85 |
|
54 |
super.addAttribute(uri, localName, qName, type, value); |
86 |
if (attributes.keySet().contains(qName)) { |
|
|
87 |
|
88 |
if (qName.equals("import")) { |
89 |
|
90 |
StringBuffer sb = new StringBuffer(3); |
91 |
sb.append(attributes.get(qName)); |
92 |
sb.append(","); |
93 |
sb.append(value); |
94 |
attributes.put(qName, sb.toString()); |
95 |
super.addAttribute(uri, localName, qName, type, sb.toString()); |
96 |
|
97 |
} else if (qName.equals("pageEncoding")) { |
98 |
|
99 |
// It's not clear in the spec on how to handle multiple pageEncoding attributes. |
100 |
|
101 |
} else if (!attributes.get(qName).equals(value)) { |
102 |
|
103 |
handleDuplicate(qName); |
104 |
} |
105 |
|
55 |
} else { |
106 |
} else { |
56 |
handleDuplicate(qName); |
107 |
attributes.put(qName, value); |
|
|
108 |
super.addAttribute(uri, localName, qName, type, value); |
57 |
} |
109 |
} |
|
|
110 |
|
58 |
} |
111 |
} |
59 |
|
112 |
|
60 |
@Override |
113 |
@Override |
61 |
public void setAttribute(int index, String uri, String localName, |
114 |
public void setAttribute(int index, String uri, String localName, |
62 |
String qName, String type, String value) { |
115 |
String qName, String type, String value) { |
63 |
qNames.remove(super.getQName(index)); |
116 |
|
64 |
if (qNames.add(qName)) { |
117 |
attributes.remove(super.getQName(index)); |
65 |
super.setAttribute(index, uri, localName, qName, type, value); |
118 |
attributes.put(qName, value); |
66 |
} else { |
119 |
super.setAttribute(index, uri, localName, qName, type, value); |
67 |
handleDuplicate(qName); |
120 |
|
68 |
} |
|
|
69 |
} |
121 |
} |
70 |
|
122 |
|
71 |
@Override |
123 |
@Override |
72 |
public void removeAttribute(int index) { |
124 |
public void removeAttribute(int index) { |
73 |
qNames.remove(super.getQName(index)); |
125 |
attributes.remove(super.getQName(index)); |
74 |
super.removeAttribute(index); |
126 |
super.removeAttribute(index); |
75 |
} |
127 |
} |
76 |
|
128 |
|
77 |
@Override |
129 |
@Override |
78 |
public void setQName(int index, String qName) { |
130 |
public void setQName(int index, String qName) { |
79 |
qNames.remove(super.getQName(index)); |
131 |
attributes.remove(super.getQName(index)); |
80 |
super.setQName(index, qName); |
132 |
super.setQName(index, qName); |
81 |
} |
133 |
} |
82 |
|
134 |
|