nokogiri 1.5.0.beta.4 → 1.5.0
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 +100 -104
- data/bin/nokogiri +1 -2
- 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/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/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 +185 -157
- data/deps.rip +0 -5
- data/ext/java/nokogiri/EncodingHandler.java +0 -124
- data/ext/java/nokogiri/HtmlDocument.java +0 -149
- data/ext/java/nokogiri/HtmlElementDescription.java +0 -145
- data/ext/java/nokogiri/HtmlEntityLookup.java +0 -79
- data/ext/java/nokogiri/HtmlSaxParserContext.java +0 -259
- data/ext/java/nokogiri/NokogiriService.java +0 -535
- data/ext/java/nokogiri/XmlAttr.java +0 -191
- data/ext/java/nokogiri/XmlAttributeDecl.java +0 -130
- data/ext/java/nokogiri/XmlCdata.java +0 -91
- data/ext/java/nokogiri/XmlComment.java +0 -86
- data/ext/java/nokogiri/XmlDocument.java +0 -529
- data/ext/java/nokogiri/XmlDocumentFragment.java +0 -217
- data/ext/java/nokogiri/XmlDtd.java +0 -467
- data/ext/java/nokogiri/XmlElement.java +0 -222
- data/ext/java/nokogiri/XmlElementContent.java +0 -382
- data/ext/java/nokogiri/XmlElementDecl.java +0 -148
- data/ext/java/nokogiri/XmlEntityDecl.java +0 -162
- data/ext/java/nokogiri/XmlEntityReference.java +0 -75
- data/ext/java/nokogiri/XmlNamespace.java +0 -128
- data/ext/java/nokogiri/XmlNode.java +0 -1399
- data/ext/java/nokogiri/XmlNodeSet.java +0 -311
- data/ext/java/nokogiri/XmlProcessingInstruction.java +0 -103
- data/ext/java/nokogiri/XmlReader.java +0 -411
- data/ext/java/nokogiri/XmlRelaxng.java +0 -144
- data/ext/java/nokogiri/XmlSaxParserContext.java +0 -367
- data/ext/java/nokogiri/XmlSaxPushParser.java +0 -184
- data/ext/java/nokogiri/XmlSchema.java +0 -319
- data/ext/java/nokogiri/XmlSyntaxError.java +0 -119
- data/ext/java/nokogiri/XmlText.java +0 -136
- data/ext/java/nokogiri/XmlXpathContext.java +0 -179
- data/ext/java/nokogiri/XsltStylesheet.java +0 -183
- data/ext/java/nokogiri/internals/HtmlDomParserContext.java +0 -206
- data/ext/java/nokogiri/internals/NokogiriDocumentCache.java +0 -73
- data/ext/java/nokogiri/internals/NokogiriErrorHandler.java +0 -86
- data/ext/java/nokogiri/internals/NokogiriHandler.java +0 -327
- data/ext/java/nokogiri/internals/NokogiriHelpers.java +0 -582
- data/ext/java/nokogiri/internals/NokogiriNamespaceCache.java +0 -171
- data/ext/java/nokogiri/internals/NokogiriNamespaceContext.java +0 -118
- data/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler.java +0 -74
- data/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler4NekoHtml.java +0 -121
- data/ext/java/nokogiri/internals/NokogiriStrictErrorHandler.java +0 -79
- data/ext/java/nokogiri/internals/NokogiriXPathFunction.java +0 -126
- data/ext/java/nokogiri/internals/NokogiriXPathFunctionResolver.java +0 -56
- data/ext/java/nokogiri/internals/ParserContext.java +0 -278
- data/ext/java/nokogiri/internals/PushInputStream.java +0 -411
- data/ext/java/nokogiri/internals/ReaderNode.java +0 -474
- data/ext/java/nokogiri/internals/SaveContext.java +0 -288
- data/ext/java/nokogiri/internals/SchemaErrorHandler.java +0 -76
- data/ext/java/nokogiri/internals/XmlDeclHandler.java +0 -42
- data/ext/java/nokogiri/internals/XmlDomParser.java +0 -77
- data/ext/java/nokogiri/internals/XmlDomParserContext.java +0 -238
- data/ext/java/nokogiri/internals/XmlSaxParser.java +0 -65
- data/ext/java/nokogiri/internals/XsltExtensionFunction.java +0 -72
- 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/xercesImpl.jar +0 -0
data/deps.rip
DELETED
@@ -1,124 +0,0 @@
|
|
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
|
-
|
37
|
-
import java.util.HashMap;
|
38
|
-
|
39
|
-
import org.jruby.Ruby;
|
40
|
-
import org.jruby.RubyClass;
|
41
|
-
import org.jruby.RubyObject;
|
42
|
-
import org.jruby.anno.JRubyClass;
|
43
|
-
import org.jruby.anno.JRubyMethod;
|
44
|
-
import org.jruby.runtime.ThreadContext;
|
45
|
-
import org.jruby.runtime.builtin.IRubyObject;
|
46
|
-
|
47
|
-
/**
|
48
|
-
* Stub class to satisfy unit tests. I'm not sure where this class is
|
49
|
-
* meant to be used. As coded it won't really interact with any other
|
50
|
-
* classes and will have no effect on character encodings reported by
|
51
|
-
* documents being parsed.
|
52
|
-
*
|
53
|
-
* @author Patrick Mahoney <pat@polycrstal.org>
|
54
|
-
*/
|
55
|
-
@JRubyClass(name="Nokogiri::EncodingHandler")
|
56
|
-
public class EncodingHandler extends RubyObject {
|
57
|
-
protected static HashMap<String,String> map = new HashMap<String,String>();
|
58
|
-
static {
|
59
|
-
addInitial();
|
60
|
-
}
|
61
|
-
|
62
|
-
protected String name;
|
63
|
-
|
64
|
-
protected static void addInitial() {
|
65
|
-
map.put("UTF-8", "UTF-8");
|
66
|
-
}
|
67
|
-
|
68
|
-
public EncodingHandler(Ruby ruby, RubyClass klass, String value) {
|
69
|
-
super(ruby, klass);
|
70
|
-
name = value;
|
71
|
-
}
|
72
|
-
|
73
|
-
@JRubyMethod(name="[]", meta=true)
|
74
|
-
public static IRubyObject get(ThreadContext context,
|
75
|
-
IRubyObject _klass,
|
76
|
-
IRubyObject keyObj) {
|
77
|
-
Ruby ruby = context.getRuntime();
|
78
|
-
String key = keyObj.toString();
|
79
|
-
String value = map.get(key);
|
80
|
-
if (value == null)
|
81
|
-
return ruby.getNil();
|
82
|
-
|
83
|
-
return new EncodingHandler(
|
84
|
-
ruby,
|
85
|
-
getNokogiriClass(ruby, "Nokogiri::EncodingHandler"),
|
86
|
-
value);
|
87
|
-
}
|
88
|
-
|
89
|
-
@JRubyMethod(meta=true)
|
90
|
-
public static IRubyObject delete(ThreadContext context,
|
91
|
-
IRubyObject _klass,
|
92
|
-
IRubyObject keyObj) {
|
93
|
-
String key = keyObj.toString();
|
94
|
-
String value = map.remove(key);
|
95
|
-
if (value == null)
|
96
|
-
return context.getRuntime().getNil();
|
97
|
-
return context.getRuntime().newString(value);
|
98
|
-
}
|
99
|
-
|
100
|
-
@JRubyMethod(name="clear_aliases!", meta=true)
|
101
|
-
public static IRubyObject clear_aliases(ThreadContext context,
|
102
|
-
IRubyObject _klass) {
|
103
|
-
map.clear();
|
104
|
-
addInitial();
|
105
|
-
return context.getRuntime().getNil();
|
106
|
-
}
|
107
|
-
|
108
|
-
@JRubyMethod(meta=true)
|
109
|
-
public static IRubyObject alias(ThreadContext context,
|
110
|
-
IRubyObject _klass,
|
111
|
-
IRubyObject orig,
|
112
|
-
IRubyObject alias) {
|
113
|
-
String value = map.get(orig.toString());
|
114
|
-
if (value != null)
|
115
|
-
map.put(alias.toString(), value);
|
116
|
-
|
117
|
-
return context.getRuntime().getNil();
|
118
|
-
}
|
119
|
-
|
120
|
-
@JRubyMethod
|
121
|
-
public IRubyObject name(ThreadContext context) {
|
122
|
-
return context.getRuntime().newString(name);
|
123
|
-
}
|
124
|
-
}
|
@@ -1,149 +0,0 @@
|
|
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 nokogiri.internals.HtmlDomParserContext;
|
37
|
-
import nokogiri.internals.SaveContext;
|
38
|
-
|
39
|
-
import org.jruby.Ruby;
|
40
|
-
import org.jruby.RubyClass;
|
41
|
-
import org.jruby.anno.JRubyClass;
|
42
|
-
import org.jruby.anno.JRubyMethod;
|
43
|
-
import org.jruby.javasupport.util.RuntimeHelpers;
|
44
|
-
import org.jruby.runtime.Arity;
|
45
|
-
import org.jruby.runtime.ThreadContext;
|
46
|
-
import org.jruby.runtime.builtin.IRubyObject;
|
47
|
-
import org.w3c.dom.Document;
|
48
|
-
import org.w3c.dom.DocumentType;
|
49
|
-
|
50
|
-
/**
|
51
|
-
* Class for Nokogiri::HTML::Document.
|
52
|
-
*
|
53
|
-
* @author sergio
|
54
|
-
* @author Yoko Harada <yokolet@gmail.com>
|
55
|
-
*/
|
56
|
-
@JRubyClass(name="Nokogiri::HTML::Document", parent="Nokogiri::XML::Document")
|
57
|
-
public class HtmlDocument extends XmlDocument {
|
58
|
-
|
59
|
-
public HtmlDocument(Ruby ruby, RubyClass klazz) {
|
60
|
-
super(ruby, klazz);
|
61
|
-
}
|
62
|
-
|
63
|
-
public HtmlDocument(Ruby ruby, RubyClass klazz, Document doc) {
|
64
|
-
super(ruby, klazz, doc);
|
65
|
-
}
|
66
|
-
|
67
|
-
@JRubyMethod(name="new", meta = true, rest = true, required=0)
|
68
|
-
public static IRubyObject rbNew(ThreadContext context, IRubyObject klazz,
|
69
|
-
IRubyObject[] args) {
|
70
|
-
HtmlDocument htmlDocument = null;
|
71
|
-
try {
|
72
|
-
Document docNode = createNewDocument();
|
73
|
-
htmlDocument = (HtmlDocument) NokogiriService.HTML_DOCUMENT_ALLOCATOR.allocate(context.getRuntime(), (RubyClass) klazz);
|
74
|
-
htmlDocument.setNode(context, docNode);
|
75
|
-
} catch (Exception ex) {
|
76
|
-
throw context.getRuntime().newRuntimeError("couldn't create document: "+ex.toString());
|
77
|
-
}
|
78
|
-
|
79
|
-
RuntimeHelpers.invoke(context, htmlDocument, "initialize", args);
|
80
|
-
|
81
|
-
return htmlDocument;
|
82
|
-
}
|
83
|
-
|
84
|
-
public static IRubyObject do_parse(ThreadContext context,
|
85
|
-
IRubyObject klass,
|
86
|
-
IRubyObject[] args) {
|
87
|
-
Ruby ruby = context.getRuntime();
|
88
|
-
Arity.checkArgumentCount(ruby, args, 4, 4);
|
89
|
-
HtmlDomParserContext ctx =
|
90
|
-
new HtmlDomParserContext(ruby, args[2], args[3]);
|
91
|
-
ctx.setInputSource(context, args[0]);
|
92
|
-
return ctx.parse(context, klass, args[1]);
|
93
|
-
}
|
94
|
-
|
95
|
-
/*
|
96
|
-
* call-seq:
|
97
|
-
* read_io(io, url, encoding, options)
|
98
|
-
*
|
99
|
-
* Read the HTML document from +io+ with given +url+, +encoding+,
|
100
|
-
* and +options+. See Nokogiri::HTML.parse
|
101
|
-
*/
|
102
|
-
@JRubyMethod(meta = true, rest = true)
|
103
|
-
public static IRubyObject read_io(ThreadContext context,
|
104
|
-
IRubyObject cls,
|
105
|
-
IRubyObject[] args) {
|
106
|
-
return do_parse(context, cls, args);
|
107
|
-
}
|
108
|
-
|
109
|
-
/*
|
110
|
-
* call-seq:
|
111
|
-
* read_memory(string, url, encoding, options)
|
112
|
-
*
|
113
|
-
* Read the HTML document contained in +string+ with given +url+, +encoding+,
|
114
|
-
* and +options+. See Nokogiri::HTML.parse
|
115
|
-
*/
|
116
|
-
@JRubyMethod(meta = true, rest = true)
|
117
|
-
public static IRubyObject read_memory(ThreadContext context,
|
118
|
-
IRubyObject cls,
|
119
|
-
IRubyObject[] args) {
|
120
|
-
return do_parse(context, cls, args);
|
121
|
-
}
|
122
|
-
|
123
|
-
@Override
|
124
|
-
public void saveContent(ThreadContext context, SaveContext ctx) {
|
125
|
-
Document doc = getDocument();
|
126
|
-
DocumentType dtd = doc.getDoctype();
|
127
|
-
|
128
|
-
if(dtd != null) {
|
129
|
-
ctx.append("<!DOCTYPE ");
|
130
|
-
ctx.append(dtd.getName());
|
131
|
-
if(dtd.getPublicId() != null) {
|
132
|
-
ctx.append(" PUBLIC ");
|
133
|
-
ctx.appendQuoted(dtd.getPublicId());
|
134
|
-
if(dtd.getSystemId() != null) {
|
135
|
-
ctx.append(" ");
|
136
|
-
ctx.appendQuoted(dtd.getSystemId());
|
137
|
-
}
|
138
|
-
} else if(dtd.getSystemId() != null) {
|
139
|
-
ctx.append(" SYSTEM ");
|
140
|
-
ctx.appendQuoted(dtd.getSystemId());
|
141
|
-
}
|
142
|
-
ctx.append(">\n");
|
143
|
-
}
|
144
|
-
|
145
|
-
this.saveNodeListContent(context,
|
146
|
-
(XmlNodeSet) this.children(context), ctx);
|
147
|
-
ctx.append("\n");
|
148
|
-
}
|
149
|
-
}
|
@@ -1,145 +0,0 @@
|
|
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 java.util.ArrayList;
|
36
|
-
import java.util.Collections;
|
37
|
-
import java.util.HashMap;
|
38
|
-
import java.util.List;
|
39
|
-
import java.util.Map;
|
40
|
-
|
41
|
-
import org.cyberneko.html.HTMLElements;
|
42
|
-
import org.jruby.Ruby;
|
43
|
-
import org.jruby.RubyClass;
|
44
|
-
import org.jruby.RubyObject;
|
45
|
-
import org.jruby.anno.JRubyClass;
|
46
|
-
import org.jruby.anno.JRubyMethod;
|
47
|
-
import org.jruby.runtime.ThreadContext;
|
48
|
-
import org.jruby.runtime.builtin.IRubyObject;
|
49
|
-
|
50
|
-
/**
|
51
|
-
* Class for Nokogiri::HTML::ElementDescription.
|
52
|
-
*
|
53
|
-
* @author Patrick Mahoney <pat@polycrystal.org>
|
54
|
-
*/
|
55
|
-
@JRubyClass(name="Nokogiri::HTML::ElementDescription")
|
56
|
-
public class HtmlElementDescription extends RubyObject {
|
57
|
-
|
58
|
-
/**
|
59
|
-
* Stores memoized hash of element -> list of valid subelements.
|
60
|
-
*/
|
61
|
-
static protected Map<Short, List<String>> subElements;
|
62
|
-
static {
|
63
|
-
Map<Short, List<String>> _subElements =
|
64
|
-
new HashMap<Short, List<String>>();
|
65
|
-
subElements = Collections.synchronizedMap(_subElements);
|
66
|
-
}
|
67
|
-
|
68
|
-
protected HTMLElements.Element element;
|
69
|
-
|
70
|
-
public HtmlElementDescription(Ruby runtime, RubyClass rubyClass) {
|
71
|
-
super(runtime, rubyClass);
|
72
|
-
}
|
73
|
-
|
74
|
-
/**
|
75
|
-
* Lookup the list of sub elements of <code>code</code>. If not
|
76
|
-
* already stored, iterate through all elements to find valid
|
77
|
-
* subelements; save this list and return it.
|
78
|
-
*/
|
79
|
-
protected static List<String> findSubElements(HTMLElements.Element elem) {
|
80
|
-
List<String> subs = subElements.get(elem.code);
|
81
|
-
|
82
|
-
if (subs == null) {
|
83
|
-
subs = new ArrayList<String>();
|
84
|
-
|
85
|
-
/*
|
86
|
-
* A bit of a hack. NekoHtml source code shows that
|
87
|
-
* UNKNOWN is the highest value element. We cannot access
|
88
|
-
* the list of elements directly because it's protected.
|
89
|
-
*/
|
90
|
-
for (short c = 0; c < HTMLElements.UNKNOWN; c++) {
|
91
|
-
HTMLElements.Element maybe_sub =
|
92
|
-
HTMLElements.getElement(c);
|
93
|
-
if (maybe_sub.isParent(elem)) {
|
94
|
-
subs.add(maybe_sub.name);
|
95
|
-
}
|
96
|
-
}
|
97
|
-
|
98
|
-
subElements.put(elem.code, subs);
|
99
|
-
}
|
100
|
-
|
101
|
-
return subs;
|
102
|
-
}
|
103
|
-
|
104
|
-
@JRubyMethod(name="[]", meta=true)
|
105
|
-
public static IRubyObject get(ThreadContext context,
|
106
|
-
IRubyObject klazz, IRubyObject name) {
|
107
|
-
|
108
|
-
HTMLElements.Element elem = HTMLElements.getElement(name.toString());
|
109
|
-
if (elem == HTMLElements.NO_SUCH_ELEMENT)
|
110
|
-
return context.getRuntime().getNil();
|
111
|
-
|
112
|
-
HtmlElementDescription desc =
|
113
|
-
new HtmlElementDescription(context.getRuntime(), (RubyClass)klazz);
|
114
|
-
desc.element = elem;
|
115
|
-
return desc;
|
116
|
-
}
|
117
|
-
|
118
|
-
@JRubyMethod()
|
119
|
-
public IRubyObject name(ThreadContext context) {
|
120
|
-
return context.getRuntime().newString(element.name.toLowerCase());
|
121
|
-
}
|
122
|
-
|
123
|
-
@JRubyMethod(name="inline?")
|
124
|
-
public IRubyObject inline_eh(ThreadContext context) {
|
125
|
-
return context.getRuntime().newBoolean(element.isInline());
|
126
|
-
}
|
127
|
-
|
128
|
-
@JRubyMethod(name="empty?")
|
129
|
-
public IRubyObject empty_eh(ThreadContext context) {
|
130
|
-
return context.getRuntime().newBoolean(element.isEmpty());
|
131
|
-
}
|
132
|
-
|
133
|
-
@JRubyMethod()
|
134
|
-
public IRubyObject sub_elements(ThreadContext context) {
|
135
|
-
Ruby ruby = context.getRuntime();
|
136
|
-
List<String> subs = findSubElements(element);
|
137
|
-
IRubyObject[] ary = new IRubyObject[subs.size()];
|
138
|
-
for (int i = 0; i < subs.size(); ++i) {
|
139
|
-
ary[i] = ruby.newString(subs.get(i));
|
140
|
-
}
|
141
|
-
|
142
|
-
return ruby.newArray(ary);
|
143
|
-
}
|
144
|
-
|
145
|
-
}
|
@@ -1,79 +0,0 @@
|
|
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 org.jruby.javasupport.util.RuntimeHelpers.invoke;
|
36
|
-
|
37
|
-
import org.cyberneko.html.HTMLEntities;
|
38
|
-
import org.jruby.Ruby;
|
39
|
-
import org.jruby.RubyClass;
|
40
|
-
import org.jruby.RubyObject;
|
41
|
-
import org.jruby.anno.JRubyClass;
|
42
|
-
import org.jruby.anno.JRubyMethod;
|
43
|
-
import org.jruby.runtime.ThreadContext;
|
44
|
-
import org.jruby.runtime.builtin.IRubyObject;
|
45
|
-
|
46
|
-
/**
|
47
|
-
* Class for Nokogiri::HTML::EntityLookup.
|
48
|
-
*
|
49
|
-
* @author Patrick Mahoney <pat@polycrystal.org>
|
50
|
-
*/
|
51
|
-
@JRubyClass(name="Nokogiri::HTML::EntityLookup")
|
52
|
-
public class HtmlEntityLookup extends RubyObject {
|
53
|
-
|
54
|
-
public HtmlEntityLookup(Ruby runtime, RubyClass rubyClass) {
|
55
|
-
super(runtime, rubyClass);
|
56
|
-
}
|
57
|
-
|
58
|
-
/**
|
59
|
-
* Looks up an HTML entity <code>key</code>.
|
60
|
-
*
|
61
|
-
* The description is a bit lacking.
|
62
|
-
*/
|
63
|
-
@JRubyMethod()
|
64
|
-
public IRubyObject get(ThreadContext context, IRubyObject key) {
|
65
|
-
Ruby ruby = context.getRuntime();
|
66
|
-
String name = key.toString();
|
67
|
-
int val = HTMLEntities.get(name);
|
68
|
-
if (val == -1) return ruby.getNil();
|
69
|
-
|
70
|
-
IRubyObject edClass =
|
71
|
-
ruby.getClassFromPath("Nokogiri::HTML::EntityDescription");
|
72
|
-
IRubyObject edObj = invoke(context, edClass, "new",
|
73
|
-
ruby.newFixnum(val), ruby.newString(name),
|
74
|
-
ruby.newString(name + " entity"));
|
75
|
-
|
76
|
-
return edObj;
|
77
|
-
}
|
78
|
-
|
79
|
-
}
|