nokogiri 1.10.8-java → 1.11.0.rc3-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 (107) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +24 -22
  3. data/ext/java/nokogiri/HtmlDocument.java +34 -46
  4. data/ext/java/nokogiri/HtmlSaxParserContext.java +87 -57
  5. data/ext/java/nokogiri/NokogiriService.java +1 -1
  6. data/ext/java/nokogiri/XmlAttr.java +13 -20
  7. data/ext/java/nokogiri/XmlAttributeDecl.java +11 -12
  8. data/ext/java/nokogiri/XmlCdata.java +3 -4
  9. data/ext/java/nokogiri/XmlComment.java +1 -1
  10. data/ext/java/nokogiri/XmlDocument.java +148 -175
  11. data/ext/java/nokogiri/XmlDocumentFragment.java +13 -31
  12. data/ext/java/nokogiri/XmlDtd.java +5 -8
  13. data/ext/java/nokogiri/XmlElement.java +1 -20
  14. data/ext/java/nokogiri/XmlElementDecl.java +23 -28
  15. data/ext/java/nokogiri/XmlEntityDecl.java +23 -27
  16. data/ext/java/nokogiri/XmlEntityReference.java +2 -2
  17. data/ext/java/nokogiri/XmlNamespace.java +72 -89
  18. data/ext/java/nokogiri/XmlNode.java +300 -401
  19. data/ext/java/nokogiri/XmlNodeSet.java +72 -77
  20. data/ext/java/nokogiri/XmlReader.java +10 -11
  21. data/ext/java/nokogiri/XmlSaxParserContext.java +7 -7
  22. data/ext/java/nokogiri/XmlSchema.java +3 -3
  23. data/ext/java/nokogiri/XmlText.java +12 -9
  24. data/ext/java/nokogiri/XmlXpathContext.java +7 -7
  25. data/ext/java/nokogiri/XsltStylesheet.java +7 -15
  26. data/ext/java/nokogiri/internals/HtmlDomParserContext.java +4 -10
  27. data/ext/java/nokogiri/internals/NokogiriHelpers.java +71 -135
  28. data/ext/java/nokogiri/internals/NokogiriNamespaceCache.java +90 -58
  29. data/ext/java/nokogiri/internals/NokogiriXPathFunction.java +5 -4
  30. data/ext/java/nokogiri/internals/ParserContext.java +27 -73
  31. data/ext/java/nokogiri/internals/ReaderNode.java +2 -4
  32. data/ext/java/nokogiri/internals/XmlDomParserContext.java +17 -32
  33. data/ext/nokogiri/extconf.rb +50 -37
  34. data/ext/nokogiri/nokogiri.c +12 -6
  35. data/ext/nokogiri/nokogiri.h +13 -0
  36. data/ext/nokogiri/xml_document.c +16 -2
  37. data/ext/nokogiri/xml_io.c +8 -6
  38. data/ext/nokogiri/xml_node.c +20 -0
  39. data/ext/nokogiri/xml_reader.c +6 -17
  40. data/ext/nokogiri/xml_schema.c +29 -0
  41. data/ext/nokogiri/xslt_stylesheet.c +0 -4
  42. data/lib/nokogiri.rb +3 -20
  43. data/lib/nokogiri/css.rb +1 -0
  44. data/lib/nokogiri/css/node.rb +1 -0
  45. data/lib/nokogiri/css/parser.rb +61 -60
  46. data/lib/nokogiri/css/parser_extras.rb +39 -36
  47. data/lib/nokogiri/css/syntax_error.rb +1 -0
  48. data/lib/nokogiri/css/tokenizer.rb +1 -0
  49. data/lib/nokogiri/css/xpath_visitor.rb +3 -1
  50. data/lib/nokogiri/decorators/slop.rb +1 -0
  51. data/lib/nokogiri/html.rb +1 -0
  52. data/lib/nokogiri/html/builder.rb +1 -0
  53. data/lib/nokogiri/html/document.rb +1 -0
  54. data/lib/nokogiri/html/document_fragment.rb +1 -0
  55. data/lib/nokogiri/html/element_description.rb +1 -0
  56. data/lib/nokogiri/html/element_description_defaults.rb +1 -0
  57. data/lib/nokogiri/html/entity_lookup.rb +1 -0
  58. data/lib/nokogiri/html/sax/parser.rb +1 -0
  59. data/lib/nokogiri/html/sax/parser_context.rb +1 -0
  60. data/lib/nokogiri/html/sax/push_parser.rb +1 -0
  61. data/lib/nokogiri/jruby/dependencies.rb +20 -0
  62. data/lib/nokogiri/nokogiri.jar +0 -0
  63. data/lib/nokogiri/syntax_error.rb +1 -0
  64. data/lib/nokogiri/version.rb +86 -45
  65. data/lib/nokogiri/xml.rb +1 -0
  66. data/lib/nokogiri/xml/attr.rb +1 -0
  67. data/lib/nokogiri/xml/attribute_decl.rb +1 -0
  68. data/lib/nokogiri/xml/builder.rb +3 -2
  69. data/lib/nokogiri/xml/cdata.rb +1 -0
  70. data/lib/nokogiri/xml/character_data.rb +1 -0
  71. data/lib/nokogiri/xml/document.rb +3 -8
  72. data/lib/nokogiri/xml/document_fragment.rb +1 -0
  73. data/lib/nokogiri/xml/dtd.rb +1 -0
  74. data/lib/nokogiri/xml/element_content.rb +1 -0
  75. data/lib/nokogiri/xml/element_decl.rb +1 -0
  76. data/lib/nokogiri/xml/entity_decl.rb +1 -0
  77. data/lib/nokogiri/xml/entity_reference.rb +1 -0
  78. data/lib/nokogiri/xml/namespace.rb +1 -0
  79. data/lib/nokogiri/xml/node.rb +539 -224
  80. data/lib/nokogiri/xml/node/save_options.rb +1 -0
  81. data/lib/nokogiri/xml/node_set.rb +1 -0
  82. data/lib/nokogiri/xml/notation.rb +1 -0
  83. data/lib/nokogiri/xml/parse_options.rb +4 -3
  84. data/lib/nokogiri/xml/pp.rb +1 -0
  85. data/lib/nokogiri/xml/pp/character_data.rb +1 -0
  86. data/lib/nokogiri/xml/pp/node.rb +1 -0
  87. data/lib/nokogiri/xml/processing_instruction.rb +1 -0
  88. data/lib/nokogiri/xml/reader.rb +7 -3
  89. data/lib/nokogiri/xml/relax_ng.rb +1 -0
  90. data/lib/nokogiri/xml/sax.rb +1 -0
  91. data/lib/nokogiri/xml/sax/document.rb +1 -0
  92. data/lib/nokogiri/xml/sax/parser.rb +1 -0
  93. data/lib/nokogiri/xml/sax/parser_context.rb +1 -0
  94. data/lib/nokogiri/xml/sax/push_parser.rb +1 -0
  95. data/lib/nokogiri/xml/schema.rb +1 -0
  96. data/lib/nokogiri/xml/searchable.rb +22 -15
  97. data/lib/nokogiri/xml/syntax_error.rb +1 -0
  98. data/lib/nokogiri/xml/text.rb +1 -0
  99. data/lib/nokogiri/xml/xpath.rb +1 -0
  100. data/lib/nokogiri/xml/xpath/syntax_error.rb +1 -0
  101. data/lib/nokogiri/xml/xpath_context.rb +1 -0
  102. data/lib/nokogiri/xslt.rb +1 -0
  103. data/lib/nokogiri/xslt/stylesheet.rb +1 -0
  104. data/lib/xsd/xmlparser/nokogiri.rb +1 -0
  105. metadata +53 -34
  106. data/ext/java/nokogiri/internals/NokogiriEncodingReaderWrapper.java +0 -107
  107. data/ext/java/nokogiri/internals/UncloseableInputStream.java +0 -102
