nokogiri 1.11.1-java → 1.11.2-java
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of nokogiri might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/LICENSE-DEPENDENCIES.md +12 -12
- data/LICENSE.md +1 -1
- data/README.md +20 -15
- data/ext/java/nokogiri/EncodingHandler.java +78 -59
- data/ext/java/nokogiri/HtmlDocument.java +137 -114
- data/ext/java/nokogiri/HtmlElementDescription.java +104 -87
- data/ext/java/nokogiri/HtmlEntityLookup.java +31 -26
- data/ext/java/nokogiri/HtmlSaxParserContext.java +220 -192
- data/ext/java/nokogiri/HtmlSaxPushParser.java +164 -139
- data/ext/java/nokogiri/NokogiriService.java +597 -526
- data/ext/java/nokogiri/XmlAttr.java +120 -96
- data/ext/java/nokogiri/XmlAttributeDecl.java +97 -76
- data/ext/java/nokogiri/XmlCdata.java +35 -26
- data/ext/java/nokogiri/XmlComment.java +48 -37
- data/ext/java/nokogiri/XmlDocument.java +642 -540
- data/ext/java/nokogiri/XmlDocumentFragment.java +127 -107
- data/ext/java/nokogiri/XmlDtd.java +450 -384
- data/ext/java/nokogiri/XmlElement.java +25 -18
- data/ext/java/nokogiri/XmlElementContent.java +345 -286
- data/ext/java/nokogiri/XmlElementDecl.java +126 -95
- data/ext/java/nokogiri/XmlEntityDecl.java +121 -97
- data/ext/java/nokogiri/XmlEntityReference.java +51 -42
- data/ext/java/nokogiri/XmlNamespace.java +177 -145
- data/ext/java/nokogiri/XmlNode.java +1843 -1588
- data/ext/java/nokogiri/XmlNodeSet.java +361 -299
- data/ext/java/nokogiri/XmlProcessingInstruction.java +49 -39
- data/ext/java/nokogiri/XmlReader.java +513 -418
- data/ext/java/nokogiri/XmlRelaxng.java +91 -78
- data/ext/java/nokogiri/XmlSaxParserContext.java +330 -285
- data/ext/java/nokogiri/XmlSaxPushParser.java +229 -190
- data/ext/java/nokogiri/XmlSchema.java +328 -263
- data/ext/java/nokogiri/XmlSyntaxError.java +113 -83
- data/ext/java/nokogiri/XmlText.java +57 -46
- data/ext/java/nokogiri/XmlXpathContext.java +240 -206
- data/ext/java/nokogiri/XsltStylesheet.java +282 -239
- data/ext/java/nokogiri/internals/ClosedStreamException.java +5 -2
- data/ext/java/nokogiri/internals/HtmlDomParserContext.java +199 -168
- data/ext/java/nokogiri/internals/IgnoreSchemaErrorsErrorHandler.java +17 -10
- data/ext/java/nokogiri/internals/NokogiriBlockingQueueInputStream.java +43 -16
- data/ext/java/nokogiri/internals/NokogiriDomParser.java +65 -50
- data/ext/java/nokogiri/internals/NokogiriEntityResolver.java +107 -88
- data/ext/java/nokogiri/internals/NokogiriErrorHandler.java +25 -18
- data/ext/java/nokogiri/internals/NokogiriHandler.java +316 -254
- data/ext/java/nokogiri/internals/NokogiriHelpers.java +738 -622
- data/ext/java/nokogiri/internals/NokogiriNamespaceCache.java +186 -143
- data/ext/java/nokogiri/internals/NokogiriNamespaceContext.java +83 -68
- data/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler.java +66 -49
- data/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler4NekoHtml.java +86 -69
- data/ext/java/nokogiri/internals/NokogiriStrictErrorHandler.java +44 -29
- data/ext/java/nokogiri/internals/NokogiriXPathFunction.java +118 -101
- data/ext/java/nokogiri/internals/NokogiriXPathFunctionResolver.java +34 -24
- data/ext/java/nokogiri/internals/NokogiriXPathVariableResolver.java +25 -17
- data/ext/java/nokogiri/internals/NokogiriXsltErrorListener.java +57 -42
- data/ext/java/nokogiri/internals/ParserContext.java +206 -179
- data/ext/java/nokogiri/internals/ReaderNode.java +478 -371
- data/ext/java/nokogiri/internals/SaveContextVisitor.java +822 -707
- data/ext/java/nokogiri/internals/SchemaErrorHandler.java +28 -19
- data/ext/java/nokogiri/internals/XalanDTMManagerPatch.java +129 -123
- data/ext/java/nokogiri/internals/XmlDeclHandler.java +5 -4
- data/ext/java/nokogiri/internals/XmlDomParserContext.java +208 -177
- data/ext/java/nokogiri/internals/XmlSaxParser.java +24 -17
- data/ext/java/nokogiri/internals/c14n/AttrCompare.java +71 -68
- data/ext/java/nokogiri/internals/c14n/C14nHelper.java +137 -118
- data/ext/java/nokogiri/internals/c14n/CanonicalFilter.java +27 -21
- data/ext/java/nokogiri/internals/c14n/CanonicalizationException.java +74 -61
- data/ext/java/nokogiri/internals/c14n/Canonicalizer.java +230 -205
- data/ext/java/nokogiri/internals/c14n/Canonicalizer11.java +572 -547
- data/ext/java/nokogiri/internals/c14n/Canonicalizer11_OmitComments.java +17 -10
- data/ext/java/nokogiri/internals/c14n/Canonicalizer11_WithComments.java +17 -10
- data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315.java +323 -302
- data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315Excl.java +232 -219
- data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315ExclOmitComments.java +22 -15
- data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315ExclWithComments.java +23 -16
- data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315OmitComments.java +23 -16
- data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315WithComments.java +22 -15
- data/ext/java/nokogiri/internals/c14n/CanonicalizerBase.java +575 -545
- data/ext/java/nokogiri/internals/c14n/CanonicalizerPhysical.java +141 -120
- data/ext/java/nokogiri/internals/c14n/CanonicalizerSpi.java +39 -38
- data/ext/java/nokogiri/internals/c14n/Constants.java +13 -10
- data/ext/java/nokogiri/internals/c14n/ElementProxy.java +279 -247
- data/ext/java/nokogiri/internals/c14n/HelperNodeList.java +66 -53
- data/ext/java/nokogiri/internals/c14n/IgnoreAllErrorHandler.java +44 -37
- data/ext/java/nokogiri/internals/c14n/InclusiveNamespaces.java +135 -120
- data/ext/java/nokogiri/internals/c14n/InvalidCanonicalizerException.java +59 -48
- data/ext/java/nokogiri/internals/c14n/NameSpaceSymbTable.java +384 -334
- data/ext/java/nokogiri/internals/c14n/NodeFilter.java +25 -24
- data/ext/java/nokogiri/internals/c14n/UtfHelpper.java +151 -140
- data/ext/java/nokogiri/internals/c14n/XMLUtils.java +456 -423
- data/ext/java/nokogiri/internals/dom2dtm/DOM2DTM.java +1466 -1500
- data/ext/java/nokogiri/internals/dom2dtm/DOM2DTMdefaultNamespaceDeclarationNode.java +626 -570
- data/ext/nokogiri/depend +34 -474
- data/ext/nokogiri/extconf.rb +253 -183
- data/ext/nokogiri/html_document.c +10 -15
- data/ext/nokogiri/html_element_description.c +84 -71
- data/ext/nokogiri/html_entity_lookup.c +21 -16
- data/ext/nokogiri/html_sax_parser_context.c +66 -65
- data/ext/nokogiri/html_sax_push_parser.c +29 -27
- data/ext/nokogiri/libxml2_backwards_compat.c +121 -0
- data/ext/nokogiri/nokogiri.c +171 -63
- data/ext/nokogiri/test_global_handlers.c +3 -4
- data/ext/nokogiri/xml_attr.c +15 -15
- data/ext/nokogiri/xml_attribute_decl.c +18 -18
- data/ext/nokogiri/xml_cdata.c +13 -18
- data/ext/nokogiri/xml_comment.c +19 -26
- data/ext/nokogiri/xml_document.c +221 -164
- data/ext/nokogiri/xml_document_fragment.c +13 -15
- data/ext/nokogiri/xml_dtd.c +54 -48
- data/ext/nokogiri/xml_element_content.c +30 -27
- data/ext/nokogiri/xml_element_decl.c +22 -22
- data/ext/nokogiri/xml_encoding_handler.c +17 -11
- data/ext/nokogiri/xml_entity_decl.c +32 -30
- data/ext/nokogiri/xml_entity_reference.c +16 -18
- data/ext/nokogiri/xml_namespace.c +56 -49
- data/ext/nokogiri/xml_node.c +338 -286
- data/ext/nokogiri/xml_node_set.c +168 -156
- data/ext/nokogiri/xml_processing_instruction.c +17 -19
- data/ext/nokogiri/xml_reader.c +191 -157
- data/ext/nokogiri/xml_relax_ng.c +29 -23
- data/ext/nokogiri/xml_sax_parser.c +117 -112
- data/ext/nokogiri/xml_sax_parser_context.c +100 -85
- data/ext/nokogiri/xml_sax_push_parser.c +34 -27
- data/ext/nokogiri/xml_schema.c +48 -42
- data/ext/nokogiri/xml_syntax_error.c +21 -23
- data/ext/nokogiri/xml_text.c +13 -17
- data/ext/nokogiri/xml_xpath_context.c +134 -127
- data/ext/nokogiri/xslt_stylesheet.c +157 -157
- data/lib/nokogiri.rb +1 -22
- data/lib/nokogiri/css/parser.rb +1 -1
- data/lib/nokogiri/extension.rb +26 -0
- data/lib/nokogiri/html/document_fragment.rb +15 -15
- data/lib/nokogiri/nokogiri.jar +0 -0
- data/lib/nokogiri/version/constant.rb +1 -1
- data/lib/nokogiri/version/info.rb +31 -8
- data/lib/nokogiri/xml/document.rb +31 -11
- data/lib/nokogiri/xml/node.rb +38 -42
- data/lib/nokogiri/xml/reader.rb +2 -9
- data/lib/nokogiri/xml/xpath.rb +1 -3
- data/lib/nokogiri/xml/xpath/syntax_error.rb +1 -1
- metadata +7 -8
- data/ext/nokogiri/xml_io.c +0 -63
- data/ext/nokogiri/xml_libxml2_hacks.c +0 -112
@@ -22,17 +22,24 @@ package nokogiri.internals.c14n;
|
|
22
22
|
/**
|
23
23
|
* @author Sean Mullan
|
24
24
|
*/
|
25
|
-
public class Canonicalizer11_OmitComments extends Canonicalizer11
|
25
|
+
public class Canonicalizer11_OmitComments extends Canonicalizer11
|
26
|
+
{
|
26
27
|
|
27
|
-
|
28
|
-
|
29
|
-
|
28
|
+
public
|
29
|
+
Canonicalizer11_OmitComments()
|
30
|
+
{
|
31
|
+
super(false);
|
32
|
+
}
|
30
33
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
+
public final String
|
35
|
+
engineGetURI()
|
36
|
+
{
|
37
|
+
return Canonicalizer.ALGO_ID_C14N11_OMIT_COMMENTS;
|
38
|
+
}
|
34
39
|
|
35
|
-
|
36
|
-
|
37
|
-
|
40
|
+
public final boolean
|
41
|
+
engineGetIncludeComments()
|
42
|
+
{
|
43
|
+
return false;
|
44
|
+
}
|
38
45
|
}
|
@@ -22,17 +22,24 @@ package nokogiri.internals.c14n;
|
|
22
22
|
/**
|
23
23
|
* @author Sean Mullan
|
24
24
|
*/
|
25
|
-
public class Canonicalizer11_WithComments extends Canonicalizer11
|
25
|
+
public class Canonicalizer11_WithComments extends Canonicalizer11
|
26
|
+
{
|
26
27
|
|
27
|
-
|
28
|
-
|
29
|
-
|
28
|
+
public
|
29
|
+
Canonicalizer11_WithComments()
|
30
|
+
{
|
31
|
+
super(true);
|
32
|
+
}
|
30
33
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
+
public final String
|
35
|
+
engineGetURI()
|
36
|
+
{
|
37
|
+
return Canonicalizer.ALGO_ID_C14N11_WITH_COMMENTS;
|
38
|
+
}
|
34
39
|
|
35
|
-
|
36
|
-
|
37
|
-
|
40
|
+
public final boolean
|
41
|
+
engineGetIncludeComments()
|
42
|
+
{
|
43
|
+
return true;
|
44
|
+
}
|
38
45
|
}
|
@@ -40,328 +40,349 @@ import org.w3c.dom.Node;
|
|
40
40
|
*
|
41
41
|
* @author Christian Geuer-Pollmann <geuerp@apache.org>
|
42
42
|
*/
|
43
|
-
public abstract class Canonicalizer20010315 extends CanonicalizerBase
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
int lastlevel = 0;
|
59
|
-
XmlsStackElement cur;
|
60
|
-
List<XmlsStackElement> levels = new ArrayList<XmlsStackElement>();
|
61
|
-
|
62
|
-
void push(int level) {
|
63
|
-
currentLevel = level;
|
64
|
-
if (currentLevel == -1) {
|
65
|
-
return;
|
66
|
-
}
|
67
|
-
cur = null;
|
68
|
-
while (lastlevel >= currentLevel) {
|
69
|
-
levels.remove(levels.size() - 1);
|
70
|
-
int newSize = levels.size();
|
71
|
-
if (newSize == 0) {
|
72
|
-
lastlevel = 0;
|
73
|
-
return;
|
74
|
-
}
|
75
|
-
lastlevel = (levels.get(newSize - 1)).level;
|
76
|
-
}
|
77
|
-
}
|
78
|
-
|
79
|
-
void addXmlnsAttr(Attr n) {
|
80
|
-
if (cur == null) {
|
81
|
-
cur = new XmlsStackElement();
|
82
|
-
cur.level = currentLevel;
|
83
|
-
levels.add(cur);
|
84
|
-
lastlevel = currentLevel;
|
85
|
-
}
|
86
|
-
cur.nodes.add(n);
|
87
|
-
}
|
88
|
-
|
89
|
-
void getXmlnsAttr(Collection<Attr> col) {
|
90
|
-
int size = levels.size() - 1;
|
91
|
-
if (cur == null) {
|
92
|
-
cur = new XmlsStackElement();
|
93
|
-
cur.level = currentLevel;
|
94
|
-
lastlevel = currentLevel;
|
95
|
-
levels.add(cur);
|
96
|
-
}
|
97
|
-
boolean parentRendered = false;
|
98
|
-
if (size == -1) {
|
99
|
-
parentRendered = true;
|
100
|
-
} else {
|
101
|
-
XmlsStackElement e = levels.get(size);
|
102
|
-
if (e.rendered && e.level + 1 == currentLevel) {
|
103
|
-
parentRendered = true;
|
104
|
-
}
|
105
|
-
}
|
106
|
-
if (parentRendered) {
|
107
|
-
col.addAll(cur.nodes);
|
108
|
-
cur.rendered = true;
|
109
|
-
return;
|
110
|
-
}
|
111
|
-
|
112
|
-
Map<String, Attr> loa = new HashMap<String, Attr>();
|
113
|
-
for (; size >= 0; size--) {
|
114
|
-
XmlsStackElement e = levels.get(size);
|
115
|
-
Iterator<Attr> it = e.nodes.iterator();
|
116
|
-
while (it.hasNext()) {
|
117
|
-
Attr n = it.next();
|
118
|
-
if (!loa.containsKey(n.getName())) {
|
119
|
-
loa.put(n.getName(), n);
|
120
|
-
}
|
121
|
-
}
|
122
|
-
}
|
123
|
-
|
124
|
-
cur.rendered = true;
|
125
|
-
col.addAll(loa.values());
|
126
|
-
}
|
127
|
-
|
43
|
+
public abstract class Canonicalizer20010315 extends CanonicalizerBase
|
44
|
+
{
|
45
|
+
private static final String XMLNS_URI = Constants.NamespaceSpecNS;
|
46
|
+
private static final String XML_LANG_URI = Constants.XML_LANG_SPACE_SpecNS;
|
47
|
+
|
48
|
+
private boolean firstCall = true;
|
49
|
+
private final SortedSet<Attr> result = new TreeSet<Attr>(COMPARE);
|
50
|
+
|
51
|
+
private static class XmlAttrStack
|
52
|
+
{
|
53
|
+
static class XmlsStackElement
|
54
|
+
{
|
55
|
+
int level;
|
56
|
+
boolean rendered = false;
|
57
|
+
List<Attr> nodes = new ArrayList<Attr>();
|
128
58
|
}
|
129
59
|
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
/** $todo$ well, should we throw UnsupportedOperationException ? */
|
153
|
-
throw new CanonicalizationException("c14n.Canonicalizer.UnsupportedOperation");
|
60
|
+
int currentLevel = 0;
|
61
|
+
int lastlevel = 0;
|
62
|
+
XmlsStackElement cur;
|
63
|
+
List<XmlsStackElement> levels = new ArrayList<XmlsStackElement>();
|
64
|
+
|
65
|
+
void
|
66
|
+
push(int level)
|
67
|
+
{
|
68
|
+
currentLevel = level;
|
69
|
+
if (currentLevel == -1) {
|
70
|
+
return;
|
71
|
+
}
|
72
|
+
cur = null;
|
73
|
+
while (lastlevel >= currentLevel) {
|
74
|
+
levels.remove(levels.size() - 1);
|
75
|
+
int newSize = levels.size();
|
76
|
+
if (newSize == 0) {
|
77
|
+
lastlevel = 0;
|
78
|
+
return;
|
79
|
+
}
|
80
|
+
lastlevel = (levels.get(newSize - 1)).level;
|
81
|
+
}
|
154
82
|
}
|
155
83
|
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
throws CanonicalizationException {
|
167
|
-
|
168
|
-
/** $todo$ well, should we throw UnsupportedOperationException ? */
|
169
|
-
throw new CanonicalizationException("c14n.Canonicalizer.UnsupportedOperation");
|
84
|
+
void
|
85
|
+
addXmlnsAttr(Attr n)
|
86
|
+
{
|
87
|
+
if (cur == null) {
|
88
|
+
cur = new XmlsStackElement();
|
89
|
+
cur.level = currentLevel;
|
90
|
+
levels.add(cur);
|
91
|
+
lastlevel = currentLevel;
|
92
|
+
}
|
93
|
+
cur.nodes.add(n);
|
170
94
|
}
|
171
95
|
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
if (!element.hasAttributes() && !firstCall) {
|
190
|
-
return null;
|
191
|
-
}
|
192
|
-
// result will contain the attrs which have to be output
|
193
|
-
final SortedSet<Attr> result = this.result;
|
194
|
-
result.clear();
|
195
|
-
|
196
|
-
if (element.hasAttributes()) {
|
197
|
-
NamedNodeMap attrs = element.getAttributes();
|
198
|
-
int attrsLength = attrs.getLength();
|
199
|
-
|
200
|
-
for (int i = 0; i < attrsLength; i++) {
|
201
|
-
Attr attribute = (Attr) attrs.item(i);
|
202
|
-
String NUri = attribute.getNamespaceURI();
|
203
|
-
String NName = attribute.getLocalName();
|
204
|
-
String NValue = attribute.getValue();
|
205
|
-
|
206
|
-
if (!XMLNS_URI.equals(NUri)) {
|
207
|
-
//It's not a namespace attr node. Add to the result and continue.
|
208
|
-
result.add(attribute);
|
209
|
-
} else if (!(XML.equals(NName) && XML_LANG_URI.equals(NValue))) {
|
210
|
-
//The default mapping for xml must not be output.
|
211
|
-
Node n = ns.addMappingAndRender(NName, NValue, attribute);
|
212
|
-
|
213
|
-
if (n != null) {
|
214
|
-
//Render the ns definition
|
215
|
-
result.add((Attr)n);
|
216
|
-
if (C14nHelper.namespaceIsRelative(attribute)) {
|
217
|
-
Object exArgs[] = { element.getTagName(), NName, attribute.getNodeValue() };
|
218
|
-
throw new CanonicalizationException(
|
219
|
-
"c14n.Canonicalizer.RelativeNamespace", exArgs
|
220
|
-
);
|
221
|
-
}
|
222
|
-
}
|
223
|
-
}
|
224
|
-
}
|
96
|
+
void
|
97
|
+
getXmlnsAttr(Collection<Attr> col)
|
98
|
+
{
|
99
|
+
int size = levels.size() - 1;
|
100
|
+
if (cur == null) {
|
101
|
+
cur = new XmlsStackElement();
|
102
|
+
cur.level = currentLevel;
|
103
|
+
lastlevel = currentLevel;
|
104
|
+
levels.add(cur);
|
105
|
+
}
|
106
|
+
boolean parentRendered = false;
|
107
|
+
if (size == -1) {
|
108
|
+
parentRendered = true;
|
109
|
+
} else {
|
110
|
+
XmlsStackElement e = levels.get(size);
|
111
|
+
if (e.rendered && e.level + 1 == currentLevel) {
|
112
|
+
parentRendered = true;
|
225
113
|
}
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
114
|
+
}
|
115
|
+
if (parentRendered) {
|
116
|
+
col.addAll(cur.nodes);
|
117
|
+
cur.rendered = true;
|
118
|
+
return;
|
119
|
+
}
|
120
|
+
|
121
|
+
Map<String, Attr> loa = new HashMap<String, Attr>();
|
122
|
+
for (; size >= 0; size--) {
|
123
|
+
XmlsStackElement e = levels.get(size);
|
124
|
+
Iterator<Attr> it = e.nodes.iterator();
|
125
|
+
while (it.hasNext()) {
|
126
|
+
Attr n = it.next();
|
127
|
+
if (!loa.containsKey(n.getName())) {
|
128
|
+
loa.put(n.getName(), n);
|
129
|
+
}
|
234
130
|
}
|
131
|
+
}
|
235
132
|
|
236
|
-
|
133
|
+
cur.rendered = true;
|
134
|
+
col.addAll(loa.values());
|
237
135
|
}
|
238
136
|
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
137
|
+
}
|
138
|
+
|
139
|
+
private final XmlAttrStack xmlattrStack = new XmlAttrStack();
|
140
|
+
|
141
|
+
/**
|
142
|
+
* Constructor Canonicalizer20010315
|
143
|
+
*
|
144
|
+
* @param includeComments
|
145
|
+
*/
|
146
|
+
public
|
147
|
+
Canonicalizer20010315(boolean includeComments)
|
148
|
+
{
|
149
|
+
super(includeComments);
|
150
|
+
}
|
151
|
+
|
152
|
+
/**
|
153
|
+
* Always throws a CanonicalizationException because this is inclusive c14n.
|
154
|
+
*
|
155
|
+
* @param xpathNodeSet
|
156
|
+
* @param inclusiveNamespaces
|
157
|
+
* @return none it always fails
|
158
|
+
* @throws CanonicalizationException always
|
159
|
+
*/
|
160
|
+
public byte[]
|
161
|
+
engineCanonicalizeXPathNodeSet(Set<Node> xpathNodeSet, String inclusiveNamespaces, CanonicalFilter filter)
|
162
|
+
throws CanonicalizationException
|
163
|
+
{
|
164
|
+
|
165
|
+
/** $todo$ well, should we throw UnsupportedOperationException ? */
|
166
|
+
throw new CanonicalizationException("c14n.Canonicalizer.UnsupportedOperation");
|
167
|
+
}
|
168
|
+
|
169
|
+
/**
|
170
|
+
* Always throws a CanonicalizationException because this is inclusive c14n.
|
171
|
+
*
|
172
|
+
* @param rootNode
|
173
|
+
* @param inclusiveNamespaces
|
174
|
+
* @return none it always fails
|
175
|
+
* @throws CanonicalizationException
|
176
|
+
*/
|
177
|
+
@Override
|
178
|
+
public byte[]
|
179
|
+
engineCanonicalizeSubTree(Node rootNode, String inclusiveNamespaces, CanonicalFilter filter)
|
180
|
+
throws CanonicalizationException
|
181
|
+
{
|
182
|
+
|
183
|
+
/** $todo$ well, should we throw UnsupportedOperationException ? */
|
184
|
+
throw new CanonicalizationException("c14n.Canonicalizer.UnsupportedOperation");
|
185
|
+
}
|
186
|
+
|
187
|
+
/**
|
188
|
+
* Returns the Attr[]s to be output for the given element.
|
189
|
+
* <br>
|
190
|
+
* The code of this method is a copy of {@link #handleAttributes(Element,
|
191
|
+
* NameSpaceSymbTable)},
|
192
|
+
* whereas it takes into account that subtree-c14n is -- well -- subtree-based.
|
193
|
+
* So if the element in question isRoot of c14n, it's parent is not in the
|
194
|
+
* node set, as well as all other ancestors.
|
195
|
+
*
|
196
|
+
* @param element
|
197
|
+
* @param ns
|
198
|
+
* @return the Attr[]s to be output
|
199
|
+
* @throws CanonicalizationException
|
200
|
+
*/
|
201
|
+
@Override
|
202
|
+
protected Iterator<Attr>
|
203
|
+
handleAttributesSubtree(Element element, NameSpaceSymbTable ns)
|
204
|
+
throws CanonicalizationException
|
205
|
+
{
|
206
|
+
if (!element.hasAttributes() && !firstCall) {
|
207
|
+
return null;
|
208
|
+
}
|
209
|
+
// result will contain the attrs which have to be output
|
210
|
+
final SortedSet<Attr> result = this.result;
|
211
|
+
result.clear();
|
212
|
+
|
213
|
+
if (element.hasAttributes()) {
|
214
|
+
NamedNodeMap attrs = element.getAttributes();
|
215
|
+
int attrsLength = attrs.getLength();
|
216
|
+
|
217
|
+
for (int i = 0; i < attrsLength; i++) {
|
218
|
+
Attr attribute = (Attr) attrs.item(i);
|
219
|
+
String NUri = attribute.getNamespaceURI();
|
220
|
+
String NName = attribute.getLocalName();
|
221
|
+
String NValue = attribute.getValue();
|
222
|
+
|
223
|
+
if (!XMLNS_URI.equals(NUri)) {
|
224
|
+
//It's not a namespace attr node. Add to the result and continue.
|
225
|
+
result.add(attribute);
|
226
|
+
} else if (!(XML.equals(NName) && XML_LANG_URI.equals(NValue))) {
|
227
|
+
//The default mapping for xml must not be output.
|
228
|
+
Node n = ns.addMappingAndRender(NName, NValue, attribute);
|
229
|
+
|
230
|
+
if (n != null) {
|
231
|
+
//Render the ns definition
|
232
|
+
result.add((Attr)n);
|
233
|
+
if (C14nHelper.namespaceIsRelative(attribute)) {
|
234
|
+
Object exArgs[] = { element.getTagName(), NName, attribute.getNodeValue() };
|
235
|
+
throw new CanonicalizationException(
|
236
|
+
"c14n.Canonicalizer.RelativeNamespace", exArgs
|
237
|
+
);
|
322
238
|
}
|
323
|
-
|
324
|
-
xmlattrStack.getXmlnsAttr(result);
|
325
|
-
ns.getUnrenderedNodes(result);
|
239
|
+
}
|
326
240
|
}
|
241
|
+
}
|
242
|
+
}
|
327
243
|
|
328
|
-
|
244
|
+
if (firstCall) {
|
245
|
+
//It is the first node of the subtree
|
246
|
+
//Obtain all the namespaces defined in the parents, and added to the output.
|
247
|
+
ns.getUnrenderedNodes(result);
|
248
|
+
//output the attributes in the xml namespace.
|
249
|
+
xmlattrStack.getXmlnsAttr(result);
|
250
|
+
firstCall = false;
|
329
251
|
}
|
330
252
|
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
253
|
+
return result.iterator();
|
254
|
+
}
|
255
|
+
|
256
|
+
/**
|
257
|
+
* Returns the Attr[]s to be output for the given element.
|
258
|
+
* <br>
|
259
|
+
* IMPORTANT: This method expects to work on a modified DOM tree, i.e. a DOM which has
|
260
|
+
* been prepared using {@link nokogiri.internals.c14n.security.utils.XMLUtils#circumventBug2650(
|
261
|
+
* org.w3c.dom.Document)}.
|
262
|
+
*
|
263
|
+
* @param element
|
264
|
+
* @param ns
|
265
|
+
* @return the Attr[]s to be output
|
266
|
+
* @throws CanonicalizationException
|
267
|
+
*/
|
268
|
+
@Override
|
269
|
+
protected Iterator<Attr>
|
270
|
+
handleAttributes(Element element, NameSpaceSymbTable ns)
|
271
|
+
throws CanonicalizationException
|
272
|
+
{
|
273
|
+
// result will contain the attrs which have to be output
|
274
|
+
xmlattrStack.push(ns.getLevel());
|
275
|
+
boolean isRealVisible = isVisibleDO(element, ns.getLevel()) == 1;
|
276
|
+
final SortedSet<Attr> result = this.result;
|
277
|
+
result.clear();
|
278
|
+
|
279
|
+
if (element.hasAttributes()) {
|
280
|
+
NamedNodeMap attrs = element.getAttributes();
|
281
|
+
int attrsLength = attrs.getLength();
|
282
|
+
|
283
|
+
for (int i = 0; i < attrsLength; i++) {
|
284
|
+
Attr attribute = (Attr) attrs.item(i);
|
285
|
+
String NUri = attribute.getNamespaceURI();
|
286
|
+
String NName = attribute.getLocalName();
|
287
|
+
String NValue = attribute.getValue();
|
288
|
+
|
289
|
+
if (!XMLNS_URI.equals(NUri)) {
|
290
|
+
//A non namespace definition node.
|
291
|
+
if (XML_LANG_URI.equals(NUri)) {
|
292
|
+
xmlattrStack.addXmlnsAttr(attribute);
|
293
|
+
} else if (isRealVisible) {
|
294
|
+
//The node is visible add the attribute to the list of output attributes.
|
295
|
+
result.add(attribute);
|
296
|
+
}
|
297
|
+
} else if (!XML.equals(NName) || !XML_LANG_URI.equals(NValue)) {
|
298
|
+
/* except omit namespace node with local name xml, which defines
|
299
|
+
* the xml prefix, if its string value is http://www.w3.org/XML/1998/namespace.
|
300
|
+
*/
|
301
|
+
//add the prefix binding to the ns symb table.
|
302
|
+
if (isVisible(attribute)) {
|
303
|
+
if (isRealVisible || !ns.removeMappingIfRender(NName)) {
|
304
|
+
//The xpath select this node output it if needed.
|
305
|
+
Node n = ns.addMappingAndRender(NName, NValue, attribute);
|
306
|
+
if (n != null) {
|
307
|
+
result.add((Attr)n);
|
308
|
+
if (C14nHelper.namespaceIsRelative(attribute)) {
|
309
|
+
Object exArgs[] = { element.getTagName(), NName, attribute.getNodeValue() };
|
310
|
+
throw new CanonicalizationException(
|
311
|
+
"c14n.Canonicalizer.RelativeNamespace", exArgs
|
312
|
+
);
|
347
313
|
}
|
348
|
-
|
349
|
-
xmlattrStack.addXmlnsAttr(attribute);
|
314
|
+
}
|
350
315
|
}
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
String NValue = e.getNamespaceURI();
|
355
|
-
String Name;
|
356
|
-
if (NName == null || NName.equals("")) {
|
357
|
-
NName = "xmlns";
|
358
|
-
Name = "xmlns";
|
316
|
+
} else {
|
317
|
+
if (isRealVisible && !XMLNS.equals(NName)) {
|
318
|
+
ns.removeMapping(NName);
|
359
319
|
} else {
|
360
|
-
|
320
|
+
ns.addMapping(NName, NValue, attribute);
|
361
321
|
}
|
362
|
-
|
363
|
-
n.setValue(NValue);
|
364
|
-
ns.addMapping(NName, NValue, n);
|
322
|
+
}
|
365
323
|
}
|
324
|
+
}
|
325
|
+
}
|
326
|
+
if (isRealVisible) {
|
327
|
+
//The element is visible, handle the xmlns definition
|
328
|
+
Attr xmlns = element.getAttributeNodeNS(XMLNS_URI, XMLNS);
|
329
|
+
Node n = null;
|
330
|
+
if (xmlns == null) {
|
331
|
+
//No xmlns def just get the already defined.
|
332
|
+
n = ns.getMapping(XMLNS);
|
333
|
+
} else if (!isVisible(xmlns)) {
|
334
|
+
//There is a definition but the xmlns is not selected by the xpath.
|
335
|
+
//then xmlns=""
|
336
|
+
n = ns.addMappingAndRender(XMLNS, "", nullNode);
|
337
|
+
}
|
338
|
+
//output the xmlns def if needed.
|
339
|
+
if (n != null) {
|
340
|
+
result.add((Attr)n);
|
341
|
+
}
|
342
|
+
//Float all xml:* attributes of the unselected parent elements to this one.
|
343
|
+
xmlattrStack.getXmlnsAttr(result);
|
344
|
+
ns.getUnrenderedNodes(result);
|
345
|
+
}
|
346
|
+
|
347
|
+
return result.iterator();
|
348
|
+
}
|
349
|
+
|
350
|
+
@Override
|
351
|
+
protected void
|
352
|
+
handleParent(Element e, NameSpaceSymbTable ns)
|
353
|
+
{
|
354
|
+
if (!e.hasAttributes() && e.getNamespaceURI() == null) {
|
355
|
+
return;
|
356
|
+
}
|
357
|
+
xmlattrStack.push(-1);
|
358
|
+
NamedNodeMap attrs = e.getAttributes();
|
359
|
+
int attrsLength = attrs.getLength();
|
360
|
+
for (int i = 0; i < attrsLength; i++) {
|
361
|
+
Attr attribute = (Attr) attrs.item(i);
|
362
|
+
String NName = attribute.getLocalName();
|
363
|
+
String NValue = attribute.getNodeValue();
|
364
|
+
|
365
|
+
if (Constants.NamespaceSpecNS.equals(attribute.getNamespaceURI())) {
|
366
|
+
if (!XML.equals(NName) || !Constants.XML_LANG_SPACE_SpecNS.equals(NValue)) {
|
367
|
+
ns.addMapping(NName, NValue, attribute);
|
368
|
+
}
|
369
|
+
} else if (XML_LANG_URI.equals(attribute.getNamespaceURI())) {
|
370
|
+
xmlattrStack.addXmlnsAttr(attribute);
|
371
|
+
}
|
372
|
+
}
|
373
|
+
if (e.getNamespaceURI() != null) {
|
374
|
+
String NName = e.getPrefix();
|
375
|
+
String NValue = e.getNamespaceURI();
|
376
|
+
String Name;
|
377
|
+
if (NName == null || NName.equals("")) {
|
378
|
+
NName = "xmlns";
|
379
|
+
Name = "xmlns";
|
380
|
+
} else {
|
381
|
+
Name = "xmlns:" + NName;
|
382
|
+
}
|
383
|
+
Attr n = e.getOwnerDocument().createAttributeNS("http://www.w3.org/2000/xmlns/", Name);
|
384
|
+
n.setValue(NValue);
|
385
|
+
ns.addMapping(NName, NValue, n);
|
366
386
|
}
|
387
|
+
}
|
367
388
|
}
|