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
@@ -1,35 +1,3 @@
1
- /**
2
- * (The MIT License)
3
- *
4
- * Copyright (c) 2008 - 2012:
5
- *
6
- * * {Aaron Patterson}[http://tenderlovemaking.com]
7
- * * {Mike Dalessio}[http://mike.daless.io]
8
- * * {Charles Nutter}[http://blog.headius.com]
9
- * * {Sergio Arbeo}[http://www.serabe.com]
10
- * * {Patrick Mahoney}[http://polycrystal.org]
11
- * * {Yoko Harada}[http://yokolet.blogspot.com]
12
- *
13
- * Permission is hereby granted, free of charge, to any person obtaining
14
- * a copy of this software and associated documentation files (the
15
- * 'Software'), to deal in the Software without restriction, including
16
- * without limitation the rights to use, copy, modify, merge, publish,
17
- * distribute, sublicense, and/or sell copies of the Software, and to
18
- * permit persons to whom the Software is furnished to do so, subject to
19
- * the following conditions:
20
- *
21
- * The above copyright notice and this permission notice shall be
22
- * included in all copies or substantial portions of the Software.
23
- *
24
- * THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
25
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
27
- * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
28
- * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
29
- * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
30
- * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31
- */
32
-
33
1
  package nokogiri;
34
2
 
35
3
  import static nokogiri.internals.NokogiriHelpers.getNokogiriClass;
@@ -66,221 +34,260 @@ import nokogiri.internals.ParserContext;
66
34
  * @author Patrick Mahoney <pat@polycrystal.org>
67
35
  * @author Yoko Harada <yokolet@gmail.com>
68
36
  */
