nokogiri 1.10.10-java → 1.11.0-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.
- checksums.yaml +4 -4
- data/Gemfile +3 -0
- data/LICENSE-DEPENDENCIES.md +1015 -947
- data/README.md +165 -91
- data/ext/java/nokogiri/HtmlDocument.java +34 -46
- data/ext/java/nokogiri/HtmlSaxParserContext.java +88 -58
- data/ext/java/nokogiri/HtmlSaxPushParser.java +1 -1
- data/ext/java/nokogiri/NokogiriService.java +1 -1
- data/ext/java/nokogiri/XmlAttr.java +13 -20
- data/ext/java/nokogiri/XmlAttributeDecl.java +11 -12
- data/ext/java/nokogiri/XmlCdata.java +3 -4
- data/ext/java/nokogiri/XmlComment.java +1 -1
- data/ext/java/nokogiri/XmlDocument.java +148 -175
- data/ext/java/nokogiri/XmlDocumentFragment.java +13 -31
- data/ext/java/nokogiri/XmlDtd.java +5 -8
- data/ext/java/nokogiri/XmlElement.java +1 -20
- data/ext/java/nokogiri/XmlElementDecl.java +23 -28
- data/ext/java/nokogiri/XmlEntityDecl.java +23 -27
- data/ext/java/nokogiri/XmlEntityReference.java +2 -2
- data/ext/java/nokogiri/XmlNamespace.java +72 -89
- data/ext/java/nokogiri/XmlNode.java +303 -406
- data/ext/java/nokogiri/XmlNodeSet.java +70 -76
- data/ext/java/nokogiri/XmlReader.java +12 -13
- data/ext/java/nokogiri/XmlRelaxng.java +10 -3
- data/ext/java/nokogiri/XmlSaxParserContext.java +15 -10
- data/ext/java/nokogiri/XmlSchema.java +87 -27
- data/ext/java/nokogiri/XmlSyntaxError.java +2 -6
- data/ext/java/nokogiri/XmlText.java +12 -9
- data/ext/java/nokogiri/XmlXpathContext.java +55 -25
- data/ext/java/nokogiri/XsltStylesheet.java +7 -15
- data/ext/java/nokogiri/internals/HtmlDomParserContext.java +52 -46
- data/ext/java/nokogiri/internals/NokogiriHandler.java +1 -1
- data/ext/java/nokogiri/internals/NokogiriHelpers.java +71 -135
- data/ext/java/nokogiri/internals/NokogiriNamespaceCache.java +90 -58
- data/ext/java/nokogiri/internals/NokogiriNamespaceContext.java +9 -2
- data/ext/java/nokogiri/internals/NokogiriXPathFunction.java +67 -10
- data/ext/java/nokogiri/internals/NokogiriXPathFunctionResolver.java +4 -2
- data/ext/java/nokogiri/internals/ParserContext.java +27 -73
- data/ext/java/nokogiri/internals/ReaderNode.java +2 -4
- data/ext/java/nokogiri/internals/XmlDomParserContext.java +18 -33
- data/ext/nokogiri/depend +476 -357
- data/ext/nokogiri/extconf.rb +507 -357
- data/ext/nokogiri/html_document.c +79 -78
- data/ext/nokogiri/html_sax_parser_context.c +2 -2
- data/ext/nokogiri/nokogiri.c +34 -40
- data/ext/nokogiri/xml_document.c +18 -4
- data/ext/nokogiri/xml_io.c +8 -6
- data/ext/nokogiri/xml_node.c +21 -1
- data/ext/nokogiri/xml_node_set.c +1 -1
- data/ext/nokogiri/xml_reader.c +6 -17
- data/ext/nokogiri/xml_relax_ng.c +29 -11
- data/ext/nokogiri/xml_sax_parser.c +2 -7
- data/ext/nokogiri/xml_sax_parser_context.c +2 -2
- data/ext/nokogiri/xml_schema.c +55 -13
- data/ext/nokogiri/xml_xpath_context.c +80 -4
- data/ext/nokogiri/xslt_stylesheet.c +1 -8
- data/lib/nokogiri.rb +22 -22
- data/lib/nokogiri/css.rb +1 -0
- data/lib/nokogiri/css/node.rb +1 -0
- data/lib/nokogiri/css/parser.rb +63 -62
- data/lib/nokogiri/css/parser.y +2 -2
- data/lib/nokogiri/css/parser_extras.rb +39 -36
- data/lib/nokogiri/css/syntax_error.rb +1 -0
- data/lib/nokogiri/css/tokenizer.rb +1 -0
- data/lib/nokogiri/css/xpath_visitor.rb +73 -43
- data/lib/nokogiri/decorators/slop.rb +1 -0
- data/lib/nokogiri/html.rb +1 -0
- data/lib/nokogiri/html/builder.rb +1 -0
- data/lib/nokogiri/html/document.rb +13 -26
- data/lib/nokogiri/html/document_fragment.rb +1 -0
- data/lib/nokogiri/html/element_description.rb +1 -0
- data/lib/nokogiri/html/element_description_defaults.rb +1 -0
- data/lib/nokogiri/html/entity_lookup.rb +1 -0
- data/lib/nokogiri/html/sax/parser.rb +1 -0
- data/lib/nokogiri/html/sax/parser_context.rb +1 -0
- data/lib/nokogiri/html/sax/push_parser.rb +1 -0
- data/lib/nokogiri/jruby/dependencies.rb +20 -0
- data/lib/nokogiri/nokogiri.jar +0 -0
- data/lib/nokogiri/syntax_error.rb +1 -0
- data/lib/nokogiri/version.rb +3 -109
- data/lib/nokogiri/version/constant.rb +5 -0
- data/lib/nokogiri/version/info.rb +182 -0
- data/lib/nokogiri/xml.rb +1 -0
- data/lib/nokogiri/xml/attr.rb +1 -0
- data/lib/nokogiri/xml/attribute_decl.rb +1 -0
- data/lib/nokogiri/xml/builder.rb +3 -2
- data/lib/nokogiri/xml/cdata.rb +1 -0
- data/lib/nokogiri/xml/character_data.rb +1 -0
- data/lib/nokogiri/xml/document.rb +20 -15
- data/lib/nokogiri/xml/document_fragment.rb +5 -6
- data/lib/nokogiri/xml/dtd.rb +1 -0
- data/lib/nokogiri/xml/element_content.rb +1 -0
- data/lib/nokogiri/xml/element_decl.rb +1 -0
- data/lib/nokogiri/xml/entity_decl.rb +1 -0
- data/lib/nokogiri/xml/entity_reference.rb +1 -0
- data/lib/nokogiri/xml/namespace.rb +1 -0
- data/lib/nokogiri/xml/node.rb +587 -249
- data/lib/nokogiri/xml/node/save_options.rb +1 -0
- data/lib/nokogiri/xml/node_set.rb +1 -0
- data/lib/nokogiri/xml/notation.rb +1 -0
- data/lib/nokogiri/xml/parse_options.rb +10 -3
- data/lib/nokogiri/xml/pp.rb +1 -0
- data/lib/nokogiri/xml/pp/character_data.rb +1 -0
- data/lib/nokogiri/xml/pp/node.rb +1 -0
- data/lib/nokogiri/xml/processing_instruction.rb +1 -0
- data/lib/nokogiri/xml/reader.rb +7 -3
- data/lib/nokogiri/xml/relax_ng.rb +7 -2
- data/lib/nokogiri/xml/sax.rb +1 -0
- data/lib/nokogiri/xml/sax/document.rb +1 -0
- data/lib/nokogiri/xml/sax/parser.rb +1 -0
- data/lib/nokogiri/xml/sax/parser_context.rb +1 -0
- data/lib/nokogiri/xml/sax/push_parser.rb +1 -0
- data/lib/nokogiri/xml/schema.rb +13 -4
- data/lib/nokogiri/xml/searchable.rb +25 -16
- data/lib/nokogiri/xml/syntax_error.rb +1 -0
- data/lib/nokogiri/xml/text.rb +1 -0
- data/lib/nokogiri/xml/xpath.rb +1 -0
- data/lib/nokogiri/xml/xpath/syntax_error.rb +1 -0
- data/lib/nokogiri/xml/xpath_context.rb +1 -0
- data/lib/nokogiri/xslt.rb +1 -0
- data/lib/nokogiri/xslt/stylesheet.rb +1 -0
- data/lib/xsd/xmlparser/nokogiri.rb +1 -0
- metadata +86 -159
- data/ext/java/nokogiri/internals/NokogiriEncodingReaderWrapper.java +0 -107
- data/ext/java/nokogiri/internals/UncloseableInputStream.java +0 -102
- data/ext/nokogiri/html_document.h +0 -10
- data/ext/nokogiri/html_element_description.h +0 -10
- data/ext/nokogiri/html_entity_lookup.h +0 -8
- data/ext/nokogiri/html_sax_parser_context.h +0 -11
- data/ext/nokogiri/html_sax_push_parser.h +0 -9
- data/ext/nokogiri/nokogiri.h +0 -121
- data/ext/nokogiri/xml_attr.h +0 -9
- data/ext/nokogiri/xml_attribute_decl.h +0 -9
- data/ext/nokogiri/xml_cdata.h +0 -9
- data/ext/nokogiri/xml_comment.h +0 -9
- data/ext/nokogiri/xml_document.h +0 -23
- data/ext/nokogiri/xml_document_fragment.h +0 -10
- data/ext/nokogiri/xml_dtd.h +0 -10
- data/ext/nokogiri/xml_element_content.h +0 -10
- data/ext/nokogiri/xml_element_decl.h +0 -9
- data/ext/nokogiri/xml_encoding_handler.h +0 -8
- data/ext/nokogiri/xml_entity_decl.h +0 -10
- data/ext/nokogiri/xml_entity_reference.h +0 -9
- data/ext/nokogiri/xml_io.h +0 -11
- data/ext/nokogiri/xml_libxml2_hacks.h +0 -12
- data/ext/nokogiri/xml_namespace.h +0 -14
- data/ext/nokogiri/xml_node.h +0 -13
- data/ext/nokogiri/xml_node_set.h +0 -12
- data/ext/nokogiri/xml_processing_instruction.h +0 -9
- data/ext/nokogiri/xml_reader.h +0 -10
- data/ext/nokogiri/xml_relax_ng.h +0 -9
- data/ext/nokogiri/xml_sax_parser.h +0 -39
- data/ext/nokogiri/xml_sax_parser_context.h +0 -10
- data/ext/nokogiri/xml_sax_push_parser.h +0 -9
- data/ext/nokogiri/xml_schema.h +0 -9
- data/ext/nokogiri/xml_syntax_error.h +0 -13
- data/ext/nokogiri/xml_text.h +0 -9
- data/ext/nokogiri/xml_xpath_context.h +0 -10
- data/ext/nokogiri/xslt_stylesheet.h +0 -14
@@ -46,7 +46,6 @@ import org.jruby.RubyObject;
|
|
46
46
|
import org.jruby.RubyRange;
|
47
47
|
import org.jruby.anno.JRubyClass;
|
48
48
|
import org.jruby.anno.JRubyMethod;
|
49
|
-
import org.jruby.runtime.Block;
|
50
49
|
import org.jruby.runtime.ThreadContext;
|
51
50
|
import org.jruby.runtime.builtin.IRubyObject;
|
52
51
|
import org.w3c.dom.Node;
|
@@ -61,38 +60,44 @@ import org.w3c.dom.NodeList;
|
|
61
60
|
@JRubyClass(name="Nokogiri::XML::NodeSet")
|
62
61
|
public class XmlNodeSet extends RubyObject implements NodeList {
|
63
62
|
|
64
|
-
|
63
|
+
IRubyObject[] nodes;
|
65
64
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
RubyClass klass = (RubyClass) cls;
|
70
|
-
XmlNodeSet set = (XmlNodeSet) klass.allocate();
|
71
|
-
set.setNodes(new IRubyObject[0]);
|
72
|
-
set.callInit(args, block);
|
73
|
-
return set;
|
65
|
+
public XmlNodeSet(Ruby ruby, RubyClass klazz) {
|
66
|
+
super(ruby, klazz);
|
67
|
+
nodes = IRubyObject.NULL_ARRAY;
|
74
68
|
}
|
75
69
|
|
76
|
-
|
70
|
+
XmlNodeSet(Ruby ruby, RubyClass klazz, IRubyObject[] nodes) {
|
77
71
|
super(ruby, klazz);
|
72
|
+
this.nodes = nodes;
|
78
73
|
}
|
79
74
|
|
80
|
-
|
81
|
-
|
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;
|
82
80
|
}
|
83
81
|
|
84
|
-
public static XmlNodeSet newEmptyNodeSet(ThreadContext context) {
|
85
|
-
|
86
|
-
set
|
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);
|
87
86
|
return set;
|
88
87
|
}
|
89
88
|
|
90
|
-
public static XmlNodeSet
|
91
|
-
XmlNodeSet xmlNodeSet =
|
89
|
+
public static XmlNodeSet newNodeSet(Ruby runtime, IRubyObject[] nodes) {
|
90
|
+
XmlNodeSet xmlNodeSet = new XmlNodeSet(runtime, getNokogiriClass(runtime, "Nokogiri::XML::NodeSet"));
|
92
91
|
xmlNodeSet.setNodes(nodes);
|
93
92
|
return xmlNodeSet;
|
94
93
|
}
|
95
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
|
+
|
96
101
|
/**
|
97
102
|
* Create and return a copy of this object.
|
98
103
|
*
|
@@ -103,39 +108,33 @@ public class XmlNodeSet extends RubyObject implements NodeList {
|
|
103
108
|
return super.clone();
|
104
109
|
}
|
105
110
|
|
106
|
-
void setNodes(IRubyObject[] array) {
|
111
|
+
private void setNodes(IRubyObject[] array) {
|
107
112
|
this.nodes = array;
|
108
113
|
|
109
114
|
IRubyObject first = array.length > 0 ? array[0] : null;
|
110
115
|
initialize(getRuntime(), first);
|
111
116
|
}
|
112
117
|
|
113
|
-
private void
|
114
|
-
IRubyObject
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
public void setNodeList(NodeList nodeList) {
|
119
|
-
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
|
+
}
|
120
123
|
}
|
121
124
|
|
122
125
|
final void initialize(Ruby runtime, IRubyObject refNode) {
|
123
126
|
if (refNode instanceof XmlNode) {
|
124
|
-
|
127
|
+
XmlDocument doc = ((XmlNode) refNode).document(runtime);
|
125
128
|
setDocumentAndDecorate(runtime.getCurrentContext(), this, doc);
|
126
129
|
}
|
127
130
|
}
|
128
131
|
|
129
|
-
|
130
|
-
|
132
|
+
private void initialize(ThreadContext context, XmlDocument doc) {
|
133
|
+
setDocumentAndDecorate(context, this, doc);
|
131
134
|
}
|
132
135
|
|
133
|
-
public
|
134
|
-
|
135
|
-
if (nodes[i] instanceof XmlNode) {
|
136
|
-
((XmlNode) nodes[i]).relink_namespace(context);
|
137
|
-
}
|
138
|
-
}
|
136
|
+
public int length() {
|
137
|
+
return nodes == null ? 0 : nodes.length;
|
139
138
|
}
|
140
139
|
|
141
140
|
@JRubyMethod(name="&")
|
@@ -143,11 +142,11 @@ public class XmlNodeSet extends RubyObject implements NodeList {
|
|
143
142
|
IRubyObject[] otherNodes = getNodes(context, nodeSet);
|
144
143
|
|
145
144
|
if (otherNodes == null || otherNodes.length == 0) {
|
146
|
-
return newEmptyNodeSet(context);
|
145
|
+
return newEmptyNodeSet(context, this);
|
147
146
|
}
|
148
147
|
|
149
148
|
if (nodes == null || nodes.length == 0) {
|
150
|
-
return newEmptyNodeSet(context);
|
149
|
+
return newEmptyNodeSet(context, this);
|
151
150
|
}
|
152
151
|
|
153
152
|
IRubyObject[] curr = nodes;
|
@@ -167,8 +166,8 @@ outer:
|
|
167
166
|
}
|
168
167
|
}
|
169
168
|
|
170
|
-
XmlNodeSet newSet =
|
171
|
-
newSet.
|
169
|
+
XmlNodeSet newSet = newNodeSet(context.runtime, Arrays.copyOf(result, last));
|
170
|
+
newSet.initializeFrom(context, this);
|
172
171
|
return newSet;
|
173
172
|
}
|
174
173
|
|
@@ -211,7 +210,9 @@ outer:
|
|
211
210
|
|
212
211
|
@JRubyMethod
|
213
212
|
public IRubyObject dup(ThreadContext context) {
|
214
|
-
|
213
|
+
XmlNodeSet dup = newNodeSet(context.runtime, nodes.clone());
|
214
|
+
dup.initializeFrom(context, this);
|
215
|
+
return dup;
|
215
216
|
}
|
216
217
|
|
217
218
|
@JRubyMethod(name = "include?")
|
@@ -222,12 +223,12 @@ outer:
|
|
222
223
|
}
|
223
224
|
}
|
224
225
|
|
225
|
-
return context.
|
226
|
+
return context.fals;
|
226
227
|
}
|
227
228
|
|
228
229
|
@JRubyMethod(name = {"length", "size"})
|
229
230
|
public IRubyObject length(ThreadContext context) {
|
230
|
-
return context.
|
231
|
+
return context.runtime.newFixnum(nodes.length);
|
231
232
|
}
|
232
233
|
|
233
234
|
@JRubyMethod(name="-")
|
@@ -235,11 +236,11 @@ outer:
|
|
235
236
|
IRubyObject[] otherNodes = getNodes(context, nodeSet);
|
236
237
|
|
237
238
|
if (otherNodes.length == 0) {
|
238
|
-
|
239
|
+
return dup(context);
|
239
240
|
}
|
240
241
|
|
241
242
|
if (nodes.length == 0) {
|
242
|
-
|
243
|
+
return newEmptyNodeSet(context, this);
|
243
244
|
}
|
244
245
|
|
245
246
|
IRubyObject[] curr = nodes;
|
@@ -260,8 +261,8 @@ outer:
|
|
260
261
|
result[last++] = n;
|
261
262
|
}
|
262
263
|
|
263
|
-
XmlNodeSet newSet =
|
264
|
-
newSet.
|
264
|
+
XmlNodeSet newSet = newNodeSet(context.runtime, Arrays.copyOf(result, last));
|
265
|
+
newSet.initializeFrom(context, this);
|
265
266
|
return newSet;
|
266
267
|
}
|
267
268
|
|
@@ -295,8 +296,8 @@ outer:
|
|
295
296
|
result[last++] = n;
|
296
297
|
}
|
297
298
|
|
298
|
-
XmlNodeSet newSet =
|
299
|
-
newSet.
|
299
|
+
XmlNodeSet newSet = newNodeSet(context.runtime, Arrays.copyOf(result, last));
|
300
|
+
newSet.initializeFrom(context, this);
|
300
301
|
return newSet;
|
301
302
|
}
|
302
303
|
|
@@ -339,17 +340,7 @@ outer:
|
|
339
340
|
@JRubyMethod(name={"[]", "slice"})
|
340
341
|
public IRubyObject slice(ThreadContext context, IRubyObject indexOrRange) {
|
341
342
|
if (indexOrRange instanceof RubyFixnum) {
|
342
|
-
|
343
|
-
|
344
|
-
if (idx < 0) {
|
345
|
-
idx += nodes.length;
|
346
|
-
}
|
347
|
-
|
348
|
-
if (idx >= nodes.length || idx < 0) {
|
349
|
-
return context.nil;
|
350
|
-
}
|
351
|
-
|
352
|
-
return nodes[idx];
|
343
|
+
return slice(context, ((RubyFixnum) indexOrRange).getIntValue());
|
353
344
|
}
|
354
345
|
|
355
346
|
int[] begLen = new int[2];
|
@@ -359,13 +350,25 @@ outer:
|
|
359
350
|
return subseq(context, min, max - min);
|
360
351
|
}
|
361
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
|
+
|
362
365
|
@JRubyMethod(name={"[]", "slice"})
|
363
366
|
public IRubyObject slice(ThreadContext context, IRubyObject start, IRubyObject length) {
|
364
367
|
int s = ((RubyFixnum) start).getIntValue();
|
365
368
|
int l = ((RubyFixnum) length).getIntValue();
|
366
369
|
|
367
370
|
if (s < 0) {
|
368
|
-
|
371
|
+
s += nodes.length;
|
369
372
|
}
|
370
373
|
|
371
374
|
return subseq(context, s, l);
|
@@ -373,22 +376,20 @@ outer:
|
|
373
376
|
|
374
377
|
public IRubyObject subseq(ThreadContext context, int start, int length) {
|
375
378
|
if (start > nodes.length) {
|
376
|
-
|
379
|
+
return context.nil;
|
377
380
|
}
|
378
381
|
|
379
382
|
if (start < 0 || length < 0) {
|
380
|
-
|
383
|
+
return context.nil;
|
381
384
|
}
|
382
385
|
|
383
386
|
if (start + length > nodes.length) {
|
384
|
-
|
387
|
+
length = nodes.length - start;
|
385
388
|
}
|
386
389
|
|
387
390
|
int to = start + length;
|
388
391
|
|
389
|
-
|
390
|
-
|
391
|
-
return newXmlNodeSet(context, newNodes);
|
392
|
+
return newNodeSet(context.runtime, Arrays.copyOfRange(nodes, start, to));
|
392
393
|
}
|
393
394
|
|
394
395
|
@JRubyMethod(name = {"to_a", "to_ary"})
|
@@ -406,13 +407,6 @@ outer:
|
|
406
407
|
return this;
|
407
408
|
}
|
408
409
|
|
409
|
-
private static XmlNodeSet newXmlNodeSet(ThreadContext context, XmlNodeSet reference) {
|
410
|
-
XmlNodeSet xmlNodeSet = create(context.getRuntime());
|
411
|
-
xmlNodeSet.setReference(reference);
|
412
|
-
xmlNodeSet.nodes = new IRubyObject[0];
|
413
|
-
return xmlNodeSet;
|
414
|
-
}
|
415
|
-
|
416
410
|
private static IRubyObject asXmlNodeOrNamespace(ThreadContext context, IRubyObject possibleNode) {
|
417
411
|
if (possibleNode instanceof XmlNode || possibleNode instanceof XmlNamespace) {
|
418
412
|
return possibleNode;
|
@@ -420,7 +414,7 @@ outer:
|
|
420
414
|
throw context.getRuntime().newArgumentError("node must be a Nokogiri::XML::Node or Nokogiri::XML::Namespace");
|
421
415
|
}
|
422
416
|
|
423
|
-
static IRubyObject[] getNodes(ThreadContext context, IRubyObject possibleNodeSet) {
|
417
|
+
private static IRubyObject[] getNodes(ThreadContext context, IRubyObject possibleNodeSet) {
|
424
418
|
if (possibleNodeSet instanceof XmlNodeSet) {
|
425
419
|
return ((XmlNodeSet) possibleNodeSet).nodes;
|
426
420
|
}
|
@@ -433,8 +427,8 @@ outer:
|
|
433
427
|
|
434
428
|
public Node item(int index) {
|
435
429
|
Object n = nodes[index];
|
436
|
-
if (n instanceof XmlNode) return ((XmlNode)n).node;
|
437
|
-
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();
|
438
432
|
return null;
|
439
433
|
}
|
440
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
|
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
|
247
|
+
InputStream in = new IOInputStream(stringIO);
|
249
248
|
reader.setInput(context, in, url, options);
|
250
249
|
return reader;
|
251
250
|
}
|
@@ -329,7 +328,7 @@ public class XmlReader extends RubyObject {
|
|
329
328
|
continueParsing = config.parse(false);
|
330
329
|
}
|
331
330
|
catch (XNIException e) {
|
332
|
-
throw
|
331
|
+
throw XmlSyntaxError.createXMLSyntaxError(context.runtime, e).toThrowable(); // Nokogiri::XML::SyntaxError
|
333
332
|
}
|
334
333
|
catch (IOException e) {
|
335
334
|
throw context.runtime.newRuntimeError(e.toString());
|
@@ -365,7 +364,7 @@ public class XmlReader extends RubyObject {
|
|
365
364
|
errors.append(error);
|
366
365
|
setInstanceVariable("@errors", errors);
|
367
366
|
|
368
|
-
throw ex != null ? ex :
|
367
|
+
throw ex != null ? ex : ((XmlSyntaxError) error).toThrowable();
|
369
368
|
}
|
370
369
|
if ( ex != null ) throw ex;
|
371
370
|
return this;
|
@@ -56,6 +56,7 @@ import org.jruby.Ruby;
|
|
56
56
|
import org.jruby.RubyClass;
|
57
57
|
import org.jruby.anno.JRubyClass;
|
58
58
|
import org.jruby.runtime.ThreadContext;
|
59
|
+
import org.jruby.runtime.builtin.IRubyObject;
|
59
60
|
import org.w3c.dom.Document;
|
60
61
|
import org.xml.sax.ErrorHandler;
|
61
62
|
import org.xml.sax.SAXException;
|
@@ -78,11 +79,17 @@ public class XmlRelaxng extends XmlSchema {
|
|
78
79
|
this.verifier = verifier;
|
79
80
|
}
|
80
81
|
|
81
|
-
static XmlSchema createSchemaInstance(ThreadContext context, RubyClass klazz, Source source) {
|
82
|
+
static XmlSchema createSchemaInstance(ThreadContext context, RubyClass klazz, Source source, IRubyObject parseOptions) {
|
82
83
|
Ruby runtime = context.getRuntime();
|
83
84
|
XmlRelaxng xmlRelaxng = (XmlRelaxng) NokogiriService.XML_RELAXNG_ALLOCATOR.allocate(runtime, klazz);
|
85
|
+
|
86
|
+
if (parseOptions == null) {
|
87
|
+
parseOptions = defaultParseOptions(context.getRuntime());
|
88
|
+
}
|
89
|
+
|
84
90
|
xmlRelaxng.setInstanceVariable("@errors", runtime.newEmptyArray());
|
85
|
-
|
91
|
+
xmlRelaxng.setInstanceVariable("@parse_options", parseOptions);
|
92
|
+
|
86
93
|
try {
|
87
94
|
Schema schema = xmlRelaxng.getSchema(source, context);
|
88
95
|
xmlRelaxng.setVerifier(schema.newVerifier());
|
@@ -128,7 +135,7 @@ public class XmlRelaxng extends XmlSchema {
|
|
128
135
|
throw context.getRuntime()
|
129
136
|
.newRuntimeError("Could not parse document: "+ex.getMessage());
|
130
137
|
} catch (IOException ex) {
|
131
|
-
throw context.getRuntime().newIOError(ex.getMessage());
|
138
|
+
throw context.getRuntime().newIOError(ex.getClass() + ": " + ex.getMessage());
|
132
139
|
}
|
133
140
|
}
|
134
141
|
|
@@ -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
|
*
|
@@ -94,7 +94,10 @@ public class XmlSaxParserContext extends ParserContext {
|
|
94
94
|
parser = createParser();
|
95
95
|
}
|
96
96
|
catch (SAXException se) {
|
97
|
-
|
97
|
+
// Unexpected failure in XML subsystem
|
98
|
+
RaiseException ex = runtime.newRuntimeError(se.toString());
|
99
|
+
ex.initCause(se);
|
100
|
+
throw ex;
|
98
101
|
}
|
99
102
|
}
|
100
103
|
|
@@ -126,7 +129,7 @@ public class XmlSaxParserContext extends ParserContext {
|
|
126
129
|
final Ruby runtime = context.runtime;
|
127
130
|
XmlSaxParserContext ctx = newInstance(runtime, (RubyClass) klazz);
|
128
131
|
ctx.initialize(runtime);
|
129
|
-
ctx.
|
132
|
+
ctx.setStringInputSource(context, data, runtime.getNil());
|
130
133
|
return ctx;
|
131
134
|
}
|
132
135
|
|
@@ -160,7 +163,7 @@ public class XmlSaxParserContext extends ParserContext {
|
|
160
163
|
final Ruby runtime = context.runtime;
|
161
164
|
XmlSaxParserContext ctx = newInstance(runtime, (RubyClass) klazz);
|
162
165
|
ctx.initialize(runtime);
|
163
|
-
ctx.
|
166
|
+
ctx.setIOInputSource(context, data, runtime.getNil());
|
164
167
|
return ctx;
|
165
168
|
}
|
166
169
|
|
@@ -208,7 +211,8 @@ public class XmlSaxParserContext extends ParserContext {
|
|
208
211
|
parser.setFeature(FEATURE_CONTINUE_AFTER_FATAL_ERROR, true);
|
209
212
|
}
|
210
213
|
catch (Exception e) {
|
211
|
-
|
214
|
+
// Unexpected failure in XML subsystem
|
215
|
+
throw runtime.newRuntimeError(e.getMessage());
|
212
216
|
}
|
213
217
|
}
|
214
218
|
}
|
@@ -261,7 +265,8 @@ public class XmlSaxParserContext extends ParserContext {
|
|
261
265
|
}
|
262
266
|
}
|
263
267
|
catch (SAXException ex) {
|
264
|
-
|
268
|
+
// Unexpected failure in XML subsystem
|
269
|
+
throw runtime.newRuntimeError(ex.getMessage());
|
265
270
|
}
|
266
271
|
catch (IOException ex) {
|
267
272
|
throw runtime.newIOErrorFromException(ex);
|