nokogiri 1.11.1-java → 1.11.6-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.

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