69
- @JRubyClass(name="Nokogiri::XML::SAX::PushParser")
70
- public class XmlSaxPushParser extends RubyObject {
71
- ParserContext.Options options;
72
- IRubyObject saxParser;
73
-
74
- NokogiriBlockingQueueInputStream stream;
75
-
76
- private ParserTask parserTask = null;
77
- private FutureTask<XmlSaxParserContext> futureTask = null;
78
- private ExecutorService executor = null;
79
- RaiseException ex = null;
80
-
81
- public XmlSaxPushParser(Ruby ruby, RubyClass rubyClass) {
82
- super(ruby, rubyClass);
37
+ @JRubyClass(name = "Nokogiri::XML::SAX::PushParser")
38
+ public class XmlSaxPushParser extends RubyObject
39
+ {
40
+ ParserContext.Options options;
41
+ IRubyObject saxParser;
42
+
43
+ NokogiriBlockingQueueInputStream stream;
44
+
45
+ private ParserTask parserTask = null;
46
+ private FutureTask<XmlSaxParserContext> futureTask = null;
47
+ private ExecutorService executor = null;
48
+ RaiseException ex = null;
49
+
50
+ public
51
+ XmlSaxPushParser(Ruby ruby, RubyClass rubyClass)
52
+ {
53
+ super(ruby, rubyClass);
54
+ }
55
+
56
+ @Override
57
+ public void
58
+ finalize()
59
+ {
60
+ try {
61
+ terminateImpl();
62
+ } catch (Exception e) { /* ignored */ }
63
+ }
64
+
65
+ @JRubyMethod
66
+ public IRubyObject
67
+ initialize_native(final ThreadContext context, IRubyObject saxParser, IRubyObject fileName)
68
+ {
69
+ options = new ParserContext.Options(0);
70
+ this.saxParser = saxParser;
71
+ return this;
72
+ }
73
+
74
+ private transient IRubyObject parse_options;
75
+
76
+ private IRubyObject
77
+ parse_options(final ThreadContext context)
78
+ {
79
+ if (parse_options == null) {
80
+ parse_options = invoke(context, context.runtime.getClassFromPath("Nokogiri::XML::ParseOptions"), "new");
83
81
  }
84
-
85
- @Override
86
- public void finalize() {
87
- try {
88
- terminateImpl();
89
- }
90
- catch (Exception e) { /* ignored */ }
82
+ return parse_options;
83
+ }
84
+
85
+ @JRubyMethod(name = "options")
86
+ public IRubyObject
87
+ getOptions(ThreadContext context)
88
+ {
89
+ return invoke(context, parse_options(context), "options");
90
+ }
91
+
92
+ @JRubyMethod(name = "options=")
93
+ public IRubyObject
94
+ setOptions(ThreadContext context, IRubyObject opts)
95
+ {
96
+ invoke(context, parse_options(context), "options=", opts);
97
+ options = new ParserContext.Options(opts.convertToInteger().getLongValue());
98
+ return getOptions(context);
99
+ }
100
+
101
+ /**
102
+ * Can take a boolean assignment.
103
+ *
104
+ * @param context
105
+ * @param value
106
+ * @return
107
+ */
108
+ @JRubyMethod(name = "replace_entities=")
109
+ public IRubyObject
110
+ setReplaceEntities(ThreadContext context, IRubyObject value)
111
+ {
112
+ // Ignore the value.
113
+ return this;
114
+ }
115
+
116
+ @JRubyMethod(name = "replace_entities")
117
+ public IRubyObject
118
+ getReplaceEntities(ThreadContext context)
119
+ {
120
+ // The java parser always replaces entities.
121
+ return context.getRuntime().getTrue();
122
+ }
123
+
124
+ @JRubyMethod
125
+ public IRubyObject
126
+ native_write(ThreadContext context, IRubyObject chunk,
127
+ IRubyObject isLast)
128
+ {
129
+ if (ex != null) {
130
+ // parser has already errored, rethrow the exception
131
+ throw ex;
91
132
  }
92
133
 
93
- @JRubyMethod
94
- public IRubyObject initialize_native(final ThreadContext context, IRubyObject saxParser, IRubyObject fileName) {
95
- options = new ParserContext.Options(0);
96
- this.saxParser = saxParser;
97
- return this;
134
+ try {
135
+ initialize_task(context);
136
+ } catch (IOException e) {
137
+ throw context.runtime.newRuntimeError(e.getMessage());
98
138
  }
99
-
100
- private transient IRubyObject parse_options;
101
-
102
- private IRubyObject parse_options(final ThreadContext context) {
103
- if (parse_options == null) {
104
- parse_options = invoke(context, context.runtime.getClassFromPath("Nokogiri::XML::ParseOptions"), "new");
105
- }
106
- return parse_options;
139
+ final ByteArrayInputStream data = NokogiriHelpers.stringBytesToStream(chunk);
140
+ if (data == null) {
141
+ return this;
107
142
  }
108
143
 
109
- @JRubyMethod(name="options")
110
- public IRubyObject getOptions(ThreadContext context) {
111
- return invoke(context, parse_options(context), "options");
112
- }
144
+ int errorCount0 = parserTask.getErrorCount();
113
145
 
114
- @JRubyMethod(name="options=")
115
- public IRubyObject setOptions(ThreadContext context, IRubyObject opts) {
116
- invoke(context, parse_options(context), "options=", opts);
117
- options = new ParserContext.Options(opts.convertToInteger().getLongValue());
118
- return getOptions(context);
146
+ try {
147
+ Future<Void> task = stream.addChunk(data);
148
+ task.get();
149
+ } catch (ClosedStreamException ex) {
150
+ // this means the stream is closed, ignore this exception
151
+ } catch (Exception e) {
152
+ throw context.runtime.newRuntimeError(e.toString());
119
153
  }
120
154
 
121
- /**
122
- * Can take a boolean assignment.
123
- *
124
- * @param context
125
- * @param value
126
- * @return
127
- */
128
- @JRubyMethod(name = "replace_entities=")
129
- public IRubyObject setReplaceEntities(ThreadContext context, IRubyObject value) {
130
- // Ignore the value.
131
- return this;
155
+ if (isLast.isTrue()) {
156
+ parserTask.getNokogiriHandler().endDocument();
157
+ terminateTask(context.runtime);
132
158
  }
133
159
 
134
- @JRubyMethod(name="replace_entities")
135
- public IRubyObject getReplaceEntities(ThreadContext context) {
136
- // The java parser always replaces entities.
137
- return context.getRuntime().getTrue();
160
+ if (!options.recover && parserTask.getErrorCount() > errorCount0) {
161
+ terminateTask(context.runtime);
162
+ throw ex = parserTask.getLastError();
138
163
  }
139
164
 
140
- @JRubyMethod
141
- public IRubyObject native_write(ThreadContext context, IRubyObject chunk,
142
- IRubyObject isLast) {
143
- if (ex != null) {
144
- // parser has already errored, rethrow the exception
145
- throw ex;
146
- }
147
-
148
- try {
149
- initialize_task(context);
150
- } catch (IOException e) {
151
- throw context.runtime.newRuntimeError(e.getMessage());
152
- }
153
- final ByteArrayInputStream data = NokogiriHelpers.stringBytesToStream(chunk);
154
- if (data == null) {
155
- return this;
156
- }
157
-
158
- int errorCount0 = parserTask.getErrorCount();
165
+ return this;
166
+ }
159
167
 
160
- try {
161
- Future<Void> task = stream.addChunk(data);
162
- task.get();
163
- } catch (ClosedStreamException ex) {
164
- // this means the stream is closed, ignore this exception
165
- } catch (Exception e) {
166
- throw context.runtime.newRuntimeError(e.toString());
167
- }
168
-
169
- if (isLast.isTrue()) {
170
- parserTask.getNokogiriHandler().endDocument();
171
- terminateTask(context.runtime);
172
- }
168
+ private void
169
+ initialize_task(ThreadContext context) throws IOException
170
+ {
171
+ if (futureTask == null || stream == null) {
172
+ stream = new NokogiriBlockingQueueInputStream();
173
173
 
174
- if (!options.recover && parserTask.getErrorCount() > errorCount0) {
175
- terminateTask(context.runtime);
176
- throw ex = parserTask.getLastError();
174
+ assert saxParser != null : "saxParser null";
175
+ parserTask = new ParserTask(context, saxParser, stream);
176
+ futureTask = new FutureTask<XmlSaxParserContext>(parserTask);
177
+ executor = Executors.newSingleThreadExecutor(new ThreadFactory() {
178
+ @Override
179
+ public Thread newThread(Runnable r) {
180
+ Thread t = new Thread(r);
181
+ t.setName("XmlSaxPushParser");
182
+ t.setDaemon(true);
183
+ return t;
177
184
  }
178
-
179
- return this;
185
+ });
186
+ executor.submit(futureTask);
180
187
  }
181
-
182
- private void initialize_task(ThreadContext context) throws IOException {
183
- if (futureTask == null || stream == null) {
184
- stream = new NokogiriBlockingQueueInputStream();
185
-
186
- assert saxParser != null : "saxParser null";
187
- parserTask = new ParserTask(context, saxParser, stream);
188
- futureTask = new FutureTask<XmlSaxParserContext>(parserTask);
189
- executor = Executors.newSingleThreadExecutor(new ThreadFactory() {
190
- @Override
191
- public Thread newThread(Runnable r) {
192
- Thread t = new Thread(r);
193
- t.setName("XmlSaxPushParser");
194
- t.setDaemon(true);
195
- return t;
196
- }
197
- });
198
- executor.submit(futureTask);
199
- }
188
+ }
189
+
190
+ private void
191
+ terminateTask(final Ruby runtime)
192
+ {
193
+ if (executor == null) { return; }
194
+
195
+ try {
196
+ terminateImpl();
197
+ } catch (InterruptedException e) {
198
+ throw runtime.newRuntimeError(e.toString());
199
+ } catch (Exception e) {
200
+ throw runtime.newRuntimeError(e.toString());
200
201
  }
201
-
202
- private void terminateTask(final Ruby runtime) {
203
- if (executor == null) return;
204
-
205
- try {
206
- terminateImpl();
207
- }
208
- catch (InterruptedException e) {
209
- throw runtime.newRuntimeError(e.toString());
210
- }
211
- catch (Exception e) {
212
- throw runtime.newRuntimeError(e.toString());
213
- }
202
+ }
203
+
204
+ private synchronized void
205
+ terminateImpl() throws InterruptedException, ExecutionException
206
+ {
207
+ terminateExecution(executor, stream, futureTask);
208
+
209
+ executor = null;
210
+ stream = null;
211
+ futureTask = null;
212
+ }
213
+
214
+ // SHARED for HtmlSaxPushParser
215
+ static void
216
+ terminateExecution(final ExecutorService executor, final NokogiriBlockingQueueInputStream stream,
217
+ final FutureTask<?> futureTask)
218
+ throws InterruptedException, ExecutionException
219
+ {
220
+
221
+ if (executor == null) { return; }
222
+
223
+ try {
224
+ Future<Void> task = stream.addChunk(NokogiriBlockingQueueInputStream.END);
225
+ task.get();
226
+ } catch (ClosedStreamException ex) {
227
+ // ignore this exception, it means the stream was closed
214
228
  }
215
-
216
- private synchronized void terminateImpl() throws InterruptedException, ExecutionException {
217
- terminateExecution(executor, stream, futureTask);
218
-
219
- executor = null; stream = null; futureTask = null;
229
+ futureTask.cancel(true);
230
+ executor.shutdown();
231
+ }
232
+
233
+ private static XmlSaxParserContext
234
+ parse(final Ruby runtime, final InputStream stream)
235
+ {
236
+ RubyClass klazz = getNokogiriClass(runtime, "Nokogiri::XML::SAX::ParserContext");
237
+ return XmlSaxParserContext.parse_stream(runtime, klazz, stream);
238
+ }
239
+
240
+ static class ParserTask extends ParserContext.ParserTask<XmlSaxParserContext>
241
+ {
242
+
243
+ final InputStream stream;
244
+
245
+ private
246
+ ParserTask(ThreadContext context, IRubyObject handler, InputStream stream)
247
+ {
248
+ this(context, handler, parse(context.runtime, stream), stream);
220
249
  }
221
250
 
222
- // SHARED for HtmlSaxPushParser
223
- static void terminateExecution(final ExecutorService executor, final NokogiriBlockingQueueInputStream stream,
224
- final FutureTask<?> futureTask)
225
- throws InterruptedException, ExecutionException {
226
-
227
- if (executor == null) return;
228
-
229
- try {
230
- Future<Void> task = stream.addChunk(NokogiriBlockingQueueInputStream.END);
231
- task.get();
232
- }
233
- catch (ClosedStreamException ex) {
234
- // ignore this exception, it means the stream was closed
235
- }
236
- futureTask.cancel(true);
237
- executor.shutdown();
251
+ // IMPL with HtmlSaxPushParser
252
+ protected
253
+ ParserTask(ThreadContext context, IRubyObject handler, XmlSaxParserContext parser, InputStream stream)
254
+ {
255
+ super(context, handler, parser);
256
+ this.stream = stream;
238
257
  }
239
258
 
240
- private static XmlSaxParserContext parse(final Ruby runtime, final InputStream stream) {
241
- RubyClass klazz = getNokogiriClass(runtime, "Nokogiri::XML::SAX::ParserContext");
242
- return XmlSaxParserContext.parse_stream(runtime, klazz, stream);
259
+ @Override
260
+ public XmlSaxParserContext
261
+ call() throws Exception
262
+ {
263
+ try {
264
+ parser.parse_with(context, handler);
265
+ } finally { stream.close(); }
266
+ // we have to close the stream before exiting, otherwise someone
267
+ // can add a chunk and block on task.get() forever.
268
+ return parser;
243
269
  }
244
270
 
245
- static class ParserTask extends ParserContext.ParserTask<XmlSaxParserContext> {
246
-
247
- final InputStream stream;
248
-
249
- private ParserTask(ThreadContext context, IRubyObject handler, InputStream stream) {
250
- this(context, handler, parse(context.runtime, stream), stream);
251
- }
252
-
253
- // IMPL with HtmlSaxPushParser
254
- protected ParserTask(ThreadContext context, IRubyObject handler, XmlSaxParserContext parser, InputStream stream) {
255
- super(context, handler, parser);
256
- this.stream = stream;
257
- }
258
-
259
- @Override
260
- public XmlSaxParserContext call() throws Exception {
261
- try {
262
- parser.parse_with(context, handler);
263
- }
264
- finally { stream.close(); }
265
- // we have to close the stream before exiting, otherwise someone
266
- // can add a chunk and block on task.get() forever.
267
- return parser;
268
- }
269
-
270
- final NokogiriHandler getNokogiriHandler() {
271
- return parser.getNokogiriHandler();
272
- }
273
-
274
- synchronized final int getErrorCount() {
275
- // check for null because thread may not have started yet
276
- if (parser.getNokogiriHandler() == null) return 0;
277
- return parser.getNokogiriHandler().getErrorCount();
278
- }
271
+ final NokogiriHandler
272
+ getNokogiriHandler()
273
+ {
274
+ return parser.getNokogiriHandler();
275
+ }
279
276
 
280
- synchronized final RaiseException getLastError() {
281
- return parser.getNokogiriHandler().getLastError();
282
- }
277
+ synchronized final int
278
+ getErrorCount()
279
+ {
280
+ // check for null because thread may not have started yet
281
+ if (parser.getNokogiriHandler() == null) { return 0; }
282
+ return parser.getNokogiriHandler().getErrorCount();
283
+ }
283
284
 
285
+ synchronized final RaiseException
286
+ getLastError()
287
+ {
288
+ return parser.getNokogiriHandler().getLastError();
284
289
  }
285
290
 
291
+ }
292
+
286
293
  }