@@ -39,13 +39,13 @@ import static nokogiri.internals.NokogiriHelpers.nodeListToRubyArray;
39
39
  import java.util.Arrays;
40
40
 
41
41
  import org.jruby.Ruby;
42
+ import org.jruby.RubyArray;
42
43
  import org.jruby.RubyClass;
43
44
  import org.jruby.RubyFixnum;
44
45
  import org.jruby.RubyObject;
45
46
  import org.jruby.RubyRange;
46
47
  import org.jruby.anno.JRubyClass;
47
48
  import org.jruby.anno.JRubyMethod;
48
- import org.jruby.runtime.Block;
49
49
  import org.jruby.runtime.ThreadContext;
50
50
  import org.jruby.runtime.builtin.IRubyObject;
51
51
  import org.w3c.dom.Node;
@@ -60,38 +60,44 @@ import org.w3c.dom.NodeList;
60
60
  @JRubyClass(name="Nokogiri::XML::NodeSet")
61
61
  public class XmlNodeSet extends RubyObject implements NodeList {
62
62
 
63
- private IRubyObject[] nodes;
63
+ IRubyObject[] nodes;
64
64
 
65
- @JRubyMethod(name = "new", meta = true, rest = true)
66
- public static IRubyObject rbNew(ThreadContext context, IRubyObject cls,
67
- IRubyObject[] args, Block block) {
68
- RubyClass klass = (RubyClass) cls;
69
- XmlNodeSet set = (XmlNodeSet) klass.allocate();
70
- set.setNodes(new IRubyObject[0]);
71
- set.callInit(args, block);
72
- return set;
65
+ public XmlNodeSet(Ruby ruby, RubyClass klazz) {
66
+ super(ruby, klazz);
67
+ nodes = IRubyObject.NULL_ARRAY;
73
68
  }
74
69
 
75
- public XmlNodeSet(Ruby ruby, RubyClass klazz) {
70
+ XmlNodeSet(Ruby ruby, RubyClass klazz, IRubyObject[] nodes) {
76
71
  super(ruby, klazz);
72
+ this.nodes = nodes;
77
73
  }
78
74
 
79
- private static XmlNodeSet create(final Ruby runtime) {
80
- return (XmlNodeSet) NokogiriService.XML_NODESET_ALLOCATOR.allocate(runtime, getNokogiriClass(runtime, "Nokogiri::XML::NodeSet"));
75
+ public static XmlNodeSet newEmptyNodeSet(ThreadContext context, XmlNodeSet docOwner) {
76
+ final Ruby runtime = context.runtime;
77
+ XmlNodeSet set = new XmlNodeSet(runtime, getNokogiriClass(runtime, "Nokogiri::XML::NodeSet"));
78
+ set.initializeFrom(context, docOwner);
79
+ return set;
81
80
  }
82
81
 
83
- public static XmlNodeSet newEmptyNodeSet(ThreadContext context) {
84
- XmlNodeSet set = create(context.getRuntime());
85
- set.nodes = new IRubyObject[0];
82
+ public static XmlNodeSet newEmptyNodeSet(ThreadContext context, XmlNode docOwner) {
83
+ final Ruby runtime = context.runtime;
84
+ XmlNodeSet set = new XmlNodeSet(runtime, getNokogiriClass(runtime, "Nokogiri::XML::NodeSet"));
85
+ set.initialize(runtime, docOwner);
86
86
  return set;
87
87
  }
88
88
 
89
- public static XmlNodeSet newXmlNodeSet(ThreadContext context, IRubyObject[] nodes) {
90
- XmlNodeSet xmlNodeSet = create(context.runtime);
89
+ public static XmlNodeSet newNodeSet(Ruby runtime, IRubyObject[] nodes) {
90
+ XmlNodeSet xmlNodeSet = new XmlNodeSet(runtime, getNokogiriClass(runtime, "Nokogiri::XML::NodeSet"));
91
91
  xmlNodeSet.setNodes(nodes);
92
92
  return xmlNodeSet;
93
93
  }
94
94
 
95
+ public static XmlNodeSet newNodeSet(Ruby runtime, IRubyObject[] nodes, XmlNode docOwner) {
96
+ XmlNodeSet set = new XmlNodeSet(runtime, getNokogiriClass(runtime, "Nokogiri::XML::NodeSet"), nodes);
97
+ set.initialize(runtime, docOwner);
98
+ return set;
99
+ }
100
+
95
101
  /**
96
102
  * Create and return a copy of this object.
97
103
  *
@@ -102,39 +108,33 @@ public class XmlNodeSet extends RubyObject implements NodeList {
102
108
  return super.clone();
103
109
  }
104
110
 
105
- void setNodes(IRubyObject[] array) {
111
+ private void setNodes(IRubyObject[] array) {
106
112
  this.nodes = array;
107
113
 
108
114
  IRubyObject first = array.length > 0 ? array[0] : null;
109
115
  initialize(getRuntime(), first);
110
116
  }
111
117
 
112
- private void setReference(XmlNodeSet reference) {
113
- IRubyObject first = reference.nodes.length > 0 ? reference.nodes[0] : null;
114
- initialize(getRuntime(), first);
115
- }
116
-
117
- public void setNodeList(NodeList nodeList) {
118
- setNodes(nodeListToRubyArray(getRuntime(), nodeList));
118
+ private void initializeFrom(ThreadContext context, XmlNodeSet ref) {
119
+ IRubyObject document = ref.getInstanceVariable("@document");
120
+ if (document != null && !document.isNil()) {
121
+ initialize(context, (XmlDocument) document);
122
+ }
119
123
  }
120
124
 
121
125
  final void initialize(Ruby runtime, IRubyObject refNode) {
122
126
  if (refNode instanceof XmlNode) {
123
- IRubyObject doc = ((XmlNode) refNode).document(runtime);
127
+ XmlDocument doc = ((XmlNode) refNode).document(runtime);
124
128
  setDocumentAndDecorate(runtime.getCurrentContext(), this, doc);
125
129
  }
126
130
  }
127
131
 
128
- public int length() {
129
- return nodes == null ? 0 : nodes.length;
132
+ private void initialize(ThreadContext context, XmlDocument doc) {
133
+ setDocumentAndDecorate(context, this, doc);
130
134
  }
131
135
 
132
- public void relink_namespace(ThreadContext context) {
133
- for (int i = 0; i < nodes.length; i++) {
134
- if (nodes[i] instanceof XmlNode) {
135
- ((XmlNode) nodes[i]).relink_namespace(context);
136
- }
137
- }
136
+ public int length() {
137
+ return nodes == null ? 0 : nodes.length;
138
138
  }
139
139
 
140
140
  @JRubyMethod(name="&")
@@ -142,11 +142,11 @@ public class XmlNodeSet extends RubyObject implements NodeList {
142
142
  IRubyObject[] otherNodes = getNodes(context, nodeSet);
143
143
 
144
144
  if (otherNodes == null || otherNodes.length == 0) {
145
- return newEmptyNodeSet(context);
145
+ return newEmptyNodeSet(context, this);
146
146
  }
147
147
 
148
148
  if (nodes == null || nodes.length == 0) {
149
- return newEmptyNodeSet(context);
149
+ return newEmptyNodeSet(context, this);
150
150
  }
151
151
 
152
152
  IRubyObject[] curr = nodes;
@@ -166,8 +166,8 @@ outer:
166
166
  }
167
167
  }
168
168
 
169
- XmlNodeSet newSet = newXmlNodeSet(context, Arrays.copyOf(result, last));
170
- newSet.setReference(this);
169
+ XmlNodeSet newSet = newNodeSet(context.runtime, Arrays.copyOf(result, last));
170
+ newSet.initializeFrom(context, this);
171
171
  return newSet;
172
172
  }
173
173
 
@@ -210,7 +210,9 @@ outer:
210
210
 
211
211
  @JRubyMethod
212
212
  public IRubyObject dup(ThreadContext context) {
213
- return newXmlNodeSet(context, nodes);
213
+ XmlNodeSet dup = newNodeSet(context.runtime, nodes.clone());
214
+ dup.initializeFrom(context, this);
215
+ return dup;
214
216
  }
215
217
 
216
218
  @JRubyMethod(name = "include?")
@@ -221,12 +223,12 @@ outer:
221
223
  }
222
224
  }
223
225
 
224
- return context.runtime.getFalse();
226
+ return context.fals;
225
227
  }
226
228
 
227
229
  @JRubyMethod(name = {"length", "size"})
228
230
  public IRubyObject length(ThreadContext context) {
229
- return context.getRuntime().newFixnum(nodes.length);
231
+ return context.runtime.newFixnum(nodes.length);
230
232
  }
231
233
 
232
234
  @JRubyMethod(name="-")
@@ -234,11 +236,11 @@ outer:
234
236
  IRubyObject[] otherNodes = getNodes(context, nodeSet);
235
237
 
236
238
  if (otherNodes.length == 0) {
237
- return dup(context);
239
+ return dup(context);
238
240
  }
239
241
 
240
242
  if (nodes.length == 0) {
241
- return newEmptyNodeSet(context);
243
+ return newEmptyNodeSet(context, this);
242
244
  }
243
245
 
244
246
  IRubyObject[] curr = nodes;
@@ -259,8 +261,8 @@ outer:
259
261
  result[last++] = n;
260
262
  }
261
263
 
262
- XmlNodeSet newSet = newXmlNodeSet(context, Arrays.copyOf(result, last));
263
- newSet.setReference(this);
264
+ XmlNodeSet newSet = newNodeSet(context.runtime, Arrays.copyOf(result, last));
265
+ newSet.initializeFrom(context, this);
264
266
  return newSet;
265
267
  }
266
268
 
@@ -294,8 +296,8 @@ outer:
294
296
  result[last++] = n;
295
297
  }
296
298
 
297
- XmlNodeSet newSet = newXmlNodeSet(context, Arrays.copyOf(result, last));
298
- newSet.setReference(this);
299
+ XmlNodeSet newSet = newNodeSet(context.runtime, Arrays.copyOf(result, last));
300
+ newSet.initializeFrom(context, this);
299
301
  return newSet;
300
302
  }
301
303
 
@@ -338,17 +340,7 @@ outer:
338
340
  @JRubyMethod(name={"[]", "slice"})
339
341
  public IRubyObject slice(ThreadContext context, IRubyObject indexOrRange) {
340
342
  if (indexOrRange instanceof RubyFixnum) {
341
- int idx = ((RubyFixnum)indexOrRange).getIntValue();
342
-
343
- if (idx < 0) {
344
- idx += nodes.length;
345
- }
346
-
347
- if (idx >= nodes.length || idx < 0) {
348
- return context.nil;
349
- }
350
-
351
- return nodes[idx];
343
+ return slice(context, ((RubyFixnum) indexOrRange).getIntValue());
352
344
  }
353
345
 
354
346
  int[] begLen = new int[2];
@@ -358,13 +350,25 @@ outer:
358
350
  return subseq(context, min, max - min);
359
351
  }
360
352
 
353
+ IRubyObject slice(ThreadContext context, int idx) {
354
+ if (idx < 0) {
355
+ idx += nodes.length;
356
+ }
357
+
358
+ if (idx >= nodes.length || idx < 0) {
359
+ return context.nil;
360
+ }
361
+
362
+ return nodes[idx];
363
+ }
364
+
361
365
  @JRubyMethod(name={"[]", "slice"})
362
366
  public IRubyObject slice(ThreadContext context, IRubyObject start, IRubyObject length) {
363
367
  int s = ((RubyFixnum) start).getIntValue();
364
368
  int l = ((RubyFixnum) length).getIntValue();
365
369
 
366
370
  if (s < 0) {
367
- s += nodes.length;
371
+ s += nodes.length;
368
372
  }
369
373
 
370
374
  return subseq(context, s, l);
@@ -372,26 +376,24 @@ outer:
372
376
 
373
377
  public IRubyObject subseq(ThreadContext context, int start, int length) {
374
378
  if (start > nodes.length) {
375
- return context.nil;
379
+ return context.nil;
376
380
  }
377
381
 
378
382
  if (start < 0 || length < 0) {
379
- return context.nil;
383
+ return context.nil;
380
384
  }
381
385
 
382
386
  if (start + length > nodes.length) {
383
- length = nodes.length - start;
387
+ length = nodes.length - start;
384
388
  }
385
389
 
386
390
  int to = start + length;
387
391
 
388
- IRubyObject[] newNodes = Arrays.copyOfRange(nodes, start, to);
389
-
390
- return newXmlNodeSet(context, newNodes);
392
+ return newNodeSet(context.runtime, Arrays.copyOfRange(nodes, start, to));
391
393
  }
392
394
 
393
395
  @JRubyMethod(name = {"to_a", "to_ary"})
394
- public IRubyObject to_a(ThreadContext context) {
396
+ public RubyArray to_a(ThreadContext context) {
395
397
  return context.runtime.newArrayNoCopy(nodes);
396
398
  }
397
399
 
@@ -405,13 +407,6 @@ outer:
405
407
  return this;
406
408
  }
407
409
 
408
- private static XmlNodeSet newXmlNodeSet(ThreadContext context, XmlNodeSet reference) {
409
- XmlNodeSet xmlNodeSet = create(context.getRuntime());
410
- xmlNodeSet.setReference(reference);
411
- xmlNodeSet.nodes = new IRubyObject[0];
412
- return xmlNodeSet;
413
- }
414
-
415
410
  private static IRubyObject asXmlNodeOrNamespace(ThreadContext context, IRubyObject possibleNode) {
416
411
  if (possibleNode instanceof XmlNode || possibleNode instanceof XmlNamespace) {
417
412
  return possibleNode;
@@ -419,7 +414,7 @@ outer:
419
414
  throw context.getRuntime().newArgumentError("node must be a Nokogiri::XML::Node or Nokogiri::XML::Namespace");
420
415
  }
421
416
 
422
- static IRubyObject[] getNodes(ThreadContext context, IRubyObject possibleNodeSet) {
417
+ private static IRubyObject[] getNodes(ThreadContext context, IRubyObject possibleNodeSet) {
423
418
  if (possibleNodeSet instanceof XmlNodeSet) {
424
419
  return ((XmlNodeSet) possibleNodeSet).nodes;
425
420
  }
@@ -432,8 +427,8 @@ outer:
432
427
 
433
428
  public Node item(int index) {
434
429
  Object n = nodes[index];
435
- if (n instanceof XmlNode) return ((XmlNode)n).node;
436
- if (n instanceof XmlNamespace) return ((XmlNamespace)n).getNode();
430
+ if (n instanceof XmlNode) return ((XmlNode) n).node;
431
+ if (n instanceof XmlNamespace) return ((XmlNamespace) n).getNode();
437
432
  return null;
438
433
  }
439
434
  }
@@ -41,15 +41,6 @@ import java.util.LinkedList;
41
41
  import java.util.List;
42
42
  import java.util.Stack;
43
43
 
44
- import nokogiri.internals.NokogiriEntityResolver;
45
- import nokogiri.internals.ParserContext;
46
- import nokogiri.internals.ParserContext.Options;
47
- import nokogiri.internals.ReaderNode;
48
- import nokogiri.internals.ReaderNode.ClosingNode;
49
- import nokogiri.internals.ReaderNode.ElementNode;
50
- import nokogiri.internals.ReaderNode.TextNode;
51
- import nokogiri.internals.UncloseableInputStream;
52
-
53
44
  import org.apache.xerces.impl.Constants;
54
45
  import org.apache.xerces.impl.xs.opti.DefaultXMLDocumentHandler;
55
46
  import org.apache.xerces.parsers.StandardParserConfiguration;
@@ -81,6 +72,14 @@ import org.jruby.runtime.builtin.IRubyObject;
81
72
  import org.jruby.util.IOInputStream;
82
73
  import org.xml.sax.InputSource;
83
74
 
75
+ import nokogiri.internals.NokogiriEntityResolver;
76
+ import nokogiri.internals.ParserContext;
77
+ import nokogiri.internals.ParserContext.Options;
78
+ import nokogiri.internals.ReaderNode;
79
+ import nokogiri.internals.ReaderNode.ClosingNode;
80
+ import nokogiri.internals.ReaderNode.ElementNode;
81
+ import nokogiri.internals.ReaderNode.TextNode;
82
+
84
83
  /**
85
84
  * Class for Nokogiri:XML::Reader
86
85
  *
@@ -217,7 +216,7 @@ public class XmlReader extends RubyObject {
217
216
  options = new ParserContext.Options(2048 | 1);
218
217
  }
219
218
 
220
- InputStream in = new UncloseableInputStream(new IOInputStream(args[0]));
219
+ InputStream in = new IOInputStream(args[0]);
221
220
  reader.setInput(context, in, url, options);
222
221
  return reader;
223
222
  }
@@ -245,7 +244,7 @@ public class XmlReader extends RubyObject {
245
244
  options = new ParserContext.Options(2048 | 1);
246
245
  }
247
246
  IRubyObject stringIO = runtime.getClass("StringIO").newInstance(context, args[0], Block.NULL_BLOCK);
248
- InputStream in = new UncloseableInputStream(new IOInputStream(stringIO));
247
+ InputStream in = new IOInputStream(stringIO);
249
248
  reader.setInput(context, in, url, options);
250
249
  return reader;
251
250
  }
@@ -37,11 +37,6 @@ import static org.jruby.runtime.Helpers.invoke;
37
37
  import java.io.IOException;
38
38
  import java.io.InputStream;
39
39
 
40
- import nokogiri.internals.NokogiriHandler;
41
- import nokogiri.internals.NokogiriHelpers;
42
- import nokogiri.internals.ParserContext;
43
- import nokogiri.internals.XmlSaxParser;
44
-
45
40
  import org.apache.xerces.parsers.AbstractSAXParser;
46
41
  import org.jruby.Ruby;
47
42
  import org.jruby.RubyClass;
@@ -61,6 +56,11 @@ import org.xml.sax.SAXNotRecognizedException;
61
56
  import org.xml.sax.SAXNotSupportedException;
62
57
  import org.xml.sax.SAXParseException;
63
58
 
59
+ import nokogiri.internals.NokogiriHandler;
60
+ import nokogiri.internals.NokogiriHelpers;
61
+ import nokogiri.internals.ParserContext;
62
+ import nokogiri.internals.XmlSaxParser;
63
+
64
64
  /**
65
65
  * Base class for the SAX parsers.
66
66
  *
@@ -126,7 +126,7 @@ public class XmlSaxParserContext extends ParserContext {
126
126
  final Ruby runtime = context.runtime;
127
127
  XmlSaxParserContext ctx = newInstance(runtime, (RubyClass) klazz);
128
128
  ctx.initialize(runtime);
129
- ctx.setInputSource(context, data, runtime.getNil());
129
+ ctx.setStringInputSource(context, data, runtime.getNil());
130
130
  return ctx;
131
131
  }
132
132
 
@@ -160,7 +160,7 @@ public class XmlSaxParserContext extends ParserContext {
160
160
  final Ruby runtime = context.runtime;
161
161
  XmlSaxParserContext ctx = newInstance(runtime, (RubyClass) klazz);
162
162
  ctx.initialize(runtime);
163
- ctx.setInputSource(context, data, runtime.getNil());
163
+ ctx.setIOInputSource(context, data, runtime.getNil());
164
164
  return ctx;
165
165
  }
166
166
 
@@ -168,11 +168,11 @@ public class XmlSchema extends RubyObject {
168
168
 
169
169
  @JRubyMethod(visibility=Visibility.PRIVATE)
170
170
  public IRubyObject validate_file(ThreadContext context, IRubyObject file) {
171
- Ruby ruby = context.getRuntime();
171
+ Ruby runtime = context.runtime;
172
172
 
173
- XmlDomParserContext ctx = new XmlDomParserContext(ruby, RubyFixnum.newFixnum(ruby, 1L));
173
+ XmlDomParserContext ctx = new XmlDomParserContext(runtime, RubyFixnum.newFixnum(runtime, 1L));
174
174
  ctx.setInputSourceFile(context, file);
175
- XmlDocument xmlDocument = ctx.parse(context, getNokogiriClass(ruby, "Nokogiri::XML::Document"), ruby.getNil());
175
+ XmlDocument xmlDocument = ctx.parse(context, getNokogiriClass(runtime, "Nokogiri::XML::Document"), context.nil);
176
176
  return validate_document_or_file(context, xmlDocument);
177
177
  }
178
178
 
@@ -36,11 +36,14 @@ import static nokogiri.internals.NokogiriHelpers.getCachedNodeOrCreate;
36
36
  import static nokogiri.internals.NokogiriHelpers.rubyStringToString;
37
37
  import nokogiri.internals.SaveContextVisitor;
38
38
 
39
+ import org.jcodings.specific.USASCIIEncoding;
39
40
  import org.jruby.Ruby;
40
41
  import org.jruby.RubyClass;
42
+ import org.jruby.RubyString;
41
43
  import org.jruby.anno.JRubyClass;
42
44
  import org.jruby.runtime.ThreadContext;
43
45
  import org.jruby.runtime.builtin.IRubyObject;
46
+ import org.jruby.util.ByteList;
44
47
  import org.w3c.dom.Document;
45
48
  import org.w3c.dom.Node;
46
49
  import org.w3c.dom.Text;
@@ -54,6 +57,9 @@ import org.w3c.dom.Text;
54
57
  @JRubyClass(name="Nokogiri::XML::Text", parent="Nokogiri::XML::CharacterData")
55
58
  public class XmlText extends XmlNode {
56
59
 
60
+ private static final ByteList TEXT = ByteList.create("text");
61
+ static { TEXT.setEncoding(USASCIIEncoding.INSTANCE); }
62
+
57
63
  public XmlText(Ruby runtime, RubyClass rubyClass, Node node) {
58
64
  super(runtime, rubyClass, node);
59
65
  }
@@ -65,34 +71,31 @@ public class XmlText extends XmlNode {
65
71
  @Override
66
72
  protected void init(ThreadContext context, IRubyObject[] args) {
67
73
  if (args.length < 2) {
68
- throw getRuntime().newArgumentError(args.length, 2);
74
+ throw context.runtime.newArgumentError(args.length, 2);
69
75
  }
70
76
 
71
77
  content = args[0];
72
78
  IRubyObject xNode = args[1];
73
79
 
74
- XmlNode xmlNode = asXmlNode(context, xNode);
75
- XmlDocument xmlDoc = (XmlDocument)xmlNode.document(context);
76
- doc = xmlDoc;
77
- Document document = xmlDoc.getDocument();
80
+ Document document = asXmlNode(context, xNode).getOwnerDocument();
78
81
  // text node content should not be encoded when it is created by Text node.
79
82
  // while content should be encoded when it is created by Element node.
80
83
  Node node = document.createTextNode(rubyStringToString(content));
81
- setNode(context, node);
84
+ setNode(context.runtime, node);
82
85
  }
83
86
 
84
87
  @Override
85
88
  protected IRubyObject getNodeName(ThreadContext context) {
86
- if (name == null) name = context.getRuntime().newString("text");
89
+ if (name == null) name = RubyString.newStringShared(context.runtime, TEXT);
87
90
  return name;
88
91
  }
89
92
 
90
93
  @Override
91
94
  public void accept(ThreadContext context, SaveContextVisitor visitor) {
92
- visitor.enter((Text)node);
95
+ visitor.enter((Text) node);
93
96
  Node child = node.getFirstChild();
94
97
  while (child != null) {
95
- IRubyObject nokoNode = getCachedNodeOrCreate(context.getRuntime(), child);
98
+ IRubyObject nokoNode = getCachedNodeOrCreate(context.runtime, child);
96
99
  if (nokoNode instanceof XmlNode) {
97
100
  XmlNode cur = (XmlNode) nokoNode;
98
101
  cur.accept(context, visitor);