Nokogiri_precompiled_aarch64_dedshit 1.14.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (263) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +44 -0
  3. data/LICENSE-DEPENDENCIES.md +2224 -0
  4. data/LICENSE.md +9 -0
  5. data/README.md +287 -0
  6. data/bin/nokogiri +131 -0
  7. data/dependencies.yml +41 -0
  8. data/ext/java/nokogiri/Html4Document.java +157 -0
  9. data/ext/java/nokogiri/Html4ElementDescription.java +133 -0
  10. data/ext/java/nokogiri/Html4EntityLookup.java +63 -0
  11. data/ext/java/nokogiri/Html4SaxParserContext.java +289 -0
  12. data/ext/java/nokogiri/Html4SaxPushParser.java +213 -0
  13. data/ext/java/nokogiri/NokogiriService.java +613 -0
  14. data/ext/java/nokogiri/XmlAttr.java +154 -0
  15. data/ext/java/nokogiri/XmlAttributeDecl.java +119 -0
  16. data/ext/java/nokogiri/XmlCdata.java +60 -0
  17. data/ext/java/nokogiri/XmlComment.java +77 -0
  18. data/ext/java/nokogiri/XmlDocument.java +705 -0
  19. data/ext/java/nokogiri/XmlDocumentFragment.java +163 -0
  20. data/ext/java/nokogiri/XmlDtd.java +516 -0
  21. data/ext/java/nokogiri/XmlElement.java +44 -0
  22. data/ext/java/nokogiri/XmlElementContent.java +412 -0
  23. data/ext/java/nokogiri/XmlElementDecl.java +148 -0
  24. data/ext/java/nokogiri/XmlEntityDecl.java +151 -0
  25. data/ext/java/nokogiri/XmlEntityReference.java +79 -0
  26. data/ext/java/nokogiri/XmlNamespace.java +193 -0
  27. data/ext/java/nokogiri/XmlNode.java +1938 -0
  28. data/ext/java/nokogiri/XmlNodeSet.java +463 -0
  29. data/ext/java/nokogiri/XmlProcessingInstruction.java +79 -0
  30. data/ext/java/nokogiri/XmlReader.java +615 -0
  31. data/ext/java/nokogiri/XmlRelaxng.java +133 -0
  32. data/ext/java/nokogiri/XmlSaxParserContext.java +329 -0
  33. data/ext/java/nokogiri/XmlSaxPushParser.java +288 -0
  34. data/ext/java/nokogiri/XmlSchema.java +423 -0
  35. data/ext/java/nokogiri/XmlSyntaxError.java +137 -0
  36. data/ext/java/nokogiri/XmlText.java +90 -0
  37. data/ext/java/nokogiri/XmlXpathContext.java +305 -0
  38. data/ext/java/nokogiri/XsltStylesheet.java +368 -0
  39. data/ext/java/nokogiri/internals/ClosedStreamException.java +13 -0
  40. data/ext/java/nokogiri/internals/HtmlDomParserContext.java +252 -0
  41. data/ext/java/nokogiri/internals/IgnoreSchemaErrorsErrorHandler.java +27 -0
  42. data/ext/java/nokogiri/internals/NokogiriBlockingQueueInputStream.java +178 -0
  43. data/ext/java/nokogiri/internals/NokogiriDomParser.java +99 -0
  44. data/ext/java/nokogiri/internals/NokogiriEntityResolver.java +140 -0
  45. data/ext/java/nokogiri/internals/NokogiriErrorHandler.java +65 -0
  46. data/ext/java/nokogiri/internals/NokogiriHandler.java +339 -0
  47. data/ext/java/nokogiri/internals/NokogiriHelpers.java +817 -0
  48. data/ext/java/nokogiri/internals/NokogiriNamespaceCache.java +228 -0
  49. data/ext/java/nokogiri/internals/NokogiriNamespaceContext.java +110 -0
  50. data/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler.java +86 -0
  51. data/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler4NekoHtml.java +107 -0
  52. data/ext/java/nokogiri/internals/NokogiriStrictErrorHandler.java +62 -0
  53. data/ext/java/nokogiri/internals/NokogiriXPathFunction.java +165 -0
  54. data/ext/java/nokogiri/internals/NokogiriXPathFunctionResolver.java +50 -0
  55. data/ext/java/nokogiri/internals/NokogiriXPathVariableResolver.java +37 -0
  56. data/ext/java/nokogiri/internals/NokogiriXsltErrorListener.java +70 -0
  57. data/ext/java/nokogiri/internals/ParserContext.java +262 -0
  58. data/ext/java/nokogiri/internals/ReaderNode.java +564 -0
  59. data/ext/java/nokogiri/internals/SaveContextVisitor.java +865 -0
  60. data/ext/java/nokogiri/internals/SchemaErrorHandler.java +50 -0
  61. data/ext/java/nokogiri/internals/XalanDTMManagerPatch.java +174 -0
  62. data/ext/java/nokogiri/internals/XmlDeclHandler.java +11 -0
  63. data/ext/java/nokogiri/internals/XmlDomParserContext.java +265 -0
  64. data/ext/java/nokogiri/internals/XmlSaxParser.java +40 -0
  65. data/ext/java/nokogiri/internals/c14n/AttrCompare.java +122 -0
  66. data/ext/java/nokogiri/internals/c14n/C14nHelper.java +178 -0
  67. data/ext/java/nokogiri/internals/c14n/CanonicalFilter.java +43 -0
  68. data/ext/java/nokogiri/internals/c14n/CanonicalizationException.java +106 -0
  69. data/ext/java/nokogiri/internals/c14n/Canonicalizer.java +278 -0
  70. data/ext/java/nokogiri/internals/c14n/Canonicalizer11.java +664 -0
  71. data/ext/java/nokogiri/internals/c14n/Canonicalizer11_OmitComments.java +45 -0
  72. data/ext/java/nokogiri/internals/c14n/Canonicalizer11_WithComments.java +45 -0
  73. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315.java +388 -0
  74. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315Excl.java +308 -0
  75. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315ExclOmitComments.java +47 -0
  76. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315ExclWithComments.java +51 -0
  77. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315OmitComments.java +51 -0
  78. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315WithComments.java +50 -0
  79. data/ext/java/nokogiri/internals/c14n/CanonicalizerBase.java +660 -0
  80. data/ext/java/nokogiri/internals/c14n/CanonicalizerPhysical.java +194 -0
  81. data/ext/java/nokogiri/internals/c14n/CanonicalizerSpi.java +77 -0
  82. data/ext/java/nokogiri/internals/c14n/Constants.java +45 -0
  83. data/ext/java/nokogiri/internals/c14n/ElementProxy.java +325 -0
  84. data/ext/java/nokogiri/internals/c14n/HelperNodeList.java +106 -0
  85. data/ext/java/nokogiri/internals/c14n/IgnoreAllErrorHandler.java +86 -0
  86. data/ext/java/nokogiri/internals/c14n/InclusiveNamespaces.java +181 -0
  87. data/ext/java/nokogiri/internals/c14n/InvalidCanonicalizerException.java +87 -0
  88. data/ext/java/nokogiri/internals/c14n/NameSpaceSymbTable.java +452 -0
  89. data/ext/java/nokogiri/internals/c14n/NodeFilter.java +52 -0
  90. data/ext/java/nokogiri/internals/c14n/UtfHelpper.java +190 -0
  91. data/ext/java/nokogiri/internals/c14n/XMLUtils.java +540 -0
  92. data/ext/java/nokogiri/internals/dom2dtm/DOM2DTM.java +1712 -0
  93. data/ext/java/nokogiri/internals/dom2dtm/DOM2DTMdefaultNamespaceDeclarationNode.java +737 -0
  94. data/ext/nokogiri/depend +38 -0
  95. data/ext/nokogiri/extconf.rb +1086 -0
  96. data/ext/nokogiri/gumbo.c +594 -0
  97. data/ext/nokogiri/html4_document.c +167 -0
  98. data/ext/nokogiri/html4_element_description.c +294 -0
  99. data/ext/nokogiri/html4_entity_lookup.c +37 -0
  100. data/ext/nokogiri/html4_sax_parser_context.c +116 -0
  101. data/ext/nokogiri/html4_sax_push_parser.c +95 -0
  102. data/ext/nokogiri/libxml2_backwards_compat.c +121 -0
  103. data/ext/nokogiri/nokogiri.c +265 -0
  104. data/ext/nokogiri/nokogiri.h +235 -0
  105. data/ext/nokogiri/test_global_handlers.c +42 -0
  106. data/ext/nokogiri/xml_attr.c +103 -0
  107. data/ext/nokogiri/xml_attribute_decl.c +70 -0
  108. data/ext/nokogiri/xml_cdata.c +57 -0
  109. data/ext/nokogiri/xml_comment.c +62 -0
  110. data/ext/nokogiri/xml_document.c +689 -0
  111. data/ext/nokogiri/xml_document_fragment.c +44 -0
  112. data/ext/nokogiri/xml_dtd.c +210 -0
  113. data/ext/nokogiri/xml_element_content.c +128 -0
  114. data/ext/nokogiri/xml_element_decl.c +69 -0
  115. data/ext/nokogiri/xml_encoding_handler.c +104 -0
  116. data/ext/nokogiri/xml_entity_decl.c +112 -0
  117. data/ext/nokogiri/xml_entity_reference.c +50 -0
  118. data/ext/nokogiri/xml_namespace.c +186 -0
  119. data/ext/nokogiri/xml_node.c +2426 -0
  120. data/ext/nokogiri/xml_node_set.c +496 -0
  121. data/ext/nokogiri/xml_processing_instruction.c +54 -0
  122. data/ext/nokogiri/xml_reader.c +794 -0
  123. data/ext/nokogiri/xml_relax_ng.c +164 -0
  124. data/ext/nokogiri/xml_sax_parser.c +316 -0
  125. data/ext/nokogiri/xml_sax_parser_context.c +283 -0
  126. data/ext/nokogiri/xml_sax_push_parser.c +166 -0
  127. data/ext/nokogiri/xml_schema.c +260 -0
  128. data/ext/nokogiri/xml_syntax_error.c +85 -0
  129. data/ext/nokogiri/xml_text.c +48 -0
  130. data/ext/nokogiri/xml_xpath_context.c +415 -0
  131. data/ext/nokogiri/xslt_stylesheet.c +363 -0
  132. data/gumbo-parser/CHANGES.md +63 -0
  133. data/gumbo-parser/Makefile +111 -0
  134. data/gumbo-parser/THANKS +27 -0
  135. data/gumbo-parser/src/Makefile +34 -0
  136. data/gumbo-parser/src/README.md +41 -0
  137. data/gumbo-parser/src/ascii.c +75 -0
  138. data/gumbo-parser/src/ascii.h +115 -0
  139. data/gumbo-parser/src/attribute.c +42 -0
  140. data/gumbo-parser/src/attribute.h +17 -0
  141. data/gumbo-parser/src/char_ref.c +22225 -0
  142. data/gumbo-parser/src/char_ref.h +29 -0
  143. data/gumbo-parser/src/char_ref.rl +2154 -0
  144. data/gumbo-parser/src/error.c +626 -0
  145. data/gumbo-parser/src/error.h +148 -0
  146. data/gumbo-parser/src/foreign_attrs.c +104 -0
  147. data/gumbo-parser/src/foreign_attrs.gperf +27 -0
  148. data/gumbo-parser/src/insertion_mode.h +33 -0
  149. data/gumbo-parser/src/macros.h +91 -0
  150. data/gumbo-parser/src/nokogiri_gumbo.h +944 -0
  151. data/gumbo-parser/src/parser.c +4878 -0
  152. data/gumbo-parser/src/parser.h +41 -0
  153. data/gumbo-parser/src/replacement.h +33 -0
  154. data/gumbo-parser/src/string_buffer.c +103 -0
  155. data/gumbo-parser/src/string_buffer.h +68 -0
  156. data/gumbo-parser/src/string_piece.c +48 -0
  157. data/gumbo-parser/src/svg_attrs.c +174 -0
  158. data/gumbo-parser/src/svg_attrs.gperf +77 -0
  159. data/gumbo-parser/src/svg_tags.c +137 -0
  160. data/gumbo-parser/src/svg_tags.gperf +55 -0
  161. data/gumbo-parser/src/tag.c +223 -0
  162. data/gumbo-parser/src/tag_lookup.c +382 -0
  163. data/gumbo-parser/src/tag_lookup.gperf +170 -0
  164. data/gumbo-parser/src/tag_lookup.h +13 -0
  165. data/gumbo-parser/src/token_buffer.c +79 -0
  166. data/gumbo-parser/src/token_buffer.h +71 -0
  167. data/gumbo-parser/src/token_type.h +17 -0
  168. data/gumbo-parser/src/tokenizer.c +3463 -0
  169. data/gumbo-parser/src/tokenizer.h +112 -0
  170. data/gumbo-parser/src/tokenizer_states.h +339 -0
  171. data/gumbo-parser/src/utf8.c +245 -0
  172. data/gumbo-parser/src/utf8.h +164 -0
  173. data/gumbo-parser/src/util.c +66 -0
  174. data/gumbo-parser/src/util.h +34 -0
  175. data/gumbo-parser/src/vector.c +111 -0
  176. data/gumbo-parser/src/vector.h +45 -0
  177. data/lib/nokogiri/class_resolver.rb +67 -0
  178. data/lib/nokogiri/css/node.rb +54 -0
  179. data/lib/nokogiri/css/parser.rb +770 -0
  180. data/lib/nokogiri/css/parser.y +277 -0
  181. data/lib/nokogiri/css/parser_extras.rb +96 -0
  182. data/lib/nokogiri/css/syntax_error.rb +9 -0
  183. data/lib/nokogiri/css/tokenizer.rb +155 -0
  184. data/lib/nokogiri/css/tokenizer.rex +56 -0
  185. data/lib/nokogiri/css/xpath_visitor.rb +359 -0
  186. data/lib/nokogiri/css.rb +66 -0
  187. data/lib/nokogiri/decorators/slop.rb +44 -0
  188. data/lib/nokogiri/encoding_handler.rb +57 -0
  189. data/lib/nokogiri/extension.rb +32 -0
  190. data/lib/nokogiri/gumbo.rb +15 -0
  191. data/lib/nokogiri/html.rb +48 -0
  192. data/lib/nokogiri/html4/builder.rb +37 -0
  193. data/lib/nokogiri/html4/document.rb +214 -0
  194. data/lib/nokogiri/html4/document_fragment.rb +54 -0
  195. data/lib/nokogiri/html4/element_description.rb +25 -0
  196. data/lib/nokogiri/html4/element_description_defaults.rb +572 -0
  197. data/lib/nokogiri/html4/encoding_reader.rb +121 -0
  198. data/lib/nokogiri/html4/entity_lookup.rb +15 -0
  199. data/lib/nokogiri/html4/sax/parser.rb +63 -0
  200. data/lib/nokogiri/html4/sax/parser_context.rb +20 -0
  201. data/lib/nokogiri/html4/sax/push_parser.rb +37 -0
  202. data/lib/nokogiri/html4.rb +47 -0
  203. data/lib/nokogiri/html5/document.rb +168 -0
  204. data/lib/nokogiri/html5/document_fragment.rb +90 -0
  205. data/lib/nokogiri/html5/node.rb +98 -0
  206. data/lib/nokogiri/html5.rb +389 -0
  207. data/lib/nokogiri/jruby/dependencies.rb +3 -0
  208. data/lib/nokogiri/jruby/isorelax/isorelax/20030108/isorelax-20030108.jar +0 -0
  209. data/lib/nokogiri/jruby/net/sf/saxon/Saxon-HE/9.6.0-4/Saxon-HE-9.6.0-4.jar +0 -0
  210. data/lib/nokogiri/jruby/net/sourceforge/htmlunit/neko-htmlunit/2.63.0/neko-htmlunit-2.63.0.jar +0 -0
  211. data/lib/nokogiri/jruby/nokogiri_jars.rb +43 -0
  212. data/lib/nokogiri/jruby/nu/validator/jing/20200702VNU/jing-20200702VNU.jar +0 -0
  213. data/lib/nokogiri/jruby/org/nokogiri/nekodtd/0.1.11.noko2/nekodtd-0.1.11.noko2.jar +0 -0
  214. data/lib/nokogiri/jruby/xalan/serializer/2.7.3/serializer-2.7.3.jar +0 -0
  215. data/lib/nokogiri/jruby/xalan/xalan/2.7.3/xalan-2.7.3.jar +0 -0
  216. data/lib/nokogiri/jruby/xerces/xercesImpl/2.12.2/xercesImpl-2.12.2.jar +0 -0
  217. data/lib/nokogiri/jruby/xml-apis/xml-apis/1.4.01/xml-apis-1.4.01.jar +0 -0
  218. data/lib/nokogiri/syntax_error.rb +6 -0
  219. data/lib/nokogiri/version/constant.rb +6 -0
  220. data/lib/nokogiri/version/info.rb +223 -0
  221. data/lib/nokogiri/version.rb +4 -0
  222. data/lib/nokogiri/xml/attr.rb +66 -0
  223. data/lib/nokogiri/xml/attribute_decl.rb +20 -0
  224. data/lib/nokogiri/xml/builder.rb +487 -0
  225. data/lib/nokogiri/xml/cdata.rb +13 -0
  226. data/lib/nokogiri/xml/character_data.rb +9 -0
  227. data/lib/nokogiri/xml/document.rb +471 -0
  228. data/lib/nokogiri/xml/document_fragment.rb +205 -0
  229. data/lib/nokogiri/xml/dtd.rb +34 -0
  230. data/lib/nokogiri/xml/element_content.rb +38 -0
  231. data/lib/nokogiri/xml/element_decl.rb +15 -0
  232. data/lib/nokogiri/xml/entity_decl.rb +21 -0
  233. data/lib/nokogiri/xml/entity_reference.rb +20 -0
  234. data/lib/nokogiri/xml/namespace.rb +58 -0
  235. data/lib/nokogiri/xml/node/save_options.rb +68 -0
  236. data/lib/nokogiri/xml/node.rb +1563 -0
  237. data/lib/nokogiri/xml/node_set.rb +447 -0
  238. data/lib/nokogiri/xml/notation.rb +19 -0
  239. data/lib/nokogiri/xml/parse_options.rb +213 -0
  240. data/lib/nokogiri/xml/pp/character_data.rb +21 -0
  241. data/lib/nokogiri/xml/pp/node.rb +57 -0
  242. data/lib/nokogiri/xml/pp.rb +4 -0
  243. data/lib/nokogiri/xml/processing_instruction.rb +11 -0
  244. data/lib/nokogiri/xml/reader.rb +105 -0
  245. data/lib/nokogiri/xml/relax_ng.rb +38 -0
  246. data/lib/nokogiri/xml/sax/document.rb +167 -0
  247. data/lib/nokogiri/xml/sax/parser.rb +125 -0
  248. data/lib/nokogiri/xml/sax/parser_context.rb +21 -0
  249. data/lib/nokogiri/xml/sax/push_parser.rb +61 -0
  250. data/lib/nokogiri/xml/sax.rb +6 -0
  251. data/lib/nokogiri/xml/schema.rb +73 -0
  252. data/lib/nokogiri/xml/searchable.rb +270 -0
  253. data/lib/nokogiri/xml/syntax_error.rb +72 -0
  254. data/lib/nokogiri/xml/text.rb +11 -0
  255. data/lib/nokogiri/xml/xpath/syntax_error.rb +13 -0
  256. data/lib/nokogiri/xml/xpath.rb +21 -0
  257. data/lib/nokogiri/xml/xpath_context.rb +16 -0
  258. data/lib/nokogiri/xml.rb +76 -0
  259. data/lib/nokogiri/xslt/stylesheet.rb +27 -0
  260. data/lib/nokogiri/xslt.rb +65 -0
  261. data/lib/nokogiri.rb +120 -0
  262. data/lib/xsd/xmlparser/nokogiri.rb +106 -0
  263. metadata +391 -0
