nokogiri 1.11.1-java → 1.11.2-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 (142) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE-DEPENDENCIES.md +12 -12
  3. data/LICENSE.md +1 -1
  4. data/README.md +20 -15
  5. data/ext/java/nokogiri/EncodingHandler.java +78 -59
  6. data/ext/java/nokogiri/HtmlDocument.java +137 -114
  7. data/ext/java/nokogiri/HtmlElementDescription.java +104 -87
  8. data/ext/java/nokogiri/HtmlEntityLookup.java +31 -26
  9. data/ext/java/nokogiri/HtmlSaxParserContext.java +220 -192
  10. data/ext/java/nokogiri/HtmlSaxPushParser.java +164 -139
  11. data/ext/java/nokogiri/NokogiriService.java +597 -526
  12. data/ext/java/nokogiri/XmlAttr.java +120 -96
  13. data/ext/java/nokogiri/XmlAttributeDecl.java +97 -76
  14. data/ext/java/nokogiri/XmlCdata.java +35 -26
  15. data/ext/java/nokogiri/XmlComment.java +48 -37
  16. data/ext/java/nokogiri/XmlDocument.java +642 -540
  17. data/ext/java/nokogiri/XmlDocumentFragment.java +127 -107
  18. data/ext/java/nokogiri/XmlDtd.java +450 -384
  19. data/ext/java/nokogiri/XmlElement.java +25 -18
  20. data/ext/java/nokogiri/XmlElementContent.java +345 -286
  21. data/ext/java/nokogiri/XmlElementDecl.java +126 -95
  22. data/ext/java/nokogiri/XmlEntityDecl.java +121 -97
  23. data/ext/java/nokogiri/XmlEntityReference.java +51 -42
  24. data/ext/java/nokogiri/XmlNamespace.java +177 -145
  25. data/ext/java/nokogiri/XmlNode.java +1843 -1588
  26. data/ext/java/nokogiri/XmlNodeSet.java +361 -299
  27. data/ext/java/nokogiri/XmlProcessingInstruction.java +49 -39
  28. data/ext/java/nokogiri/XmlReader.java +513 -418
  29. data/ext/java/nokogiri/XmlRelaxng.java +91 -78
  30. data/ext/java/nokogiri/XmlSaxParserContext.java +330 -285
  31. data/ext/java/nokogiri/XmlSaxPushParser.java +229 -190
  32. data/ext/java/nokogiri/XmlSchema.java +328 -263
  33. data/ext/java/nokogiri/XmlSyntaxError.java +113 -83
  34. data/ext/java/nokogiri/XmlText.java +57 -46
  35. data/ext/java/nokogiri/XmlXpathContext.java +240 -206
  36. data/ext/java/nokogiri/XsltStylesheet.java +282 -239
  37. data/ext/java/nokogiri/internals/ClosedStreamException.java +5 -2
  38. data/ext/java/nokogiri/internals/HtmlDomParserContext.java +199 -168
  39. data/ext/java/nokogiri/internals/IgnoreSchemaErrorsErrorHandler.java +17 -10
  40. data/ext/java/nokogiri/internals/NokogiriBlockingQueueInputStream.java +43 -16
  41. data/ext/java/nokogiri/internals/NokogiriDomParser.java +65 -50
  42. data/ext/java/nokogiri/internals/NokogiriEntityResolver.java +107 -88
  43. data/ext/java/nokogiri/internals/NokogiriErrorHandler.java +25 -18
  44. data/ext/java/nokogiri/internals/NokogiriHandler.java +316 -254
  45. data/ext/java/nokogiri/internals/NokogiriHelpers.java +738 -622
  46. data/ext/java/nokogiri/internals/NokogiriNamespaceCache.java +186 -143
  47. data/ext/java/nokogiri/internals/NokogiriNamespaceContext.java +83 -68
  48. data/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler.java +66 -49
  49. data/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler4NekoHtml.java +86 -69
  50. data/ext/java/nokogiri/internals/NokogiriStrictErrorHandler.java +44 -29
  51. data/ext/java/nokogiri/internals/NokogiriXPathFunction.java +118 -101
  52. data/ext/java/nokogiri/internals/NokogiriXPathFunctionResolver.java +34 -24
  53. data/ext/java/nokogiri/internals/NokogiriXPathVariableResolver.java +25 -17
  54. data/ext/java/nokogiri/internals/NokogiriXsltErrorListener.java +57 -42
  55. data/ext/java/nokogiri/internals/ParserContext.java +206 -179
  56. data/ext/java/nokogiri/internals/ReaderNode.java +478 -371
  57. data/ext/java/nokogiri/internals/SaveContextVisitor.java +822 -707
  58. data/ext/java/nokogiri/internals/SchemaErrorHandler.java +28 -19
  59. data/ext/java/nokogiri/internals/XalanDTMManagerPatch.java +129 -123
  60. data/ext/java/nokogiri/internals/XmlDeclHandler.java +5 -4
  61. data/ext/java/nokogiri/internals/XmlDomParserContext.java +208 -177
  62. data/ext/java/nokogiri/internals/XmlSaxParser.java +24 -17
  63. data/ext/java/nokogiri/internals/c14n/AttrCompare.java +71 -68
  64. data/ext/java/nokogiri/internals/c14n/C14nHelper.java +137 -118
  65. data/ext/java/nokogiri/internals/c14n/CanonicalFilter.java +27 -21
  66. data/ext/java/nokogiri/internals/c14n/CanonicalizationException.java +74 -61
  67. data/ext/java/nokogiri/internals/c14n/Canonicalizer.java +230 -205
  68. data/ext/java/nokogiri/internals/c14n/Canonicalizer11.java +572 -547
  69. data/ext/java/nokogiri/internals/c14n/Canonicalizer11_OmitComments.java +17 -10
  70. data/ext/java/nokogiri/internals/c14n/Canonicalizer11_WithComments.java +17 -10
  71. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315.java +323 -302
  72. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315Excl.java +232 -219
  73. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315ExclOmitComments.java +22 -15
  74. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315ExclWithComments.java +23 -16
  75. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315OmitComments.java +23 -16
  76. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315WithComments.java +22 -15
  77. data/ext/java/nokogiri/internals/c14n/CanonicalizerBase.java +575 -545
  78. data/ext/java/nokogiri/internals/c14n/CanonicalizerPhysical.java +141 -120
  79. data/ext/java/nokogiri/internals/c14n/CanonicalizerSpi.java +39 -38
  80. data/ext/java/nokogiri/internals/c14n/Constants.java +13 -10
  81. data/ext/java/nokogiri/internals/c14n/ElementProxy.java +279 -247
  82. data/ext/java/nokogiri/internals/c14n/HelperNodeList.java +66 -53
  83. data/ext/java/nokogiri/internals/c14n/IgnoreAllErrorHandler.java +44 -37
  84. data/ext/java/nokogiri/internals/c14n/InclusiveNamespaces.java +135 -120
  85. data/ext/java/nokogiri/internals/c14n/InvalidCanonicalizerException.java +59 -48
  86. data/ext/java/nokogiri/internals/c14n/NameSpaceSymbTable.java +384 -334
  87. data/ext/java/nokogiri/internals/c14n/NodeFilter.java +25 -24
  88. data/ext/java/nokogiri/internals/c14n/UtfHelpper.java +151 -140
  89. data/ext/java/nokogiri/internals/c14n/XMLUtils.java +456 -423
  90. data/ext/java/nokogiri/internals/dom2dtm/DOM2DTM.java +1466 -1500
  91. data/ext/java/nokogiri/internals/dom2dtm/DOM2DTMdefaultNamespaceDeclarationNode.java +626 -570
  92. data/ext/nokogiri/depend +34 -474
  93. data/ext/nokogiri/extconf.rb +253 -183
  94. data/ext/nokogiri/html_document.c +10 -15
  95. data/ext/nokogiri/html_element_description.c +84 -71
  96. data/ext/nokogiri/html_entity_lookup.c +21 -16
  97. data/ext/nokogiri/html_sax_parser_context.c +66 -65
  98. data/ext/nokogiri/html_sax_push_parser.c +29 -27
  99. data/ext/nokogiri/libxml2_backwards_compat.c +121 -0
  100. data/ext/nokogiri/nokogiri.c +171 -63
  101. data/ext/nokogiri/test_global_handlers.c +3 -4
  102. data/ext/nokogiri/xml_attr.c +15 -15
  103. data/ext/nokogiri/xml_attribute_decl.c +18 -18
  104. data/ext/nokogiri/xml_cdata.c +13 -18
  105. data/ext/nokogiri/xml_comment.c +19 -26
  106. data/ext/nokogiri/xml_document.c +221 -164
  107. data/ext/nokogiri/xml_document_fragment.c +13 -15
  108. data/ext/nokogiri/xml_dtd.c +54 -48
  109. data/ext/nokogiri/xml_element_content.c +30 -27
  110. data/ext/nokogiri/xml_element_decl.c +22 -22
  111. data/ext/nokogiri/xml_encoding_handler.c +17 -11
  112. data/ext/nokogiri/xml_entity_decl.c +32 -30
  113. data/ext/nokogiri/xml_entity_reference.c +16 -18
  114. data/ext/nokogiri/xml_namespace.c +56 -49
  115. data/ext/nokogiri/xml_node.c +338 -286
  116. data/ext/nokogiri/xml_node_set.c +168 -156
  117. data/ext/nokogiri/xml_processing_instruction.c +17 -19
  118. data/ext/nokogiri/xml_reader.c +191 -157
  119. data/ext/nokogiri/xml_relax_ng.c +29 -23
  120. data/ext/nokogiri/xml_sax_parser.c +117 -112
  121. data/ext/nokogiri/xml_sax_parser_context.c +100 -85
  122. data/ext/nokogiri/xml_sax_push_parser.c +34 -27
  123. data/ext/nokogiri/xml_schema.c +48 -42
  124. data/ext/nokogiri/xml_syntax_error.c +21 -23
  125. data/ext/nokogiri/xml_text.c +13 -17
  126. data/ext/nokogiri/xml_xpath_context.c +134 -127
  127. data/ext/nokogiri/xslt_stylesheet.c +157 -157
  128. data/lib/nokogiri.rb +1 -22
  129. data/lib/nokogiri/css/parser.rb +1 -1
  130. data/lib/nokogiri/extension.rb +26 -0
  131. data/lib/nokogiri/html/document_fragment.rb +15 -15
  132. data/lib/nokogiri/nokogiri.jar +0 -0
  133. data/lib/nokogiri/version/constant.rb +1 -1
  134. data/lib/nokogiri/version/info.rb +31 -8
  135. data/lib/nokogiri/xml/document.rb +31 -11
  136. data/lib/nokogiri/xml/node.rb +38 -42
  137. data/lib/nokogiri/xml/reader.rb +2 -9
  138. data/lib/nokogiri/xml/xpath.rb +1 -3
  139. data/lib/nokogiri/xml/xpath/syntax_error.rb +1 -1
  140. metadata +7 -8
  141. data/ext/nokogiri/xml_io.c +0 -63
  142. data/ext/nokogiri/xml_libxml2_hacks.c +0 -112
@@ -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,34 +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
- if (!handler.isNil()) {
54
- freshResolver.setHandler(handler);
55
- }
56
- return freshResolver;
57
- }
58
-
59
- private NokogiriXPathFunctionResolver() {}
50
+ private IRubyObject handler;
60
51
 
61
- public final IRubyObject getHandler() {
62
- return handler;
52
+ public static NokogiriXPathFunctionResolver
53
+ create(IRubyObject handler)
54
+ {
55
+ NokogiriXPathFunctionResolver freshResolver = new NokogiriXPathFunctionResolver();
56
+ if (!handler.isNil()) {
57
+ freshResolver.setHandler(handler);
63
58
  }
59
+ return freshResolver;
60
+ }
64
61
 
65
- public void setHandler(IRubyObject handler) {
66
- this.handler = handler;
67
- }
62
+ private
63
+ NokogiriXPathFunctionResolver() {}
68
64
 
69
- public XPathFunction resolveFunction(QName name, int arity) {
70
- return NokogiriXPathFunction.create(handler, name, arity);
71
- }
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
+ }
72
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
  }