nokogiri 1.4.3.1-java → 1.5.0-java
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gemtest +0 -0
- data/CHANGELOG.ja.rdoc +113 -0
- data/CHANGELOG.rdoc +113 -1
- data/Manifest.txt +72 -68
- data/README.ja.rdoc +4 -4
- data/README.rdoc +31 -7
- data/Rakefile +110 -132
- data/bin/nokogiri +7 -3
- data/ext/java/nokogiri/EncodingHandler.java +124 -0
- data/ext/java/nokogiri/HtmlDocument.java +119 -0
- data/ext/java/nokogiri/HtmlElementDescription.java +145 -0
- data/ext/java/nokogiri/HtmlEntityLookup.java +79 -0
- data/ext/java/nokogiri/HtmlSaxParserContext.java +259 -0
- data/ext/java/nokogiri/NokogiriService.java +590 -0
- data/ext/java/nokogiri/XmlAttr.java +180 -0
- data/ext/java/nokogiri/XmlAttributeDecl.java +130 -0
- data/ext/java/nokogiri/XmlCdata.java +84 -0
- data/ext/java/nokogiri/XmlComment.java +86 -0
- data/ext/java/nokogiri/XmlDocument.java +519 -0
- data/ext/java/nokogiri/XmlDocumentFragment.java +223 -0
- data/ext/java/nokogiri/XmlDtd.java +469 -0
- data/ext/java/nokogiri/XmlElement.java +195 -0
- data/ext/java/nokogiri/XmlElementContent.java +382 -0
- data/ext/java/nokogiri/XmlElementDecl.java +152 -0
- data/ext/java/nokogiri/XmlEntityDecl.java +162 -0
- data/ext/java/nokogiri/XmlEntityReference.java +97 -0
- data/ext/java/nokogiri/XmlNamespace.java +183 -0
- data/ext/java/nokogiri/XmlNode.java +1378 -0
- data/ext/java/nokogiri/XmlNodeSet.java +267 -0
- data/ext/java/nokogiri/XmlProcessingInstruction.java +99 -0
- data/ext/java/nokogiri/XmlReader.java +408 -0
- data/ext/java/nokogiri/XmlRelaxng.java +144 -0
- data/ext/java/nokogiri/XmlSaxParserContext.java +367 -0
- data/ext/java/nokogiri/XmlSaxPushParser.java +184 -0
- data/ext/java/nokogiri/XmlSchema.java +324 -0
- data/ext/java/nokogiri/XmlSyntaxError.java +119 -0
- data/ext/java/nokogiri/XmlText.java +119 -0
- data/ext/java/nokogiri/XmlXpathContext.java +199 -0
- data/ext/java/nokogiri/XsltStylesheet.java +197 -0
- data/ext/java/nokogiri/internals/HtmlDomParserContext.java +204 -0
- data/ext/java/nokogiri/internals/NokogiriDocumentCache.java +73 -0
- data/ext/java/nokogiri/internals/NokogiriErrorHandler.java +86 -0
- data/ext/java/nokogiri/internals/NokogiriHandler.java +327 -0
- data/ext/java/nokogiri/internals/NokogiriHelpers.java +639 -0
- data/ext/java/nokogiri/internals/NokogiriNamespaceCache.java +167 -0
- data/ext/java/nokogiri/internals/NokogiriNamespaceContext.java +130 -0
- data/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler.java +74 -0
- data/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler4NekoHtml.java +121 -0
- data/ext/java/nokogiri/internals/NokogiriStrictErrorHandler.java +79 -0
- data/ext/java/nokogiri/internals/NokogiriXPathFunction.java +141 -0
- data/ext/java/nokogiri/internals/NokogiriXPathFunctionResolver.java +73 -0
- 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 +276 -0
- data/ext/java/nokogiri/internals/PushInputStream.java +411 -0
- data/ext/java/nokogiri/internals/ReaderNode.java +531 -0
- data/ext/java/nokogiri/internals/SaveContextVisitor.java +567 -0
- data/ext/java/nokogiri/internals/SchemaErrorHandler.java +76 -0
- data/ext/java/nokogiri/internals/XmlDeclHandler.java +42 -0
- data/ext/java/nokogiri/internals/XmlDomParser.java +76 -0
- data/ext/java/nokogiri/internals/XmlDomParserContext.java +244 -0
- data/ext/java/nokogiri/internals/XmlSaxParser.java +65 -0
- data/ext/java/nokogiri/internals/XsltExtensionFunction.java +72 -0
- data/ext/nokogiri/depend +358 -32
- data/ext/nokogiri/extconf.rb +10 -6
- data/ext/nokogiri/nokogiri.c +23 -3
- data/ext/nokogiri/nokogiri.h +7 -2
- data/ext/nokogiri/xml_document.c +9 -0
- data/ext/nokogiri/xml_dtd.c +2 -2
- data/ext/nokogiri/xml_io.c +32 -7
- data/ext/nokogiri/xml_node.c +45 -25
- data/ext/nokogiri/xml_node_set.c +1 -1
- data/ext/nokogiri/xml_relax_ng.c +0 -7
- data/ext/nokogiri/xml_sax_parser.c +14 -7
- data/ext/nokogiri/xml_sax_parser_context.c +40 -0
- data/ext/nokogiri/xml_xpath_context.c +33 -2
- data/ext/nokogiri/xslt_stylesheet.c +128 -6
- data/lib/isorelax.jar +0 -0
- data/lib/jing.jar +0 -0
- data/lib/nekodtd.jar +0 -0
- data/lib/nekohtml.jar +0 -0
- data/lib/nokogiri/css/parser.rb +665 -70
- data/lib/nokogiri/css/parser.y +3 -1
- data/lib/nokogiri/css/parser_extras.rb +91 -0
- data/lib/nokogiri/css/tokenizer.rb +148 -3
- data/lib/nokogiri/css/tokenizer.rex +1 -1
- data/lib/nokogiri/css/xpath_visitor.rb +15 -7
- data/lib/nokogiri/css.rb +5 -3
- data/lib/nokogiri/decorators/slop.rb +5 -3
- data/lib/nokogiri/html/document.rb +142 -19
- data/lib/nokogiri/html/document_fragment.rb +19 -17
- data/lib/nokogiri/html/element_description_defaults.rb +671 -0
- data/lib/nokogiri/html/sax/parser.rb +6 -2
- data/lib/nokogiri/html.rb +1 -0
- data/lib/nokogiri/nokogiri.jar +0 -0
- data/lib/nokogiri/version.rb +76 -26
- data/lib/nokogiri/xml/attribute_decl.rb +1 -1
- data/lib/nokogiri/xml/builder.rb +7 -0
- data/lib/nokogiri/xml/document.rb +43 -2
- data/lib/nokogiri/xml/document_fragment.rb +16 -2
- data/lib/nokogiri/xml/dtd.rb +12 -1
- data/lib/nokogiri/xml/element_decl.rb +1 -1
- data/lib/nokogiri/xml/entity_decl.rb +1 -1
- data/lib/nokogiri/xml/node/save_options.rb +20 -1
- data/lib/nokogiri/xml/node.rb +198 -78
- data/lib/nokogiri/xml/node_set.rb +10 -3
- data/lib/nokogiri/xml/parse_options.rb +8 -0
- data/lib/nokogiri/xml/reader.rb +42 -6
- data/lib/nokogiri/xml/sax/document.rb +4 -2
- data/lib/nokogiri/xml/schema.rb +7 -1
- data/lib/nokogiri/xslt/stylesheet.rb +1 -1
- data/lib/nokogiri/xslt.rb +9 -5
- data/lib/nokogiri.rb +19 -25
- data/lib/xercesImpl.jar +0 -0
- data/nokogiri_help_responses.md +40 -0
- data/tasks/cross_compile.rb +130 -136
- data/tasks/nokogiri.org.rb +18 -0
- data/tasks/test.rb +2 -2
- data/test/css/test_parser.rb +29 -18
- data/test/css/test_tokenizer.rb +8 -0
- data/test/decorators/test_slop.rb +16 -0
- 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 +5 -1
- data/test/html/sax/test_parser.rb +65 -3
- data/test/html/test_document.rb +75 -1
- data/test/html/test_document_encoding.rb +61 -0
- data/test/html/test_document_fragment.rb +50 -5
- data/test/html/test_element_description.rb +4 -2
- data/test/html/test_node.rb +9 -0
- data/test/test_memory_leak.rb +20 -35
- data/test/test_nokogiri.rb +14 -20
- data/test/test_reader.rb +23 -6
- data/test/test_xslt_transforms.rb +6 -2
- data/test/xml/node/test_save_options.rb +10 -2
- data/test/xml/sax/test_parser.rb +39 -8
- data/test/xml/sax/test_parser_context.rb +50 -0
- data/test/xml/sax/test_push_parser.rb +18 -1
- data/test/xml/test_attribute_decl.rb +7 -3
- data/test/xml/test_builder.rb +17 -0
- data/test/xml/test_document.rb +34 -5
- data/test/xml/test_document_fragment.rb +14 -2
- data/test/xml/test_dtd.rb +28 -3
- data/test/xml/test_element_content.rb +1 -1
- data/test/xml/test_element_decl.rb +1 -1
- data/test/xml/test_entity_decl.rb +12 -10
- data/test/xml/test_namespace.rb +7 -5
- data/test/xml/test_node.rb +65 -13
- data/test/xml/test_node_reparenting.rb +72 -31
- data/test/xml/test_node_set.rb +57 -0
- data/test/xml/test_schema.rb +5 -0
- data/test/xml/test_xpath.rb +32 -0
- data/test/xslt/test_custom_functions.rb +94 -0
- data/test/xslt/test_exception_handling.rb +37 -0
- metadata +512 -517
- data/deps.rip +0 -5
- data/ext/nokogiri/libcharset-1.dll +0 -0
- data/ext/nokogiri/libexslt.dll +0 -0
- data/ext/nokogiri/libiconv-2.dll +0 -0
- data/ext/nokogiri/libxml2.dll +0 -0
- data/ext/nokogiri/libxslt.dll +0 -0
- data/ext/nokogiri/zlib1.dll +0 -0
- data/lib/nokogiri/css/generated_parser.rb +0 -676
- data/lib/nokogiri/css/generated_tokenizer.rb +0 -146
- data/lib/nokogiri/ffi/encoding_handler.rb +0 -42
- data/lib/nokogiri/ffi/html/document.rb +0 -28
- data/lib/nokogiri/ffi/html/element_description.rb +0 -81
- data/lib/nokogiri/ffi/html/entity_lookup.rb +0 -16
- data/lib/nokogiri/ffi/html/sax/parser_context.rb +0 -38
- data/lib/nokogiri/ffi/io_callbacks.rb +0 -42
- data/lib/nokogiri/ffi/libxml.rb +0 -411
- data/lib/nokogiri/ffi/structs/common_node.rb +0 -38
- data/lib/nokogiri/ffi/structs/html_elem_desc.rb +0 -24
- data/lib/nokogiri/ffi/structs/html_entity_desc.rb +0 -13
- data/lib/nokogiri/ffi/structs/xml_alloc.rb +0 -16
- data/lib/nokogiri/ffi/structs/xml_attr.rb +0 -19
- data/lib/nokogiri/ffi/structs/xml_attribute.rb +0 -27
- data/lib/nokogiri/ffi/structs/xml_buffer.rb +0 -16
- data/lib/nokogiri/ffi/structs/xml_char_encoding_handler.rb +0 -11
- data/lib/nokogiri/ffi/structs/xml_document.rb +0 -117
- data/lib/nokogiri/ffi/structs/xml_dtd.rb +0 -28
- data/lib/nokogiri/ffi/structs/xml_element.rb +0 -26
- data/lib/nokogiri/ffi/structs/xml_element_content.rb +0 -17
- data/lib/nokogiri/ffi/structs/xml_entity.rb +0 -32
- data/lib/nokogiri/ffi/structs/xml_enumeration.rb +0 -12
- data/lib/nokogiri/ffi/structs/xml_node.rb +0 -28
- data/lib/nokogiri/ffi/structs/xml_node_set.rb +0 -53
- data/lib/nokogiri/ffi/structs/xml_notation.rb +0 -11
- data/lib/nokogiri/ffi/structs/xml_ns.rb +0 -15
- data/lib/nokogiri/ffi/structs/xml_parser_context.rb +0 -19
- data/lib/nokogiri/ffi/structs/xml_relax_ng.rb +0 -14
- data/lib/nokogiri/ffi/structs/xml_sax_handler.rb +0 -51
- data/lib/nokogiri/ffi/structs/xml_sax_push_parser_context.rb +0 -124
- data/lib/nokogiri/ffi/structs/xml_schema.rb +0 -13
- data/lib/nokogiri/ffi/structs/xml_syntax_error.rb +0 -31
- data/lib/nokogiri/ffi/structs/xml_text_reader.rb +0 -12
- data/lib/nokogiri/ffi/structs/xml_xpath_context.rb +0 -38
- data/lib/nokogiri/ffi/structs/xml_xpath_object.rb +0 -35
- data/lib/nokogiri/ffi/structs/xml_xpath_parser_context.rb +0 -20
- data/lib/nokogiri/ffi/structs/xslt_stylesheet.rb +0 -13
- data/lib/nokogiri/ffi/weak_bucket.rb +0 -40
- data/lib/nokogiri/ffi/xml/attr.rb +0 -41
- data/lib/nokogiri/ffi/xml/attribute_decl.rb +0 -27
- data/lib/nokogiri/ffi/xml/cdata.rb +0 -19
- data/lib/nokogiri/ffi/xml/comment.rb +0 -18
- data/lib/nokogiri/ffi/xml/document.rb +0 -166
- data/lib/nokogiri/ffi/xml/document_fragment.rb +0 -21
- data/lib/nokogiri/ffi/xml/dtd.rb +0 -67
- data/lib/nokogiri/ffi/xml/element_content.rb +0 -43
- data/lib/nokogiri/ffi/xml/element_decl.rb +0 -19
- data/lib/nokogiri/ffi/xml/entity_decl.rb +0 -36
- data/lib/nokogiri/ffi/xml/entity_reference.rb +0 -19
- data/lib/nokogiri/ffi/xml/namespace.rb +0 -44
- data/lib/nokogiri/ffi/xml/node.rb +0 -554
- data/lib/nokogiri/ffi/xml/node_set.rb +0 -149
- data/lib/nokogiri/ffi/xml/processing_instruction.rb +0 -20
- data/lib/nokogiri/ffi/xml/reader.rb +0 -236
- data/lib/nokogiri/ffi/xml/relax_ng.rb +0 -85
- data/lib/nokogiri/ffi/xml/sax/parser.rb +0 -135
- data/lib/nokogiri/ffi/xml/sax/parser_context.rb +0 -67
- data/lib/nokogiri/ffi/xml/sax/push_parser.rb +0 -51
- data/lib/nokogiri/ffi/xml/schema.rb +0 -109
- data/lib/nokogiri/ffi/xml/syntax_error.rb +0 -98
- data/lib/nokogiri/ffi/xml/text.rb +0 -18
- data/lib/nokogiri/ffi/xml/xpath.rb +0 -9
- data/lib/nokogiri/ffi/xml/xpath_context.rb +0 -148
- data/lib/nokogiri/ffi/xslt/stylesheet.rb +0 -53
- data/lib/nokogiri/version_warning.rb +0 -14
- data/test/ffi/test_document.rb +0 -35
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* (The MIT License)
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2008 - 2011:
|
|
5
|
+
*
|
|
6
|
+
* * {Aaron Patterson}[http://tenderlovemaking.com]
|
|
7
|
+
* * {Mike Dalessio}[http://mike.daless.io]
|
|
8
|
+
* * {Charles Nutter}[http://blog.headius.com]
|
|
9
|
+
* * {Sergio Arbeo}[http://www.serabe.com]
|
|
10
|
+
* * {Patrick Mahoney}[http://polycrystal.org]
|
|
11
|
+
* * {Yoko Harada}[http://yokolet.blogspot.com]
|
|
12
|
+
*
|
|
13
|
+
* Permission is hereby granted, free of charge, to any person obtaining
|
|
14
|
+
* a copy of this software and associated documentation files (the
|
|
15
|
+
* 'Software'), to deal in the Software without restriction, including
|
|
16
|
+
* without limitation the rights to use, copy, modify, merge, publish,
|
|
17
|
+
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
18
|
+
* permit persons to whom the Software is furnished to do so, subject to
|
|
19
|
+
* the following conditions:
|
|
20
|
+
*
|
|
21
|
+
* The above copyright notice and this permission notice shall be
|
|
22
|
+
* included in all copies or substantial portions of the Software.
|
|
23
|
+
*
|
|
24
|
+
* THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
|
25
|
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
26
|
+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
27
|
+
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
28
|
+
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
29
|
+
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
30
|
+
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
package nokogiri;
|
|
34
|
+
|
|
35
|
+
import static nokogiri.internals.NokogiriHelpers.getNokogiriClass;
|
|
36
|
+
import static nokogiri.internals.NokogiriHelpers.nodeListToRubyArray;
|
|
37
|
+
|
|
38
|
+
import java.util.List;
|
|
39
|
+
|
|
40
|
+
import org.jruby.Ruby;
|
|
41
|
+
import org.jruby.RubyArray;
|
|
42
|
+
import org.jruby.RubyClass;
|
|
43
|
+
import org.jruby.RubyObject;
|
|
44
|
+
import org.jruby.anno.JRubyClass;
|
|
45
|
+
import org.jruby.anno.JRubyMethod;
|
|
46
|
+
import org.jruby.javasupport.util.RuntimeHelpers;
|
|
47
|
+
import org.jruby.runtime.Block;
|
|
48
|
+
import org.jruby.runtime.ThreadContext;
|
|
49
|
+
import org.jruby.runtime.builtin.IRubyObject;
|
|
50
|
+
import org.w3c.dom.Node;
|
|
51
|
+
import org.w3c.dom.NodeList;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Class for Nokogiri::XML::NodeSet
|
|
55
|
+
*
|
|
56
|
+
* @author sergio
|
|
57
|
+
* @author Yoko Harada <yokolet@gmail.com>
|
|
58
|
+
*/
|
|
59
|
+
@JRubyClass(name="Nokogiri::XML::NodeSet")
|
|
60
|
+
public class XmlNodeSet extends RubyObject implements NodeList {
|
|
61
|
+
private List<?> list;
|
|
62
|
+
private RubyArray nodes;
|
|
63
|
+
private IRubyObject doc;
|
|
64
|
+
|
|
65
|
+
public XmlNodeSet(Ruby ruby, RubyClass klazz) {
|
|
66
|
+
super(ruby, klazz);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Create and return a copy of this object.
|
|
71
|
+
*
|
|
72
|
+
* @return a clone of this object
|
|
73
|
+
*/
|
|
74
|
+
@Override
|
|
75
|
+
public Object clone() throws CloneNotSupportedException {
|
|
76
|
+
return super.clone();
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
void setNodes(RubyArray array) {
|
|
80
|
+
this.nodes = array;
|
|
81
|
+
|
|
82
|
+
IRubyObject first = array.first();
|
|
83
|
+
initialize(array.getRuntime(), first);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
private void setReference(XmlNodeSet reference) {
|
|
87
|
+
this.nodes = null;
|
|
88
|
+
IRubyObject first = reference.nodes.first();
|
|
89
|
+
initialize(reference.getRuntime(), first);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
public void setNodeList(NodeList nodeList) {
|
|
93
|
+
setNodes(nodeListToRubyArray(getRuntime(), nodeList));
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
private void initialize(Ruby ruby, IRubyObject refNode) {
|
|
97
|
+
if (refNode instanceof XmlNode) {
|
|
98
|
+
XmlNode n = (XmlNode)refNode;
|
|
99
|
+
doc = n.document(ruby.getCurrentContext());
|
|
100
|
+
setInstanceVariable("@document", doc);
|
|
101
|
+
if (doc != null) {
|
|
102
|
+
RuntimeHelpers.invoke(ruby.getCurrentContext(), doc, "decorate", this);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
public static IRubyObject newEmptyNodeSet(ThreadContext context) {
|
|
108
|
+
return (XmlNodeSet)NokogiriService.XML_NODESET_ALLOCATOR.allocate(context.getRuntime(), getNokogiriClass(context.getRuntime(), "Nokogiri::XML::NodeSet"));
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
public long length() {
|
|
112
|
+
if (nodes == null) return 0L;
|
|
113
|
+
return nodes.length().getLongValue();
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
public void relink_namespace(ThreadContext context) {
|
|
117
|
+
List<?> n = nodes.getList();
|
|
118
|
+
|
|
119
|
+
for (int i = 0; i < n.size(); i++) {
|
|
120
|
+
if (n.get(i) instanceof XmlNode) {
|
|
121
|
+
((XmlNode) n.get(i)).relink_namespace(context);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
@JRubyMethod(name="&")
|
|
127
|
+
public IRubyObject and(ThreadContext context, IRubyObject nodeSet){
|
|
128
|
+
if (nodes == null) setNodes(RubyArray.newEmptyArray(context.getRuntime()));
|
|
129
|
+
return newXmlNodeSet(context, (RubyArray) nodes.op_and(asXmlNodeSet(context, nodeSet).nodes));
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
@JRubyMethod
|
|
133
|
+
public IRubyObject delete(ThreadContext context, IRubyObject node_or_namespace){
|
|
134
|
+
if (nodes == null) return context.getRuntime().getNil();
|
|
135
|
+
return nodes.delete(context, asXmlNodeOrNamespace(context, node_or_namespace), Block.NULL_BLOCK);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
@JRubyMethod
|
|
139
|
+
public IRubyObject dup(ThreadContext context){
|
|
140
|
+
if (nodes == null) setNodes(RubyArray.newEmptyArray(context.getRuntime()));
|
|
141
|
+
return newXmlNodeSet(context, nodes.aryDup());
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
@JRubyMethod(name = "include?")
|
|
145
|
+
public IRubyObject include_p(ThreadContext context, IRubyObject node_or_namespace){
|
|
146
|
+
if (nodes == null) setNodes(RubyArray.newEmptyArray(context.getRuntime()));
|
|
147
|
+
return nodes.include_p(context, asXmlNodeOrNamespace(context, node_or_namespace));
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
@JRubyMethod(name = {"length", "size"})
|
|
151
|
+
public IRubyObject length(ThreadContext context) {
|
|
152
|
+
if (nodes != null) return nodes.length();
|
|
153
|
+
else return context.getRuntime().newFixnum(0);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
@JRubyMethod(name="-")
|
|
157
|
+
public IRubyObject op_diff(ThreadContext context, IRubyObject nodeSet){
|
|
158
|
+
XmlNodeSet xmlNodeSet = newXmlNodeSet(context, this);
|
|
159
|
+
if (nodes == null) setNodes(RubyArray.newEmptyArray(context.getRuntime()));
|
|
160
|
+
xmlNodeSet.setNodes((RubyArray) nodes.op_diff(asXmlNodeSet(context, nodeSet).nodes));
|
|
161
|
+
return xmlNodeSet;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
@JRubyMethod(name={"|", "+"})
|
|
165
|
+
public IRubyObject op_or(ThreadContext context, IRubyObject nodeSet){
|
|
166
|
+
if (nodes == null) setNodes(RubyArray.newEmptyArray(context.getRuntime()));
|
|
167
|
+
return newXmlNodeSet(context, (RubyArray) nodes.op_or(asXmlNodeSet(context, nodeSet).nodes));
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
@JRubyMethod(name = {"push", "<<"})
|
|
171
|
+
public IRubyObject push(ThreadContext context, IRubyObject node_or_namespace) {
|
|
172
|
+
if (nodes == null) setNodes(RubyArray.newEmptyArray(context.getRuntime()));
|
|
173
|
+
nodes.append(asXmlNodeOrNamespace(context, node_or_namespace));
|
|
174
|
+
return this;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
@JRubyMethod(name={"[]", "slice"})
|
|
178
|
+
public IRubyObject slice(ThreadContext context, IRubyObject indexOrRange){
|
|
179
|
+
IRubyObject result;
|
|
180
|
+
if (nodes == null) return context.getRuntime().getNil();
|
|
181
|
+
if (context.getRuntime().is1_9()) {
|
|
182
|
+
result = nodes.aref19(indexOrRange);
|
|
183
|
+
} else {
|
|
184
|
+
result = nodes.aref(indexOrRange);
|
|
185
|
+
}
|
|
186
|
+
if (result instanceof RubyArray) {
|
|
187
|
+
return newXmlNodeSet(context, (RubyArray)result);
|
|
188
|
+
} else {
|
|
189
|
+
return result;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
@JRubyMethod(name={"[]", "slice"})
|
|
194
|
+
public IRubyObject slice(ThreadContext context, IRubyObject start, IRubyObject length){
|
|
195
|
+
IRubyObject result;
|
|
196
|
+
if (nodes == null) return context.getRuntime().getNil();
|
|
197
|
+
if (context.getRuntime().is1_9()) {
|
|
198
|
+
result = nodes.aref19(start, length);
|
|
199
|
+
} else {
|
|
200
|
+
result = nodes.aref(start, length);
|
|
201
|
+
}
|
|
202
|
+
if (result instanceof RubyArray) return newXmlNodeSet(context, (RubyArray)result);
|
|
203
|
+
else return context.getRuntime().getNil();
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
@JRubyMethod(name = {"to_a", "to_ary"})
|
|
207
|
+
public IRubyObject to_a(ThreadContext context) {
|
|
208
|
+
return nodes;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
@JRubyMethod(name = {"unlink", "remove"})
|
|
212
|
+
public IRubyObject unlink(ThreadContext context){
|
|
213
|
+
if (nodes == null) setNodes(RubyArray.newEmptyArray(context.getRuntime()));
|
|
214
|
+
IRubyObject[] arr = this.nodes.toJavaArrayUnsafe();
|
|
215
|
+
long length = arr.length;
|
|
216
|
+
for (int i = 0; i < length; i++) {
|
|
217
|
+
if (arr[i] instanceof XmlNode) {
|
|
218
|
+
((XmlNode) arr[i] ).unlink(context);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
return this;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
public static XmlNodeSet newXmlNodeSet(ThreadContext context, RubyArray array) {
|
|
225
|
+
XmlNodeSet xmlNodeSet = (XmlNodeSet)NokogiriService.XML_NODESET_ALLOCATOR.allocate(context.getRuntime(), getNokogiriClass(context.getRuntime(), "Nokogiri::XML::NodeSet"));
|
|
226
|
+
xmlNodeSet.setNodes(array);
|
|
227
|
+
return xmlNodeSet;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
private XmlNodeSet newXmlNodeSet(ThreadContext context, XmlNodeSet reference) {
|
|
231
|
+
XmlNodeSet xmlNodeSet = (XmlNodeSet)NokogiriService.XML_NODESET_ALLOCATOR.allocate(context.getRuntime(), getNokogiriClass(context.getRuntime(), "Nokogiri::XML::NodeSet"));
|
|
232
|
+
xmlNodeSet.setReference(reference);
|
|
233
|
+
return xmlNodeSet;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
private IRubyObject asXmlNodeOrNamespace(ThreadContext context, IRubyObject possibleNode) {
|
|
237
|
+
if (possibleNode instanceof XmlNode || possibleNode instanceof XmlNamespace) {
|
|
238
|
+
return possibleNode;
|
|
239
|
+
} else {
|
|
240
|
+
throw context.getRuntime().newArgumentError("node must be a Nokogiri::XML::Node or Nokogiri::XML::Namespace");
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
private XmlNodeSet asXmlNodeSet(ThreadContext context, IRubyObject possibleNodeSet) {
|
|
245
|
+
// if(!(possibleNodeSet instanceof XmlNodeSet)) {
|
|
246
|
+
if(!RuntimeHelpers.invoke(context, possibleNodeSet, "is_a?",
|
|
247
|
+
getNokogiriClass(context.getRuntime(), "Nokogiri::XML::NodeSet")).isTrue()) {
|
|
248
|
+
throw context.getRuntime().newArgumentError("node must be a Nokogiri::XML::NodeSet");
|
|
249
|
+
}
|
|
250
|
+
XmlNodeSet xmlNodeSet = (XmlNodeSet)possibleNodeSet;
|
|
251
|
+
if (xmlNodeSet.nodes == null) xmlNodeSet.setNodes(RubyArray.newEmptyArray(context.getRuntime()));
|
|
252
|
+
return xmlNodeSet;
|
|
253
|
+
}
|
|
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;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* (The MIT License)
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2008 - 2011:
|
|
5
|
+
*
|
|
6
|
+
* * {Aaron Patterson}[http://tenderlovemaking.com]
|
|
7
|
+
* * {Mike Dalessio}[http://mike.daless.io]
|
|
8
|
+
* * {Charles Nutter}[http://blog.headius.com]
|
|
9
|
+
* * {Sergio Arbeo}[http://www.serabe.com]
|
|
10
|
+
* * {Patrick Mahoney}[http://polycrystal.org]
|
|
11
|
+
* * {Yoko Harada}[http://yokolet.blogspot.com]
|
|
12
|
+
*
|
|
13
|
+
* Permission is hereby granted, free of charge, to any person obtaining
|
|
14
|
+
* a copy of this software and associated documentation files (the
|
|
15
|
+
* 'Software'), to deal in the Software without restriction, including
|
|
16
|
+
* without limitation the rights to use, copy, modify, merge, publish,
|
|
17
|
+
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
18
|
+
* permit persons to whom the Software is furnished to do so, subject to
|
|
19
|
+
* the following conditions:
|
|
20
|
+
*
|
|
21
|
+
* The above copyright notice and this permission notice shall be
|
|
22
|
+
* included in all copies or substantial portions of the Software.
|
|
23
|
+
*
|
|
24
|
+
* THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
|
25
|
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
26
|
+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
27
|
+
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
28
|
+
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
29
|
+
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
30
|
+
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
package nokogiri;
|
|
34
|
+
|
|
35
|
+
import static nokogiri.internals.NokogiriHelpers.rubyStringToString;
|
|
36
|
+
import nokogiri.internals.SaveContextVisitor;
|
|
37
|
+
|
|
38
|
+
import org.jruby.Ruby;
|
|
39
|
+
import org.jruby.RubyClass;
|
|
40
|
+
import org.jruby.anno.JRubyClass;
|
|
41
|
+
import org.jruby.anno.JRubyMethod;
|
|
42
|
+
import org.jruby.javasupport.util.RuntimeHelpers;
|
|
43
|
+
import org.jruby.runtime.ThreadContext;
|
|
44
|
+
import org.jruby.runtime.builtin.IRubyObject;
|
|
45
|
+
import org.w3c.dom.Document;
|
|
46
|
+
import org.w3c.dom.Node;
|
|
47
|
+
import org.w3c.dom.ProcessingInstruction;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Class for Nokogiri::XML::ProcessingInstruction
|
|
51
|
+
*
|
|
52
|
+
* @author sergio
|
|
53
|
+
* @author Yoko Harada <yokolet@gmail.com>
|
|
54
|
+
*/
|
|
55
|
+
@JRubyClass(name="Nokogiri::XML::ProcessingInstruction", parent="Nokogiri::XML::Node")
|
|
56
|
+
public class XmlProcessingInstruction extends XmlNode {
|
|
57
|
+
|
|
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);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
@JRubyMethod(name="new", meta=true, rest=true, required=3)
|
|
67
|
+
public static IRubyObject rbNew(ThreadContext context,
|
|
68
|
+
IRubyObject klazz,
|
|
69
|
+
IRubyObject[] args) {
|
|
70
|
+
|
|
71
|
+
IRubyObject doc = args[0];
|
|
72
|
+
IRubyObject target = args[1];
|
|
73
|
+
IRubyObject data = args[2];
|
|
74
|
+
|
|
75
|
+
Document document = ((XmlNode) doc).getOwnerDocument();
|
|
76
|
+
Node node =
|
|
77
|
+
document.createProcessingInstruction(rubyStringToString(target),
|
|
78
|
+
rubyStringToString(data));
|
|
79
|
+
XmlProcessingInstruction self =
|
|
80
|
+
new XmlProcessingInstruction(context.getRuntime(),
|
|
81
|
+
(RubyClass) klazz,
|
|
82
|
+
node);
|
|
83
|
+
|
|
84
|
+
RuntimeHelpers.invoke(context, self, "initialize", args);
|
|
85
|
+
|
|
86
|
+
// TODO: if_block_given.
|
|
87
|
+
|
|
88
|
+
return self;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
@Override
|
|
92
|
+
public boolean isProcessingInstruction() { return true; }
|
|
93
|
+
|
|
94
|
+
@Override
|
|
95
|
+
public void accept(ThreadContext context, SaveContextVisitor visitor) {
|
|
96
|
+
visitor.enter((ProcessingInstruction)node);
|
|
97
|
+
visitor.leave((ProcessingInstruction)node);
|
|
98
|
+
}
|
|
99
|
+
}
|