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,288 @@
1
+ package nokogiri;
2
+
3
+ import nokogiri.internals.*;
4
+ import org.jruby.Ruby;
5
+ import org.jruby.RubyClass;
6
+ import org.jruby.RubyException;
7
+ import org.jruby.RubyObject;
8
+ import org.jruby.anno.JRubyClass;
9
+ import org.jruby.anno.JRubyMethod;
10
+ import org.jruby.exceptions.RaiseException;
11
+ import org.jruby.runtime.ThreadContext;
12
+ import org.jruby.runtime.builtin.IRubyObject;
13
+
14
+ import java.io.ByteArrayInputStream;
15
+ import java.io.IOException;
16
+ import java.io.InputStream;
17
+ import java.util.List;
18
+ import java.util.concurrent.*;
19
+
20
+ import static nokogiri.internals.NokogiriHelpers.getNokogiriClass;
21
+ import static org.jruby.runtime.Helpers.invoke;
22
+
23
+ /**
24
+ * Class for Nokogiri::XML::SAX::PushParser
25
+ *
26
+ * @author Patrick Mahoney <pat@polycrystal.org>
27
+ * @author Yoko Harada <yokolet@gmail.com>
28
+ */
29
+ @JRubyClass(name = "Nokogiri::XML::SAX::PushParser")
30
+ public class XmlSaxPushParser extends RubyObject
31
+ {
32
+ private static final long serialVersionUID = 1L;
33
+
34
+ ParserContext.Options options;
35
+ IRubyObject saxParser;
36
+
37
+ NokogiriBlockingQueueInputStream stream;
38
+
39
+ private ParserTask parserTask = null;
40
+ private FutureTask<XmlSaxParserContext> futureTask = null;
41
+ private ExecutorService executor = null;
42
+ RaiseException ex = null;
43
+
44
+ public
45
+ XmlSaxPushParser(Ruby ruby, RubyClass rubyClass)
46
+ {
47
+ super(ruby, rubyClass);
48
+ }
49
+
50
+ @SuppressWarnings("deprecation")
51
+ @Override
52
+ public void
53
+ finalize()
54
+ {
55
+ try {
56
+ terminateImpl();
57
+ } catch (Exception e) { /* ignored */ }
58
+ }
59
+
60
+ @JRubyMethod
61
+ public IRubyObject
62
+ initialize_native(final ThreadContext context, IRubyObject saxParser, IRubyObject fileName)
63
+ {
64
+ options = new ParserContext.Options(0);
65
+ this.saxParser = saxParser;
66
+ return this;
67
+ }
68
+
69
+ private transient IRubyObject parse_options;
70
+
71
+ private IRubyObject
72
+ parse_options(final ThreadContext context)
73
+ {
74
+ if (parse_options == null) {
75
+ parse_options = invoke(context, context.runtime.getClassFromPath("Nokogiri::XML::ParseOptions"), "new");
76
+ }
77
+ return parse_options;
78
+ }
79
+
80
+ @JRubyMethod(name = "options")
81
+ public IRubyObject
82
+ getOptions(ThreadContext context)
83
+ {
84
+ return invoke(context, parse_options(context), "options");
85
+ }
86
+
87
+ @JRubyMethod(name = "options=")
88
+ public IRubyObject
89
+ setOptions(ThreadContext context, IRubyObject opts)
90
+ {
91
+ invoke(context, parse_options(context), "options=", opts);
92
+ options = new ParserContext.Options(opts.convertToInteger().getLongValue());
93
+ return getOptions(context);
94
+ }
95
+
96
+ /**
97
+ * Can take a boolean assignment.
98
+ *
99
+ * @param context
100
+ * @param value
101
+ * @return
102
+ */
103
+ @JRubyMethod(name = "replace_entities=")
104
+ public IRubyObject
105
+ setReplaceEntities(ThreadContext context, IRubyObject value)
106
+ {
107
+ // Ignore the value.
108
+ return this;
109
+ }
110
+
111
+ @JRubyMethod(name = "replace_entities")
112
+ public IRubyObject
113
+ getReplaceEntities(ThreadContext context)
114
+ {
115
+ // The java parser always replaces entities.
116
+ return context.getRuntime().getTrue();
117
+ }
118
+
119
+ @JRubyMethod
120
+ public IRubyObject
121
+ native_write(ThreadContext context, IRubyObject chunk,
122
+ IRubyObject isLast)
123
+ {
124
+ if (ex != null) {
125
+ // parser has already errored, rethrow the exception
126
+ throw ex;
127
+ }
128
+
129
+ try {
130
+ initialize_task(context);
131
+ } catch (IOException e) {
132
+ throw context.runtime.newRuntimeError(e.getMessage());
133
+ }
134
+ final ByteArrayInputStream data = NokogiriHelpers.stringBytesToStream(chunk);
135
+ if (data == null) {
136
+ return this;
137
+ }
138
+
139
+ int errorCount0 = parserTask.getErrorCount();
140
+
141
+ try {
142
+ Future<Void> task = stream.addChunk(data);
143
+ task.get();
144
+ } catch (ClosedStreamException ex) {
145
+ // this means the stream is closed, ignore this exception
146
+ } catch (Exception e) {
147
+ throw context.runtime.newRuntimeError(e.toString());
148
+ }
149
+
150
+ if (isLast.isTrue()) {
151
+ parserTask.getNokogiriHandler().endDocument();
152
+ terminateTask(context.runtime);
153
+ }
154
+
155
+ if (!options.recover && parserTask.getErrorCount() > errorCount0) {
156
+ terminateTask(context.runtime);
157
+ ex = parserTask.getLastError().toThrowable();
158
+ throw ex;
159
+ }
160
+
161
+ return this;
162
+ }
163
+
164
+ private void
165
+ initialize_task(ThreadContext context) throws IOException
166
+ {
167
+ if (futureTask == null || stream == null) {
168
+ stream = new NokogiriBlockingQueueInputStream();
169
+
170
+ assert saxParser != null : "saxParser null";
171
+ parserTask = new ParserTask(context, saxParser, stream);
172
+ futureTask = new FutureTask<XmlSaxParserContext>(parserTask);
173
+ executor = Executors.newSingleThreadExecutor(new ThreadFactory() {
174
+ @Override
175
+ public Thread newThread(Runnable r) {
176
+ Thread t = new Thread(r);
177
+ t.setName("XmlSaxPushParser");
178
+ t.setDaemon(true);
179
+ return t;
180
+ }
181
+ });
182
+ executor.submit(futureTask);
183
+ }
184
+ }
185
+
186
+ private void
187
+ terminateTask(final Ruby runtime)
188
+ {
189
+ if (executor == null) { return; }
190
+
191
+ try {
192
+ terminateImpl();
193
+ } catch (InterruptedException e) {
194
+ throw runtime.newRuntimeError(e.toString());
195
+ } catch (Exception e) {
196
+ throw runtime.newRuntimeError(e.toString());
197
+ }
198
+ }
199
+
200
+ private synchronized void
201
+ terminateImpl() throws InterruptedException, ExecutionException
202
+ {
203
+ terminateExecution(executor, stream, futureTask);
204
+
205
+ executor = null;
206
+ stream = null;
207
+ futureTask = null;
208
+ }
209
+
210
+ // SHARED for Html4SaxPushParser
211
+ static void
212
+ terminateExecution(final ExecutorService executor, final NokogiriBlockingQueueInputStream stream,
213
+ final FutureTask<?> futureTask)
214
+ throws InterruptedException, ExecutionException
215
+ {
216
+
217
+ if (executor == null) { return; }
218
+
219
+ try {
220
+ Future<Void> task = stream.addChunk(NokogiriBlockingQueueInputStream.END);
221
+ task.get();
222
+ } catch (ClosedStreamException ex) {
223
+ // ignore this exception, it means the stream was closed
224
+ }
225
+ futureTask.cancel(true);
226
+ executor.shutdown();
227
+ }
228
+
229
+ private static XmlSaxParserContext
230
+ parse(final Ruby runtime, final InputStream stream)
231
+ {
232
+ RubyClass klazz = getNokogiriClass(runtime, "Nokogiri::XML::SAX::ParserContext");
233
+ return XmlSaxParserContext.parse_stream(runtime, klazz, stream);
234
+ }
235
+
236
+ static class ParserTask extends ParserContext.ParserTask<XmlSaxParserContext>
237
+ {
238
+
239
+ final InputStream stream;
240
+
241
+ private
242
+ ParserTask(ThreadContext context, IRubyObject handler, InputStream stream)
243
+ {
244
+ this(context, handler, parse(context.runtime, stream), stream);
245
+ }
246
+
247
+ // IMPL with Html4SaxPushParser
248
+ protected
249
+ ParserTask(ThreadContext context, IRubyObject handler, XmlSaxParserContext parser, InputStream stream)
250
+ {
251
+ super(context, handler, parser);
252
+ this.stream = stream;
253
+ }
254
+
255
+ @Override
256
+ public XmlSaxParserContext
257
+ call() throws Exception
258
+ {
259
+ try {
260
+ parser.parse_with(context, handler);
261
+ } finally { stream.close(); }
262
+ // we have to close the stream before exiting, otherwise someone
263
+ // can add a chunk and block on task.get() forever.
264
+ return parser;
265
+ }
266
+
267
+ final NokogiriHandler
268
+ getNokogiriHandler()
269
+ {
270
+ return parser.getNokogiriHandler();
271
+ }
272
+
273
+ synchronized final int
274
+ getErrorCount()
275
+ {
276
+ // check for null because thread may not have started yet
277
+ if (parser.getNokogiriErrorHandler() == null) { return 0; }
278
+ return parser.getNokogiriErrorHandler().getErrors().size();
279
+ }
280
+
281
+ synchronized final RubyException
282
+ getLastError()
283
+ {
284
+ List<RubyException> errors = parser.getNokogiriErrorHandler().getErrors();
285
+ return errors.get(errors.size() - 1);
286
+ }
287
+ }
288
+ }
@@ -0,0 +1,423 @@
1
+ package nokogiri;
2
+
3
+ import static nokogiri.internals.NokogiriHelpers.adjustSystemIdIfNecessary;
4
+ import static nokogiri.internals.NokogiriHelpers.getNokogiriClass;
5
+
6
+ import java.io.IOException;
7
+ import java.io.InputStream;
8
+ import java.io.Reader;
9
+ import java.io.StringReader;
10
+
11
+ import javax.xml.XMLConstants;
12
+ import javax.xml.transform.Source;
13
+ import javax.xml.transform.dom.DOMSource;
14
+ import javax.xml.transform.stream.StreamSource;
15
+ import javax.xml.validation.Schema;
16
+ import javax.xml.validation.SchemaFactory;
17
+ import javax.xml.validation.Validator;
18
+
19
+ import nokogiri.internals.IgnoreSchemaErrorsErrorHandler;
20
+ import nokogiri.internals.SchemaErrorHandler;
21
+ import nokogiri.internals.XmlDomParserContext;
22
+ import nokogiri.internals.ParserContext;
23
+ import nokogiri.internals.ParserContext.Options;
24
+
25
+ import org.jruby.Ruby;
26
+ import org.jruby.RubyArray;
27
+ import org.jruby.RubyClass;
28
+ import org.jruby.RubyFixnum;
29
+ import org.jruby.RubyObject;
30
+ import org.jruby.anno.JRubyClass;
31
+ import org.jruby.anno.JRubyMethod;
32
+ import org.jruby.exceptions.RaiseException;
33
+ import org.jruby.runtime.ThreadContext;
34
+ import org.jruby.runtime.Visibility;
35
+ import org.jruby.runtime.builtin.IRubyObject;
36
+ import org.jruby.runtime.Helpers;
37
+ import org.w3c.dom.Document;
38
+ import org.w3c.dom.ls.LSInput;
39
+ import org.w3c.dom.ls.LSResourceResolver;
40
+ import org.xml.sax.ErrorHandler;
41
+ import org.xml.sax.SAXException;
42
+ import org.xml.sax.SAXParseException;
43
+
44
+ /**
45
+ * Class for Nokogiri::XML::Schema
46
+ *
47
+ * @author sergio
48
+ * @author Yoko Harada <yokolet@gmail.com>
49
+ */
50
+ @JRubyClass(name = "Nokogiri::XML::Schema")
51
+ public class XmlSchema extends RubyObject
52
+ {
53
+ private static final long serialVersionUID = 1L;
54
+
55
+ private Validator validator;
56
+
57
+ public
58
+ XmlSchema(Ruby ruby, RubyClass klazz)
59
+ {
60
+ super(ruby, klazz);
61
+ }
62
+
63
+ /**
64
+ * Create and return a copy of this object.
65
+ *
66
+ * @return a clone of this object
67
+ */
68
+ @Override
69
+ public Object
70
+ clone() throws CloneNotSupportedException
71
+ {
72
+ return super.clone();
73
+ }
74
+
75
+ private Schema
76
+ getSchema(Source source,
77
+ String currentDir,
78
+ String scriptFileName,
79
+ SchemaErrorHandler errorHandler,
80
+ long parseOptions) throws SAXException
81
+ {
82
+ boolean noNet = new ParserContext.Options(parseOptions).noNet;
83
+
84
+ SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
85
+ SchemaResourceResolver resourceResolver =
86
+ new SchemaResourceResolver(currentDir, scriptFileName, null, errorHandler, noNet);
87
+
88
+ schemaFactory.setResourceResolver(resourceResolver);
89
+ schemaFactory.setErrorHandler(errorHandler);
90
+
91
+ return schemaFactory.newSchema(source);
92
+ }
93
+
94
+ private void
95
+ setValidator(Validator validator)
96
+ {
97
+ this.validator = validator;
98
+ }
99
+
100
+ static XmlSchema
101
+ createSchemaInstance(ThreadContext context, RubyClass klazz, Source source, IRubyObject parseOptions)
102
+ {
103
+ Ruby runtime = context.getRuntime();
104
+ XmlSchema xmlSchema = (XmlSchema) NokogiriService.XML_SCHEMA_ALLOCATOR.allocate(runtime, klazz);
105
+
106
+ if (parseOptions == null) {
107
+ parseOptions = defaultParseOptions(context.getRuntime());
108
+ }
109
+ long intParseOptions = RubyFixnum.fix2long(Helpers.invoke(context, parseOptions, "to_i"));
110
+
111
+ xmlSchema.setInstanceVariable("@errors", runtime.newEmptyArray());
112
+ xmlSchema.setInstanceVariable("@parse_options", parseOptions);
113
+
114
+ try {
115
+ SchemaErrorHandler errorHandler =
116
+ new SchemaErrorHandler(context.getRuntime(), (RubyArray)xmlSchema.getInstanceVariable("@errors"));
117
+ Schema schema =
118
+ xmlSchema.getSchema(source,
119
+ context.getRuntime().getCurrentDirectory(),
120
+ context.getRuntime().getInstanceConfig().getScriptFileName(),
121
+ errorHandler,
122
+ intParseOptions);
123
+ xmlSchema.setValidator(schema.newValidator());
124
+ return xmlSchema;
125
+ } catch (SAXException ex) {
126
+ throw context.getRuntime().newRuntimeError("Could not parse document: " + ex.getMessage());
127
+ }
128
+ }
129
+
130
+ protected static IRubyObject
131
+ defaultParseOptions(Ruby runtime)
132
+ {
133
+ return ((RubyClass)runtime.getClassFromPath("Nokogiri::XML::ParseOptions")).getConstant("DEFAULT_SCHEMA");
134
+ }
135
+
136
+ /*
137
+ * call-seq:
138
+ * from_document(doc)
139
+ *
140
+ * Create a new Schema from the Nokogiri::XML::Document +doc+
141
+ */
142
+ @JRubyMethod(meta = true, required = 1, optional = 1)
143
+ public static IRubyObject
144
+ from_document(ThreadContext context, IRubyObject klazz, IRubyObject[] args)
145
+ {
146
+ IRubyObject document = args[0];
147
+ IRubyObject parseOptions = null;
148
+ if (args.length > 1) {
149
+ parseOptions = args[1];
150
+ }
151
+
152
+ XmlDocument doc = ((XmlDocument)((XmlNode) document).document(context));
153
+
154
+ RubyArray<?> errors = (RubyArray) doc.getInstanceVariable("@errors");
155
+ if (!errors.isEmpty()) {
156
+ throw((XmlSyntaxError) errors.first()).toThrowable();
157
+ }
158
+
159
+ DOMSource source = new DOMSource(doc.getDocument());
160
+
161
+ IRubyObject uri = doc.url(context);
162
+
163
+ if (!uri.isNil()) {
164
+ source.setSystemId(uri.convertToString().asJavaString());
165
+ }
166
+
167
+ return getSchema(context, (RubyClass)klazz, source, parseOptions);
168
+ }
169
+
170
+ @JRubyMethod(meta = true, required = 1, optional = 1)
171
+ public static IRubyObject
172
+ read_memory(ThreadContext context, IRubyObject klazz, IRubyObject[] args)
173
+ {
174
+ IRubyObject content = args[0];
175
+ IRubyObject parseOptions = null;
176
+ if (args.length > 1) {
177
+ parseOptions = args[1];
178
+ }
179
+ String data = content.convertToString().asJavaString();
180
+ return getSchema(context, (RubyClass) klazz, new StreamSource(new StringReader(data)), parseOptions);
181
+ }
182
+
183
+ private static IRubyObject
184
+ getSchema(ThreadContext context, RubyClass klazz, Source source, IRubyObject parseOptions)
185
+ {
186
+ String moduleName = klazz.getName();
187
+ if ("Nokogiri::XML::Schema".equals(moduleName)) {
188
+ return XmlSchema.createSchemaInstance(context, klazz, source, parseOptions);
189
+ } else if ("Nokogiri::XML::RelaxNG".equals(moduleName)) {
190
+ return XmlRelaxng.createSchemaInstance(context, klazz, source, parseOptions);
191
+ }
192
+ return context.getRuntime().getNil();
193
+ }
194
+
195
+ @JRubyMethod(visibility = Visibility.PRIVATE)
196
+ public IRubyObject
197
+ validate_document(ThreadContext context, IRubyObject document)
198
+ {
199
+ return validate_document_or_file(context, (XmlDocument)document);
200
+ }
201
+
202
+ @JRubyMethod(visibility = Visibility.PRIVATE)
203
+ public IRubyObject
204
+ validate_file(ThreadContext context, IRubyObject file)
205
+ {
206
+ Ruby runtime = context.runtime;
207
+
208
+ XmlDomParserContext ctx = new XmlDomParserContext(runtime, RubyFixnum.newFixnum(runtime, 1L));
209
+ ctx.setInputSourceFile(context, file);
210
+ XmlDocument xmlDocument = ctx.parse(context, getNokogiriClass(runtime, "Nokogiri::XML::Document"), context.nil);
211
+ return validate_document_or_file(context, xmlDocument);
212
+ }
213
+
214
+ IRubyObject
215
+ validate_document_or_file(ThreadContext context, XmlDocument xmlDocument)
216
+ {
217
+ RubyArray<?> errors = (RubyArray) this.getInstanceVariable("@errors");
218
+ ErrorHandler errorHandler = new SchemaErrorHandler(context.runtime, errors);
219
+ setErrorHandler(errorHandler);
220
+
221
+ try {
222
+ validate(xmlDocument.getDocument());
223
+ } catch (SAXException ex) {
224
+ XmlSyntaxError xmlSyntaxError = XmlSyntaxError.createXMLSyntaxError(context.runtime);
225
+ xmlSyntaxError.setException(ex);
226
+ errors.append(xmlSyntaxError);
227
+ } catch (IOException ex) {
228
+ throw context.runtime.newIOError(ex.getMessage());
229
+ }
230
+
231
+ return errors;
232
+ }
233
+
234
+ protected void
235
+ setErrorHandler(ErrorHandler errorHandler)
236
+ {
237
+ validator.setErrorHandler(errorHandler);
238
+ }
239
+
240
+ protected void
241
+ validate(Document document) throws SAXException, IOException
242
+ {
243
+ DOMSource docSource = new DOMSource(document);
244
+ validator.validate(docSource);
245
+ }
246
+
247
+ private class SchemaResourceResolver implements LSResourceResolver
248
+ {
249
+ SchemaLSInput lsInput = new SchemaLSInput();
250
+ String currentDir;
251
+ String scriptFileName;
252
+ SchemaErrorHandler errorHandler;
253
+ boolean noNet;
254
+ //String defaultURI;
255
+
256
+ SchemaResourceResolver(String currentDir, String scriptFileName, Object input, SchemaErrorHandler errorHandler,
257
+ boolean noNet)
258
+ {
259
+ this.currentDir = currentDir;
260
+ this.scriptFileName = scriptFileName;
261
+ this.errorHandler = errorHandler;
262
+ this.noNet = noNet;
263
+ if (input == null) { return; }
264
+ if (input instanceof String) {
265
+ lsInput.setStringData((String)input);
266
+ } else if (input instanceof Reader) {
267
+ lsInput.setCharacterStream((Reader)input);
268
+ } else if (input instanceof InputStream) {
269
+ lsInput.setByteStream((InputStream)input);
270
+ }
271
+ }
272
+
273
+ @Override
274
+ public LSInput
275
+ resolveResource(String type,
276
+ String namespaceURI,
277
+ String publicId,
278
+ String systemId,
279
+ String baseURI)
280
+ {
281
+ if (noNet && systemId != null && (systemId.startsWith("http://") || systemId.startsWith("ftp://"))) {
282
+ if (systemId.startsWith(XMLConstants.W3C_XML_SCHEMA_NS_URI)) {
283
+ return null; // use default resolver
284
+ }
285
+ try {
286
+ this.errorHandler.warning(new SAXParseException(String.format("Attempt to load network entity '%s'", systemId), null));
287
+ } catch (SAXException ex) {
288
+ }
289
+ } else {
290
+ String adjusted = adjustSystemIdIfNecessary(currentDir, scriptFileName, baseURI, systemId);
291
+ lsInput.setPublicId(publicId);
292
+ lsInput.setSystemId(adjusted != null ? adjusted : systemId);
293
+ lsInput.setBaseURI(baseURI);
294
+ }
295
+ return lsInput;
296
+ }
297
+ }
298
+
299
+ private class SchemaLSInput implements LSInput
300
+ {
301
+ protected String fPublicId;
302
+ protected String fSystemId;
303
+ protected String fBaseSystemId;
304
+ protected InputStream fByteStream;
305
+ protected Reader fCharStream;
306
+ protected String fData;
307
+ protected String fEncoding;
308
+ protected boolean fCertifiedText = false;
309
+
310
+ @Override
311
+ public String
312
+ getBaseURI()
313
+ {
314
+ return fBaseSystemId;
315
+ }
316
+
317
+ @Override
318
+ public InputStream
319
+ getByteStream()
320
+ {
321
+ return fByteStream;
322
+ }
323
+
324
+ @Override
325
+ public boolean
326
+ getCertifiedText()
327
+ {
328
+ return fCertifiedText;
329
+ }
330
+
331
+ @Override
332
+ public Reader
333
+ getCharacterStream()
334
+ {
335
+ return fCharStream;
336
+ }
337
+
338
+ @Override
339
+ public String
340
+ getEncoding()
341
+ {
342
+ return fEncoding;
343
+ }
344
+
345
+ @Override
346
+ public String
347
+ getPublicId()
348
+ {
349
+ return fPublicId;
350
+ }
351
+
352
+ @Override
353
+ public String
354
+ getStringData()
355
+ {
356
+ return fData;
357
+ }
358
+
359
+ @Override
360
+ public String
361
+ getSystemId()
362
+ {
363
+ return fSystemId;
364
+ }
365
+
366
+ @Override
367
+ public void
368
+ setBaseURI(String baseURI)
369
+ {
370
+ fBaseSystemId = baseURI;
371
+ }
372
+
373
+ @Override
374
+ public void
375
+ setByteStream(InputStream byteStream)
376
+ {
377
+ fByteStream = byteStream;
378
+ }
379
+
380
+ @Override
381
+ public void
382
+ setCertifiedText(boolean certified)
383
+ {
384
+ fCertifiedText = certified;
385
+ }
386
+
387
+ @Override
388
+ public void
389
+ setCharacterStream(Reader charStream)
390
+ {
391
+ fCharStream = charStream;
392
+ }
393
+
394
+ @Override
395
+ public void
396
+ setEncoding(String encoding)
397
+ {
398
+ fEncoding = encoding;
399
+ }
400
+
401
+ @Override
402
+ public void
403
+ setPublicId(String pubId)
404
+ {
405
+ fPublicId = pubId;
406
+ }
407
+
408
+ @Override
409
+ public void
410
+ setStringData(String stringData)
411
+ {
412
+ fData = stringData;
413
+ }
414
+
415
+ @Override
416
+ public void
417
+ setSystemId(String sysId)
418
+ {
419
+ fSystemId = sysId;
420
+ }
421
+
422
+ }
423
+ }