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
@@ -1,259 +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.rubyStringToString;
|
36
|
-
|
37
|
-
import java.io.ByteArrayInputStream;
|
38
|
-
import java.io.InputStream;
|
39
|
-
import java.nio.charset.Charset;
|
40
|
-
import java.nio.charset.IllegalCharsetNameException;
|
41
|
-
import java.util.EnumSet;
|
42
|
-
import java.util.regex.Matcher;
|
43
|
-
import java.util.regex.Pattern;
|
44
|
-
|
45
|
-
import nokogiri.internals.NokogiriHandler;
|
46
|
-
|
47
|
-
import org.apache.xerces.parsers.AbstractSAXParser;
|
48
|
-
import org.cyberneko.html.parsers.SAXParser;
|
49
|
-
import org.jruby.Ruby;
|
50
|
-
import org.jruby.RubyClass;
|
51
|
-
import org.jruby.RubyFixnum;
|
52
|
-
import org.jruby.RubyString;
|
53
|
-
import org.jruby.anno.JRubyClass;
|
54
|
-
import org.jruby.anno.JRubyMethod;
|
55
|
-
import org.jruby.runtime.ThreadContext;
|
56
|
-
import org.jruby.runtime.builtin.IRubyObject;
|
57
|
-
import org.xml.sax.SAXException;
|
58
|
-
|
59
|
-
/**
|
60
|
-
* Class for Nokogiri::HTML::SAX::ParserContext.
|
61
|
-
*
|
62
|
-
* @author serabe
|
63
|
-
* @author Patrick Mahoney <pat@polycrystal.org>
|
64
|
-
* @author Yoko Harada <yokolet@gmail.com>
|
65
|
-
*/
|
66
|
-
|
67
|
-
@JRubyClass(name="Nokogiri::HTML::SAX::ParserContext", parent="Nokogiri::XML::SAX::ParserContext")
|
68
|
-
public class HtmlSaxParserContext extends XmlSaxParserContext {
|
69
|
-
|
70
|
-
public HtmlSaxParserContext(Ruby ruby, RubyClass rubyClass) {
|
71
|
-
super(ruby, rubyClass);
|
72
|
-
}
|
73
|
-
|
74
|
-
@Override
|
75
|
-
protected AbstractSAXParser createParser() throws SAXException {
|
76
|
-
SAXParser parser = new SAXParser();
|
77
|
-
|
78
|
-
try{
|
79
|
-
parser.setProperty(
|
80
|
-
"http://cyberneko.org/html/properties/names/elems", "lower");
|
81
|
-
parser.setProperty(
|
82
|
-
"http://cyberneko.org/html/properties/names/attrs", "lower");
|
83
|
-
return parser;
|
84
|
-
} catch(SAXException ex) {
|
85
|
-
throw new SAXException(
|
86
|
-
"Problem while creating HTML SAX Parser: " + ex.toString());
|
87
|
-
}
|
88
|
-
}
|
89
|
-
|
90
|
-
@JRubyMethod(name="memory", meta=true)
|
91
|
-
public static IRubyObject parse_memory(ThreadContext context,
|
92
|
-
IRubyObject klazz,
|
93
|
-
IRubyObject data,
|
94
|
-
IRubyObject encoding) {
|
95
|
-
HtmlSaxParserContext ctx = (HtmlSaxParserContext) NokogiriService.HTML_SAXPARSER_CONTEXT_ALLOCATOR.allocate(context.getRuntime(), (RubyClass)klazz);
|
96
|
-
ctx.initialize(context.getRuntime());
|
97
|
-
String javaEncoding = findEncoding(context, encoding);
|
98
|
-
if (javaEncoding != null) {
|
99
|
-
String input = applyEncoding(rubyStringToString(data), javaEncoding);
|
100
|
-
ByteArrayInputStream istream = new ByteArrayInputStream(input.getBytes());
|
101
|
-
ctx.setInputSource(istream);
|
102
|
-
ctx.getInputSource().setEncoding(javaEncoding);
|
103
|
-
}
|
104
|
-
return ctx;
|
105
|
-
}
|
106
|
-
|
107
|
-
public static enum EncodingType {
|
108
|
-
NONE(0, "NONE"),
|
109
|
-
UTF_8(1, "UTF-8"),
|
110
|
-
UTF16LE(2, "UTF16LE"),
|
111
|
-
UTF16BE(3, "UTF16BE"),
|
112
|
-
UCS4LE(4, "UCS4LE"),
|
113
|
-
UCS4BE(5, "UCS4BE"),
|
114
|
-
EBCDIC(6, "EBCDIC"),
|
115
|
-
UCS4_2143(7, "ICS4-2143"),
|
116
|
-
UCS4_3412(8, "UCS4-3412"),
|
117
|
-
UCS2(9, "UCS2"),
|
118
|
-
ISO_8859_1(10, "ISO-8859-1"),
|
119
|
-
ISO_8859_2(11, "ISO-8859-2"),
|
120
|
-
ISO_8859_3(12, "ISO-8859-3"),
|
121
|
-
ISO_8859_4(13, "ISO-8859-4"),
|
122
|
-
ISO_8859_5(14, "ISO-8859-5"),
|
123
|
-
ISO_8859_6(15, "ISO-8859-6"),
|
124
|
-
ISO_8859_7(16, "ISO-8859-7"),
|
125
|
-
ISO_8859_8(17, "ISO-8859-8"),
|
126
|
-
ISO_8859_9(18, "ISO-8859-9"),
|
127
|
-
ISO_2022_JP(19, "ISO-2022-JP"),
|
128
|
-
SHIFT_JIS(20, "SHIFT-JIS"),
|
129
|
-
EUC_JP(21, "EUC-JP"),
|
130
|
-
ASCII(22, "ASCII");
|
131
|
-
|
132
|
-
private final int value;
|
133
|
-
private final String name;
|
134
|
-
EncodingType(int value, String name) {
|
135
|
-
this.value = value;
|
136
|
-
this.name = name;
|
137
|
-
}
|
138
|
-
|
139
|
-
public int getValue() {
|
140
|
-
return value;
|
141
|
-
}
|
142
|
-
|
143
|
-
public String toString() {
|
144
|
-
return name;
|
145
|
-
}
|
146
|
-
}
|
147
|
-
|
148
|
-
private static String findName(int value) {
|
149
|
-
EnumSet<EncodingType> set = EnumSet.allOf(EncodingType.class);
|
150
|
-
for (EncodingType type : set) {
|
151
|
-
if (type.getValue() == value) return type.toString();
|
152
|
-
}
|
153
|
-
return null;
|
154
|
-
}
|
155
|
-
|
156
|
-
private static String findEncoding(ThreadContext context, IRubyObject encoding) {
|
157
|
-
String rubyEncoding = null;
|
158
|
-
if (encoding instanceof RubyString) {
|
159
|
-
rubyEncoding = rubyStringToString(encoding);
|
160
|
-
} else if (encoding instanceof RubyFixnum) {
|
161
|
-
int value = (Integer)encoding.toJava(Integer.class);
|
162
|
-
rubyEncoding = findName(value);
|
163
|
-
}
|
164
|
-
if (rubyEncoding == null) return null;
|
165
|
-
try {
|
166
|
-
Charset charset = Charset.forName(rubyEncoding);
|
167
|
-
return charset.displayName();
|
168
|
-
} catch (IllegalCharsetNameException e) {
|
169
|
-
throw context.getRuntime().newEncodingCompatibilityError(
|
170
|
-
rubyEncoding + "is not supported in Java.");
|
171
|
-
} catch (IllegalArgumentException e) {
|
172
|
-
throw context.getRuntime().newInvalidEncoding(
|
173
|
-
"encoding should not be nil");
|
174
|
-
}
|
175
|
-
}
|
176
|
-
|
177
|
-
private static String applyEncoding(String input, String enc) {
|
178
|
-
String str = input.toLowerCase();
|
179
|
-
int start_pos = 0;
|
180
|
-
int end_pos = 0;
|
181
|
-
if (input.contains("meta") && input.contains("charset")) {
|
182
|
-
Pattern p = Pattern.compile("charset(()|\\s)=(()|\\s)([a-z]|-|_|\\d)+");
|
183
|
-
Matcher m = p.matcher(str);
|
184
|
-
while (m.find()) {
|
185
|
-
start_pos = m.start();
|
186
|
-
end_pos = m.end();
|
187
|
-
}
|
188
|
-
}
|
189
|
-
if (start_pos != end_pos) {
|
190
|
-
String substr = input.substring(start_pos, end_pos);
|
191
|
-
input = input.replace(substr, "charset=" + enc);
|
192
|
-
}
|
193
|
-
return input;
|
194
|
-
}
|
195
|
-
|
196
|
-
@JRubyMethod(name="file", meta=true)
|
197
|
-
public static IRubyObject parse_file(ThreadContext context,
|
198
|
-
IRubyObject klazz,
|
199
|
-
IRubyObject data,
|
200
|
-
IRubyObject encoding) {
|
201
|
-
HtmlSaxParserContext ctx = (HtmlSaxParserContext) NokogiriService.HTML_SAXPARSER_CONTEXT_ALLOCATOR.allocate(context.getRuntime(), (RubyClass)klazz);
|
202
|
-
ctx.initialize(context.getRuntime());
|
203
|
-
ctx.setInputSourceFile(context, data);
|
204
|
-
String javaEncoding = findEncoding(context, encoding);
|
205
|
-
if (javaEncoding != null) {
|
206
|
-
ctx.getInputSource().setEncoding(javaEncoding);
|
207
|
-
}
|
208
|
-
return ctx;
|
209
|
-
}
|
210
|
-
|
211
|
-
@JRubyMethod(name="io", meta=true)
|
212
|
-
public static IRubyObject parse_io(ThreadContext context,
|
213
|
-
IRubyObject klazz,
|
214
|
-
IRubyObject data,
|
215
|
-
IRubyObject encoding) {
|
216
|
-
HtmlSaxParserContext ctx = (HtmlSaxParserContext) NokogiriService.HTML_SAXPARSER_CONTEXT_ALLOCATOR.allocate(context.getRuntime(), (RubyClass)klazz);
|
217
|
-
ctx.initialize(context.getRuntime());
|
218
|
-
ctx.setInputSource(context, data);
|
219
|
-
String javaEncoding = findEncoding(context, encoding);
|
220
|
-
if (javaEncoding != null) {
|
221
|
-
ctx.getInputSource().setEncoding(javaEncoding);
|
222
|
-
}
|
223
|
-
return ctx;
|
224
|
-
}
|
225
|
-
|
226
|
-
/**
|
227
|
-
* Create a new parser context that will read from a raw input
|
228
|
-
* stream. Not a JRuby method. Meant to be run in a separate
|
229
|
-
* thread by XmlSaxPushParser.
|
230
|
-
*/
|
231
|
-
public static IRubyObject parse_stream(ThreadContext context,
|
232
|
-
IRubyObject klazz,
|
233
|
-
InputStream stream) {
|
234
|
-
HtmlSaxParserContext ctx = (HtmlSaxParserContext) NokogiriService.HTML_SAXPARSER_CONTEXT_ALLOCATOR.allocate(context.getRuntime(), (RubyClass)klazz);
|
235
|
-
ctx.initialize(context.getRuntime());
|
236
|
-
ctx.setInputSource(stream);
|
237
|
-
return ctx;
|
238
|
-
}
|
239
|
-
|
240
|
-
@Override
|
241
|
-
protected void preParse(ThreadContext context,
|
242
|
-
IRubyObject handlerRuby,
|
243
|
-
NokogiriHandler handler) {
|
244
|
-
// final String path = "Nokogiri::XML::FragmentHandler";
|
245
|
-
// final String docFrag =
|
246
|
-
// "http://cyberneko.org/html/features/balance-tags/document-fragment";
|
247
|
-
// RubyObjectAdapter adapter = JavaEmbedUtils.newObjectAdapter();
|
248
|
-
// IRubyObject doc = adapter.getInstanceVariable(handlerRuby, "@document");
|
249
|
-
// RubyModule mod =
|
250
|
-
// context.getRuntime().getClassFromPath(path);
|
251
|
-
// try {
|
252
|
-
// if (doc != null && !doc.isNil() && adapter.isKindOf(doc, mod))
|
253
|
-
// parser.setFeature(docFrag, true);
|
254
|
-
// } catch (Exception e) {
|
255
|
-
// // ignore
|
256
|
-
// }
|
257
|
-
}
|
258
|
-
|
259
|
-
}
|
@@ -1,535 +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.Collections;
|
36
|
-
import java.util.HashMap;
|
37
|
-
import java.util.Map;
|
38
|
-
|
39
|
-
import org.jruby.Ruby;
|
40
|
-
import org.jruby.RubyArray;
|
41
|
-
import org.jruby.RubyClass;
|
42
|
-
import org.jruby.RubyFixnum;
|
43
|
-
import org.jruby.RubyModule;
|
44
|
-
import org.jruby.runtime.ObjectAllocator;
|
45
|
-
import org.jruby.runtime.builtin.IRubyObject;
|
46
|
-
import org.jruby.runtime.load.BasicLibraryService;
|
47
|
-
|
48
|
-
/**
|
49
|
-
* Class to provide Nokogiri. This class is used to make "require 'nokogiri'" work
|
50
|
-
* in JRuby. Also, this class holds a Ruby type cache and allocators of Ruby types.
|
51
|
-
*
|
52
|
-
* @author headius
|
53
|
-
* @author Yoko Harada <yokolet@gmail.com>
|
54
|
-
*/
|
55
|
-
public class NokogiriService implements BasicLibraryService {
|
56
|
-
public static final String nokogiriClassCacheGvarName = "$NOKOGIRI_CLASS_CACHE";
|
57
|
-
public static Map<String, RubyClass> nokogiriClassCache;
|
58
|
-
|
59
|
-
public boolean basicLoad(Ruby ruby) {
|
60
|
-
init(ruby);
|
61
|
-
createNokogiriClassCahce(ruby);
|
62
|
-
return true;
|
63
|
-
}
|
64
|
-
|
65
|
-
private static void createNokogiriClassCahce(Ruby ruby) {
|
66
|
-
nokogiriClassCache = Collections.synchronizedMap(new HashMap<String, RubyClass>());
|
67
|
-
nokogiriClassCache.put("Nokogiri::EncodingHandler", (RubyClass)ruby.getClassFromPath("Nokogiri::EncodingHandler"));
|
68
|
-
nokogiriClassCache.put("Nokogiri::HTML::Document", (RubyClass)ruby.getClassFromPath("Nokogiri::HTML::Document"));
|
69
|
-
nokogiriClassCache.put("Nokogiri::HTML::ElementDescription", (RubyClass)ruby.getClassFromPath("Nokogiri::HTML::ElementDescription"));
|
70
|
-
nokogiriClassCache.put("Nokogiri::XML::Attr", (RubyClass)ruby.getClassFromPath("Nokogiri::XML::Attr"));
|
71
|
-
nokogiriClassCache.put("Nokogiri::XML::Document", (RubyClass)ruby.getClassFromPath("Nokogiri::XML::Document"));
|
72
|
-
nokogiriClassCache.put("Nokogiri::XML::DocumentFragment", (RubyClass)ruby.getClassFromPath("Nokogiri::XML::DocumentFragment"));
|
73
|
-
nokogiriClassCache.put("Nokogiri::XML::DTD", (RubyClass)ruby.getClassFromPath("Nokogiri::XML::DTD"));
|
74
|
-
nokogiriClassCache.put("Nokogiri::XML::Text", (RubyClass)ruby.getClassFromPath("Nokogiri::XML::Text"));
|
75
|
-
nokogiriClassCache.put("Nokogiri::XML::Comment", (RubyClass)ruby.getClassFromPath("Nokogiri::XML::Comment"));
|
76
|
-
nokogiriClassCache.put("Nokogiri::XML::Element", (RubyClass)ruby.getClassFromPath("Nokogiri::XML::Element"));
|
77
|
-
nokogiriClassCache.put("Nokogiri::XML::ElementContent", (RubyClass)ruby.getClassFromPath("Nokogiri::XML::ElementContent"));
|
78
|
-
nokogiriClassCache.put("Nokogiri::XML::ElementDecl", (RubyClass)ruby.getClassFromPath("Nokogiri::XML::ElementDecl"));
|
79
|
-
nokogiriClassCache.put("Nokogiri::XML::EntityDecl", (RubyClass)ruby.getClassFromPath("Nokogiri::XML::EntityDecl"));
|
80
|
-
nokogiriClassCache.put("Nokogiri::XML::CDATA", (RubyClass)ruby.getClassFromPath("Nokogiri::XML::CDATA"));
|
81
|
-
nokogiriClassCache.put("Nokogiri::XML::Node", (RubyClass)ruby.getClassFromPath("Nokogiri::XML::Node"));
|
82
|
-
nokogiriClassCache.put("Nokogiri::XML::NodeSet", (RubyClass)ruby.getClassFromPath("Nokogiri::XML::NodeSet"));
|
83
|
-
nokogiriClassCache.put("Nokogiri::XML::Namespace", (RubyClass)ruby.getClassFromPath("Nokogiri::XML::Namespace"));
|
84
|
-
nokogiriClassCache.put("Nokogiri::XML::SyntaxError", (RubyClass)ruby.getClassFromPath("Nokogiri::XML::SyntaxError"));
|
85
|
-
nokogiriClassCache.put("Nokogiri::XML::RelaxNG", (RubyClass)ruby.getClassFromPath("Nokogiri::XML::RelaxNG"));
|
86
|
-
nokogiriClassCache.put("Nokogiri::XML::Schema", (RubyClass)ruby.getClassFromPath("Nokogiri::XML::Schema"));
|
87
|
-
nokogiriClassCache.put("Nokogiri::XML::AttributeDecl", (RubyClass)ruby.getClassFromPath("Nokogiri::XML::AttributeDecl"));
|
88
|
-
nokogiriClassCache.put("Nokogiri::XML::SAX::ParserContext", (RubyClass)ruby.getClassFromPath("Nokogiri::XML::SAX::ParserContext"));
|
89
|
-
}
|
90
|
-
|
91
|
-
private void init(Ruby ruby) {
|
92
|
-
RubyModule nokogiri = ruby.defineModule("Nokogiri");
|
93
|
-
RubyModule xmlModule = nokogiri.defineModuleUnder("XML");
|
94
|
-
RubyModule xmlSaxModule = xmlModule.defineModuleUnder("SAX");
|
95
|
-
RubyModule htmlModule = nokogiri.defineModuleUnder("HTML");
|
96
|
-
RubyModule htmlSaxModule = htmlModule.defineModuleUnder("SAX");
|
97
|
-
RubyModule xsltModule = nokogiri.defineModuleUnder("XSLT");
|
98
|
-
|
99
|
-
createNokogiriModule(ruby, nokogiri);
|
100
|
-
createSyntaxErrors(ruby, nokogiri, xmlModule);
|
101
|
-
RubyClass xmlNode = createXmlModule(ruby, xmlModule);
|
102
|
-
createHtmlModule(ruby, htmlModule);
|
103
|
-
createDocuments(ruby, xmlModule, htmlModule, xmlNode);
|
104
|
-
createSaxModule(ruby, xmlSaxModule, htmlSaxModule);
|
105
|
-
createXsltModule(ruby, xsltModule);
|
106
|
-
}
|
107
|
-
|
108
|
-
private void createNokogiriModule(Ruby ruby, RubyModule nokogiri) {;
|
109
|
-
RubyClass encHandler = nokogiri.defineClassUnder("EncodingHandler", ruby.getObject(), ENCODING_HANDLER_ALLOCATOR);
|
110
|
-
encHandler.defineAnnotatedMethods(EncodingHandler.class);
|
111
|
-
}
|
112
|
-
|
113
|
-
private void createSyntaxErrors(Ruby ruby, RubyModule nokogiri, RubyModule xmlModule) {
|
114
|
-
RubyClass syntaxError = nokogiri.defineClassUnder("SyntaxError", ruby.getStandardError(), ruby.getStandardError().getAllocator());
|
115
|
-
RubyClass xmlSyntaxError = xmlModule.defineClassUnder("SyntaxError", syntaxError, XML_SYNTAXERROR_ALLOCATOR);
|
116
|
-
xmlSyntaxError.defineAnnotatedMethods(XmlSyntaxError.class);
|
117
|
-
}
|
118
|
-
|
119
|
-
private RubyClass createXmlModule(Ruby ruby, RubyModule xmlModule) {
|
120
|
-
RubyClass node = xmlModule.defineClassUnder("Node", ruby.getObject(), XML_NODE_ALLOCATOR);
|
121
|
-
node.defineAnnotatedMethods(XmlNode.class);
|
122
|
-
|
123
|
-
RubyClass attr = xmlModule.defineClassUnder("Attr", node, XML_ATTR_ALLOCATOR);
|
124
|
-
attr.defineAnnotatedMethods(XmlAttr.class);
|
125
|
-
|
126
|
-
RubyClass attrDecl = xmlModule.defineClassUnder("AttributeDecl", node, XML_ATTRIBUTE_DECL_ALLOCATOR);
|
127
|
-
attrDecl.defineAnnotatedMethods(XmlAttributeDecl.class);
|
128
|
-
|
129
|
-
RubyClass characterData = xmlModule.defineClassUnder("CharacterData", node, null);
|
130
|
-
|
131
|
-
RubyClass comment = xmlModule.defineClassUnder("Comment", characterData, XML_COMMENT_ALLOCATOR);
|
132
|
-
comment.defineAnnotatedMethods(XmlComment.class);
|
133
|
-
|
134
|
-
RubyClass text = xmlModule.defineClassUnder("Text", characterData, XML_TEXT_ALLOCATOR);
|
135
|
-
text.defineAnnotatedMethods(XmlText.class);
|
136
|
-
|
137
|
-
RubyModule cdata = xmlModule.defineClassUnder("CDATA", text, XML_CDATA_ALLOCATOR);
|
138
|
-
cdata.defineAnnotatedMethods(XmlCdata.class);
|
139
|
-
|
140
|
-
RubyClass dtd = xmlModule.defineClassUnder("DTD", node, XML_DTD_ALLOCATOR);
|
141
|
-
dtd.defineAnnotatedMethods(XmlDtd.class);
|
142
|
-
|
143
|
-
RubyClass documentFragment = xmlModule.defineClassUnder("DocumentFragment", node, XML_DOCUMENT_FRAGMENT_ALLOCATOR);
|
144
|
-
documentFragment.defineAnnotatedMethods(XmlDocumentFragment.class);
|
145
|
-
|
146
|
-
RubyClass element = xmlModule.defineClassUnder("Element", node, XML_ELEMENT_ALLOCATOR);
|
147
|
-
element.defineAnnotatedMethods(XmlElement.class);
|
148
|
-
|
149
|
-
RubyClass elementContent = xmlModule.defineClassUnder("ElementContent", ruby.getObject(), XML_ELEMENT_CONTENT_ALLOCATOR);
|
150
|
-
elementContent.defineAnnotatedMethods(XmlElementContent.class);
|
151
|
-
|
152
|
-
RubyClass elementDecl = xmlModule.defineClassUnder("ElementDecl", node, XML_ELEMENT_DECL_ALLOCATOR);
|
153
|
-
elementDecl.defineAnnotatedMethods(XmlElementDecl.class);
|
154
|
-
|
155
|
-
RubyClass entityDecl = xmlModule.defineClassUnder("EntityDecl", node, XML_ENTITY_DECL_ALLOCATOR);
|
156
|
-
entityDecl.defineAnnotatedMethods(XmlEntityDecl.class);
|
157
|
-
entityDecl.defineConstant("INTERNAL_GENERAL", RubyFixnum.newFixnum(ruby, XmlEntityDecl.INTERNAL_GENERAL));
|
158
|
-
entityDecl.defineConstant("EXTERNAL_GENERAL_PARSED", RubyFixnum.newFixnum(ruby, XmlEntityDecl.EXTERNAL_GENERAL_PARSED));
|
159
|
-
entityDecl.defineConstant("EXTERNAL_GENERAL_UNPARSED", RubyFixnum.newFixnum(ruby, XmlEntityDecl.EXTERNAL_GENERAL_UNPARSED));
|
160
|
-
entityDecl.defineConstant("INTERNAL_PARAMETER", RubyFixnum.newFixnum(ruby, XmlEntityDecl.INTERNAL_PARAMETER));
|
161
|
-
entityDecl.defineConstant("EXTERNAL_PARAMETER", RubyFixnum.newFixnum(ruby, XmlEntityDecl.EXTERNAL_PARAMETER));
|
162
|
-
entityDecl.defineConstant("INTERNAL_PREDEFINED", RubyFixnum.newFixnum(ruby, XmlEntityDecl.INTERNAL_PREDEFINED));
|
163
|
-
|
164
|
-
RubyClass entref = xmlModule.defineClassUnder("EntityReference", node, XML_ENTITY_REFERENCE_ALLOCATOR);
|
165
|
-
entref.defineAnnotatedMethods(XmlEntityReference.class);
|
166
|
-
|
167
|
-
RubyClass namespace = xmlModule.defineClassUnder("Namespace", ruby.getObject(), XML_NAMESPACE_ALLOCATOR);
|
168
|
-
namespace.defineAnnotatedMethods(XmlNamespace.class);
|
169
|
-
|
170
|
-
RubyClass nodeSet = xmlModule.defineClassUnder("NodeSet", ruby.getObject(), XML_NODESET_ALLOCATOR);
|
171
|
-
nodeSet.defineAnnotatedMethods(XmlNodeSet.class);
|
172
|
-
|
173
|
-
RubyClass pi = xmlModule.defineClassUnder("ProcessingInstruction", node, XML_PROCESSING_INSTRUCTION_ALLOCATOR);
|
174
|
-
pi.defineAnnotatedMethods(XmlProcessingInstruction.class);
|
175
|
-
|
176
|
-
RubyClass reader = xmlModule.defineClassUnder("Reader", ruby.getObject(), XML_READER_ALLOCATOR);
|
177
|
-
reader.defineAnnotatedMethods(XmlReader.class);
|
178
|
-
|
179
|
-
RubyClass schema = xmlModule.defineClassUnder("Schema", ruby.getObject(), XML_SCHEMA_ALLOCATOR);
|
180
|
-
schema.defineAnnotatedMethods(XmlSchema.class);
|
181
|
-
|
182
|
-
RubyClass relaxng = xmlModule.defineClassUnder("RelaxNG", schema, XML_RELAXNG_ALLOCATOR);
|
183
|
-
relaxng.defineAnnotatedMethods(XmlRelaxng.class);
|
184
|
-
|
185
|
-
RubyClass xpathContext = xmlModule.defineClassUnder("XPathContext", ruby.getObject(), XML_XPATHCONTEXT_ALLOCATOR);
|
186
|
-
xpathContext.defineAnnotatedMethods(XmlXpathContext.class);
|
187
|
-
|
188
|
-
return node;
|
189
|
-
}
|
190
|
-
|
191
|
-
private void createHtmlModule(Ruby ruby, RubyModule htmlModule) {
|
192
|
-
RubyClass htmlElemDesc = htmlModule.defineClassUnder("ElementDescription", ruby.getObject(), HTML_ELEMENT_DESCRIPTION_ALLOCATOR);
|
193
|
-
htmlElemDesc.defineAnnotatedMethods(HtmlElementDescription.class);
|
194
|
-
|
195
|
-
RubyClass htmlEntityLookup = htmlModule.defineClassUnder("EntityLookup", ruby.getObject(), HTML_ENTITY_LOOKUP_ALLOCATOR);
|
196
|
-
htmlEntityLookup.defineAnnotatedMethods(HtmlEntityLookup.class);
|
197
|
-
}
|
198
|
-
|
199
|
-
private void createDocuments(Ruby ruby, RubyModule xmlModule, RubyModule htmlModule, RubyClass node) {
|
200
|
-
RubyClass xmlDocument = xmlModule.defineClassUnder("Document", node, XML_DOCUMENT_ALLOCATOR);
|
201
|
-
xmlDocument.defineAnnotatedMethods(XmlDocument.class);
|
202
|
-
|
203
|
-
//RubyModule htmlDoc = html.defineOrGetClassUnder("Document", document);
|
204
|
-
RubyModule htmlDocument = htmlModule.defineClassUnder("Document", xmlDocument, HTML_DOCUMENT_ALLOCATOR);
|
205
|
-
htmlDocument.defineAnnotatedMethods(HtmlDocument.class);
|
206
|
-
}
|
207
|
-
|
208
|
-
private void createSaxModule(Ruby ruby, RubyModule xmlSaxModule, RubyModule htmlSaxModule) {
|
209
|
-
RubyClass xmlSaxParserContext = xmlSaxModule.defineClassUnder("ParserContext", ruby.getObject(), XML_SAXPARSER_CONTEXT_ALLOCATOR);
|
210
|
-
xmlSaxParserContext.defineAnnotatedMethods(XmlSaxParserContext.class);
|
211
|
-
|
212
|
-
RubyClass xmlSaxPushParser = xmlSaxModule.defineClassUnder("PushParser", ruby.getObject(), XML_SAXPUSHPARSER_ALLOCATOR);
|
213
|
-
xmlSaxPushParser.defineAnnotatedMethods(XmlSaxPushParser.class);
|
214
|
-
|
215
|
-
RubyClass htmlSaxParserContext = htmlSaxModule.defineClassUnder("ParserContext", xmlSaxParserContext, HTML_SAXPARSER_CONTEXT_ALLOCATOR);
|
216
|
-
htmlSaxParserContext.defineAnnotatedMethods(HtmlSaxParserContext.class);
|
217
|
-
}
|
218
|
-
|
219
|
-
private void createXsltModule(Ruby ruby, RubyModule xsltModule) {
|
220
|
-
RubyClass stylesheet = xsltModule.defineClassUnder("Stylesheet", ruby.getObject(), XSLT_STYLESHEET_ALLOCATOR);
|
221
|
-
stylesheet.defineAnnotatedMethods(XsltStylesheet.class);
|
222
|
-
xsltModule.defineAnnotatedMethod(XsltStylesheet.class, "register");
|
223
|
-
}
|
224
|
-
|
225
|
-
private static ObjectAllocator ENCODING_HANDLER_ALLOCATOR = new ObjectAllocator() {
|
226
|
-
public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
|
227
|
-
return new EncodingHandler(runtime, klazz, "");
|
228
|
-
}
|
229
|
-
};
|
230
|
-
|
231
|
-
public static final ObjectAllocator HTML_DOCUMENT_ALLOCATOR = new ObjectAllocator() {
|
232
|
-
private HtmlDocument htmlDocument = null;
|
233
|
-
public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
|
234
|
-
if (htmlDocument == null) htmlDocument = new HtmlDocument(runtime, klazz);
|
235
|
-
try {
|
236
|
-
HtmlDocument clone = (HtmlDocument) htmlDocument.clone();
|
237
|
-
clone.setMetaClass(klazz);
|
238
|
-
return clone;
|
239
|
-
} catch (CloneNotSupportedException e) {
|
240
|
-
return new HtmlDocument(runtime, klazz);
|
241
|
-
}
|
242
|
-
}
|
243
|
-
};
|
244
|
-
|
245
|
-
public static final ObjectAllocator HTML_SAXPARSER_CONTEXT_ALLOCATOR = new ObjectAllocator() {
|
246
|
-
private HtmlSaxParserContext htmlSaxParserContext = null;
|
247
|
-
public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
|
248
|
-
if (htmlSaxParserContext == null) htmlSaxParserContext = new HtmlSaxParserContext(runtime, klazz);
|
249
|
-
try {
|
250
|
-
HtmlSaxParserContext clone = (HtmlSaxParserContext) htmlSaxParserContext.clone();
|
251
|
-
clone.setMetaClass(klazz);
|
252
|
-
return clone;
|
253
|
-
} catch (CloneNotSupportedException e) {
|
254
|
-
return new HtmlSaxParserContext(runtime, klazz);
|
255
|
-
}
|
256
|
-
}
|
257
|
-
};
|
258
|
-
|
259
|
-
private static ObjectAllocator HTML_ELEMENT_DESCRIPTION_ALLOCATOR =
|
260
|
-
new ObjectAllocator() {
|
261
|
-
public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
|
262
|
-
return new HtmlElementDescription(runtime, klazz);
|
263
|
-
}
|
264
|
-
};
|
265
|
-
|
266
|
-
private static ObjectAllocator HTML_ENTITY_LOOKUP_ALLOCATOR =
|
267
|
-
new ObjectAllocator() {
|
268
|
-
public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
|
269
|
-
return new HtmlEntityLookup(runtime, klazz);
|
270
|
-
}
|
271
|
-
};
|
272
|
-
|
273
|
-
public static final ObjectAllocator XML_ATTR_ALLOCATOR = new ObjectAllocator() {
|
274
|
-
private XmlAttr xmlAttr = null;
|
275
|
-
public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
|
276
|
-
if (xmlAttr == null) xmlAttr = new XmlAttr(runtime, klazz);
|
277
|
-
try {
|
278
|
-
XmlAttr clone = (XmlAttr) xmlAttr.clone();
|
279
|
-
clone.setMetaClass(klazz);
|
280
|
-
return clone;
|
281
|
-
} catch (CloneNotSupportedException e) {
|
282
|
-
return new XmlAttr(runtime, klazz);
|
283
|
-
}
|
284
|
-
}
|
285
|
-
};
|
286
|
-
|
287
|
-
public static final ObjectAllocator XML_CDATA_ALLOCATOR = new ObjectAllocator() {
|
288
|
-
private XmlCdata xmlCdata = null;
|
289
|
-
public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
|
290
|
-
if (xmlCdata == null) xmlCdata = new XmlCdata(runtime, klazz);
|
291
|
-
try {
|
292
|
-
XmlCdata clone = (XmlCdata) xmlCdata.clone();
|
293
|
-
clone.setMetaClass(klazz);
|
294
|
-
return clone;
|
295
|
-
} catch (CloneNotSupportedException e) {
|
296
|
-
return new XmlCdata(runtime, klazz);
|
297
|
-
}
|
298
|
-
}
|
299
|
-
};
|
300
|
-
|
301
|
-
public static final ObjectAllocator XML_COMMENT_ALLOCATOR = new ObjectAllocator() {
|
302
|
-
private XmlComment xmlComment = null;
|
303
|
-
public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
|
304
|
-
if (xmlComment == null) xmlComment = new XmlComment(runtime, klazz);
|
305
|
-
try {
|
306
|
-
XmlComment clone = (XmlComment) xmlComment.clone();
|
307
|
-
clone.setMetaClass(klazz);
|
308
|
-
return clone;
|
309
|
-
} catch (CloneNotSupportedException e) {
|
310
|
-
return new XmlComment(runtime, klazz);
|
311
|
-
}
|
312
|
-
}
|
313
|
-
};
|
314
|
-
|
315
|
-
private static ObjectAllocator XML_PROCESSING_INSTRUCTION_ALLOCATOR =
|
316
|
-
new ObjectAllocator() {
|
317
|
-
public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
|
318
|
-
throw runtime.newNotImplementedError("not implemented");
|
319
|
-
}
|
320
|
-
};
|
321
|
-
|
322
|
-
public static final ObjectAllocator XML_DOCUMENT_ALLOCATOR = new ObjectAllocator() {
|
323
|
-
private XmlDocument xmlDocument = null;
|
324
|
-
public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
|
325
|
-
if (xmlDocument == null) xmlDocument = new XmlDocument(runtime, klazz);
|
326
|
-
try {
|
327
|
-
XmlDocument clone = (XmlDocument) xmlDocument.clone();
|
328
|
-
clone.setMetaClass(klazz);
|
329
|
-
return clone;
|
330
|
-
} catch (CloneNotSupportedException e) {
|
331
|
-
return new XmlDocument(runtime, klazz);
|
332
|
-
}
|
333
|
-
}
|
334
|
-
};
|
335
|
-
|
336
|
-
public static final ObjectAllocator XML_DOCUMENT_FRAGMENT_ALLOCATOR = new ObjectAllocator() {
|
337
|
-
private XmlDocumentFragment xmlDocumentFragment = null;
|
338
|
-
public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
|
339
|
-
if (xmlDocumentFragment == null) xmlDocumentFragment = new XmlDocumentFragment(runtime, klazz);
|
340
|
-
try {
|
341
|
-
XmlDocumentFragment clone = (XmlDocumentFragment)xmlDocumentFragment.clone();
|
342
|
-
clone.setMetaClass(klazz);
|
343
|
-
return clone;
|
344
|
-
} catch (CloneNotSupportedException e) {
|
345
|
-
return new XmlDocumentFragment(runtime, klazz);
|
346
|
-
}
|
347
|
-
}
|
348
|
-
};
|
349
|
-
|
350
|
-
private static ObjectAllocator XML_DTD_ALLOCATOR = new ObjectAllocator() {
|
351
|
-
public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
|
352
|
-
return new XmlDtd(runtime, klazz);
|
353
|
-
}
|
354
|
-
};
|
355
|
-
|
356
|
-
public static final ObjectAllocator XML_ELEMENT_ALLOCATOR = new ObjectAllocator() {
|
357
|
-
private XmlElement xmlElement = null;
|
358
|
-
public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
|
359
|
-
if (xmlElement == null) xmlElement = new XmlElement(runtime, klazz);
|
360
|
-
try {
|
361
|
-
XmlElement clone = (XmlElement)xmlElement.clone();
|
362
|
-
clone.setMetaClass(klazz);
|
363
|
-
return clone;
|
364
|
-
} catch (CloneNotSupportedException e) {
|
365
|
-
return new XmlElement(runtime, klazz);
|
366
|
-
}
|
367
|
-
}
|
368
|
-
};
|
369
|
-
|
370
|
-
private static ObjectAllocator XML_ENTITY_REFERENCE_ALLOCATOR = new ObjectAllocator() {
|
371
|
-
public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
|
372
|
-
return new XmlEntityReference(runtime, klazz);
|
373
|
-
}
|
374
|
-
};
|
375
|
-
|
376
|
-
public static final ObjectAllocator XML_NAMESPACE_ALLOCATOR = new ObjectAllocator() {
|
377
|
-
private XmlNamespace xmlNamespace = null;
|
378
|
-
public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
|
379
|
-
if (xmlNamespace == null) xmlNamespace = new XmlNamespace(runtime, klazz);
|
380
|
-
try {
|
381
|
-
XmlNamespace clone = (XmlNamespace) xmlNamespace.clone();
|
382
|
-
clone.setMetaClass(klazz);
|
383
|
-
return clone;
|
384
|
-
} catch (CloneNotSupportedException e) {
|
385
|
-
return new XmlNamespace(runtime, klazz);
|
386
|
-
}
|
387
|
-
}
|
388
|
-
};
|
389
|
-
|
390
|
-
public static final ObjectAllocator XML_NODE_ALLOCATOR = new ObjectAllocator() {
|
391
|
-
private XmlNode xmlNode = null;
|
392
|
-
public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
|
393
|
-
if (xmlNode == null) xmlNode = new XmlNode(runtime, klazz);
|
394
|
-
try {
|
395
|
-
XmlNode clone = (XmlNode) xmlNode.clone();
|
396
|
-
clone.setMetaClass(klazz);
|
397
|
-
return clone;
|
398
|
-
} catch (CloneNotSupportedException e) {
|
399
|
-
return new XmlNode(runtime, klazz);
|
400
|
-
}
|
401
|
-
}
|
402
|
-
};
|
403
|
-
|
404
|
-
public static final ObjectAllocator XML_NODESET_ALLOCATOR = new ObjectAllocator() {
|
405
|
-
private XmlNodeSet xmlNodeSet = null;
|
406
|
-
public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
|
407
|
-
if (xmlNodeSet == null) xmlNodeSet = new XmlNodeSet(runtime, klazz);
|
408
|
-
try {
|
409
|
-
XmlNodeSet clone = (XmlNodeSet) xmlNodeSet.clone();
|
410
|
-
clone.setMetaClass(klazz);
|
411
|
-
return clone;
|
412
|
-
} catch (CloneNotSupportedException e) {
|
413
|
-
return new XmlNodeSet(runtime, klazz, RubyArray.newEmptyArray(runtime));
|
414
|
-
}
|
415
|
-
}
|
416
|
-
};
|
417
|
-
|
418
|
-
private static ObjectAllocator XML_READER_ALLOCATOR = new ObjectAllocator() {
|
419
|
-
public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
|
420
|
-
return new XmlReader(runtime, klazz);
|
421
|
-
}
|
422
|
-
};
|
423
|
-
|
424
|
-
private static ObjectAllocator XML_ATTRIBUTE_DECL_ALLOCATOR = new ObjectAllocator() {
|
425
|
-
public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
|
426
|
-
return new XmlAttributeDecl(runtime, klazz);
|
427
|
-
}
|
428
|
-
};
|
429
|
-
|
430
|
-
private static ObjectAllocator XML_ELEMENT_DECL_ALLOCATOR = new ObjectAllocator() {
|
431
|
-
public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
|
432
|
-
return new XmlElementDecl(runtime, klazz);
|
433
|
-
}
|
434
|
-
};
|
435
|
-
|
436
|
-
private static ObjectAllocator XML_ENTITY_DECL_ALLOCATOR = new ObjectAllocator() {
|
437
|
-
public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
|
438
|
-
return new XmlEntityDecl(runtime, klazz);
|
439
|
-
}
|
440
|
-
};
|
441
|
-
|
442
|
-
private static ObjectAllocator XML_ELEMENT_CONTENT_ALLOCATOR = new ObjectAllocator() {
|
443
|
-
public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
|
444
|
-
throw runtime.newNotImplementedError("not implemented");
|
445
|
-
}
|
446
|
-
};
|
447
|
-
|
448
|
-
public static final ObjectAllocator XML_RELAXNG_ALLOCATOR = new ObjectAllocator() {
|
449
|
-
private XmlRelaxng xmlRelaxng = null;
|
450
|
-
public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
|
451
|
-
if (xmlRelaxng == null) xmlRelaxng = new XmlRelaxng(runtime, klazz);
|
452
|
-
try {
|
453
|
-
XmlRelaxng clone = (XmlRelaxng) xmlRelaxng.clone();
|
454
|
-
clone.setMetaClass(klazz);
|
455
|
-
return clone;
|
456
|
-
} catch (CloneNotSupportedException e) {
|
457
|
-
return new XmlRelaxng(runtime, klazz);
|
458
|
-
}
|
459
|
-
}
|
460
|
-
};
|
461
|
-
|
462
|
-
public static final ObjectAllocator XML_SAXPARSER_CONTEXT_ALLOCATOR = new ObjectAllocator() {
|
463
|
-
private XmlSaxParserContext xmlSaxParserContext = null;
|
464
|
-
public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
|
465
|
-
if (xmlSaxParserContext == null) xmlSaxParserContext = new XmlSaxParserContext(runtime, klazz);
|
466
|
-
try {
|
467
|
-
XmlSaxParserContext clone = (XmlSaxParserContext) xmlSaxParserContext.clone();
|
468
|
-
clone.setMetaClass(klazz);
|
469
|
-
return clone;
|
470
|
-
} catch (CloneNotSupportedException e) {
|
471
|
-
return new XmlSaxParserContext(runtime, klazz);
|
472
|
-
}
|
473
|
-
}
|
474
|
-
};
|
475
|
-
|
476
|
-
private static ObjectAllocator XML_SAXPUSHPARSER_ALLOCATOR = new ObjectAllocator() {
|
477
|
-
public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
|
478
|
-
return new XmlSaxPushParser(runtime, klazz);
|
479
|
-
}
|
480
|
-
};
|
481
|
-
|
482
|
-
public static final ObjectAllocator XML_SCHEMA_ALLOCATOR = new ObjectAllocator() {
|
483
|
-
private XmlSchema xmlSchema = null;
|
484
|
-
public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
|
485
|
-
if (xmlSchema == null) xmlSchema = new XmlSchema(runtime, klazz);
|
486
|
-
try {
|
487
|
-
XmlSchema clone = (XmlSchema) xmlSchema.clone();
|
488
|
-
clone.setMetaClass(klazz);
|
489
|
-
return clone;
|
490
|
-
} catch (CloneNotSupportedException e) {
|
491
|
-
return new XmlSchema(runtime, klazz);
|
492
|
-
}
|
493
|
-
}
|
494
|
-
};
|
495
|
-
|
496
|
-
public static final ObjectAllocator XML_SYNTAXERROR_ALLOCATOR = new ObjectAllocator() {
|
497
|
-
private XmlSyntaxError xmlSyntaxError = null;
|
498
|
-
public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
|
499
|
-
if (xmlSyntaxError == null) xmlSyntaxError = new XmlSyntaxError(runtime, klazz);
|
500
|
-
try {
|
501
|
-
XmlSyntaxError clone = (XmlSyntaxError) xmlSyntaxError.clone();
|
502
|
-
clone.setMetaClass(klazz);
|
503
|
-
return clone;
|
504
|
-
} catch (CloneNotSupportedException e) {
|
505
|
-
return new XmlSyntaxError(runtime, klazz);
|
506
|
-
}
|
507
|
-
}
|
508
|
-
};
|
509
|
-
|
510
|
-
public static final ObjectAllocator XML_TEXT_ALLOCATOR = new ObjectAllocator() {
|
511
|
-
private XmlText xmlText = null;
|
512
|
-
public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
|
513
|
-
if (xmlText == null) xmlText = new XmlText(runtime, klazz);
|
514
|
-
try {
|
515
|
-
XmlText clone = (XmlText) xmlText.clone();
|
516
|
-
clone.setMetaClass(klazz);
|
517
|
-
return clone;
|
518
|
-
} catch (CloneNotSupportedException e) {
|
519
|
-
return new XmlText(runtime, klazz);
|
520
|
-
}
|
521
|
-
}
|
522
|
-
};
|
523
|
-
|
524
|
-
private static ObjectAllocator XML_XPATHCONTEXT_ALLOCATOR = new ObjectAllocator() {
|
525
|
-
public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
|
526
|
-
throw runtime.newNotImplementedError("not implemented");
|
527
|
-
}
|
528
|
-
};
|
529
|
-
|
530
|
-
private static ObjectAllocator XSLT_STYLESHEET_ALLOCATOR = new ObjectAllocator() {
|
531
|
-
public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
|
532
|
-
return new XsltStylesheet(runtime, klazz);
|
533
|
-
}
|
534
|
-
};
|
535
|
-
}
|