nokogiri 1.5.0.beta.4-java → 1.5.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.
- data/.gemtest +0 -0
- data/CHANGELOG.ja.rdoc +34 -0
- data/CHANGELOG.rdoc +40 -1
- data/Manifest.txt +11 -2
- data/README.rdoc +1 -1
- data/Rakefile +96 -105
- data/bin/nokogiri +1 -2
- data/ext/java/nokogiri/HtmlDocument.java +1 -31
- data/ext/java/nokogiri/HtmlSaxParserContext.java +1 -1
- data/ext/java/nokogiri/NokogiriService.java +77 -22
- data/ext/java/nokogiri/XmlAttr.java +5 -16
- data/ext/java/nokogiri/XmlCdata.java +4 -11
- data/ext/java/nokogiri/XmlComment.java +5 -5
- data/ext/java/nokogiri/XmlDocument.java +49 -59
- data/ext/java/nokogiri/XmlDocumentFragment.java +14 -8
- data/ext/java/nokogiri/XmlDtd.java +45 -43
- data/ext/java/nokogiri/XmlElement.java +19 -46
- data/ext/java/nokogiri/XmlElementDecl.java +9 -5
- data/ext/java/nokogiri/XmlEntityReference.java +24 -2
- data/ext/java/nokogiri/XmlNamespace.java +89 -34
- data/ext/java/nokogiri/XmlNode.java +31 -52
- data/ext/java/nokogiri/XmlNodeSet.java +42 -86
- data/ext/java/nokogiri/XmlProcessingInstruction.java +15 -19
- data/ext/java/nokogiri/XmlReader.java +40 -43
- data/ext/java/nokogiri/XmlSaxParserContext.java +2 -2
- data/ext/java/nokogiri/XmlSchema.java +14 -9
- data/ext/java/nokogiri/XmlText.java +18 -35
- data/ext/java/nokogiri/XmlXpathContext.java +43 -23
- data/ext/java/nokogiri/XsltStylesheet.java +17 -3
- data/ext/java/nokogiri/internals/HtmlDomParserContext.java +2 -4
- data/ext/java/nokogiri/internals/NokogiriHelpers.java +77 -20
- data/ext/java/nokogiri/internals/NokogiriNamespaceCache.java +13 -17
- data/ext/java/nokogiri/internals/NokogiriNamespaceContext.java +13 -1
- data/ext/java/nokogiri/internals/NokogiriXPathFunction.java +23 -8
- data/ext/java/nokogiri/internals/NokogiriXPathFunctionResolver.java +20 -3
- data/ext/java/nokogiri/internals/NokogiriXPathVariableResolver.java +67 -0
- data/ext/java/nokogiri/internals/NokogiriXsltErrorListener.java +86 -0
- data/ext/java/nokogiri/internals/ParserContext.java +25 -27
- data/ext/java/nokogiri/internals/ReaderNode.java +58 -1
- data/ext/java/nokogiri/internals/SaveContextVisitor.java +567 -0
- data/ext/java/nokogiri/internals/XmlDomParser.java +1 -2
- data/ext/java/nokogiri/internals/XmlDomParserContext.java +6 -0
- data/ext/nokogiri/nokogiri.c +24 -1
- data/ext/nokogiri/xml_io.c +32 -7
- data/ext/nokogiri/xml_node.c +14 -13
- data/ext/nokogiri/xml_sax_parser.c +9 -4
- data/ext/nokogiri/xslt_stylesheet.c +7 -1
- data/lib/nokogiri.rb +3 -22
- data/lib/nokogiri/css.rb +4 -0
- data/lib/nokogiri/html/document.rb +10 -14
- data/lib/nokogiri/nokogiri.jar +0 -0
- data/lib/nokogiri/version.rb +76 -23
- data/lib/nokogiri/xml/builder.rb +7 -0
- data/lib/nokogiri/xml/document.rb +17 -1
- data/lib/nokogiri/xml/document_fragment.rb +14 -0
- data/lib/nokogiri/xml/node.rb +36 -28
- data/lib/nokogiri/xml/node/save_options.rb +17 -1
- data/lib/nokogiri/xml/node_set.rb +7 -0
- data/lib/nokogiri/xml/parse_options.rb +8 -0
- data/lib/nokogiri/xml/reader.rb +6 -6
- data/lib/nokogiri/xml/schema.rb +7 -1
- data/lib/xercesImpl.jar +0 -0
- data/nokogiri_help_responses.md +40 -0
- data/tasks/cross_compile.rb +134 -159
- data/tasks/nokogiri.org.rb +18 -0
- data/tasks/test.rb +1 -1
- data/test/files/encoding.html +82 -0
- data/test/files/encoding.xhtml +84 -0
- data/test/files/metacharset.html +10 -0
- data/test/files/noencoding.html +47 -0
- data/test/helper.rb +2 -0
- data/test/html/test_document.rb +15 -0
- data/test/html/test_document_encoding.rb +13 -0
- data/test/test_memory_leak.rb +20 -0
- data/test/test_reader.rb +22 -0
- data/test/test_xslt_transforms.rb +6 -2
- data/test/xml/node/test_save_options.rb +10 -2
- data/test/xml/test_builder.rb +17 -0
- data/test/xml/test_document.rb +22 -0
- data/test/xml/test_node.rb +19 -1
- data/test/xml/test_node_reparenting.rb +16 -3
- data/test/xml/test_node_set.rb +34 -0
- data/test/xml/test_schema.rb +5 -0
- data/test/xslt/test_exception_handling.rb +37 -0
- metadata +141 -107
- data/deps.rip +0 -5
- data/ext/java/nokogiri/internals/SaveContext.java +0 -288
@@ -48,7 +48,7 @@ import java.util.List;
|
|
48
48
|
import nokogiri.internals.HtmlDomParserContext;
|
49
49
|
import nokogiri.internals.NokogiriHelpers;
|
50
50
|
import nokogiri.internals.NokogiriNamespaceCache;
|
51
|
-
import nokogiri.internals.
|
51
|
+
import nokogiri.internals.SaveContextVisitor;
|
52
52
|
import nokogiri.internals.XmlDomParserContext;
|
53
53
|
|
54
54
|
import org.jruby.Ruby;
|
@@ -68,6 +68,7 @@ import org.jruby.runtime.Visibility;
|
|
68
68
|
import org.jruby.runtime.builtin.IRubyObject;
|
69
69
|
import org.w3c.dom.Attr;
|
70
70
|
import org.w3c.dom.Document;
|
71
|
+
import org.w3c.dom.DocumentFragment;
|
71
72
|
import org.w3c.dom.Element;
|
72
73
|
import org.w3c.dom.NamedNodeMap;
|
73
74
|
import org.w3c.dom.Node;
|
@@ -430,7 +431,7 @@ public class XmlNode extends RubyObject {
|
|
430
431
|
//this should delegate to subclasses' implementation
|
431
432
|
}
|
432
433
|
|
433
|
-
public void
|
434
|
+
public void accept(ThreadContext context, SaveContextVisitor visitor) {}
|
434
435
|
|
435
436
|
public void setName(IRubyObject name) {
|
436
437
|
this.name = name;
|
@@ -484,35 +485,6 @@ public class XmlNode extends RubyObject {
|
|
484
485
|
return name;
|
485
486
|
}
|
486
487
|
|
487
|
-
protected void saveNodeListContent(ThreadContext context, XmlNodeSet list, SaveContext ctx) {
|
488
|
-
saveNodeListContent(context, (RubyArray) list.to_a(context), ctx);
|
489
|
-
}
|
490
|
-
|
491
|
-
protected void saveNodeListContent(ThreadContext context, RubyArray array, SaveContext ctx) {
|
492
|
-
int length = array.getLength();
|
493
|
-
|
494
|
-
boolean formatIndentation = ctx.format() && ctx.indentString()!=null;
|
495
|
-
|
496
|
-
for(int i = 0; i < length; i++) {
|
497
|
-
Object item = array.get(i);
|
498
|
-
if (item instanceof XmlNode) {
|
499
|
-
XmlNode cur = (XmlNode) item;
|
500
|
-
|
501
|
-
// if(formatIndentation &&
|
502
|
-
// (cur.isElement() || cur.isComment() || cur.isProcessingInstruction())) {
|
503
|
-
// ctx.append(ctx.getCurrentIndentString());
|
504
|
-
// }
|
505
|
-
|
506
|
-
cur.saveContent(context, ctx);
|
507
|
-
} else if (item instanceof XmlNamespace) {
|
508
|
-
XmlNamespace cur = (XmlNamespace)item;
|
509
|
-
cur.saveContent(context, ctx);
|
510
|
-
}
|
511
|
-
|
512
|
-
// if(ctx.format()) ctx.append("\n");
|
513
|
-
}
|
514
|
-
}
|
515
|
-
|
516
488
|
/**
|
517
489
|
* Add a namespace definition to this node. To the underlying
|
518
490
|
* node, add an attribute of the form
|
@@ -522,16 +494,13 @@ public class XmlNode extends RubyObject {
|
|
522
494
|
public IRubyObject add_namespace_definition(ThreadContext context,
|
523
495
|
IRubyObject prefix,
|
524
496
|
IRubyObject href) {
|
525
|
-
String prefixString = prefix.isNil() ? "" : rubyStringToString(prefix);
|
526
|
-
String hrefString = rubyStringToString(href);
|
527
|
-
XmlDocument xmlDocument = (XmlDocument) doc;
|
528
497
|
Node namespaceOwner;
|
529
498
|
if (node.getNodeType() == Node.ELEMENT_NODE) namespaceOwner = node;
|
530
499
|
else if (node.getNodeType() == Node.ATTRIBUTE_NODE) namespaceOwner = ((Attr)node).getOwnerElement();
|
531
500
|
else namespaceOwner = node.getParentNode();
|
532
|
-
XmlNamespace ns =
|
501
|
+
XmlNamespace ns = XmlNamespace.createFromPrefixAndHref(namespaceOwner, prefix, href);
|
533
502
|
if (node != namespaceOwner) {
|
534
|
-
node.getOwnerDocument().renameNode(node,
|
503
|
+
node.getOwnerDocument().renameNode(node, ns.getHref(), ns.getPrefix() + node.getLocalName());
|
535
504
|
}
|
536
505
|
|
537
506
|
return ns;
|
@@ -542,7 +511,7 @@ public class XmlNode extends RubyObject {
|
|
542
511
|
NamedNodeMap attrs = this.node.getAttributes();
|
543
512
|
Node attr = attrs.getNamedItem(rubyStringToString(name));
|
544
513
|
if(attr == null) {
|
545
|
-
return context.getRuntime().
|
514
|
+
return context.getRuntime().getNil();
|
546
515
|
}
|
547
516
|
return getCachedNodeOrCreate(context.getRuntime(), attr);
|
548
517
|
}
|
@@ -621,8 +590,7 @@ public class XmlNode extends RubyObject {
|
|
621
590
|
addElements(node, elementNodes, false);
|
622
591
|
if (elementNodes.size() == 0) return XmlNodeSet.newEmptyNodeSet(context);
|
623
592
|
RubyArray array = NokogiriHelpers.nodeArrayToRubyArray(context.getRuntime(), elementNodes.toArray(new Node[0]));
|
624
|
-
XmlNodeSet xmlNodeSet =
|
625
|
-
xmlNodeSet.setInitialNodes(array);
|
593
|
+
XmlNodeSet xmlNodeSet = XmlNodeSet.newXmlNodeSet(context, array);
|
626
594
|
return xmlNodeSet;
|
627
595
|
}
|
628
596
|
|
@@ -720,8 +688,7 @@ public class XmlNode extends RubyObject {
|
|
720
688
|
documentErrors.add(docErrors.get(i));
|
721
689
|
}
|
722
690
|
document.setInstanceVariable("@errors", documentErrors);
|
723
|
-
XmlNodeSet xmlNodeSet =
|
724
|
-
xmlNodeSet.setInitialNodes(RubyArray.newArray(runtime));
|
691
|
+
XmlNodeSet xmlNodeSet = XmlNodeSet.newXmlNodeSet(context, RubyArray.newArray(runtime));
|
725
692
|
return xmlNodeSet;
|
726
693
|
}
|
727
694
|
|
@@ -737,8 +704,7 @@ public class XmlNode extends RubyObject {
|
|
737
704
|
nodeArray.add(NokogiriHelpers.getCachedNodeOrCreate(runtime, first));
|
738
705
|
|
739
706
|
NokogiriHelpers.nodeListToRubyArray(runtime, first.getChildNodes(), nodeArray);
|
740
|
-
XmlNodeSet xmlNodeSet =
|
741
|
-
xmlNodeSet.setInitialNodes(nodeArray);
|
707
|
+
XmlNodeSet xmlNodeSet = XmlNodeSet.newXmlNodeSet(context, nodeArray);
|
742
708
|
return xmlNodeSet;
|
743
709
|
}
|
744
710
|
|
@@ -772,8 +738,12 @@ public class XmlNode extends RubyObject {
|
|
772
738
|
|
773
739
|
@JRubyMethod
|
774
740
|
public IRubyObject document(ThreadContext context) {
|
775
|
-
if(doc == null) {
|
741
|
+
if (doc == null) {
|
742
|
+
doc = (XmlDocument) node.getOwnerDocument().getUserData(NokogiriHelpers.CACHED_NODE);
|
743
|
+
}
|
744
|
+
if (doc == null) {
|
776
745
|
doc = getCachedNodeOrCreate(context.getRuntime(), node.getOwnerDocument());
|
746
|
+
node.getOwnerDocument().setUserData(NokogiriHelpers.CACHED_NODE, doc, null);
|
777
747
|
}
|
778
748
|
return doc;
|
779
749
|
}
|
@@ -882,7 +852,7 @@ public class XmlNode extends RubyObject {
|
|
882
852
|
public IRubyObject external_subset(ThreadContext context) {
|
883
853
|
Document document = getOwnerDocument();
|
884
854
|
|
885
|
-
if(document == null) {
|
855
|
+
if (document == null) {
|
886
856
|
return context.getRuntime().getNil();
|
887
857
|
}
|
888
858
|
|
@@ -1014,16 +984,25 @@ public class XmlNode extends RubyObject {
|
|
1014
984
|
|
1015
985
|
String encString = encoding.isNil() ? null : rubyStringToString(encoding);
|
1016
986
|
|
1017
|
-
|
1018
|
-
|
1019
|
-
|
1020
|
-
|
1021
|
-
|
1022
|
-
|
1023
|
-
RuntimeHelpers.invoke(context, io, "write", ctx.toRubyString(context.getRuntime()));
|
987
|
+
SaveContextVisitor visitor =
|
988
|
+
new SaveContextVisitor((Integer)options.toJava(Integer.class), rubyStringToString(indentString), encString,
|
989
|
+
isHtmlDoc(context), isFragment());
|
990
|
+
accept(context, visitor);
|
991
|
+
IRubyObject rubyString = stringOrNil(context.getRuntime(), visitor.toString());
|
992
|
+
RuntimeHelpers.invoke(context, io, "write", rubyString);
|
1024
993
|
|
1025
994
|
return io;
|
1026
995
|
}
|
996
|
+
|
997
|
+
private boolean isHtmlDoc(ThreadContext context) {
|
998
|
+
return document(context).getMetaClass().isKindOfModule(getNokogiriClass(context.getRuntime(), "Nokogiri::HTML::Document"));
|
999
|
+
}
|
1000
|
+
|
1001
|
+
private boolean isFragment() {
|
1002
|
+
if (node instanceof DocumentFragment) return true;
|
1003
|
+
if (node.getParentNode() != null && node.getParentNode() instanceof DocumentFragment) return true;
|
1004
|
+
return false;
|
1005
|
+
}
|
1027
1006
|
|
1028
1007
|
@JRubyMethod(name = {"next_sibling", "next"})
|
1029
1008
|
public IRubyObject next_sibling(ThreadContext context) {
|
@@ -57,8 +57,8 @@ import org.w3c.dom.NodeList;
|
|
57
57
|
* @author Yoko Harada <yokolet@gmail.com>
|
58
58
|
*/
|
59
59
|
@JRubyClass(name="Nokogiri::XML::NodeSet")
|
60
|
-
public class XmlNodeSet extends RubyObject {
|
61
|
-
private
|
60
|
+
public class XmlNodeSet extends RubyObject implements NodeList {
|
61
|
+
private List<?> list;
|
62
62
|
private RubyArray nodes;
|
63
63
|
private IRubyObject doc;
|
64
64
|
|
@@ -76,49 +76,21 @@ public class XmlNodeSet extends RubyObject {
|
|
76
76
|
return super.clone();
|
77
77
|
}
|
78
78
|
|
79
|
-
|
80
|
-
this
|
81
|
-
}
|
82
|
-
|
83
|
-
public XmlNodeSet(Ruby ruby, RubyArray nodes) {
|
84
|
-
this(ruby, getNokogiriClass(ruby, "Nokogiri::XML::NodeSet"), nodes);
|
85
|
-
}
|
79
|
+
void setNodes(RubyArray array) {
|
80
|
+
this.nodes = array;
|
86
81
|
|
87
|
-
|
88
|
-
|
89
|
-
nodeList = nodes;
|
82
|
+
IRubyObject first = array.first();
|
83
|
+
initialize(array.getRuntime(), first);
|
90
84
|
}
|
91
85
|
|
92
|
-
|
93
|
-
super(ruby, rubyClass);
|
94
|
-
this.nodes = nodes;
|
95
|
-
|
96
|
-
IRubyObject first = nodes.first();
|
97
|
-
initialize(ruby, first);
|
98
|
-
}
|
99
|
-
|
100
|
-
public XmlNodeSet(Ruby ruby, XmlNodeSet reference){
|
101
|
-
super(ruby, getNokogiriClass(ruby, "Nokogiri::XML::NodeSet"));
|
86
|
+
private void setReference(XmlNodeSet reference) {
|
102
87
|
this.nodes = null;
|
103
|
-
|
104
88
|
IRubyObject first = reference.nodes.first();
|
105
|
-
initialize(
|
106
|
-
}
|
107
|
-
|
108
|
-
void setNodes(RubyArray nodes) {
|
109
|
-
this.nodes = nodes;
|
110
|
-
nodeList = null;
|
111
|
-
}
|
112
|
-
|
113
|
-
public void setInitialNodes(RubyArray nodes) {
|
114
|
-
this.nodes = nodes;
|
115
|
-
IRubyObject first = nodes.first();
|
116
|
-
initialize(getRuntime(), first);
|
89
|
+
initialize(reference.getRuntime(), first);
|
117
90
|
}
|
118
91
|
|
119
92
|
public void setNodeList(NodeList nodeList) {
|
120
|
-
|
121
|
-
this.nodeList = nodeList;
|
93
|
+
setNodes(nodeListToRubyArray(getRuntime(), nodeList));
|
122
94
|
}
|
123
95
|
|
124
96
|
private void initialize(Ruby ruby, IRubyObject refNode) {
|
@@ -142,7 +114,6 @@ public class XmlNodeSet extends RubyObject {
|
|
142
114
|
}
|
143
115
|
|
144
116
|
public void relink_namespace(ThreadContext context) {
|
145
|
-
nodeList = null;
|
146
117
|
List<?> n = nodes.getList();
|
147
118
|
|
148
119
|
for (int i = 0; i < n.size(); i++) {
|
@@ -152,63 +123,53 @@ public class XmlNodeSet extends RubyObject {
|
|
152
123
|
}
|
153
124
|
}
|
154
125
|
|
155
|
-
public void setDocument(IRubyObject document) {
|
156
|
-
setInstanceVariable("@document", document);
|
157
|
-
this.doc = document;
|
158
|
-
}
|
159
|
-
|
160
|
-
public NodeList toNodeList(Ruby ruby) {
|
161
|
-
if (nodeList != null) return nodeList;
|
162
|
-
return new NokogiriNodeList(ruby, this.nodes);
|
163
|
-
}
|
164
|
-
|
165
126
|
@JRubyMethod(name="&")
|
166
127
|
public IRubyObject and(ThreadContext context, IRubyObject nodeSet){
|
167
|
-
|
128
|
+
if (nodes == null) setNodes(RubyArray.newEmptyArray(context.getRuntime()));
|
168
129
|
return newXmlNodeSet(context, (RubyArray) nodes.op_and(asXmlNodeSet(context, nodeSet).nodes));
|
169
130
|
}
|
170
131
|
|
171
132
|
@JRubyMethod
|
172
133
|
public IRubyObject delete(ThreadContext context, IRubyObject node_or_namespace){
|
173
|
-
|
134
|
+
if (nodes == null) return context.getRuntime().getNil();
|
174
135
|
return nodes.delete(context, asXmlNodeOrNamespace(context, node_or_namespace), Block.NULL_BLOCK);
|
175
136
|
}
|
176
137
|
|
177
138
|
@JRubyMethod
|
178
139
|
public IRubyObject dup(ThreadContext context){
|
140
|
+
if (nodes == null) setNodes(RubyArray.newEmptyArray(context.getRuntime()));
|
179
141
|
return newXmlNodeSet(context, nodes.aryDup());
|
180
142
|
}
|
181
143
|
|
182
144
|
@JRubyMethod(name = "include?")
|
183
145
|
public IRubyObject include_p(ThreadContext context, IRubyObject node_or_namespace){
|
146
|
+
if (nodes == null) setNodes(RubyArray.newEmptyArray(context.getRuntime()));
|
184
147
|
return nodes.include_p(context, asXmlNodeOrNamespace(context, node_or_namespace));
|
185
148
|
}
|
186
149
|
|
187
150
|
@JRubyMethod(name = {"length", "size"})
|
188
151
|
public IRubyObject length(ThreadContext context) {
|
189
|
-
if (nodes
|
190
|
-
return
|
152
|
+
if (nodes != null) return nodes.length();
|
153
|
+
else return context.getRuntime().newFixnum(0);
|
191
154
|
}
|
192
155
|
|
193
156
|
@JRubyMethod(name="-")
|
194
157
|
public IRubyObject op_diff(ThreadContext context, IRubyObject nodeSet){
|
195
|
-
nodeList = null;
|
196
158
|
XmlNodeSet xmlNodeSet = newXmlNodeSet(context, this);
|
159
|
+
if (nodes == null) setNodes(RubyArray.newEmptyArray(context.getRuntime()));
|
197
160
|
xmlNodeSet.setNodes((RubyArray) nodes.op_diff(asXmlNodeSet(context, nodeSet).nodes));
|
198
161
|
return xmlNodeSet;
|
199
162
|
}
|
200
163
|
|
201
164
|
@JRubyMethod(name={"|", "+"})
|
202
165
|
public IRubyObject op_or(ThreadContext context, IRubyObject nodeSet){
|
203
|
-
|
204
|
-
if (nodes == null) setInitialNodes(RubyArray.newEmptyArray(context.getRuntime()));
|
166
|
+
if (nodes == null) setNodes(RubyArray.newEmptyArray(context.getRuntime()));
|
205
167
|
return newXmlNodeSet(context, (RubyArray) nodes.op_or(asXmlNodeSet(context, nodeSet).nodes));
|
206
168
|
}
|
207
169
|
|
208
170
|
@JRubyMethod(name = {"push", "<<"})
|
209
171
|
public IRubyObject push(ThreadContext context, IRubyObject node_or_namespace) {
|
210
|
-
|
211
|
-
if (nodes == null) setInitialNodes(RubyArray.newEmptyArray(context.getRuntime()));
|
172
|
+
if (nodes == null) setNodes(RubyArray.newEmptyArray(context.getRuntime()));
|
212
173
|
nodes.append(asXmlNodeOrNamespace(context, node_or_namespace));
|
213
174
|
return this;
|
214
175
|
}
|
@@ -216,6 +177,7 @@ public class XmlNodeSet extends RubyObject {
|
|
216
177
|
@JRubyMethod(name={"[]", "slice"})
|
217
178
|
public IRubyObject slice(ThreadContext context, IRubyObject indexOrRange){
|
218
179
|
IRubyObject result;
|
180
|
+
if (nodes == null) return context.getRuntime().getNil();
|
219
181
|
if (context.getRuntime().is1_9()) {
|
220
182
|
result = nodes.aref19(indexOrRange);
|
221
183
|
} else {
|
@@ -231,6 +193,7 @@ public class XmlNodeSet extends RubyObject {
|
|
231
193
|
@JRubyMethod(name={"[]", "slice"})
|
232
194
|
public IRubyObject slice(ThreadContext context, IRubyObject start, IRubyObject length){
|
233
195
|
IRubyObject result;
|
196
|
+
if (nodes == null) return context.getRuntime().getNil();
|
234
197
|
if (context.getRuntime().is1_9()) {
|
235
198
|
result = nodes.aref19(start, length);
|
236
199
|
} else {
|
@@ -241,13 +204,13 @@ public class XmlNodeSet extends RubyObject {
|
|
241
204
|
}
|
242
205
|
|
243
206
|
@JRubyMethod(name = {"to_a", "to_ary"})
|
244
|
-
public IRubyObject to_a(ThreadContext context){
|
245
|
-
|
207
|
+
public IRubyObject to_a(ThreadContext context) {
|
208
|
+
return nodes;
|
246
209
|
}
|
247
210
|
|
248
211
|
@JRubyMethod(name = {"unlink", "remove"})
|
249
212
|
public IRubyObject unlink(ThreadContext context){
|
250
|
-
|
213
|
+
if (nodes == null) setNodes(RubyArray.newEmptyArray(context.getRuntime()));
|
251
214
|
IRubyObject[] arr = this.nodes.toJavaArrayUnsafe();
|
252
215
|
long length = arr.length;
|
253
216
|
for (int i = 0; i < length; i++) {
|
@@ -258,15 +221,16 @@ public class XmlNodeSet extends RubyObject {
|
|
258
221
|
return this;
|
259
222
|
}
|
260
223
|
|
261
|
-
|
224
|
+
public static XmlNodeSet newXmlNodeSet(ThreadContext context, RubyArray array) {
|
262
225
|
XmlNodeSet xmlNodeSet = (XmlNodeSet)NokogiriService.XML_NODESET_ALLOCATOR.allocate(context.getRuntime(), getNokogiriClass(context.getRuntime(), "Nokogiri::XML::NodeSet"));
|
263
|
-
xmlNodeSet.
|
226
|
+
xmlNodeSet.setNodes(array);
|
264
227
|
return xmlNodeSet;
|
265
228
|
}
|
266
|
-
|
229
|
+
|
267
230
|
private XmlNodeSet newXmlNodeSet(ThreadContext context, XmlNodeSet reference) {
|
268
|
-
XmlNodeSet
|
269
|
-
|
231
|
+
XmlNodeSet xmlNodeSet = (XmlNodeSet)NokogiriService.XML_NODESET_ALLOCATOR.allocate(context.getRuntime(), getNokogiriClass(context.getRuntime(), "Nokogiri::XML::NodeSet"));
|
232
|
+
xmlNodeSet.setReference(reference);
|
233
|
+
return xmlNodeSet;
|
270
234
|
}
|
271
235
|
|
272
236
|
private IRubyObject asXmlNodeOrNamespace(ThreadContext context, IRubyObject possibleNode) {
|
@@ -284,28 +248,20 @@ public class XmlNodeSet extends RubyObject {
|
|
284
248
|
throw context.getRuntime().newArgumentError("node must be a Nokogiri::XML::NodeSet");
|
285
249
|
}
|
286
250
|
XmlNodeSet xmlNodeSet = (XmlNodeSet)possibleNodeSet;
|
287
|
-
if (xmlNodeSet.nodes == null) xmlNodeSet.
|
251
|
+
if (xmlNodeSet.nodes == null) xmlNodeSet.setNodes(RubyArray.newEmptyArray(context.getRuntime()));
|
288
252
|
return xmlNodeSet;
|
289
253
|
}
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
return XmlNode.getNodeFromXmlNode(ruby.getCurrentContext(),
|
303
|
-
this.nodes.aref(ruby.newFixnum(i)));
|
304
|
-
}
|
305
|
-
|
306
|
-
public int getLength() {
|
307
|
-
return this.nodes.getLength();
|
308
|
-
}
|
309
|
-
|
254
|
+
|
255
|
+
public int getLength() {
|
256
|
+
if (nodes == null) return 0 ;
|
257
|
+
return nodes.size();
|
258
|
+
}
|
259
|
+
|
260
|
+
public Node item(int index) {
|
261
|
+
if (nodes == null) return null ;
|
262
|
+
Object n = nodes.get(index);
|
263
|
+
if (n instanceof XmlNode) return ((XmlNode)n).node;
|
264
|
+
if (n instanceof XmlNamespace) return ((XmlNamespace)n).getNode();
|
265
|
+
return null;
|
310
266
|
}
|
311
267
|
}
|
@@ -33,7 +33,7 @@
|
|
33
33
|
package nokogiri;
|
34
34
|
|
35
35
|
import static nokogiri.internals.NokogiriHelpers.rubyStringToString;
|
36
|
-
import nokogiri.internals.
|
36
|
+
import nokogiri.internals.SaveContextVisitor;
|
37
37
|
|
38
38
|
import org.jruby.Ruby;
|
39
39
|
import org.jruby.RubyClass;
|
@@ -44,22 +44,28 @@ import org.jruby.runtime.ThreadContext;
|
|
44
44
|
import org.jruby.runtime.builtin.IRubyObject;
|
45
45
|
import org.w3c.dom.Document;
|
46
46
|
import org.w3c.dom.Node;
|
47
|
+
import org.w3c.dom.ProcessingInstruction;
|
47
48
|
|
48
49
|
/**
|
49
50
|
* Class for Nokogiri::XML::ProcessingInstruction
|
50
51
|
*
|
51
52
|
* @author sergio
|
53
|
+
* @author Yoko Harada <yokolet@gmail.com>
|
52
54
|
*/
|
53
55
|
@JRubyClass(name="Nokogiri::XML::ProcessingInstruction", parent="Nokogiri::XML::Node")
|
54
56
|
public class XmlProcessingInstruction extends XmlNode {
|
55
57
|
|
56
|
-
public XmlProcessingInstruction(Ruby ruby, RubyClass
|
57
|
-
super(ruby,
|
58
|
+
public XmlProcessingInstruction(Ruby ruby, RubyClass klazz) {
|
59
|
+
super(ruby, klazz);
|
60
|
+
}
|
61
|
+
|
62
|
+
public XmlProcessingInstruction(Ruby ruby, RubyClass klazz, Node node) {
|
63
|
+
super(ruby, klazz, node);
|
58
64
|
}
|
59
65
|
|
60
66
|
@JRubyMethod(name="new", meta=true, rest=true, required=3)
|
61
67
|
public static IRubyObject rbNew(ThreadContext context,
|
62
|
-
IRubyObject
|
68
|
+
IRubyObject klazz,
|
63
69
|
IRubyObject[] args) {
|
64
70
|
|
65
71
|
IRubyObject doc = args[0];
|
@@ -72,7 +78,7 @@ public class XmlProcessingInstruction extends XmlNode {
|
|
72
78
|
rubyStringToString(data));
|
73
79
|
XmlProcessingInstruction self =
|
74
80
|
new XmlProcessingInstruction(context.getRuntime(),
|
75
|
-
(RubyClass)
|
81
|
+
(RubyClass) klazz,
|
76
82
|
node);
|
77
83
|
|
78
84
|
RuntimeHelpers.invoke(context, self, "initialize", args);
|
@@ -84,20 +90,10 @@ public class XmlProcessingInstruction extends XmlNode {
|
|
84
90
|
|
85
91
|
@Override
|
86
92
|
public boolean isProcessingInstruction() { return true; }
|
87
|
-
|
93
|
+
|
88
94
|
@Override
|
89
|
-
public void
|
90
|
-
|
91
|
-
|
92
|
-
IRubyObject content = content(context);
|
93
|
-
if(!content.isNil()) {
|
94
|
-
if (ctx.asHtml()) ctx.append(" ");
|
95
|
-
ctx.append(content.convertToString().asJavaString());
|
96
|
-
}
|
97
|
-
if (ctx.asHtml())
|
98
|
-
ctx.append(">");
|
99
|
-
else
|
100
|
-
ctx.append("?>");
|
95
|
+
public void accept(ThreadContext context, SaveContextVisitor visitor) {
|
96
|
+
visitor.enter((ProcessingInstruction)node);
|
97
|
+
visitor.leave((ProcessingInstruction)node);
|
101
98
|
}
|
102
|
-
|
103
99
|
}
|