@@ -0,0 +1,664 @@
1
+ /**
2
+ * Licensed to the Apache Software Foundation (ASF) under one
3
+ * or more contributor license agreements. See the NOTICE file
4
+ * distributed with this work for additional information
5
+ * regarding copyright ownership. The ASF licenses this file
6
+ * to you under the Apache License, Version 2.0 (the
7
+ * "License"); you may not use this file except in compliance
8
+ * with the License. You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing,
13
+ * software distributed under the License is distributed on an
14
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+ * KIND, either express or implied. See the License for the
16
+ * specific language governing permissions and limitations
17
+ * under the License.
18
+ */
19
+ package nokogiri.internals.c14n;
20
+
21
+ import java.net.URI;
22
+ import java.net.URISyntaxException;
23
+ import java.util.ArrayList;
24
+ import java.util.Collection;
25
+ import java.util.HashMap;
26
+ import java.util.Iterator;
27
+ import java.util.List;
28
+ import java.util.Map;
29
+ import java.util.SortedSet;
30
+ import java.util.TreeSet;
31
+
32
+
33
+ import org.w3c.dom.Attr;
34
+ import org.w3c.dom.Element;
35
+ import org.w3c.dom.NamedNodeMap;
36
+ import org.w3c.dom.Node;
37
+
38
+ /**
39
+ * Implements <A HREF="http://www.w3.org/TR/2008/PR-xml-c14n11-20080129/">
40
+ * Canonical XML Version 1.1</A>, a W3C Proposed Recommendation from 29
41
+ * January 2008.
42
+ *
43
+ * @author Sean Mullan
44
+ * @author Raul Benito
45
+ */
46
+ public abstract class Canonicalizer11 extends CanonicalizerBase
47
+ {
48
+
49
+ private static final String XMLNS_URI = Constants.NamespaceSpecNS;
50
+ private static final String XML_LANG_URI = Constants.XML_LANG_SPACE_SpecNS;
51
+ private final SortedSet<Attr> result = new TreeSet<Attr>(COMPARE);
52
+
53
+ private boolean firstCall = true;
54
+
55
+ private static class XmlAttrStack
56
+ {
57
+ static class XmlsStackElement
58
+ {
59
+ int level;
60
+ boolean rendered = false;
61
+ List<Attr> nodes = new ArrayList<Attr>();
62
+ }
63
+
64
+ int currentLevel = 0;
65
+ int lastlevel = 0;
66
+ XmlsStackElement cur;
67
+ List<XmlsStackElement> levels = new ArrayList<XmlsStackElement>();
68
+
69
+ void
70
+ push(int level)
71
+ {
72
+ currentLevel = level;
73
+ if (currentLevel == -1) {
74
+ return;
75
+ }
76
+ cur = null;
77
+ while (lastlevel >= currentLevel) {
78
+ levels.remove(levels.size() - 1);
79
+ int newSize = levels.size();
80
+ if (newSize == 0) {
81
+ lastlevel = 0;
82
+ return;
83
+ }
84
+ lastlevel = (levels.get(newSize - 1)).level;
85
+ }
86
+ }
87
+
88
+ void
89
+ addXmlnsAttr(Attr n)
90
+ {
91
+ if (cur == null) {
92
+ cur = new XmlsStackElement();
93
+ cur.level = currentLevel;
94
+ levels.add(cur);
95
+ lastlevel = currentLevel;
96
+ }
97
+ cur.nodes.add(n);
98
+ }
99
+
100
+ void
101
+ getXmlnsAttr(Collection<Attr> col) throws CanonicalizationException
102
+ {
103
+ int size = levels.size() - 1;
104
+ if (cur == null) {
105
+ cur = new XmlsStackElement();
106
+ cur.level = currentLevel;
107
+ lastlevel = currentLevel;
108
+ levels.add(cur);
109
+ }
110
+ boolean parentRendered = false;
111
+ if (size == -1) {
112
+ parentRendered = true;
113
+ } else {
114
+ XmlsStackElement e = levels.get(size);
115
+ if (e.rendered && e.level + 1 == currentLevel) {
116
+ parentRendered = true;
117
+ }
118
+ }
119
+ if (parentRendered) {
120
+ col.addAll(cur.nodes);
121
+ cur.rendered = true;
122
+ return;
123
+ }
124
+
125
+ Map<String, Attr> loa = new HashMap<String, Attr>();
126
+ List<Attr> baseAttrs = new ArrayList<Attr>();
127
+ boolean successiveOmitted = true;
128
+ for (; size >= 0; size--) {
129
+ XmlsStackElement e = levels.get(size);
130
+ if (e.rendered) {
131
+ successiveOmitted = false;
132
+ }
133
+ Iterator<Attr> it = e.nodes.iterator();
134
+ while (it.hasNext() && successiveOmitted) {
135
+ Attr n = it.next();
136
+ if (n.getLocalName().equals("base") && !e.rendered) {
137
+ baseAttrs.add(n);
138
+ } else if (!loa.containsKey(n.getName())) {
139
+ loa.put(n.getName(), n);
140
+ }
141
+ }
142
+ }
143
+ if (!baseAttrs.isEmpty()) {
144
+ Iterator<Attr> it = col.iterator();
145
+ String base = null;
146
+ Attr baseAttr = null;
147
+ while (it.hasNext()) {
148
+ Attr n = it.next();
149
+ if (n.getLocalName().equals("base")) {
150
+ base = n.getValue();
151
+ baseAttr = n;
152
+ break;
153
+ }
154
+ }
155
+ it = baseAttrs.iterator();
156
+ while (it.hasNext()) {
157
+ Attr n = it.next();
158
+ if (base == null) {
159
+ base = n.getValue();
160
+ baseAttr = n;
161
+ } else {
162
+ try {
163
+ base = joinURI(n.getValue(), base);
164
+ } catch (URISyntaxException e1) {
165
+ throw new CanonicalizationException(e1);
166
+ }
167
+ }
168
+ }
169
+ if (base != null && base.length() != 0) {
170
+ baseAttr.setValue(base);
171
+ col.add(baseAttr);
172
+ }
173
+ }
174
+
175
+ cur.rendered = true;
176
+ col.addAll(loa.values());
177
+ }
178
+ }
179
+
180
+ private final XmlAttrStack xmlattrStack = new XmlAttrStack();
181
+
182
+ /**
183
+ * Constructor Canonicalizer11
184
+ *
185
+ * @param includeComments
186
+ */
187
+ public
188
+ Canonicalizer11(boolean includeComments)
189
+ {
190
+ super(includeComments);
191
+ }
192
+
193
+ /**
194
+ * Always throws a CanonicalizationException because this is inclusive c14n.
195
+ *
196
+ * @param rootNode
197
+ * @param inclusiveNamespaces
198
+ * @return none it always fails
199
+ * @throws CanonicalizationException
200
+ */
201
+ public byte[]
202
+ engineCanonicalizeSubTree(
203
+ Node rootNode, String inclusiveNamespaces, CanonicalFilter filter
204
+ ) throws CanonicalizationException
205
+ {
206
+ throw new CanonicalizationException("c14n.Canonicalizer.UnsupportedOperation");
207
+ }
208
+
209
+ /**
210
+ * Returns the Attr[]s to be output for the given element.
211
+ * <br>
212
+ * The code of this method is a copy of {@link #handleAttributes(Element,
213
+ * NameSpaceSymbTable)},
214
+ * whereas it takes into account that subtree-c14n is -- well --
215
+ * subtree-based.
216
+ * So if the element in question isRoot of c14n, it's parent is not in the
217
+ * node set, as well as all other ancestors.
218
+ *
219
+ * @param element
220
+ * @param ns
221
+ * @return the Attr[]s to be output
222
+ * @throws CanonicalizationException
223
+ * @throws URISyntaxException
224
+ */
225
+ @Override
226
+ protected Iterator<Attr>
227
+ handleAttributesSubtree(Element element, NameSpaceSymbTable ns)
228
+ throws CanonicalizationException
229
+ {
230
+ if (!element.hasAttributes() && !firstCall) {
231
+ return null;
232
+ }
233
+ // result will contain the attrs which have to be output
234
+ final SortedSet<Attr> result = this.result;
235
+ result.clear();
236
+
237
+ if (element.hasAttributes()) {
238
+ NamedNodeMap attrs = element.getAttributes();
239
+ int attrsLength = attrs.getLength();
240
+
241
+ for (int i = 0; i < attrsLength; i++) {
242
+ Attr attribute = (Attr) attrs.item(i);
243
+ String NUri = attribute.getNamespaceURI();
244
+ String NName = attribute.getLocalName();
245
+ String NValue = attribute.getValue();
246
+
247
+ if (!XMLNS_URI.equals(NUri)) {
248
+ // It's not a namespace attr node. Add to the result and continue.
249
+ result.add(attribute);
250
+ } else if (!(XML.equals(NName) && XML_LANG_URI.equals(NValue))) {
251
+ // The default mapping for xml must not be output.
252
+ Node n = ns.addMappingAndRender(NName, NValue, attribute);
253
+
254
+ if (n != null) {
255
+ // Render the ns definition
256
+ result.add((Attr)n);
257
+ if (C14nHelper.namespaceIsRelative(attribute)) {
258
+ Object exArgs[] = {element.getTagName(), NName, attribute.getNodeValue()};
259
+ throw new CanonicalizationException(
260
+ "c14n.Canonicalizer.RelativeNamespace", exArgs
261
+ );
262
+ }
263
+ }
264
+ }
265
+ }
266
+ }
267
+
268
+ if (firstCall) {
269
+ // It is the first node of the subtree
270
+ // Obtain all the namespaces defined in the parents, and added to the output.
271
+ ns.getUnrenderedNodes(result);
272
+ // output the attributes in the xml namespace.
273
+ xmlattrStack.getXmlnsAttr(result);
274
+ firstCall = false;
275
+ }
276
+
277
+ return result.iterator();
278
+ }
279
+
280
+ /**
281
+ * Returns the Attr[]s to be output for the given element.
282
+ * <br>
283
+ * IMPORTANT: This method expects to work on a modified DOM tree, i.e. a
284
+ * DOM which has been prepared using
285
+ * {@link nokogiri.internals.c14n.security.utils.XMLUtils#circumventBug2650(
286
+ * org.w3c.dom.Document)}.
287
+ *
288
+ * @param element
289
+ * @param ns
290
+ * @return the Attr[]s to be output
291
+ * @throws CanonicalizationException
292
+ */
293
+ @Override
294
+ protected Iterator<Attr>
295
+ handleAttributes(Element element, NameSpaceSymbTable ns)
296
+ throws CanonicalizationException
297
+ {
298
+ // result will contain the attrs which have to be output
299
+ xmlattrStack.push(ns.getLevel());
300
+ boolean isRealVisible = isVisibleDO(element, ns.getLevel()) == 1;
301
+ final SortedSet<Attr> result = this.result;
302
+ result.clear();
303
+
304
+ if (element.hasAttributes()) {
305
+ NamedNodeMap attrs = element.getAttributes();
306
+ int attrsLength = attrs.getLength();
307
+
308
+ for (int i = 0; i < attrsLength; i++) {
309
+ Attr attribute = (Attr) attrs.item(i);
310
+ String NUri = attribute.getNamespaceURI();
311
+ String NName = attribute.getLocalName();
312
+ String NValue = attribute.getValue();
313
+
314
+ if (!XMLNS_URI.equals(NUri)) {
315
+ //A non namespace definition node.
316
+ if (XML_LANG_URI.equals(NUri)) {
317
+ if (NName.equals("id")) {
318
+ if (isRealVisible) {
319
+ // treat xml:id like any other attribute
320
+ // (emit it, but don't inherit it)
321
+ result.add(attribute);
322
+ }
323
+ } else {
324
+ xmlattrStack.addXmlnsAttr(attribute);
325
+ }
326
+ } else if (isRealVisible) {
327
+ //The node is visible add the attribute to the list of output attributes.
328
+ result.add(attribute);
329
+ }
330
+ } else if (!XML.equals(NName) || !XML_LANG_URI.equals(NValue)) {
331
+ /* except omit namespace node with local name xml, which defines
332
+ * the xml prefix, if its string value is
333
+ * http://www.w3.org/XML/1998/namespace.
334
+ */
335
+ // add the prefix binding to the ns symb table.
336
+ if (isVisible(attribute)) {
337
+ if (isRealVisible || !ns.removeMappingIfRender(NName)) {
338
+ // The xpath select this node output it if needed.
339
+ Node n = ns.addMappingAndRender(NName, NValue, attribute);
340
+ if (n != null) {
341
+ result.add((Attr)n);
342
+ if (C14nHelper.namespaceIsRelative(attribute)) {
343
+ Object exArgs[] = { element.getTagName(), NName, attribute.getNodeValue() };
344
+ throw new CanonicalizationException(
345
+ "c14n.Canonicalizer.RelativeNamespace", exArgs
346
+ );
347
+ }
348
+ }
349
+ }
350
+ } else {
351
+ if (isRealVisible && !XMLNS.equals(NName)) {
352
+ ns.removeMapping(NName);
353
+ } else {
354
+ ns.addMapping(NName, NValue, attribute);
355
+ }
356
+ }
357
+ }
358
+ }
359
+ }
360
+
361
+ if (isRealVisible) {
362
+ //The element is visible, handle the xmlns definition
363
+ Attr xmlns = element.getAttributeNodeNS(XMLNS_URI, XMLNS);
364
+ Node n = null;
365
+ if (xmlns == null) {
366
+ //No xmlns def just get the already defined.
367
+ n = ns.getMapping(XMLNS);
368
+ } else if (!isVisible(xmlns)) {
369
+ //There is a definition but the xmlns is not selected by the xpath.
370
+ //then xmlns=""
371
+ n = ns.addMappingAndRender(XMLNS, "", nullNode);
372
+ }
373
+ //output the xmlns def if needed.
374
+ if (n != null) {
375
+ result.add((Attr)n);
376
+ }
377
+ //Float all xml:* attributes of the unselected parent elements to this one.
378
+ xmlattrStack.getXmlnsAttr(result);
379
+ ns.getUnrenderedNodes(result);
380
+ }
381
+
382
+ return result.iterator();
383
+ }
384
+
385
+ @Override
386
+ protected void
387
+ handleParent(Element e, NameSpaceSymbTable ns)
388
+ {
389
+ if (!e.hasAttributes() && e.getNamespaceURI() == null) {
390
+ return;
391
+ }
392
+ xmlattrStack.push(-1);
393
+ NamedNodeMap attrs = e.getAttributes();
394
+ int attrsLength = attrs.getLength();
395
+ for (int i = 0; i < attrsLength; i++) {
396
+ Attr attribute = (Attr) attrs.item(i);
397
+ String NName = attribute.getLocalName();
398
+ String NValue = attribute.getNodeValue();
399
+
400
+ if (Constants.NamespaceSpecNS.equals(attribute.getNamespaceURI())) {
401
+ if (!XML.equals(NName) || !Constants.XML_LANG_SPACE_SpecNS.equals(NValue)) {
402
+ ns.addMapping(NName, NValue, attribute);
403
+ }
404
+ } else if (!"id".equals(NName) && XML_LANG_URI.equals(attribute.getNamespaceURI())) {
405
+ xmlattrStack.addXmlnsAttr(attribute);
406
+ }
407
+ }
408
+ if (e.getNamespaceURI() != null) {
409
+ String NName = e.getPrefix();
410
+ String NValue = e.getNamespaceURI();
411
+ String Name;
412
+ if (NName == null || NName.equals("")) {
413
+ NName = "xmlns";
414
+ Name = "xmlns";
415
+ } else {
416
+ Name = "xmlns:" + NName;
417
+ }
418
+ Attr n = e.getOwnerDocument().createAttributeNS("http://www.w3.org/2000/xmlns/", Name);
419
+ n.setValue(NValue);
420
+ ns.addMapping(NName, NValue, n);
421
+ }
422
+ }
423
+
424
+ private static String
425
+ joinURI(String baseURI, String relativeURI) throws URISyntaxException
426
+ {
427
+ String bscheme = null;
428
+ String bauthority = null;
429
+ String bpath = "";
430
+ String bquery = null;
431
+
432
+ // pre-parse the baseURI
433
+ if (baseURI != null) {
434
+ if (baseURI.endsWith("..")) {
435
+ baseURI = baseURI + "/";
436
+ }
437
+ URI base = new URI(baseURI);
438
+ bscheme = base.getScheme();
439
+ bauthority = base.getAuthority();
440
+ bpath = base.getPath();
441
+ bquery = base.getQuery();
442
+ }
443
+
444
+ URI r = new URI(relativeURI);
445
+ String rscheme = r.getScheme();
446
+ String rauthority = r.getAuthority();
447
+ String rpath = r.getPath();
448
+ String rquery = r.getQuery();
449
+
450
+ String tscheme, tauthority, tpath, tquery;
451
+ if (rscheme != null && rscheme.equals(bscheme)) {
452
+ rscheme = null;
453
+ }
454
+ if (rscheme != null) {
455
+ tscheme = rscheme;
456
+ tauthority = rauthority;
457
+ tpath = removeDotSegments(rpath);
458
+ tquery = rquery;
459
+ } else {
460
+ if (rauthority != null) {
461
+ tauthority = rauthority;
462
+ tpath = removeDotSegments(rpath);
463
+ tquery = rquery;
464
+ } else {
465
+ if (rpath.length() == 0) {
466
+ tpath = bpath;
467
+ if (rquery != null) {
468
+ tquery = rquery;
469
+ } else {
470
+ tquery = bquery;
471
+ }
472
+ } else {
473
+ if (rpath.startsWith("/")) {
474
+ tpath = removeDotSegments(rpath);
475
+ } else {
476
+ if (bauthority != null && bpath.length() == 0) {
477
+ tpath = "/" + rpath;
478
+ } else {
479
+ int last = bpath.lastIndexOf('/');
480
+ if (last == -1) {
481
+ tpath = rpath;
482
+ } else {
483
+ tpath = bpath.substring(0, last + 1) + rpath;
484
+ }
485
+ }
486
+ tpath = removeDotSegments(tpath);
487
+ }
488
+ tquery = rquery;
489
+ }
490
+ tauthority = bauthority;
491
+ }
492
+ tscheme = bscheme;
493
+ }
494
+ return new URI(tscheme, tauthority, tpath, tquery, null).toString();
495
+ }
496
+
497
+ private static String
498
+ removeDotSegments(String path)
499
+ {
500
+
501
+ // 1. The input buffer is initialized with the now-appended path
502
+ // components then replace occurrences of "//" in the input buffer
503
+ // with "/" until no more occurrences of "//" are in the input buffer.
504
+ String input = path;
505
+ while (input.indexOf("//") > -1) {
506
+ input = input.replaceAll("//", "/");
507
+ }
508
+
509
+ // Initialize the output buffer with the empty string.
510
+ StringBuilder output = new StringBuilder();
511
+
512
+ // If the input buffer starts with a root slash "/" then move this
513
+ // character to the output buffer.
514
+ if (input.charAt(0) == '/') {
515
+ output.append('/');
516
+ input = input.substring(1);
517
+ }
518
+
519
+ printStep("1 ", output, input);
520
+
521
+ // While the input buffer is not empty, loop as follows
522
+ while (input.length() != 0) {
523
+ // 2A. If the input buffer begins with a prefix of "./",
524
+ // then remove that prefix from the input buffer
525
+ // else if the input buffer begins with a prefix of "../", then
526
+ // if also the output does not contain the root slash "/" only,
527
+ // then move this prefix to the end of the output buffer else
528
+ // remove that prefix
529
+ if (input.startsWith("./")) {
530
+ input = input.substring(2);
531
+ printStep("2A", output, input);
532
+ } else if (input.startsWith("../")) {
533
+ input = input.substring(3);
534
+ if (!output.toString().equals("/")) {
535
+ output.append("../");
536
+ }
537
+ printStep("2A", output, input);
538
+ // 2B. if the input buffer begins with a prefix of "/./" or "/.",
539
+ // where "." is a complete path segment, then replace that prefix
540
+ // with "/" in the input buffer; otherwise,
541
+ } else if (input.startsWith("/./")) {
542
+ input = input.substring(2);
543
+ printStep("2B", output, input);
544
+ } else if (input.equals("/.")) {
545
+ // FIXME: what is complete path segment?
546
+ input = input.replaceFirst("/.", "/");
547
+ printStep("2B", output, input);
548
+ // 2C. if the input buffer begins with a prefix of "/../" or "/..",
549
+ // where ".." is a complete path segment, then replace that prefix
550
+ // with "/" in the input buffer and if also the output buffer is
551
+ // empty, last segment in the output buffer equals "../" or "..",
552
+ // where ".." is a complete path segment, then append ".." or "/.."
553
+ // for the latter case respectively to the output buffer else
554
+ // remove the last segment and its preceding "/" (if any) from the
555
+ // output buffer and if hereby the first character in the output
556
+ // buffer was removed and it was not the root slash then delete a
557
+ // leading slash from the input buffer; otherwise,
558
+ } else if (input.startsWith("/../")) {
559
+ input = input.substring(3);
560
+ if (output.length() == 0) {
561
+ output.append("/");
562
+ } else if (output.toString().endsWith("../")) {
563
+ output.append("..");
564
+ } else if (output.toString().endsWith("..")) {
565
+ output.append("/..");
566
+ } else {
567
+ int index = output.lastIndexOf("/");
568
+ if (index == -1) {
569
+ output = new StringBuilder();
570
+ if (input.charAt(0) == '/') {
571
+ input = input.substring(1);
572
+ }
573
+ } else {
574
+ output = output.delete(index, output.length());
575
+ }
576
+ }
577
+ printStep("2C", output, input);
578
+ } else if (input.equals("/..")) {
579
+ // FIXME: what is complete path segment?
580
+ input = input.replaceFirst("/..", "/");
581
+ if (output.length() == 0) {
582
+ output.append("/");
583
+ } else if (output.toString().endsWith("../")) {
584
+ output.append("..");
585
+ } else if (output.toString().endsWith("..")) {
586
+ output.append("/..");
587
+ } else {
588
+ int index = output.lastIndexOf("/");
589
+ if (index == -1) {
590
+ output = new StringBuilder();
591
+ if (input.charAt(0) == '/') {
592
+ input = input.substring(1);
593
+ }
594
+ } else {
595
+ output = output.delete(index, output.length());
596
+ }
597
+ }
598
+ printStep("2C", output, input);
599
+ // 2D. if the input buffer consists only of ".", then remove
600
+ // that from the input buffer else if the input buffer consists
601
+ // only of ".." and if the output buffer does not contain only
602
+ // the root slash "/", then move the ".." to the output buffer
603
+ // else delte it.; otherwise,
604
+ } else if (input.equals(".")) {
605
+ input = "";
606
+ printStep("2D", output, input);
607
+ } else if (input.equals("..")) {
608
+ if (!output.toString().equals("/")) {
609
+ output.append("..");
610
+ }
611
+ input = "";
612
+ printStep("2D", output, input);
613
+ // 2E. move the first path segment (if any) in the input buffer
614
+ // to the end of the output buffer, including the initial "/"
615
+ // character (if any) and any subsequent characters up to, but not
616
+ // including, the next "/" character or the end of the input buffer.
617
+ } else {
618
+ int end;
619
+ int begin = input.indexOf('/');
620
+ if (begin == 0) {
621
+ end = input.indexOf('/', 1);
622
+ } else {
623
+ end = begin;
624
+ begin = 0;
625
+ }
626
+ String segment;
627
+ if (end == -1) {
628
+ segment = input.substring(begin);
629
+ input = "";
630
+ } else {
631
+ segment = input.substring(begin, end);
632
+ input = input.substring(end);
633
+ }
634
+ output.append(segment);
635
+ printStep("2E", output, input);
636
+ }
637
+ }
638
+
639
+ // 3. Finally, if the only or last segment of the output buffer is
640
+ // "..", where ".." is a complete path segment not followed by a slash
641
+ // then append a slash "/". The output buffer is returned as the result
642
+ // of remove_dot_segments
643
+ if (output.toString().endsWith("..")) {
644
+ output.append('/');
645
+ printStep("3 ", output, input);
646
+ }
647
+
648
+ return output.toString();
649
+ }
650
+
651
+ private static void
652
+ printStep(String step, StringBuilder output, String input)
653
+ {
654
+ //if (System.getProperty("nokogiri.c14.debug") == "on") { //
655
+ // System.out.println(" " + step + ": " + output);
656
+ // if (output.length() == 0) {
657
+ // System.out.println("\t\t\t\t" + input);
658
+ // } else {
659
+ // System.out.println("\t\t\t" + input);
660
+ // }
661
+ //}
662
+ }
663
+
664
+ }
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Licensed to the Apache Software Foundation (ASF) under one
3
+ * or more contributor license agreements. See the NOTICE file
4
+ * distributed with this work for additional information
5
+ * regarding copyright ownership. The ASF licenses this file
6
+ * to you under the Apache License, Version 2.0 (the
7
+ * "License"); you may not use this file except in compliance
8
+ * with the License. You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing,
13
+ * software distributed under the License is distributed on an
14
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+ * KIND, either express or implied. See the License for the
16
+ * specific language governing permissions and limitations
17
+ * under the License.
18
+ */
19
+ package nokogiri.internals.c14n;
20
+
21
+
22
+ /**
23
+ * @author Sean Mullan
24
+ */
25
+ public class Canonicalizer11_OmitComments extends Canonicalizer11
26
+ {
27
+
28
+ public
29
+ Canonicalizer11_OmitComments()
30
+ {
31
+ super(false);
32
+ }
33
+
34
+ public final String
35
+ engineGetURI()
36
+ {
37
+ return Canonicalizer.ALGO_ID_C14N11_OMIT_COMMENTS;
38
+ }
39
+
40
+ public final boolean
41
+ engineGetIncludeComments()
42
+ {
43
+ return false;
44
+ }
45
+ }