nokogiri 1.11.0.rc1-java → 1.11.2-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (188) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +3 -0
  3. data/LICENSE-DEPENDENCIES.md +1015 -947
  4. data/LICENSE.md +1 -1
  5. data/README.md +171 -94
  6. data/ext/java/nokogiri/EncodingHandler.java +78 -59
  7. data/ext/java/nokogiri/HtmlDocument.java +137 -114
  8. data/ext/java/nokogiri/HtmlElementDescription.java +104 -87
  9. data/ext/java/nokogiri/HtmlEntityLookup.java +31 -26
  10. data/ext/java/nokogiri/HtmlSaxParserContext.java +220 -192
  11. data/ext/java/nokogiri/HtmlSaxPushParser.java +164 -139
  12. data/ext/java/nokogiri/NokogiriService.java +597 -526
  13. data/ext/java/nokogiri/XmlAttr.java +120 -96
  14. data/ext/java/nokogiri/XmlAttributeDecl.java +97 -76
  15. data/ext/java/nokogiri/XmlCdata.java +35 -26
  16. data/ext/java/nokogiri/XmlComment.java +48 -37
  17. data/ext/java/nokogiri/XmlDocument.java +642 -540
  18. data/ext/java/nokogiri/XmlDocumentFragment.java +127 -107
  19. data/ext/java/nokogiri/XmlDtd.java +450 -384
  20. data/ext/java/nokogiri/XmlElement.java +25 -18
  21. data/ext/java/nokogiri/XmlElementContent.java +345 -286
  22. data/ext/java/nokogiri/XmlElementDecl.java +126 -95
  23. data/ext/java/nokogiri/XmlEntityDecl.java +121 -97
  24. data/ext/java/nokogiri/XmlEntityReference.java +51 -42
  25. data/ext/java/nokogiri/XmlNamespace.java +177 -145
  26. data/ext/java/nokogiri/XmlNode.java +1843 -1590
  27. data/ext/java/nokogiri/XmlNodeSet.java +361 -299
  28. data/ext/java/nokogiri/XmlProcessingInstruction.java +49 -39
  29. data/ext/java/nokogiri/XmlReader.java +513 -418
  30. data/ext/java/nokogiri/XmlRelaxng.java +92 -72
  31. data/ext/java/nokogiri/XmlSaxParserContext.java +330 -280
  32. data/ext/java/nokogiri/XmlSaxPushParser.java +229 -190
  33. data/ext/java/nokogiri/XmlSchema.java +335 -210
  34. data/ext/java/nokogiri/XmlSyntaxError.java +113 -87
  35. data/ext/java/nokogiri/XmlText.java +57 -46
  36. data/ext/java/nokogiri/XmlXpathContext.java +242 -178
  37. data/ext/java/nokogiri/XsltStylesheet.java +282 -239
  38. data/ext/java/nokogiri/internals/ClosedStreamException.java +5 -2
  39. data/ext/java/nokogiri/internals/HtmlDomParserContext.java +203 -160
  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 +65 -50
  43. data/ext/java/nokogiri/internals/NokogiriEntityResolver.java +107 -88
  44. data/ext/java/nokogiri/internals/NokogiriErrorHandler.java +25 -18
  45. data/ext/java/nokogiri/internals/NokogiriHandler.java +316 -254
  46. data/ext/java/nokogiri/internals/NokogiriHelpers.java +738 -622
  47. data/ext/java/nokogiri/internals/NokogiriNamespaceCache.java +186 -143
  48. data/ext/java/nokogiri/internals/NokogiriNamespaceContext.java +81 -59
  49. data/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler.java +66 -49
  50. data/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler4NekoHtml.java +86 -69
  51. data/ext/java/nokogiri/internals/NokogiriStrictErrorHandler.java +44 -29
  52. data/ext/java/nokogiri/internals/NokogiriXPathFunction.java +121 -48
  53. data/ext/java/nokogiri/internals/NokogiriXPathFunctionResolver.java +34 -22
  54. data/ext/java/nokogiri/internals/NokogiriXPathVariableResolver.java +25 -17
  55. data/ext/java/nokogiri/internals/NokogiriXsltErrorListener.java +57 -42
  56. data/ext/java/nokogiri/internals/ParserContext.java +206 -179
  57. data/ext/java/nokogiri/internals/ReaderNode.java +478 -371
  58. data/ext/java/nokogiri/internals/SaveContextVisitor.java +822 -707
  59. data/ext/java/nokogiri/internals/SchemaErrorHandler.java +28 -19
  60. data/ext/java/nokogiri/internals/XalanDTMManagerPatch.java +129 -123
  61. data/ext/java/nokogiri/internals/XmlDeclHandler.java +5 -4
  62. data/ext/java/nokogiri/internals/XmlDomParserContext.java +208 -177
  63. data/ext/java/nokogiri/internals/XmlSaxParser.java +24 -17
  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 -570
  93. data/ext/nokogiri/depend +37 -358
  94. data/ext/nokogiri/extconf.rb +585 -374
  95. data/ext/nokogiri/html_document.c +78 -82
  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 +69 -66
  99. data/ext/nokogiri/html_sax_push_parser.c +42 -34
  100. data/ext/nokogiri/libxml2_backwards_compat.c +121 -0
  101. data/ext/nokogiri/nokogiri.c +192 -93
  102. data/ext/nokogiri/test_global_handlers.c +40 -0
  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 +225 -163
  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 +338 -286
  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 +195 -172
  120. data/ext/nokogiri/xml_relax_ng.c +52 -28
  121. data/ext/nokogiri/xml_sax_parser.c +118 -118
  122. data/ext/nokogiri/xml_sax_parser_context.c +103 -86
  123. data/ext/nokogiri/xml_sax_push_parser.c +36 -27
  124. data/ext/nokogiri/xml_schema.c +111 -34
  125. data/ext/nokogiri/xml_syntax_error.c +42 -21
  126. data/ext/nokogiri/xml_text.c +13 -17
  127. data/ext/nokogiri/xml_xpath_context.c +206 -123
  128. data/ext/nokogiri/xslt_stylesheet.c +158 -161
  129. data/lib/nokogiri.rb +4 -8
  130. data/lib/nokogiri/css/parser.rb +62 -62
  131. data/lib/nokogiri/css/parser.y +2 -2
  132. data/lib/nokogiri/css/parser_extras.rb +38 -36
  133. data/lib/nokogiri/css/xpath_visitor.rb +70 -42
  134. data/lib/nokogiri/extension.rb +26 -0
  135. data/lib/nokogiri/html/document.rb +12 -26
  136. data/lib/nokogiri/html/document_fragment.rb +15 -15
  137. data/lib/nokogiri/nokogiri.jar +0 -0
  138. data/lib/nokogiri/version.rb +2 -148
  139. data/lib/nokogiri/version/constant.rb +5 -0
  140. data/lib/nokogiri/version/info.rb +205 -0
  141. data/lib/nokogiri/xml/builder.rb +2 -2
  142. data/lib/nokogiri/xml/document.rb +48 -18
  143. data/lib/nokogiri/xml/document_fragment.rb +4 -6
  144. data/lib/nokogiri/xml/node.rb +599 -279
  145. data/lib/nokogiri/xml/parse_options.rb +6 -0
  146. data/lib/nokogiri/xml/reader.rb +2 -9
  147. data/lib/nokogiri/xml/relax_ng.rb +6 -2
  148. data/lib/nokogiri/xml/schema.rb +12 -4
  149. data/lib/nokogiri/xml/searchable.rb +24 -16
  150. data/lib/nokogiri/xml/xpath.rb +1 -3
  151. data/lib/nokogiri/xml/xpath/syntax_error.rb +1 -1
  152. metadata +87 -158
  153. data/ext/nokogiri/html_document.h +0 -10
  154. data/ext/nokogiri/html_element_description.h +0 -10
  155. data/ext/nokogiri/html_entity_lookup.h +0 -8
  156. data/ext/nokogiri/html_sax_parser_context.h +0 -11
  157. data/ext/nokogiri/html_sax_push_parser.h +0 -9
  158. data/ext/nokogiri/nokogiri.h +0 -122
  159. data/ext/nokogiri/xml_attr.h +0 -9
  160. data/ext/nokogiri/xml_attribute_decl.h +0 -9
  161. data/ext/nokogiri/xml_cdata.h +0 -9
  162. data/ext/nokogiri/xml_comment.h +0 -9
  163. data/ext/nokogiri/xml_document.h +0 -23
  164. data/ext/nokogiri/xml_document_fragment.h +0 -10
  165. data/ext/nokogiri/xml_dtd.h +0 -10
  166. data/ext/nokogiri/xml_element_content.h +0 -10
  167. data/ext/nokogiri/xml_element_decl.h +0 -9
  168. data/ext/nokogiri/xml_encoding_handler.h +0 -8
  169. data/ext/nokogiri/xml_entity_decl.h +0 -10
  170. data/ext/nokogiri/xml_entity_reference.h +0 -9
  171. data/ext/nokogiri/xml_io.c +0 -61
  172. data/ext/nokogiri/xml_io.h +0 -11
  173. data/ext/nokogiri/xml_libxml2_hacks.c +0 -112
  174. data/ext/nokogiri/xml_libxml2_hacks.h +0 -12
  175. data/ext/nokogiri/xml_namespace.h +0 -14
  176. data/ext/nokogiri/xml_node.h +0 -13
  177. data/ext/nokogiri/xml_node_set.h +0 -12
  178. data/ext/nokogiri/xml_processing_instruction.h +0 -9
  179. data/ext/nokogiri/xml_reader.h +0 -10
  180. data/ext/nokogiri/xml_relax_ng.h +0 -9
  181. data/ext/nokogiri/xml_sax_parser.h +0 -39
  182. data/ext/nokogiri/xml_sax_parser_context.h +0 -10
  183. data/ext/nokogiri/xml_sax_push_parser.h +0 -9
  184. data/ext/nokogiri/xml_schema.h +0 -9
  185. data/ext/nokogiri/xml_syntax_error.h +0 -13
  186. data/ext/nokogiri/xml_text.h +0 -9
  187. data/ext/nokogiri/xml_xpath_context.h +0 -10
  188. data/ext/nokogiri/xslt_stylesheet.h +0 -14
@@ -17,10 +17,10 @@
17
17
  * distribute, sublicense, and/or sell copies of the Software, and to
18
18
  * permit persons to whom the Software is furnished to do so, subject to
19
19
  * the following conditions:
20
- *
20
+ *
21
21
  * The above copyright notice and this permission notice shall be
22
22
  * included in all copies or substantial portions of the Software.
23
- *
23
+ *
24
24
  * THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
25
25
  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26
26
  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
@@ -39,32 +39,44 @@ import javax.xml.xpath.XPathFunctionResolver;
39
39
  import org.jruby.runtime.builtin.IRubyObject;
40
40
 
41
41
  /**
42
- * Xpath function resolver class, which is used in XmlXpathContext.
43
- *
42
+ * Xpath function resolver class, which is used in XmlXpathContext.
43
+ *
44
44
  * @author sergio
45
45
  * @author Yoko Harada <yokolet@gmail.com>
46
46
  */
47
- public final class NokogiriXPathFunctionResolver implements XPathFunctionResolver {
47
+ public final class NokogiriXPathFunctionResolver implements XPathFunctionResolver
48
+ {
48
49
 
49
- private IRubyObject handler;
50
-
51
- public static NokogiriXPathFunctionResolver create(IRubyObject handler) {
52
- NokogiriXPathFunctionResolver freshResolver = new NokogiriXPathFunctionResolver();
53
- freshResolver.setHandler(handler);
54
- return freshResolver;
55
- }
56
-
57
- private NokogiriXPathFunctionResolver() {}
50
+ private IRubyObject handler;
58
51
 
59
- public final IRubyObject getHandler() {
60
- return handler;
52
+ public static NokogiriXPathFunctionResolver
53
+ create(IRubyObject handler)
54
+ {
55
+ NokogiriXPathFunctionResolver freshResolver = new NokogiriXPathFunctionResolver();
56
+ if (!handler.isNil()) {
57
+ freshResolver.setHandler(handler);
61
58
  }
59
+ return freshResolver;
60
+ }
62
61
 
63
- public void setHandler(IRubyObject handler) {
64
- this.handler = handler;
65
- }
62
+ private
63
+ NokogiriXPathFunctionResolver() {}
66
64
 
67
- public XPathFunction resolveFunction(QName name, int arity) {
68
- return NokogiriXPathFunction.create(handler, name.getLocalPart(), arity);
69
- }
65
+ public final IRubyObject
66
+ getHandler()
67
+ {
68
+ return handler;
69
+ }
70
+
71
+ public void
72
+ setHandler(IRubyObject handler)
73
+ {
74
+ this.handler = handler;
75
+ }
76
+
77
+ public XPathFunction
78
+ resolveFunction(QName name, int arity)
79
+ {
80
+ return NokogiriXPathFunction.create(handler, name, arity);
81
+ }
70
82
  }
@@ -17,10 +17,10 @@
17
17
  * distribute, sublicense, and/or sell copies of the Software, and to
18
18
  * permit persons to whom the Software is furnished to do so, subject to
19
19
  * the following conditions:
20
- *
20
+ *
21
21
  * The above copyright notice and this permission notice shall be
22
22
  * included in all copies or substantial portions of the Software.
23
- *
23
+ *
24
24
  * THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
25
25
  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26
26
  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
@@ -37,24 +37,32 @@ import javax.xml.xpath.XPathVariableResolver;
37
37
 
38
38
  /**
39
39
  * XPath variable support
40
- *
40
+ *
41
41
  * @author Ken Bloom <kbloom@gmail.com>
42
42
  * @author Yoko Harada <yokolet@gmail.com>
43
43
  */
44
- public class NokogiriXPathVariableResolver implements XPathVariableResolver {
44
+ public class NokogiriXPathVariableResolver implements XPathVariableResolver
45
+ {
46
+
47
+ private final HashMap<QName, String> variables = new HashMap<QName, String>();
48
+
49
+ public static NokogiriXPathVariableResolver
50
+ create()
51
+ {
52
+ return new NokogiriXPathVariableResolver();
53
+ }
45
54
 
46
- private final HashMap<QName,String> variables = new HashMap<QName,String>();
55
+ private
56
+ NokogiriXPathVariableResolver() {}
47
57
 
48
- public static NokogiriXPathVariableResolver create() {
49
- return new NokogiriXPathVariableResolver();
50
- }
51
-
52
- private NokogiriXPathVariableResolver() {}
53
-
54
- public Object resolveVariable(QName variableName){
55
- return variables.get(variableName);
56
- }
57
- public void registerVariable(String name,String value){
58
- variables.put(new QName(name),value);
59
- }
58
+ public Object
59
+ resolveVariable(QName variableName)
60
+ {
61
+ return variables.get(variableName);
62
+ }
63
+ public void
64
+ registerVariable(String name, String value)
65
+ {
66
+ variables.put(new QName(name), value);
67
+ }
60
68
  }
@@ -17,10 +17,10 @@
17
17
  * distribute, sublicense, and/or sell copies of the Software, and to
18
18
  * permit persons to whom the Software is furnished to do so, subject to
19
19
  * the following conditions:
20
- *
20
+ *
21
21
  * The above copyright notice and this permission notice shall be
22
22
  * included in all copies or substantial portions of the Software.
23
- *
23
+ *
24
24
  * THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
25
25
  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26
26
  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
@@ -37,51 +37,66 @@ import javax.xml.transform.TransformerException;
37
37
 
38
38
  /**
39
39
  * Error Listener for XSLT transformer
40
- *
40
+ *
41
41
  * @author Yoko Harada <yokolet@gmail.com>
42
42
  */
43
- public class NokogiriXsltErrorListener implements ErrorListener {
44
- public enum ErrorType {
45
- SUCCESS,
46
- WARNING,
47
- ERROR,
48
- FATAL
49
- }
43
+ public class NokogiriXsltErrorListener implements ErrorListener
44
+ {
45
+ public enum ErrorType {
46
+ SUCCESS,
47
+ WARNING,
48
+ ERROR,
49
+ FATAL
50
+ }
51
+
52
+ private ErrorType type = ErrorType.SUCCESS;
53
+ private String errorMessage = null;
54
+ private Exception exception = null;
55
+
56
+ public void
57
+ warning(TransformerException ex)
58
+ {
59
+ type = ErrorType.WARNING;
60
+ setError(ex);
61
+ }
62
+
63
+ public void
64
+ error(TransformerException ex)
65
+ {
66
+ type = ErrorType.ERROR;
67
+ setError(ex);
68
+ }
69
+
70
+ public void
71
+ fatalError(TransformerException ex)
72
+ {
73
+ type = ErrorType.FATAL;
74
+ setError(ex);
75
+ }
50
76
 
51
- private ErrorType type = ErrorType.SUCCESS;
52
- private String errorMessage = null;
53
- private Exception exception = null;
77
+ private void
78
+ setError(TransformerException ex)
79
+ {
80
+ errorMessage = ex.getMessage();
81
+ exception = ex;
82
+ }
54
83
 
55
- public void warning(TransformerException ex) {
56
- type = ErrorType.WARNING;
57
- setError(ex);
58
- }
84
+ public String
85
+ getErrorMessage()
86
+ {
87
+ return errorMessage;
88
+ }
59
89
 
60
- public void error(TransformerException ex) {
61
- type = ErrorType.ERROR;
62
- setError(ex);
63
- }
90
+ public ErrorType
91
+ getErrorType()
92
+ {
93
+ return type;
94
+ }
64
95
 
65
- public void fatalError(TransformerException ex) {
66
- type = ErrorType.FATAL;
67
- setError(ex);
68
- }
69
-
70
- private void setError(TransformerException ex) {
71
- errorMessage = ex.getMessage();
72
- exception = ex;
73
- }
74
-
75
- public String getErrorMessage() {
76
- return errorMessage;
77
- }
78
-
79
- public ErrorType getErrorType() {
80
- return type;
81
- }
82
-
83
- public Exception getException() {
84
- return exception;
85
- }
96
+ public Exception
97
+ getException()
98
+ {
99
+ return exception;
100
+ }
86
101
 
87
102
  }
@@ -58,202 +58,229 @@ import org.xml.sax.InputSource;
58
58
  * @author Patrick Mahoney <pat@polycrystal.org>
59
59
  * @author Yoko Harada <yokolet@gmail.com>
60
60
  */
61
- public abstract class ParserContext extends RubyObject {
62
- protected InputSource source = null;
63
- protected IRubyObject detected_encoding = null;
64
- protected int stringDataSize = -1;
65
- protected String java_encoding;
66
-
67
- public ParserContext(Ruby runtime) {
68
- // default to class 'Object' because this class isn't exposed to Ruby
69
- super(runtime, runtime.getObject());
61
+ public abstract class ParserContext extends RubyObject
62
+ {
63
+ protected InputSource source = null;
64
+ protected IRubyObject detected_encoding = null;
65
+ protected int stringDataSize = -1;
66
+ protected String java_encoding;
67
+
68
+ public
69
+ ParserContext(Ruby runtime)
70
+ {
71
+ // default to class 'Object' because this class isn't exposed to Ruby
72
+ super(runtime, runtime.getObject());
73
+ }
74
+
75
+ public
76
+ ParserContext(Ruby runtime, RubyClass klass)
77
+ {
78
+ super(runtime, klass);
79
+ }
80
+
81
+ protected InputSource
82
+ getInputSource()
83
+ {
84
+ return source;
85
+ }
86
+
87
+ public void
88
+ setIOInputSource(ThreadContext context, IRubyObject data, IRubyObject url)
89
+ {
90
+ source = new InputSource();
91
+ ParserContext.setUrl(context, source, url);
92
+
93
+ source.setByteStream(new IOInputStream(data));
94
+ if (java_encoding != null) {
95
+ source.setEncoding(java_encoding);
70
96
  }
97
+ }
71
98
 
72
- public ParserContext(Ruby runtime, RubyClass klass) {
73
- super(runtime, klass);
74
- }
75
-
76
- protected InputSource getInputSource() {
77
- return source;
78
- }
99
+ public void
100
+ setStringInputSource(ThreadContext context, IRubyObject data, IRubyObject url)
101
+ {
102
+ source = new InputSource();
103
+ ParserContext.setUrl(context, source, url);
79
104
 
80
- public void setIOInputSource(ThreadContext context, IRubyObject data, IRubyObject url) {
81
- source = new InputSource();
82
- ParserContext.setUrl(context, source, url);
105
+ Ruby ruby = context.getRuntime();
83
106
 
84
- source.setByteStream(new IOInputStream(data));
85
- if (java_encoding != null) {
86
- source.setEncoding(java_encoding);
87
- }
107
+ if (!(data instanceof RubyString)) {
108
+ throw ruby.newArgumentError("must be kind_of String");
88
109
  }
89
110
 
90
- public void setStringInputSource(ThreadContext context, IRubyObject data, IRubyObject url) {
91
- source = new InputSource();
92
- ParserContext.setUrl(context, source, url);
93
-
94
- Ruby ruby = context.getRuntime();
95
-
96
- if (!(data instanceof RubyString)) {
97
- throw ruby.newArgumentError("must be kind_of String");
98
- }
99
-
100
- RubyString stringData = (RubyString) data;
101
-
102
- if (stringData.encoding(context) != null) {
103
- RubyString stringEncoding = stringData.encoding(context).asString();
104
- String encName = NokogiriHelpers.getValidEncodingOrNull(stringEncoding);
105
- if (encName != null) {
106
- java_encoding = encName;
107
- }
108
- }
109
-
110
- ByteList bytes = stringData.getByteList();
111
+ RubyString stringData = (RubyString) data;
111
112
 
112
- stringDataSize = bytes.length() - bytes.begin();
113
- ByteArrayInputStream stream = new ByteArrayInputStream(bytes.unsafeBytes(), bytes.begin(), bytes.length());
114
- source.setByteStream(stream);
115
- source.setEncoding(java_encoding);
113
+ if (stringData.encoding(context) != null) {
114
+ RubyString stringEncoding = stringData.encoding(context).asString();
115
+ String encName = NokogiriHelpers.getValidEncodingOrNull(stringEncoding);
116
+ if (encName != null) {
117
+ java_encoding = encName;
118
+ }
116
119
  }
117
120
 
118
- public static void setUrl(ThreadContext context, InputSource source, IRubyObject url) {
119
- String path = rubyStringToString(url);
120
- // Dir.chdir might be called at some point before this.
121
- if (path != null) {
121
+ ByteList bytes = stringData.getByteList();
122
+
123
+ stringDataSize = bytes.length() - bytes.begin();
124
+ ByteArrayInputStream stream = new ByteArrayInputStream(bytes.unsafeBytes(), bytes.begin(), bytes.length());
125
+ source.setByteStream(stream);
126
+ source.setEncoding(java_encoding);
127
+ }
128
+
129
+ public static void
130
+ setUrl(ThreadContext context, InputSource source, IRubyObject url)
131
+ {
132
+ String path = rubyStringToString(url);
133
+ // Dir.chdir might be called at some point before this.
134
+ if (path != null) {
135
+ try {
136
+ URI uri = URI.create(path);
137
+ source.setSystemId(uri.toURL().toString());
138
+ } catch (Exception ex) {
139
+ // fallback to the old behavior
140
+ File file = new File(path);
141
+ if (file.isAbsolute()) {
142
+ source.setSystemId(path);
143
+ } else {
144
+ String pwd = context.getRuntime().getCurrentDirectory();
145
+ String absolutePath;
122
146
  try {
123
- URI uri = URI.create(path);
124
- source.setSystemId(uri.toURL().toString());
125
- } catch (Exception ex) {
126
- // fallback to the old behavior
127
- File file = new File(path);
128
- if (file.isAbsolute()) {
129
- source.setSystemId(path);
130
- } else {
131
- String pwd = context.getRuntime().getCurrentDirectory();
132
- String absolutePath;
133
- try {
134
- absolutePath = new File(pwd, path).getCanonicalPath();
135
- } catch (IOException e) {
136
- absolutePath = new File(pwd, path).getAbsolutePath();
137
- }
138
- source.setSystemId(absolutePath);
139
- }
147
+ absolutePath = new File(pwd, path).getCanonicalPath();
148
+ } catch (IOException e) {
149
+ absolutePath = new File(pwd, path).getAbsolutePath();
140
150
  }
151
+ source.setSystemId(absolutePath);
141
152
  }
153
+ }
142
154
  }
143
-
144
- protected void setEncoding(String encoding) {
145
- source.setEncoding(encoding);
155
+ }
156
+
157
+ protected void
158
+ setEncoding(String encoding)
159
+ {
160
+ source.setEncoding(encoding);
161
+ }
162
+
163
+ /**
164
+ * Set the InputSource to read from <code>file</code>, a String filename.
165
+ */
166
+ public void
167
+ setInputSourceFile(ThreadContext context, IRubyObject file)
168
+ {
169
+ source = new InputSource();
170
+ ParserContext.setUrl(context, source, file);
171
+ }
172
+
173
+ /**
174
+ * Set the InputSource from <code>stream</code>.
175
+ */
176
+ public void
177
+ setInputSource(InputStream stream)
178
+ {
179
+ source = new InputSource(stream);
180
+ }
181
+
182
+ /**
183
+ * Wrap Nokogiri parser options in a utility class. This is
184
+ * read-only.
185
+ */
186
+ public static class Options
187
+ {
188
+ protected static final long STRICT = 0;
189
+ protected static final long RECOVER = 1;
190
+ protected static final long NOENT = 2;
191
+ protected static final long DTDLOAD = 4;
192
+ protected static final long DTDATTR = 8;
193
+ protected static final long DTDVALID = 16;
194
+ protected static final long NOERROR = 32;
195
+ protected static final long NOWARNING = 64;
196
+ protected static final long PEDANTIC = 128;
197
+ protected static final long NOBLANKS = 256;
198
+ protected static final long SAX1 = 512;
199
+ protected static final long XINCLUDE = 1024;
200
+ protected static final long NONET = 2048;
201
+ protected static final long NODICT = 4096;
202
+ protected static final long NSCLEAN = 8192;
203
+ protected static final long NOCDATA = 16384;
204
+ protected static final long NOXINCNODE = 32768;
205
+
206
+ public final boolean strict;
207
+ public final boolean recover;
208
+ public final boolean noEnt;
209
+ public final boolean dtdLoad;
210
+ public final boolean dtdAttr;
211
+ public final boolean dtdValid;
212
+ public final boolean noError;
213
+ public final boolean noWarning;
214
+ public final boolean pedantic;
215
+ public final boolean noBlanks;
216
+ public final boolean sax1;
217
+ public final boolean xInclude;
218
+ public final boolean noNet;
219
+ public final boolean noDict;
220
+ public final boolean nsClean;
221
+ public final boolean noCdata;
222
+ public final boolean noXIncNode;
223
+
224
+ protected static boolean
225
+ test(long options, long mask)
226
+ {
227
+ return ((options & mask) == mask);
146
228
  }
147
229
 
148
- /**
149
- * Set the InputSource to read from <code>file</code>, a String filename.
150
- */
151
- public void setInputSourceFile(ThreadContext context, IRubyObject file) {
152
- source = new InputSource();
153
- ParserContext.setUrl(context, source, file);
230
+ public
231
+ Options(long options)
232
+ {
233
+ strict = ((options & RECOVER) == STRICT);
234
+ recover = test(options, RECOVER);
235
+ noEnt = test(options, NOENT);
236
+ dtdLoad = test(options, DTDLOAD);
237
+ dtdAttr = test(options, DTDATTR);
238
+ dtdValid = test(options, DTDVALID);
239
+ noError = test(options, NOERROR);
240
+ noWarning = test(options, NOWARNING);
241
+ pedantic = test(options, PEDANTIC);
242
+ noBlanks = test(options, NOBLANKS);
243
+ sax1 = test(options, SAX1);
244
+ xInclude = test(options, XINCLUDE);
245
+ noNet = test(options, NONET);
246
+ noDict = test(options, NODICT);
247
+ nsClean = test(options, NSCLEAN);
248
+ noCdata = test(options, NOCDATA);
249
+ noXIncNode = test(options, NOXINCNODE);
154
250
  }
155
-
156
- /**
157
- * Set the InputSource from <code>stream</code>.
158
- */
159
- public void setInputSource(InputStream stream) {
160
- source = new InputSource(stream);
251
+ }
252
+
253
+ /*
254
+ public static class NokogiriXInlcudeEntityResolver implements org.xml.sax.EntityResolver {
255
+ InputSource source;
256
+ public NokogiriXInlcudeEntityResolver(InputSource source) {
257
+ this.source = source;
258
+ }
259
+
260
+ @Override
261
+ public InputSource resolveEntity(String publicId, String systemId)
262
+ throws SAXException, IOException {
263
+ if (systemId != null) source.setSystemId(systemId);
264
+ if (publicId != null) source.setPublicId(publicId);
265
+ return source;
266
+ }
267
+ } */
268
+
269
+ public static abstract class ParserTask<T extends ParserContext> implements Callable<T>
270
+ {
271
+
272
+ protected final ThreadContext context; // TODO does not seem like a good idea!?
273
+ protected final IRubyObject handler;
274
+ protected final T parser;
275
+
276
+ protected
277
+ ParserTask(ThreadContext context, IRubyObject handler, T parser)
278
+ {
279
+ this.context = context;
280
+ this.handler = handler;
281
+ this.parser = parser;
161
282
  }
162
283
 
163
- /**
164
- * Wrap Nokogiri parser options in a utility class. This is
165
- * read-only.
166
- */
167
- public static class Options {
168
- protected static final long STRICT = 0;
169
- protected static final long RECOVER = 1;
170
- protected static final long NOENT = 2;
171
- protected static final long DTDLOAD = 4;
172
- protected static final long DTDATTR = 8;
173
- protected static final long DTDVALID = 16;
174
- protected static final long NOERROR = 32;
175
- protected static final long NOWARNING = 64;
176
- protected static final long PEDANTIC = 128;
177
- protected static final long NOBLANKS = 256;
178
- protected static final long SAX1 = 512;
179
- protected static final long XINCLUDE = 1024;
180
- protected static final long NONET = 2048;
181
- protected static final long NODICT = 4096;
182
- protected static final long NSCLEAN = 8192;
183
- protected static final long NOCDATA = 16384;
184
- protected static final long NOXINCNODE = 32768;
185
-
186
- public final boolean strict;
187
- public final boolean recover;
188
- public final boolean noEnt;
189
- public final boolean dtdLoad;
190
- public final boolean dtdAttr;
191
- public final boolean dtdValid;
192
- public final boolean noError;
193
- public final boolean noWarning;
194
- public final boolean pedantic;
195
- public final boolean noBlanks;
196
- public final boolean sax1;
197
- public final boolean xInclude;
198
- public final boolean noNet;
199
- public final boolean noDict;
200
- public final boolean nsClean;
201
- public final boolean noCdata;
202
- public final boolean noXIncNode;
203
-
204
- protected static boolean test(long options, long mask) {
205
- return ((options & mask) == mask);
206
- }
207
-
208
- public Options(long options) {
209
- strict = ((options & RECOVER) == STRICT);
210
- recover = test(options, RECOVER);
211
- noEnt = test(options, NOENT);
212
- dtdLoad = test(options, DTDLOAD);
213
- dtdAttr = test(options, DTDATTR);
214
- dtdValid = test(options, DTDVALID);
215
- noError = test(options, NOERROR);
216
- noWarning = test(options, NOWARNING);
217
- pedantic = test(options, PEDANTIC);
218
- noBlanks = test(options, NOBLANKS);
219
- sax1 = test(options, SAX1);
220
- xInclude = test(options, XINCLUDE);
221
- noNet = test(options, NONET);
222
- noDict = test(options, NODICT);
223
- nsClean = test(options, NSCLEAN);
224
- noCdata = test(options, NOCDATA);
225
- noXIncNode = test(options, NOXINCNODE);
226
- }
227
- }
228
-
229
- /*
230
- public static class NokogiriXInlcudeEntityResolver implements org.xml.sax.EntityResolver {
231
- InputSource source;
232
- public NokogiriXInlcudeEntityResolver(InputSource source) {
233
- this.source = source;
234
- }
235
-
236
- @Override
237
- public InputSource resolveEntity(String publicId, String systemId)
238
- throws SAXException, IOException {
239
- if (systemId != null) source.setSystemId(systemId);
240
- if (publicId != null) source.setPublicId(publicId);
241
- return source;
242
- }
243
- } */
244
-
245
- public static abstract class ParserTask<T extends ParserContext> implements Callable<T> {
246
-
247
- protected final ThreadContext context; // TODO does not seem like a good idea!?
248
- protected final IRubyObject handler;
249
- protected final T parser;
250
-
251
- protected ParserTask(ThreadContext context, IRubyObject handler, T parser) {
252
- this.context = context;
253
- this.handler = handler;
254
- this.parser = parser;
255
- }
256
-
257
- }
284
+ }
258
285
 
259
286
  }