nokogiri 1.11.1-java → 1.11.2-java

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of nokogiri might be problematic. Click here for more details.

Files changed (142) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE-DEPENDENCIES.md +12 -12
  3. data/LICENSE.md +1 -1
  4. data/README.md +20 -15
  5. data/ext/java/nokogiri/EncodingHandler.java +78 -59
  6. data/ext/java/nokogiri/HtmlDocument.java +137 -114
  7. data/ext/java/nokogiri/HtmlElementDescription.java +104 -87
  8. data/ext/java/nokogiri/HtmlEntityLookup.java +31 -26
  9. data/ext/java/nokogiri/HtmlSaxParserContext.java +220 -192
  10. data/ext/java/nokogiri/HtmlSaxPushParser.java +164 -139
  11. data/ext/java/nokogiri/NokogiriService.java +597 -526
  12. data/ext/java/nokogiri/XmlAttr.java +120 -96
  13. data/ext/java/nokogiri/XmlAttributeDecl.java +97 -76
  14. data/ext/java/nokogiri/XmlCdata.java +35 -26
  15. data/ext/java/nokogiri/XmlComment.java +48 -37
  16. data/ext/java/nokogiri/XmlDocument.java +642 -540
  17. data/ext/java/nokogiri/XmlDocumentFragment.java +127 -107
  18. data/ext/java/nokogiri/XmlDtd.java +450 -384
  19. data/ext/java/nokogiri/XmlElement.java +25 -18
  20. data/ext/java/nokogiri/XmlElementContent.java +345 -286
  21. data/ext/java/nokogiri/XmlElementDecl.java +126 -95
  22. data/ext/java/nokogiri/XmlEntityDecl.java +121 -97
  23. data/ext/java/nokogiri/XmlEntityReference.java +51 -42
  24. data/ext/java/nokogiri/XmlNamespace.java +177 -145
  25. data/ext/java/nokogiri/XmlNode.java +1843 -1588
  26. data/ext/java/nokogiri/XmlNodeSet.java +361 -299
  27. data/ext/java/nokogiri/XmlProcessingInstruction.java +49 -39
  28. data/ext/java/nokogiri/XmlReader.java +513 -418
  29. data/ext/java/nokogiri/XmlRelaxng.java +91 -78
  30. data/ext/java/nokogiri/XmlSaxParserContext.java +330 -285
  31. data/ext/java/nokogiri/XmlSaxPushParser.java +229 -190
  32. data/ext/java/nokogiri/XmlSchema.java +328 -263
  33. data/ext/java/nokogiri/XmlSyntaxError.java +113 -83
  34. data/ext/java/nokogiri/XmlText.java +57 -46
  35. data/ext/java/nokogiri/XmlXpathContext.java +240 -206
  36. data/ext/java/nokogiri/XsltStylesheet.java +282 -239
  37. data/ext/java/nokogiri/internals/ClosedStreamException.java +5 -2
  38. data/ext/java/nokogiri/internals/HtmlDomParserContext.java +199 -168
  39. data/ext/java/nokogiri/internals/IgnoreSchemaErrorsErrorHandler.java +17 -10
  40. data/ext/java/nokogiri/internals/NokogiriBlockingQueueInputStream.java +43 -16
  41. data/ext/java/nokogiri/internals/NokogiriDomParser.java +65 -50
  42. data/ext/java/nokogiri/internals/NokogiriEntityResolver.java +107 -88
  43. data/ext/java/nokogiri/internals/NokogiriErrorHandler.java +25 -18
  44. data/ext/java/nokogiri/internals/NokogiriHandler.java +316 -254
  45. data/ext/java/nokogiri/internals/NokogiriHelpers.java +738 -622
  46. data/ext/java/nokogiri/internals/NokogiriNamespaceCache.java +186 -143
  47. data/ext/java/nokogiri/internals/NokogiriNamespaceContext.java +83 -68
  48. data/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler.java +66 -49
  49. data/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler4NekoHtml.java +86 -69
  50. data/ext/java/nokogiri/internals/NokogiriStrictErrorHandler.java +44 -29
  51. data/ext/java/nokogiri/internals/NokogiriXPathFunction.java +118 -101
  52. data/ext/java/nokogiri/internals/NokogiriXPathFunctionResolver.java +34 -24
  53. data/ext/java/nokogiri/internals/NokogiriXPathVariableResolver.java +25 -17
  54. data/ext/java/nokogiri/internals/NokogiriXsltErrorListener.java +57 -42
  55. data/ext/java/nokogiri/internals/ParserContext.java +206 -179
  56. data/ext/java/nokogiri/internals/ReaderNode.java +478 -371
  57. data/ext/java/nokogiri/internals/SaveContextVisitor.java +822 -707
  58. data/ext/java/nokogiri/internals/SchemaErrorHandler.java +28 -19
  59. data/ext/java/nokogiri/internals/XalanDTMManagerPatch.java +129 -123
  60. data/ext/java/nokogiri/internals/XmlDeclHandler.java +5 -4
  61. data/ext/java/nokogiri/internals/XmlDomParserContext.java +208 -177
  62. data/ext/java/nokogiri/internals/XmlSaxParser.java +24 -17
  63. data/ext/java/nokogiri/internals/c14n/AttrCompare.java +71 -68
  64. data/ext/java/nokogiri/internals/c14n/C14nHelper.java +137 -118
  65. data/ext/java/nokogiri/internals/c14n/CanonicalFilter.java +27 -21
  66. data/ext/java/nokogiri/internals/c14n/CanonicalizationException.java +74 -61
  67. data/ext/java/nokogiri/internals/c14n/Canonicalizer.java +230 -205
  68. data/ext/java/nokogiri/internals/c14n/Canonicalizer11.java +572 -547
  69. data/ext/java/nokogiri/internals/c14n/Canonicalizer11_OmitComments.java +17 -10
  70. data/ext/java/nokogiri/internals/c14n/Canonicalizer11_WithComments.java +17 -10
  71. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315.java +323 -302
  72. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315Excl.java +232 -219
  73. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315ExclOmitComments.java +22 -15
  74. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315ExclWithComments.java +23 -16
  75. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315OmitComments.java +23 -16
  76. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315WithComments.java +22 -15
  77. data/ext/java/nokogiri/internals/c14n/CanonicalizerBase.java +575 -545
  78. data/ext/java/nokogiri/internals/c14n/CanonicalizerPhysical.java +141 -120
  79. data/ext/java/nokogiri/internals/c14n/CanonicalizerSpi.java +39 -38
  80. data/ext/java/nokogiri/internals/c14n/Constants.java +13 -10
  81. data/ext/java/nokogiri/internals/c14n/ElementProxy.java +279 -247
  82. data/ext/java/nokogiri/internals/c14n/HelperNodeList.java +66 -53
  83. data/ext/java/nokogiri/internals/c14n/IgnoreAllErrorHandler.java +44 -37
  84. data/ext/java/nokogiri/internals/c14n/InclusiveNamespaces.java +135 -120
  85. data/ext/java/nokogiri/internals/c14n/InvalidCanonicalizerException.java +59 -48
  86. data/ext/java/nokogiri/internals/c14n/NameSpaceSymbTable.java +384 -334
  87. data/ext/java/nokogiri/internals/c14n/NodeFilter.java +25 -24
  88. data/ext/java/nokogiri/internals/c14n/UtfHelpper.java +151 -140
  89. data/ext/java/nokogiri/internals/c14n/XMLUtils.java +456 -423
  90. data/ext/java/nokogiri/internals/dom2dtm/DOM2DTM.java +1466 -1500
  91. data/ext/java/nokogiri/internals/dom2dtm/DOM2DTMdefaultNamespaceDeclarationNode.java +626 -570
  92. data/ext/nokogiri/depend +34 -474
  93. data/ext/nokogiri/extconf.rb +253 -183
  94. data/ext/nokogiri/html_document.c +10 -15
  95. data/ext/nokogiri/html_element_description.c +84 -71
  96. data/ext/nokogiri/html_entity_lookup.c +21 -16
  97. data/ext/nokogiri/html_sax_parser_context.c +66 -65
  98. data/ext/nokogiri/html_sax_push_parser.c +29 -27
  99. data/ext/nokogiri/libxml2_backwards_compat.c +121 -0
  100. data/ext/nokogiri/nokogiri.c +171 -63
  101. data/ext/nokogiri/test_global_handlers.c +3 -4
  102. data/ext/nokogiri/xml_attr.c +15 -15
  103. data/ext/nokogiri/xml_attribute_decl.c +18 -18
  104. data/ext/nokogiri/xml_cdata.c +13 -18
  105. data/ext/nokogiri/xml_comment.c +19 -26
  106. data/ext/nokogiri/xml_document.c +221 -164
  107. data/ext/nokogiri/xml_document_fragment.c +13 -15
  108. data/ext/nokogiri/xml_dtd.c +54 -48
  109. data/ext/nokogiri/xml_element_content.c +30 -27
  110. data/ext/nokogiri/xml_element_decl.c +22 -22
  111. data/ext/nokogiri/xml_encoding_handler.c +17 -11
  112. data/ext/nokogiri/xml_entity_decl.c +32 -30
  113. data/ext/nokogiri/xml_entity_reference.c +16 -18
  114. data/ext/nokogiri/xml_namespace.c +56 -49
  115. data/ext/nokogiri/xml_node.c +338 -286
  116. data/ext/nokogiri/xml_node_set.c +168 -156
  117. data/ext/nokogiri/xml_processing_instruction.c +17 -19
  118. data/ext/nokogiri/xml_reader.c +191 -157
  119. data/ext/nokogiri/xml_relax_ng.c +29 -23
  120. data/ext/nokogiri/xml_sax_parser.c +117 -112
  121. data/ext/nokogiri/xml_sax_parser_context.c +100 -85
  122. data/ext/nokogiri/xml_sax_push_parser.c +34 -27
  123. data/ext/nokogiri/xml_schema.c +48 -42
  124. data/ext/nokogiri/xml_syntax_error.c +21 -23
  125. data/ext/nokogiri/xml_text.c +13 -17
  126. data/ext/nokogiri/xml_xpath_context.c +134 -127
  127. data/ext/nokogiri/xslt_stylesheet.c +157 -157
  128. data/lib/nokogiri.rb +1 -22
  129. data/lib/nokogiri/css/parser.rb +1 -1
  130. data/lib/nokogiri/extension.rb +26 -0
  131. data/lib/nokogiri/html/document_fragment.rb +15 -15
  132. data/lib/nokogiri/nokogiri.jar +0 -0
  133. data/lib/nokogiri/version/constant.rb +1 -1
  134. data/lib/nokogiri/version/info.rb +31 -8
  135. data/lib/nokogiri/xml/document.rb +31 -11
  136. data/lib/nokogiri/xml/node.rb +38 -42
  137. data/lib/nokogiri/xml/reader.rb +2 -9
  138. data/lib/nokogiri/xml/xpath.rb +1 -3
  139. data/lib/nokogiri/xml/xpath/syntax_error.rb +1 -1
  140. metadata +7 -8
  141. data/ext/nokogiri/xml_io.c +0 -63
  142. data/ext/nokogiri/xml_libxml2_hacks.c +0 -112
@@ -17,10 +17,10 @@
17
17
  * distribute, sublicense, and/or sell copies of the Software, and to
18
18
  * permit persons to whom the Software is furnished to do so, subject to
19
19
  * the following conditions:
20
- *
20
+ *
21
21
  * The above copyright notice and this permission notice shall be
22
22
  * included in all copies or substantial portions of the Software.
23
- *
23
+ *
24
24
  * THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
25
25
  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26
26
  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
@@ -61,162 +61,187 @@ import org.jruby.runtime.builtin.IRubyObject;
61
61
  /**
62
62
  * Class for Nokogiri::HTML::SAX::PushParser
63
63
  *
64
- * @author
64
+ * @author
65
65
  * @author Piotr Szmielew <p.szmielew@ava.waw.pl> - based on Nokogiri::XML::SAX::PushParser
66
66
  */
67
- @JRubyClass(name="Nokogiri::HTML::SAX::PushParser")
68
- public class HtmlSaxPushParser extends RubyObject {
69
- ParserContext.Options options;
70
- IRubyObject saxParser;
71
-
72
- NokogiriBlockingQueueInputStream stream;
73
-
74
- private ParserTask parserTask = null;
75
- private FutureTask<HtmlSaxParserContext> futureTask = null;
76
- private ExecutorService executor = null;
77
-
78
- public HtmlSaxPushParser(Ruby ruby, RubyClass rubyClass) {
79
- super(ruby, rubyClass);
67
+ @JRubyClass(name = "Nokogiri::HTML::SAX::PushParser")
68
+ public class HtmlSaxPushParser extends RubyObject
69
+ {
70
+ ParserContext.Options options;
71
+ IRubyObject saxParser;
72
+
73
+ NokogiriBlockingQueueInputStream stream;
74
+
75
+ private ParserTask parserTask = null;
76
+ private FutureTask<HtmlSaxParserContext> futureTask = null;
77
+ private ExecutorService executor = null;
78
+
79
+ public
80
+ HtmlSaxPushParser(Ruby ruby, RubyClass rubyClass)
81
+ {
82
+ super(ruby, rubyClass);
83
+ }
84
+
85
+ @Override
86
+ public void
87
+ finalize()
88
+ {
89
+ try {
90
+ terminateImpl();
91
+ } catch (Exception e) { /* ignored */ }
92
+ }
93
+
94
+ @JRubyMethod
95
+ public IRubyObject
96
+ initialize_native(final ThreadContext context,
97
+ IRubyObject saxParser,
98
+ IRubyObject fileName,
99
+ IRubyObject encoding)
100
+ {
101
+ // NOTE: Silently skips provided encoding
102
+ options = new ParserContext.Options(0);
103
+ this.saxParser = saxParser;
104
+ return this;
105
+ }
106
+
107
+ private transient IRubyObject parse_options;
108
+
109
+ private IRubyObject
110
+ parse_options(final ThreadContext context)
111
+ {
112
+ if (parse_options == null) {
113
+ parse_options = invoke(context, context.runtime.getClassFromPath("Nokogiri::XML::ParseOptions"), "new");
80
114
  }
81
-
82
- @Override
83
- public void finalize() {
84
- try {
85
- terminateImpl();
86
- }
87
- catch (Exception e) { /* ignored */ }
115
+ return parse_options;
116
+ }
117
+
118
+ @JRubyMethod(name = "options")
119
+ public IRubyObject
120
+ getOptions(ThreadContext context)
121
+ {
122
+ return invoke(context, parse_options(context), "options");
123
+ }
124
+
125
+ @JRubyMethod(name = "options=")
126
+ public IRubyObject
127
+ setOptions(ThreadContext context, IRubyObject opts)
128
+ {
129
+ invoke(context, parse_options(context), "options=", opts);
130
+ options = new ParserContext.Options(opts.convertToInteger().getLongValue());
131
+ return getOptions(context);
132
+ }
133
+
134
+ @JRubyMethod
135
+ public IRubyObject
136
+ native_write(ThreadContext context, IRubyObject chunk, IRubyObject isLast)
137
+ {
138
+ try {
139
+ initialize_task(context);
140
+ } catch (IOException e) {
141
+ throw context.getRuntime().newRuntimeError(e.getMessage());
88
142
  }
89
-
90
- @JRubyMethod
91
- public IRubyObject initialize_native(final ThreadContext context,
92
- IRubyObject saxParser,
93
- IRubyObject fileName,
94
- IRubyObject encoding) {
95
- // NOTE: Silently skips provided encoding
96
- options = new ParserContext.Options(0);
97
- this.saxParser = saxParser;
98
- return this;
143
+ final ByteArrayInputStream data = NokogiriHelpers.stringBytesToStream(chunk);
144
+ if (data == null) {
145
+ terminateTask(context.runtime);
146
+ throw XmlSyntaxError.createHTMLSyntaxError(context.runtime).toThrowable(); // Nokogiri::HTML::SyntaxError
99
147
  }
100
148
 
101
- private transient IRubyObject parse_options;
149
+ int errorCount0 = parserTask.getErrorCount();
150
+
151
+ if (isLast.isTrue()) {
152
+ IRubyObject document = invoke(context, this, "document");
153
+ invoke(context, document, "end_document");
154
+ terminateTask(context.runtime);
155
+ } else {
156
+ try {
157
+ Future<Void> task = stream.addChunk(data);
158
+ task.get();
159
+ } catch (ClosedStreamException ex) {
160
+ // this means the stream is closed, ignore this exception
161
+ } catch (Exception e) {
162
+ throw context.runtime.newRuntimeError(e.getMessage());
163
+ }
102
164
 
103
- private IRubyObject parse_options(final ThreadContext context) {
104
- if (parse_options == null) {
105
- parse_options = invoke(context, context.runtime.getClassFromPath("Nokogiri::XML::ParseOptions"), "new");
106
- }
107
- return parse_options;
108
- }
109
-
110
- @JRubyMethod(name="options")
111
- public IRubyObject getOptions(ThreadContext context) {
112
- return invoke(context, parse_options(context), "options");
113
165
  }
114
166
 
115
- @JRubyMethod(name="options=")
116
- public IRubyObject setOptions(ThreadContext context, IRubyObject opts) {
117
- invoke(context, parse_options(context), "options=", opts);
118
- options = new ParserContext.Options(opts.convertToInteger().getLongValue());
119
- return getOptions(context);
167
+ if (!options.recover && parserTask.getErrorCount() > errorCount0) {
168
+ terminateTask(context.runtime);
169
+ throw parserTask.getLastError();
120
170
  }
121
171
 
122
- @JRubyMethod
123
- public IRubyObject native_write(ThreadContext context, IRubyObject chunk, IRubyObject isLast) {
124
- try {
125
- initialize_task(context);
126
- } catch (IOException e) {
127
- throw context.getRuntime().newRuntimeError(e.getMessage());
128
- }
129
- final ByteArrayInputStream data = NokogiriHelpers.stringBytesToStream(chunk);
130
- if (data == null) {
131
- terminateTask(context.runtime);
132
- throw XmlSyntaxError.createHTMLSyntaxError(context.runtime).toThrowable(); // Nokogiri::HTML::SyntaxError
133
- }
134
-
135
- int errorCount0 = parserTask.getErrorCount();
136
-
137
- if (isLast.isTrue()) {
138
- IRubyObject document = invoke(context, this, "document");
139
- invoke(context, document, "end_document");
140
- terminateTask(context.runtime);
141
- } else {
142
- try {
143
- Future<Void> task = stream.addChunk(data);
144
- task.get();
145
- }
146
- catch (ClosedStreamException ex) {
147
- // this means the stream is closed, ignore this exception
148
- }
149
- catch (Exception e) {
150
- throw context.runtime.newRuntimeError(e.getMessage());
151
- }
152
-
153
- }
154
-
155
- if (!options.recover && parserTask.getErrorCount() > errorCount0) {
156
- terminateTask(context.runtime);
157
- throw parserTask.getLastError();
158
- }
172
+ return this;
173
+ }
159
174
 
160
- return this;
161
- }
175
+ @SuppressWarnings("unchecked")
176
+ private void
177
+ initialize_task(ThreadContext context) throws IOException
178
+ {
179
+ if (futureTask == null || stream == null) {
180
+ stream = new NokogiriBlockingQueueInputStream();
162
181
 
163
- @SuppressWarnings("unchecked")
164
- private void initialize_task(ThreadContext context) throws IOException {
165
- if (futureTask == null || stream == null) {
166
- stream = new NokogiriBlockingQueueInputStream();
167
-
168
- assert saxParser != null : "saxParser null";
169
- parserTask = new ParserTask(context, saxParser, stream);
170
- futureTask = new FutureTask<HtmlSaxParserContext>((Callable) parserTask);
171
- executor = Executors.newSingleThreadExecutor(new ThreadFactory() {
172
- @Override
173
- public Thread newThread(Runnable r) {
174
- Thread t = new Thread(r);
175
- t.setName("HtmlSaxPushParser");
176
- t.setDaemon(true);
177
- return t;
178
- }
179
- });
180
- executor.submit(futureTask);
182
+ assert saxParser != null : "saxParser null";
183
+ parserTask = new ParserTask(context, saxParser, stream);
184
+ futureTask = new FutureTask<HtmlSaxParserContext>((Callable) parserTask);
185
+ executor = Executors.newSingleThreadExecutor(new ThreadFactory() {
186
+ @Override
187
+ public Thread newThread(Runnable r) {
188
+ Thread t = new Thread(r);
189
+ t.setName("HtmlSaxPushParser");
190
+ t.setDaemon(true);
191
+ return t;
181
192
  }
193
+ });
194
+ executor.submit(futureTask);
182
195
  }
183
-
184
- private void terminateTask(final Ruby runtime) {
185
- if (executor == null) return;
186
-
187
- try {
188
- terminateImpl();
189
- }
190
- catch (InterruptedException e) {
191
- throw runtime.newRuntimeError(e.toString());
192
- }
193
- catch (Exception e) {
194
- throw runtime.newRuntimeError(e.toString());
195
- }
196
+ }
197
+
198
+ private void
199
+ terminateTask(final Ruby runtime)
200
+ {
201
+ if (executor == null) { return; }
202
+
203
+ try {
204
+ terminateImpl();
205
+ } catch (InterruptedException e) {
206
+ throw runtime.newRuntimeError(e.toString());
207
+ } catch (Exception e) {
208
+ throw runtime.newRuntimeError(e.toString());
196
209
  }
197
-
198
- private synchronized void terminateImpl() throws InterruptedException, ExecutionException {
199
- terminateExecution(executor, stream, futureTask);
200
-
201
- executor = null; stream = null; futureTask = null;
210
+ }
211
+
212
+ private synchronized void
213
+ terminateImpl() throws InterruptedException, ExecutionException
214
+ {
215
+ terminateExecution(executor, stream, futureTask);
216
+
217
+ executor = null;
218
+ stream = null;
219
+ futureTask = null;
220
+ }
221
+
222
+ private static HtmlSaxParserContext
223
+ parse(final Ruby runtime, final InputStream stream)
224
+ {
225
+ RubyClass klazz = getNokogiriClass(runtime, "Nokogiri::HTML::SAX::ParserContext");
226
+ return HtmlSaxParserContext.parse_stream(runtime, klazz, stream);
227
+ }
228
+
229
+ static class ParserTask extends XmlSaxPushParser.ParserTask /* <HtmlSaxPushParser> */
230
+ {
231
+
232
+ private
233
+ ParserTask(ThreadContext context, IRubyObject handler, InputStream stream)
234
+ {
235
+ super(context, handler, parse(context.runtime, stream), stream);
202
236
  }
203
237
 
204
- private static HtmlSaxParserContext parse(final Ruby runtime, final InputStream stream) {
205
- RubyClass klazz = getNokogiriClass(runtime, "Nokogiri::HTML::SAX::ParserContext");
206
- return HtmlSaxParserContext.parse_stream(runtime, klazz, stream);
238
+ @Override
239
+ public HtmlSaxParserContext
240
+ call() throws Exception
241
+ {
242
+ return (HtmlSaxParserContext) super.call();
207
243
  }
208
244
 
209
- static class ParserTask extends XmlSaxPushParser.ParserTask /* <HtmlSaxPushParser> */ {
210
-
211
- private ParserTask(ThreadContext context, IRubyObject handler, InputStream stream) {
212
- super(context, handler, parse(context.runtime, stream), stream);
213
- }
214
-
215
- @Override
216
- public HtmlSaxParserContext call() throws Exception {
217
- return (HtmlSaxParserContext) super.call();
218
- }
219
-
220
- }
245
+ }
221
246
 
222
247
  }
@@ -17,10 +17,10 @@
17
17
  * distribute, sublicense, and/or sell copies of the Software, and to
18
18
  * permit persons to whom the Software is furnished to do so, subject to
19
19
  * the following conditions:
20
- *
20
+ *
21
21
  * The above copyright notice and this permission notice shall be
22
22
  * included in all copies or substantial portions of the Software.
23
- *
23
+ *
24
24
  * THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
25
25
  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26
26
  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
@@ -48,550 +48,621 @@ import org.jruby.runtime.load.BasicLibraryService;
48
48
  /**
49
49
  * Class to provide Nokogiri. This class is used to make "require 'nokogiri'" work
50
50
  * in JRuby. Also, this class holds a Ruby type cache and allocators of Ruby types.
51
- *
51
+ *
52
52
  * @author headius
53
53
  * @author Yoko Harada <yokolet@gmail.com>
54
54
  */
55
- public class NokogiriService implements BasicLibraryService {
56
- public boolean basicLoad(Ruby ruby) {
57
- init(ruby);
58
- return true;
55
+ public class NokogiriService implements BasicLibraryService
56
+ {
57
+ public boolean
58
+ basicLoad(Ruby ruby)
59
+ {
60
+ init(ruby);
61
+ return true;
62
+ }
63
+
64
+ public static Map<String, RubyClass>
65
+ getNokogiriClassCache(Ruby ruby)
66
+ {
67
+ return (Map<String, RubyClass>) ruby.getModule("Nokogiri").getInternalVariable("cache");
68
+ }
69
+
70
+ private static Map<String, RubyClass>
71
+ populateNokogiriClassCahce(Ruby ruby)
72
+ {
73
+ Map<String, RubyClass> nokogiriClassCache = new HashMap<String, RubyClass>();
74
+ nokogiriClassCache.put("Nokogiri::EncodingHandler", (RubyClass)ruby.getClassFromPath("Nokogiri::EncodingHandler"));
75
+ nokogiriClassCache.put("Nokogiri::HTML::Document", (RubyClass)ruby.getClassFromPath("Nokogiri::HTML::Document"));
76
+ nokogiriClassCache.put("Nokogiri::HTML::ElementDescription",
77
+ (RubyClass)ruby.getClassFromPath("Nokogiri::HTML::ElementDescription"));
78
+ nokogiriClassCache.put("Nokogiri::XML::Attr", (RubyClass)ruby.getClassFromPath("Nokogiri::XML::Attr"));
79
+ nokogiriClassCache.put("Nokogiri::XML::Document", (RubyClass)ruby.getClassFromPath("Nokogiri::XML::Document"));
80
+ nokogiriClassCache.put("Nokogiri::XML::DocumentFragment",
81
+ (RubyClass)ruby.getClassFromPath("Nokogiri::XML::DocumentFragment"));
82
+ nokogiriClassCache.put("Nokogiri::XML::DTD", (RubyClass)ruby.getClassFromPath("Nokogiri::XML::DTD"));
83
+ nokogiriClassCache.put("Nokogiri::XML::Text", (RubyClass)ruby.getClassFromPath("Nokogiri::XML::Text"));
84
+ nokogiriClassCache.put("Nokogiri::XML::Comment", (RubyClass)ruby.getClassFromPath("Nokogiri::XML::Comment"));
85
+ nokogiriClassCache.put("Nokogiri::XML::Element", (RubyClass)ruby.getClassFromPath("Nokogiri::XML::Element"));
86
+ nokogiriClassCache.put("Nokogiri::XML::ElementContent",
87
+ (RubyClass)ruby.getClassFromPath("Nokogiri::XML::ElementContent"));
88
+ nokogiriClassCache.put("Nokogiri::XML::ElementDecl", (RubyClass)ruby.getClassFromPath("Nokogiri::XML::ElementDecl"));
89
+ nokogiriClassCache.put("Nokogiri::XML::EntityDecl", (RubyClass)ruby.getClassFromPath("Nokogiri::XML::EntityDecl"));
90
+ nokogiriClassCache.put("Nokogiri::XML::EntityReference",
91
+ (RubyClass)ruby.getClassFromPath("Nokogiri::XML::EntityReference"));
92
+ nokogiriClassCache.put("Nokogiri::XML::ProcessingInstruction",
93
+ (RubyClass)ruby.getClassFromPath("Nokogiri::XML::ProcessingInstruction"));
94
+ nokogiriClassCache.put("Nokogiri::XML::CDATA", (RubyClass)ruby.getClassFromPath("Nokogiri::XML::CDATA"));
95
+ nokogiriClassCache.put("Nokogiri::XML::Node", (RubyClass)ruby.getClassFromPath("Nokogiri::XML::Node"));
96
+ nokogiriClassCache.put("Nokogiri::XML::NodeSet", (RubyClass)ruby.getClassFromPath("Nokogiri::XML::NodeSet"));
97
+ nokogiriClassCache.put("Nokogiri::XML::Namespace", (RubyClass)ruby.getClassFromPath("Nokogiri::XML::Namespace"));
98
+ nokogiriClassCache.put("Nokogiri::XML::SyntaxError", (RubyClass)ruby.getClassFromPath("Nokogiri::XML::SyntaxError"));
99
+ nokogiriClassCache.put("Nokogiri::XML::Reader", (RubyClass)ruby.getClassFromPath("Nokogiri::XML::Reader"));
100
+ nokogiriClassCache.put("Nokogiri::XML::RelaxNG", (RubyClass)ruby.getClassFromPath("Nokogiri::XML::RelaxNG"));
101
+ nokogiriClassCache.put("Nokogiri::XML::Schema", (RubyClass)ruby.getClassFromPath("Nokogiri::XML::Schema"));
102
+ nokogiriClassCache.put("Nokogiri::XML::XPathContext", (RubyClass)ruby.getClassFromPath("Nokogiri::XML::XPathContext"));
103
+ nokogiriClassCache.put("Nokogiri::XML::AttributeDecl",
104
+ (RubyClass)ruby.getClassFromPath("Nokogiri::XML::AttributeDecl"));
105
+ nokogiriClassCache.put("Nokogiri::XML::SAX::ParserContext",
106
+ (RubyClass)ruby.getClassFromPath("Nokogiri::XML::SAX::ParserContext"));
107
+ return Collections.unmodifiableMap(nokogiriClassCache);
108
+ }
109
+
110
+ private void
111
+ init(Ruby ruby)
112
+ {
113
+ RubyModule nokogiri = ruby.defineModule("Nokogiri");
114
+ RubyModule xmlModule = nokogiri.defineModuleUnder("XML");
115
+ RubyModule xmlSaxModule = xmlModule.defineModuleUnder("SAX");
116
+ RubyModule htmlModule = nokogiri.defineModuleUnder("HTML");
117
+ RubyModule htmlSaxModule = htmlModule.defineModuleUnder("SAX");
118
+ RubyModule xsltModule = nokogiri.defineModuleUnder("XSLT");
119
+
120
+ createJavaLibraryVersionConstants(ruby, nokogiri);
121
+ createNokogiriModule(ruby, nokogiri);
122
+ createSyntaxErrors(ruby, nokogiri, xmlModule);
123
+ RubyClass xmlNode = createXmlModule(ruby, xmlModule);
124
+ createHtmlModule(ruby, htmlModule);
125
+ createDocuments(ruby, xmlModule, htmlModule, xmlNode);
126
+ createSaxModule(ruby, xmlSaxModule, htmlSaxModule);
127
+ createXsltModule(ruby, xsltModule);
128
+ nokogiri.setInternalVariable("cache", populateNokogiriClassCahce(ruby));
129
+ }
130
+
131
+ private void
132
+ createJavaLibraryVersionConstants(Ruby ruby, RubyModule nokogiri)
133
+ {
134
+ nokogiri.defineConstant("XERCES_VERSION", ruby.newString(org.apache.xerces.impl.Version.getVersion()));
135
+ nokogiri.defineConstant("NEKO_VERSION", ruby.newString(org.cyberneko.html.Version.getVersion()));
136
+ }
137
+
138
+ private void
139
+ createNokogiriModule(Ruby ruby, RubyModule nokogiri)
140
+ {
141
+ RubyClass encHandler = nokogiri.defineClassUnder("EncodingHandler", ruby.getObject(), ENCODING_HANDLER_ALLOCATOR);
142
+ encHandler.defineAnnotatedMethods(EncodingHandler.class);
143
+ }
144
+
145
+ private void
146
+ createSyntaxErrors(Ruby ruby, RubyModule nokogiri, RubyModule xmlModule)
147
+ {
148
+ RubyClass syntaxError = nokogiri.defineClassUnder("SyntaxError", ruby.getStandardError(),
149
+ ruby.getStandardError().getAllocator());
150
+ RubyClass xmlSyntaxError = xmlModule.defineClassUnder("SyntaxError", syntaxError, XML_SYNTAXERROR_ALLOCATOR);
151
+ xmlSyntaxError.defineAnnotatedMethods(XmlSyntaxError.class);
152
+ }
153
+
154
+ private RubyClass
155
+ createXmlModule(Ruby ruby, RubyModule xmlModule)
156
+ {
157
+ RubyClass node = xmlModule.defineClassUnder("Node", ruby.getObject(), XML_NODE_ALLOCATOR);
158
+ node.defineAnnotatedMethods(XmlNode.class);
159
+
160
+ RubyClass attr = xmlModule.defineClassUnder("Attr", node, XML_ATTR_ALLOCATOR);
161
+ attr.defineAnnotatedMethods(XmlAttr.class);
162
+
163
+ RubyClass attrDecl = xmlModule.defineClassUnder("AttributeDecl", node, XML_ATTRIBUTE_DECL_ALLOCATOR);
164
+ attrDecl.defineAnnotatedMethods(XmlAttributeDecl.class);
165
+
166
+ RubyClass characterData = xmlModule.defineClassUnder("CharacterData", node, null);
167
+
168
+ RubyClass comment = xmlModule.defineClassUnder("Comment", characterData, XML_COMMENT_ALLOCATOR);
169
+ comment.defineAnnotatedMethods(XmlComment.class);
170
+
171
+ RubyClass text = xmlModule.defineClassUnder("Text", characterData, XML_TEXT_ALLOCATOR);
172
+ text.defineAnnotatedMethods(XmlText.class);
173
+
174
+ RubyModule cdata = xmlModule.defineClassUnder("CDATA", text, XML_CDATA_ALLOCATOR);
175
+ cdata.defineAnnotatedMethods(XmlCdata.class);
176
+
177
+ RubyClass dtd = xmlModule.defineClassUnder("DTD", node, XML_DTD_ALLOCATOR);
178
+ dtd.defineAnnotatedMethods(XmlDtd.class);
179
+
180
+ RubyClass documentFragment = xmlModule.defineClassUnder("DocumentFragment", node, XML_DOCUMENT_FRAGMENT_ALLOCATOR);
181
+ documentFragment.defineAnnotatedMethods(XmlDocumentFragment.class);
182
+
183
+ RubyClass element = xmlModule.defineClassUnder("Element", node, XML_ELEMENT_ALLOCATOR);
184
+ element.defineAnnotatedMethods(XmlElement.class);
185
+
186
+ RubyClass elementContent = xmlModule.defineClassUnder("ElementContent", ruby.getObject(),
187
+ XML_ELEMENT_CONTENT_ALLOCATOR);
188
+ elementContent.defineAnnotatedMethods(XmlElementContent.class);
189
+
190
+ RubyClass elementDecl = xmlModule.defineClassUnder("ElementDecl", node, XML_ELEMENT_DECL_ALLOCATOR);
191
+ elementDecl.defineAnnotatedMethods(XmlElementDecl.class);
192
+
193
+ RubyClass entityDecl = xmlModule.defineClassUnder("EntityDecl", node, XML_ENTITY_DECL_ALLOCATOR);
194
+ entityDecl.defineAnnotatedMethods(XmlEntityDecl.class);
195
+
196
+ entityDecl.defineConstant("INTERNAL_GENERAL", RubyFixnum.newFixnum(ruby, XmlEntityDecl.INTERNAL_GENERAL));
197
+ entityDecl.defineConstant("EXTERNAL_GENERAL_PARSED", RubyFixnum.newFixnum(ruby, XmlEntityDecl.EXTERNAL_GENERAL_PARSED));
198
+ entityDecl.defineConstant("EXTERNAL_GENERAL_UNPARSED", RubyFixnum.newFixnum(ruby,
199
+ XmlEntityDecl.EXTERNAL_GENERAL_UNPARSED));
200
+ entityDecl.defineConstant("INTERNAL_PARAMETER", RubyFixnum.newFixnum(ruby, XmlEntityDecl.INTERNAL_PARAMETER));
201
+ entityDecl.defineConstant("EXTERNAL_PARAMETER", RubyFixnum.newFixnum(ruby, XmlEntityDecl.EXTERNAL_PARAMETER));
202
+ entityDecl.defineConstant("INTERNAL_PREDEFINED", RubyFixnum.newFixnum(ruby, XmlEntityDecl.INTERNAL_PREDEFINED));
203
+
204
+ RubyClass entref = xmlModule.defineClassUnder("EntityReference", node, XML_ENTITY_REFERENCE_ALLOCATOR);
205
+ entref.defineAnnotatedMethods(XmlEntityReference.class);
206
+
207
+ RubyClass namespace = xmlModule.defineClassUnder("Namespace", ruby.getObject(), XML_NAMESPACE_ALLOCATOR);
208
+ namespace.defineAnnotatedMethods(XmlNamespace.class);
209
+
210
+ RubyClass nodeSet = xmlModule.defineClassUnder("NodeSet", ruby.getObject(), XML_NODESET_ALLOCATOR);
211
+ nodeSet.defineAnnotatedMethods(XmlNodeSet.class);
212
+
213
+ RubyClass pi = xmlModule.defineClassUnder("ProcessingInstruction", node, XML_PROCESSING_INSTRUCTION_ALLOCATOR);
214
+ pi.defineAnnotatedMethods(XmlProcessingInstruction.class);
215
+
216
+ RubyClass reader = xmlModule.defineClassUnder("Reader", ruby.getObject(), XML_READER_ALLOCATOR);
217
+ reader.defineAnnotatedMethods(XmlReader.class);
218
+
219
+ RubyClass schema = xmlModule.defineClassUnder("Schema", ruby.getObject(), XML_SCHEMA_ALLOCATOR);
220
+ schema.defineAnnotatedMethods(XmlSchema.class);
221
+
222
+ RubyClass relaxng = xmlModule.defineClassUnder("RelaxNG", schema, XML_RELAXNG_ALLOCATOR);
223
+ relaxng.defineAnnotatedMethods(XmlRelaxng.class);
224
+
225
+ RubyClass xpathContext = xmlModule.defineClassUnder("XPathContext", ruby.getObject(), XML_XPATHCONTEXT_ALLOCATOR);
226
+ xpathContext.defineAnnotatedMethods(XmlXpathContext.class);
227
+
228
+ return node;
229
+ }
230
+
231
+ private void
232
+ createHtmlModule(Ruby ruby, RubyModule htmlModule)
233
+ {
234
+ RubyClass htmlElemDesc = htmlModule.defineClassUnder("ElementDescription", ruby.getObject(),
235
+ HTML_ELEMENT_DESCRIPTION_ALLOCATOR);
236
+ htmlElemDesc.defineAnnotatedMethods(HtmlElementDescription.class);
237
+
238
+ RubyClass htmlEntityLookup = htmlModule.defineClassUnder("EntityLookup", ruby.getObject(),
239
+ HTML_ENTITY_LOOKUP_ALLOCATOR);
240
+ htmlEntityLookup.defineAnnotatedMethods(HtmlEntityLookup.class);
241
+ }
242
+
243
+ private void
244
+ createDocuments(Ruby ruby, RubyModule xmlModule, RubyModule htmlModule, RubyClass node)
245
+ {
246
+ RubyClass xmlDocument = xmlModule.defineClassUnder("Document", node, XML_DOCUMENT_ALLOCATOR);
247
+ xmlDocument.defineAnnotatedMethods(XmlDocument.class);
248
+
249
+ //RubyModule htmlDoc = html.defineOrGetClassUnder("Document", document);
250
+ RubyModule htmlDocument = htmlModule.defineClassUnder("Document", xmlDocument, HTML_DOCUMENT_ALLOCATOR);
251
+ htmlDocument.defineAnnotatedMethods(HtmlDocument.class);
252
+ }
253
+
254
+ private void
255
+ createSaxModule(Ruby ruby, RubyModule xmlSaxModule, RubyModule htmlSaxModule)
256
+ {
257
+ RubyClass xmlSaxParserContext = xmlSaxModule.defineClassUnder("ParserContext", ruby.getObject(),
258
+ XML_SAXPARSER_CONTEXT_ALLOCATOR);
259
+ xmlSaxParserContext.defineAnnotatedMethods(XmlSaxParserContext.class);
260
+
261
+ RubyClass xmlSaxPushParser = xmlSaxModule.defineClassUnder("PushParser", ruby.getObject(), XML_SAXPUSHPARSER_ALLOCATOR);
262
+ xmlSaxPushParser.defineAnnotatedMethods(XmlSaxPushParser.class);
263
+
264
+ RubyClass htmlSaxPushParser = htmlSaxModule.defineClassUnder("PushParser", ruby.getObject(),
265
+ HTML_SAXPUSHPARSER_ALLOCATOR);
266
+ htmlSaxPushParser.defineAnnotatedMethods(HtmlSaxPushParser.class);
267
+
268
+ RubyClass htmlSaxParserContext = htmlSaxModule.defineClassUnder("ParserContext", xmlSaxParserContext,
269
+ HTML_SAXPARSER_CONTEXT_ALLOCATOR);
270
+ htmlSaxParserContext.defineAnnotatedMethods(HtmlSaxParserContext.class);
271
+ }
272
+
273
+ private void
274
+ createXsltModule(Ruby ruby, RubyModule xsltModule)
275
+ {
276
+ RubyClass stylesheet = xsltModule.defineClassUnder("Stylesheet", ruby.getObject(), XSLT_STYLESHEET_ALLOCATOR);
277
+ stylesheet.defineAnnotatedMethods(XsltStylesheet.class);
278
+ xsltModule.defineAnnotatedMethod(XsltStylesheet.class, "register");
279
+ }
280
+
281
+ private static ObjectAllocator ENCODING_HANDLER_ALLOCATOR = new ObjectAllocator()
282
+ {
283
+ public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
284
+ return new EncodingHandler(runtime, klazz, "");
59
285
  }
286
+ };
287
+
288
+ public static final ObjectAllocator HTML_DOCUMENT_ALLOCATOR = new ObjectAllocator()
289
+ {
290
+ private HtmlDocument htmlDocument = null;
291
+ public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
292
+ if (htmlDocument == null) { htmlDocument = new HtmlDocument(runtime, klazz); }
293
+ try {
294
+ HtmlDocument clone = (HtmlDocument) htmlDocument.clone();
295
+ clone.setMetaClass(klazz);
296
+ return clone;
297
+ } catch (CloneNotSupportedException e) {
298
+ return new HtmlDocument(runtime, klazz);
299
+ }
300
+ }
301
+ };
302
+
303
+ private static final ObjectAllocator HTML_SAXPARSER_CONTEXT_ALLOCATOR = new ObjectAllocator()
304
+ {
305
+ private HtmlSaxParserContext htmlSaxParserContext = null;
306
+ public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
307
+ if (htmlSaxParserContext == null) { htmlSaxParserContext = new HtmlSaxParserContext(runtime, klazz); }
308
+ try {
309
+ HtmlSaxParserContext clone = (HtmlSaxParserContext) htmlSaxParserContext.clone();
310
+ clone.setMetaClass(klazz);
311
+ return clone;
312
+ } catch (CloneNotSupportedException e) {
313
+ return new HtmlSaxParserContext(runtime, klazz);
314
+ }
315
+ }
316
+ };
60
317
 
61
- public static Map<String, RubyClass> getNokogiriClassCache(Ruby ruby) {
62
- return (Map<String, RubyClass>) ruby.getModule("Nokogiri").getInternalVariable("cache");
318
+ private static ObjectAllocator HTML_ELEMENT_DESCRIPTION_ALLOCATOR =
319
+ new ObjectAllocator()
320
+ {
321
+ public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
322
+ return new HtmlElementDescription(runtime, klazz);
63
323
  }
324
+ };
64
325
 
65
- private static Map<String, RubyClass> populateNokogiriClassCahce(Ruby ruby) {
66
- Map<String, RubyClass> nokogiriClassCache = 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::EntityReference", (RubyClass)ruby.getClassFromPath("Nokogiri::XML::EntityReference"));
81
- nokogiriClassCache.put("Nokogiri::XML::ProcessingInstruction", (RubyClass)ruby.getClassFromPath("Nokogiri::XML::ProcessingInstruction"));
82
- nokogiriClassCache.put("Nokogiri::XML::CDATA", (RubyClass)ruby.getClassFromPath("Nokogiri::XML::CDATA"));
83
- nokogiriClassCache.put("Nokogiri::XML::Node", (RubyClass)ruby.getClassFromPath("Nokogiri::XML::Node"));
84
- nokogiriClassCache.put("Nokogiri::XML::NodeSet", (RubyClass)ruby.getClassFromPath("Nokogiri::XML::NodeSet"));
85
- nokogiriClassCache.put("Nokogiri::XML::Namespace", (RubyClass)ruby.getClassFromPath("Nokogiri::XML::Namespace"));
86
- nokogiriClassCache.put("Nokogiri::XML::SyntaxError", (RubyClass)ruby.getClassFromPath("Nokogiri::XML::SyntaxError"));
87
- nokogiriClassCache.put("Nokogiri::XML::Reader", (RubyClass)ruby.getClassFromPath("Nokogiri::XML::Reader"));
88
- nokogiriClassCache.put("Nokogiri::XML::RelaxNG", (RubyClass)ruby.getClassFromPath("Nokogiri::XML::RelaxNG"));
89
- nokogiriClassCache.put("Nokogiri::XML::Schema", (RubyClass)ruby.getClassFromPath("Nokogiri::XML::Schema"));
90
- nokogiriClassCache.put("Nokogiri::XML::XPathContext", (RubyClass)ruby.getClassFromPath("Nokogiri::XML::XPathContext"));
91
- nokogiriClassCache.put("Nokogiri::XML::AttributeDecl", (RubyClass)ruby.getClassFromPath("Nokogiri::XML::AttributeDecl"));
92
- nokogiriClassCache.put("Nokogiri::XML::SAX::ParserContext", (RubyClass)ruby.getClassFromPath("Nokogiri::XML::SAX::ParserContext"));
93
- return Collections.unmodifiableMap(nokogiriClassCache);
326
+ private static ObjectAllocator HTML_ENTITY_LOOKUP_ALLOCATOR =
327
+ new ObjectAllocator()
328
+ {
329
+ public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
330
+ return new HtmlEntityLookup(runtime, klazz);
331
+ }
332
+ };
333
+
334
+ public static final ObjectAllocator XML_ATTR_ALLOCATOR = new ObjectAllocator()
335
+ {
336
+ private XmlAttr xmlAttr = null;
337
+ public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
338
+ if (xmlAttr == null) { xmlAttr = new XmlAttr(runtime, klazz); }
339
+ try {
340
+ XmlAttr clone = (XmlAttr) xmlAttr.clone();
341
+ clone.setMetaClass(klazz);
342
+ return clone;
343
+ } catch (CloneNotSupportedException e) {
344
+ return new XmlAttr(runtime, klazz);
345
+ }
346
+ }
347
+ };
348
+
349
+ public static final ObjectAllocator XML_CDATA_ALLOCATOR = new ObjectAllocator()
350
+ {
351
+ private XmlCdata xmlCdata = null;
352
+ public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
353
+ if (xmlCdata == null) { xmlCdata = new XmlCdata(runtime, klazz); }
354
+ try {
355
+ XmlCdata clone = (XmlCdata) xmlCdata.clone();
356
+ clone.setMetaClass(klazz);
357
+ return clone;
358
+ } catch (CloneNotSupportedException e) {
359
+ return new XmlCdata(runtime, klazz);
360
+ }
361
+ }
362
+ };
363
+
364
+ public static final ObjectAllocator XML_COMMENT_ALLOCATOR = new ObjectAllocator()
365
+ {
366
+ private XmlComment xmlComment = null;
367
+ public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
368
+ if (xmlComment == null) { xmlComment = new XmlComment(runtime, klazz); }
369
+ try {
370
+ XmlComment clone = (XmlComment) xmlComment.clone();
371
+ clone.setMetaClass(klazz);
372
+ return clone;
373
+ } catch (CloneNotSupportedException e) {
374
+ return new XmlComment(runtime, klazz);
375
+ }
376
+ }
377
+ };
378
+
379
+ public static final ObjectAllocator XML_DOCUMENT_ALLOCATOR = new ObjectAllocator()
380
+ {
381
+ private XmlDocument xmlDocument = null;
382
+ public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
383
+ if (xmlDocument == null) { xmlDocument = new XmlDocument(runtime, klazz); }
384
+ try {
385
+ XmlDocument clone = (XmlDocument) xmlDocument.clone();
386
+ clone.setMetaClass(klazz);
387
+ return clone;
388
+ } catch (CloneNotSupportedException e) {
389
+ return new XmlDocument(runtime, klazz);
390
+ }
391
+ }
392
+ };
393
+
394
+ public static final ObjectAllocator XML_DOCUMENT_FRAGMENT_ALLOCATOR = new ObjectAllocator()
395
+ {
396
+ private XmlDocumentFragment xmlDocumentFragment = null;
397
+ public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
398
+ if (xmlDocumentFragment == null) { xmlDocumentFragment = new XmlDocumentFragment(runtime, klazz); }
399
+ try {
400
+ XmlDocumentFragment clone = (XmlDocumentFragment)xmlDocumentFragment.clone();
401
+ clone.setMetaClass(klazz);
402
+ return clone;
403
+ } catch (CloneNotSupportedException e) {
404
+ return new XmlDocumentFragment(runtime, klazz);
405
+ }
94
406
  }
407
+ };
408
+
409
+ public static final ObjectAllocator XML_DTD_ALLOCATOR = new ObjectAllocator()
410
+ {
411
+ private XmlDtd xmlDtd = null;
412
+ public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
413
+ if (xmlDtd == null) { xmlDtd = new XmlDtd(runtime, klazz); }
414
+ try {
415
+ XmlDtd clone = (XmlDtd)xmlDtd.clone();
416
+ clone.setMetaClass(klazz);
417
+ return clone;
418
+ } catch (CloneNotSupportedException e) {
419
+ return new XmlDtd(runtime, klazz);
420
+ }
421
+ }
422
+ };
423
+
424
+ public static final ObjectAllocator XML_ELEMENT_ALLOCATOR = new ObjectAllocator()
425
+ {
426
+ private XmlElement xmlElement = null;
427
+ public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
428
+ if (xmlElement == null) { xmlElement = new XmlElement(runtime, klazz); }
429
+ try {
430
+ XmlElement clone = (XmlElement)xmlElement.clone();
431
+ clone.setMetaClass(klazz);
432
+ return clone;
433
+ } catch (CloneNotSupportedException e) {
434
+ return new XmlElement(runtime, klazz);
435
+ }
436
+ }
437
+ };
438
+
439
+ public static ObjectAllocator XML_ELEMENT_DECL_ALLOCATOR = new ObjectAllocator()
440
+ {
441
+ private XmlElementDecl xmlElementDecl = null;
442
+ public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
443
+ if (xmlElementDecl == null) { xmlElementDecl = new XmlElementDecl(runtime, klazz); }
444
+ try {
445
+ XmlElementDecl clone = (XmlElementDecl)xmlElementDecl.clone();
446
+ clone.setMetaClass(klazz);
447
+ return clone;
448
+ } catch (CloneNotSupportedException e) {
449
+ return new XmlElementDecl(runtime, klazz);
450
+ }
451
+ }
452
+ };
453
+
454
+ public static ObjectAllocator XML_ENTITY_REFERENCE_ALLOCATOR = new ObjectAllocator()
455
+ {
456
+ private XmlEntityReference xmlEntityRef = null;
457
+ public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
458
+ if (xmlEntityRef == null) { xmlEntityRef = new XmlEntityReference(runtime, klazz); }
459
+ try {
460
+ XmlEntityReference clone = (XmlEntityReference)xmlEntityRef.clone();
461
+ clone.setMetaClass(klazz);
462
+ return clone;
463
+ } catch (CloneNotSupportedException e) {
464
+ return new XmlEntityReference(runtime, klazz);
465
+ }
466
+ }
467
+ };
468
+
469
+ public static final ObjectAllocator XML_NAMESPACE_ALLOCATOR = new ObjectAllocator()
470
+ {
471
+ private XmlNamespace xmlNamespace = null;
472
+ public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
473
+ if (xmlNamespace == null) { xmlNamespace = new XmlNamespace(runtime, klazz); }
474
+ try {
475
+ XmlNamespace clone = (XmlNamespace) xmlNamespace.clone();
476
+ clone.setMetaClass(klazz);
477
+ return clone;
478
+ } catch (CloneNotSupportedException e) {
479
+ return new XmlNamespace(runtime, klazz);
480
+ }
481
+ }
482
+ };
483
+
484
+ public static final ObjectAllocator XML_NODE_ALLOCATOR = new ObjectAllocator()
485
+ {
486
+ private XmlNode xmlNode = null;
487
+ public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
488
+ if (xmlNode == null) { xmlNode = new XmlNode(runtime, klazz); }
489
+ try {
490
+ XmlNode clone = (XmlNode) xmlNode.clone();
491
+ clone.setMetaClass(klazz);
492
+ return clone;
493
+ } catch (CloneNotSupportedException e) {
494
+ return new XmlNode(runtime, klazz);
495
+ }
496
+ }
497
+ };
498
+
499
+ public static final ObjectAllocator XML_NODESET_ALLOCATOR = new ObjectAllocator()
500
+ {
501
+ private XmlNodeSet xmlNodeSet = null;
502
+ public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
503
+ if (xmlNodeSet == null) { xmlNodeSet = new XmlNodeSet(runtime, klazz); }
504
+ try {
505
+ XmlNodeSet clone = (XmlNodeSet) xmlNodeSet.clone();
506
+ clone.setMetaClass(klazz);
507
+ return clone;
508
+ } catch (CloneNotSupportedException e) {
509
+ return new XmlNodeSet(runtime, klazz);
510
+ }
511
+ }
512
+ };
513
+
514
+ public static ObjectAllocator XML_PROCESSING_INSTRUCTION_ALLOCATOR = new ObjectAllocator()
515
+ {
516
+ private XmlProcessingInstruction xmlProcessingInstruction = null;
517
+ public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
518
+ if (xmlProcessingInstruction == null) { xmlProcessingInstruction = new XmlProcessingInstruction(runtime, klazz); }
519
+ try {
520
+ XmlProcessingInstruction clone = (XmlProcessingInstruction)xmlProcessingInstruction.clone();
521
+ clone.setMetaClass(klazz);
522
+ return clone;
523
+ } catch (CloneNotSupportedException e) {
524
+ return new XmlProcessingInstruction(runtime, klazz);
525
+ }
526
+ }
527
+ };
528
+
529
+ public static ObjectAllocator XML_READER_ALLOCATOR = new ObjectAllocator()
530
+ {
531
+ private XmlReader xmlReader = null;
532
+ public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
533
+ if (xmlReader == null) { xmlReader = new XmlReader(runtime, klazz); }
534
+ try {
535
+ XmlReader clone = (XmlReader) xmlReader.clone();
536
+ clone.setMetaClass(klazz);
537
+ return clone;
538
+ } catch (CloneNotSupportedException e) {
539
+ xmlReader = new XmlReader(runtime, klazz);
540
+ return xmlReader;
541
+ }
542
+ }
543
+ };
95
544
 
96
- private void init(Ruby ruby) {
97
- RubyModule nokogiri = ruby.defineModule("Nokogiri");
98
- RubyModule xmlModule = nokogiri.defineModuleUnder("XML");
99
- RubyModule xmlSaxModule = xmlModule.defineModuleUnder("SAX");
100
- RubyModule htmlModule = nokogiri.defineModuleUnder("HTML");
101
- RubyModule htmlSaxModule = htmlModule.defineModuleUnder("SAX");
102
- RubyModule xsltModule = nokogiri.defineModuleUnder("XSLT");
103
-
104
- createJavaLibraryVersionConstants(ruby, nokogiri);
105
- createNokogiriModule(ruby, nokogiri);
106
- createSyntaxErrors(ruby, nokogiri, xmlModule);
107
- RubyClass xmlNode = createXmlModule(ruby, xmlModule);
108
- createHtmlModule(ruby, htmlModule);
109
- createDocuments(ruby, xmlModule, htmlModule, xmlNode);
110
- createSaxModule(ruby, xmlSaxModule, htmlSaxModule);
111
- createXsltModule(ruby, xsltModule);
112
- nokogiri.setInternalVariable("cache", populateNokogiriClassCahce(ruby));
545
+ private static ObjectAllocator XML_ATTRIBUTE_DECL_ALLOCATOR = new ObjectAllocator()
546
+ {
547
+ public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
548
+ return new XmlAttributeDecl(runtime, klazz);
113
549
  }
550
+ };
114
551
 
115
- private void createJavaLibraryVersionConstants(Ruby ruby, RubyModule nokogiri) {
116
- nokogiri.defineConstant("XERCES_VERSION", ruby.newString(org.apache.xerces.impl.Version.getVersion()));
117
- nokogiri.defineConstant("NEKO_VERSION", ruby.newString(org.cyberneko.html.Version.getVersion()));
552
+ private static ObjectAllocator XML_ENTITY_DECL_ALLOCATOR = new ObjectAllocator()
553
+ {
554
+ public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
555
+ return new XmlEntityDecl(runtime, klazz);
118
556
  }
557
+ };
119
558
 
120
- private void createNokogiriModule(Ruby ruby, RubyModule nokogiri) {
121
- RubyClass encHandler = nokogiri.defineClassUnder("EncodingHandler", ruby.getObject(), ENCODING_HANDLER_ALLOCATOR);
122
- encHandler.defineAnnotatedMethods(EncodingHandler.class);
559
+ private static ObjectAllocator XML_ELEMENT_CONTENT_ALLOCATOR = new ObjectAllocator()
560
+ {
561
+ public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
562
+ throw runtime.newNotImplementedError("not implemented");
123
563
  }
124
-
125
- private void createSyntaxErrors(Ruby ruby, RubyModule nokogiri, RubyModule xmlModule) {
126
- RubyClass syntaxError = nokogiri.defineClassUnder("SyntaxError", ruby.getStandardError(), ruby.getStandardError().getAllocator());
127
- RubyClass xmlSyntaxError = xmlModule.defineClassUnder("SyntaxError", syntaxError, XML_SYNTAXERROR_ALLOCATOR);
128
- xmlSyntaxError.defineAnnotatedMethods(XmlSyntaxError.class);
564
+ };
565
+
566
+ public static final ObjectAllocator XML_RELAXNG_ALLOCATOR = new ObjectAllocator()
567
+ {
568
+ private XmlRelaxng xmlRelaxng = null;
569
+ public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
570
+ if (xmlRelaxng == null) { xmlRelaxng = new XmlRelaxng(runtime, klazz); }
571
+ try {
572
+ XmlRelaxng clone = (XmlRelaxng) xmlRelaxng.clone();
573
+ clone.setMetaClass(klazz);
574
+ return clone;
575
+ } catch (CloneNotSupportedException e) {
576
+ return new XmlRelaxng(runtime, klazz);
577
+ }
129
578
  }
130
-
131
- private RubyClass createXmlModule(Ruby ruby, RubyModule xmlModule) {
132
- RubyClass node = xmlModule.defineClassUnder("Node", ruby.getObject(), XML_NODE_ALLOCATOR);
133
- node.defineAnnotatedMethods(XmlNode.class);
134
-
135
- RubyClass attr = xmlModule.defineClassUnder("Attr", node, XML_ATTR_ALLOCATOR);
136
- attr.defineAnnotatedMethods(XmlAttr.class);
137
-
138
- RubyClass attrDecl = xmlModule.defineClassUnder("AttributeDecl", node, XML_ATTRIBUTE_DECL_ALLOCATOR);
139
- attrDecl.defineAnnotatedMethods(XmlAttributeDecl.class);
140
-
141
- RubyClass characterData = xmlModule.defineClassUnder("CharacterData", node, null);
142
-
143
- RubyClass comment = xmlModule.defineClassUnder("Comment", characterData, XML_COMMENT_ALLOCATOR);
144
- comment.defineAnnotatedMethods(XmlComment.class);
145
-
146
- RubyClass text = xmlModule.defineClassUnder("Text", characterData, XML_TEXT_ALLOCATOR);
147
- text.defineAnnotatedMethods(XmlText.class);
148
-
149
- RubyModule cdata = xmlModule.defineClassUnder("CDATA", text, XML_CDATA_ALLOCATOR);
150
- cdata.defineAnnotatedMethods(XmlCdata.class);
151
-
152
- RubyClass dtd = xmlModule.defineClassUnder("DTD", node, XML_DTD_ALLOCATOR);
153
- dtd.defineAnnotatedMethods(XmlDtd.class);
154
-
155
- RubyClass documentFragment = xmlModule.defineClassUnder("DocumentFragment", node, XML_DOCUMENT_FRAGMENT_ALLOCATOR);
156
- documentFragment.defineAnnotatedMethods(XmlDocumentFragment.class);
157
-
158
- RubyClass element = xmlModule.defineClassUnder("Element", node, XML_ELEMENT_ALLOCATOR);
159
- element.defineAnnotatedMethods(XmlElement.class);
160
-
161
- RubyClass elementContent = xmlModule.defineClassUnder("ElementContent", ruby.getObject(), XML_ELEMENT_CONTENT_ALLOCATOR);
162
- elementContent.defineAnnotatedMethods(XmlElementContent.class);
163
-
164
- RubyClass elementDecl = xmlModule.defineClassUnder("ElementDecl", node, XML_ELEMENT_DECL_ALLOCATOR);
165
- elementDecl.defineAnnotatedMethods(XmlElementDecl.class);
166
-
167
- RubyClass entityDecl = xmlModule.defineClassUnder("EntityDecl", node, XML_ENTITY_DECL_ALLOCATOR);
168
- entityDecl.defineAnnotatedMethods(XmlEntityDecl.class);
169
-
170
- entityDecl.defineConstant("INTERNAL_GENERAL", RubyFixnum.newFixnum(ruby, XmlEntityDecl.INTERNAL_GENERAL));
171
- entityDecl.defineConstant("EXTERNAL_GENERAL_PARSED", RubyFixnum.newFixnum(ruby, XmlEntityDecl.EXTERNAL_GENERAL_PARSED));
172
- entityDecl.defineConstant("EXTERNAL_GENERAL_UNPARSED", RubyFixnum.newFixnum(ruby, XmlEntityDecl.EXTERNAL_GENERAL_UNPARSED));
173
- entityDecl.defineConstant("INTERNAL_PARAMETER", RubyFixnum.newFixnum(ruby, XmlEntityDecl.INTERNAL_PARAMETER));
174
- entityDecl.defineConstant("EXTERNAL_PARAMETER", RubyFixnum.newFixnum(ruby, XmlEntityDecl.EXTERNAL_PARAMETER));
175
- entityDecl.defineConstant("INTERNAL_PREDEFINED", RubyFixnum.newFixnum(ruby, XmlEntityDecl.INTERNAL_PREDEFINED));
176
-
177
- RubyClass entref = xmlModule.defineClassUnder("EntityReference", node, XML_ENTITY_REFERENCE_ALLOCATOR);
178
- entref.defineAnnotatedMethods(XmlEntityReference.class);
179
-
180
- RubyClass namespace = xmlModule.defineClassUnder("Namespace", ruby.getObject(), XML_NAMESPACE_ALLOCATOR);
181
- namespace.defineAnnotatedMethods(XmlNamespace.class);
182
-
183
- RubyClass nodeSet = xmlModule.defineClassUnder("NodeSet", ruby.getObject(), XML_NODESET_ALLOCATOR);
184
- nodeSet.defineAnnotatedMethods(XmlNodeSet.class);
185
-
186
- RubyClass pi = xmlModule.defineClassUnder("ProcessingInstruction", node, XML_PROCESSING_INSTRUCTION_ALLOCATOR);
187
- pi.defineAnnotatedMethods(XmlProcessingInstruction.class);
188
-
189
- RubyClass reader = xmlModule.defineClassUnder("Reader", ruby.getObject(), XML_READER_ALLOCATOR);
190
- reader.defineAnnotatedMethods(XmlReader.class);
191
-
192
- RubyClass schema = xmlModule.defineClassUnder("Schema", ruby.getObject(), XML_SCHEMA_ALLOCATOR);
193
- schema.defineAnnotatedMethods(XmlSchema.class);
194
-
195
- RubyClass relaxng = xmlModule.defineClassUnder("RelaxNG", schema, XML_RELAXNG_ALLOCATOR);
196
- relaxng.defineAnnotatedMethods(XmlRelaxng.class);
197
-
198
- RubyClass xpathContext = xmlModule.defineClassUnder("XPathContext", ruby.getObject(), XML_XPATHCONTEXT_ALLOCATOR);
199
- xpathContext.defineAnnotatedMethods(XmlXpathContext.class);
200
-
201
- return node;
579
+ };
580
+
581
+ public static final ObjectAllocator XML_SAXPARSER_CONTEXT_ALLOCATOR = new ObjectAllocator()
582
+ {
583
+ private XmlSaxParserContext xmlSaxParserContext = null;
584
+ public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
585
+ if (xmlSaxParserContext == null) { xmlSaxParserContext = new XmlSaxParserContext(runtime, klazz); }
586
+ try {
587
+ XmlSaxParserContext clone = (XmlSaxParserContext) xmlSaxParserContext.clone();
588
+ clone.setMetaClass(klazz);
589
+ return clone;
590
+ } catch (CloneNotSupportedException e) {
591
+ return new XmlSaxParserContext(runtime, klazz);
592
+ }
202
593
  }
594
+ };
203
595
 
204
- private void createHtmlModule(Ruby ruby, RubyModule htmlModule) {
205
- RubyClass htmlElemDesc = htmlModule.defineClassUnder("ElementDescription", ruby.getObject(), HTML_ELEMENT_DESCRIPTION_ALLOCATOR);
206
- htmlElemDesc.defineAnnotatedMethods(HtmlElementDescription.class);
207
-
208
- RubyClass htmlEntityLookup = htmlModule.defineClassUnder("EntityLookup", ruby.getObject(), HTML_ENTITY_LOOKUP_ALLOCATOR);
209
- htmlEntityLookup.defineAnnotatedMethods(HtmlEntityLookup.class);
596
+ private static final ObjectAllocator XML_SAXPUSHPARSER_ALLOCATOR = new ObjectAllocator()
597
+ {
598
+ public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
599
+ return new XmlSaxPushParser(runtime, klazz);
210
600
  }
211
-
212
- private void createDocuments(Ruby ruby, RubyModule xmlModule, RubyModule htmlModule, RubyClass node) {
213
- RubyClass xmlDocument = xmlModule.defineClassUnder("Document", node, XML_DOCUMENT_ALLOCATOR);
214
- xmlDocument.defineAnnotatedMethods(XmlDocument.class);
215
-
216
- //RubyModule htmlDoc = html.defineOrGetClassUnder("Document", document);
217
- RubyModule htmlDocument = htmlModule.defineClassUnder("Document", xmlDocument, HTML_DOCUMENT_ALLOCATOR);
218
- htmlDocument.defineAnnotatedMethods(HtmlDocument.class);
601
+ };
602
+
603
+ private static final ObjectAllocator HTML_SAXPUSHPARSER_ALLOCATOR = new ObjectAllocator()
604
+ {
605
+ public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
606
+ return new HtmlSaxPushParser(runtime, klazz);
219
607
  }
220
-
221
- private void createSaxModule(Ruby ruby, RubyModule xmlSaxModule, RubyModule htmlSaxModule) {
222
- RubyClass xmlSaxParserContext = xmlSaxModule.defineClassUnder("ParserContext", ruby.getObject(), XML_SAXPARSER_CONTEXT_ALLOCATOR);
223
- xmlSaxParserContext.defineAnnotatedMethods(XmlSaxParserContext.class);
224
-
225
- RubyClass xmlSaxPushParser = xmlSaxModule.defineClassUnder("PushParser", ruby.getObject(), XML_SAXPUSHPARSER_ALLOCATOR);
226
- xmlSaxPushParser.defineAnnotatedMethods(XmlSaxPushParser.class);
227
-
228
- RubyClass htmlSaxPushParser = htmlSaxModule.defineClassUnder("PushParser", ruby.getObject(), HTML_SAXPUSHPARSER_ALLOCATOR);
229
- htmlSaxPushParser.defineAnnotatedMethods(HtmlSaxPushParser.class);
230
-
231
- RubyClass htmlSaxParserContext = htmlSaxModule.defineClassUnder("ParserContext", xmlSaxParserContext, HTML_SAXPARSER_CONTEXT_ALLOCATOR);
232
- htmlSaxParserContext.defineAnnotatedMethods(HtmlSaxParserContext.class);
608
+ };
609
+
610
+ public static final ObjectAllocator XML_SCHEMA_ALLOCATOR = new ObjectAllocator()
611
+ {
612
+ private XmlSchema xmlSchema = null;
613
+ public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
614
+ if (xmlSchema == null) { xmlSchema = new XmlSchema(runtime, klazz); }
615
+ try {
616
+ XmlSchema clone = (XmlSchema) xmlSchema.clone();
617
+ clone.setMetaClass(klazz);
618
+ return clone;
619
+ } catch (CloneNotSupportedException e) {
620
+ return new XmlSchema(runtime, klazz);
621
+ }
233
622
  }
234
-
235
- private void createXsltModule(Ruby ruby, RubyModule xsltModule) {
236
- RubyClass stylesheet = xsltModule.defineClassUnder("Stylesheet", ruby.getObject(), XSLT_STYLESHEET_ALLOCATOR);
237
- stylesheet.defineAnnotatedMethods(XsltStylesheet.class);
238
- xsltModule.defineAnnotatedMethod(XsltStylesheet.class, "register");
623
+ };
624
+
625
+ public static final ObjectAllocator XML_SYNTAXERROR_ALLOCATOR = new ObjectAllocator()
626
+ {
627
+ public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
628
+ return new XmlSyntaxError(runtime, klazz);
239
629
  }
630
+ };
631
+
632
+ public static final ObjectAllocator XML_TEXT_ALLOCATOR = new ObjectAllocator()
633
+ {
634
+ private XmlText xmlText = null;
635
+ public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
636
+ if (xmlText == null) { xmlText = new XmlText(runtime, klazz); }
637
+ try {
638
+ XmlText clone = (XmlText) xmlText.clone();
639
+ clone.setMetaClass(klazz);
640
+ return clone;
641
+ } catch (CloneNotSupportedException e) {
642
+ return new XmlText(runtime, klazz);
643
+ }
644
+ }
645
+ };
240
646
 
241
- private static ObjectAllocator ENCODING_HANDLER_ALLOCATOR = new ObjectAllocator() {
242
- public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
243
- return new EncodingHandler(runtime, klazz, "");
244
- }
245
- };
246
-
247
- public static final ObjectAllocator HTML_DOCUMENT_ALLOCATOR = new ObjectAllocator() {
248
- private HtmlDocument htmlDocument = null;
249
- public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
250
- if (htmlDocument == null) htmlDocument = new HtmlDocument(runtime, klazz);
251
- try {
252
- HtmlDocument clone = (HtmlDocument) htmlDocument.clone();
253
- clone.setMetaClass(klazz);
254
- return clone;
255
- } catch (CloneNotSupportedException e) {
256
- return new HtmlDocument(runtime, klazz);
257
- }
258
- }
259
- };
260
-
261
- private static final ObjectAllocator HTML_SAXPARSER_CONTEXT_ALLOCATOR = new ObjectAllocator() {
262
- private HtmlSaxParserContext htmlSaxParserContext = null;
263
- public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
264
- if (htmlSaxParserContext == null) htmlSaxParserContext = new HtmlSaxParserContext(runtime, klazz);
265
- try {
266
- HtmlSaxParserContext clone = (HtmlSaxParserContext) htmlSaxParserContext.clone();
267
- clone.setMetaClass(klazz);
268
- return clone;
269
- } catch (CloneNotSupportedException e) {
270
- return new HtmlSaxParserContext(runtime, klazz);
271
- }
272
- }
273
- };
274
-
275
- private static ObjectAllocator HTML_ELEMENT_DESCRIPTION_ALLOCATOR =
276
- new ObjectAllocator() {
277
- public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
278
- return new HtmlElementDescription(runtime, klazz);
279
- }
280
- };
281
-
282
- private static ObjectAllocator HTML_ENTITY_LOOKUP_ALLOCATOR =
283
- new ObjectAllocator() {
284
- public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
285
- return new HtmlEntityLookup(runtime, klazz);
286
- }
287
- };
288
-
289
- public static final ObjectAllocator XML_ATTR_ALLOCATOR = new ObjectAllocator() {
290
- private XmlAttr xmlAttr = null;
291
- public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
292
- if (xmlAttr == null) xmlAttr = new XmlAttr(runtime, klazz);
293
- try {
294
- XmlAttr clone = (XmlAttr) xmlAttr.clone();
295
- clone.setMetaClass(klazz);
296
- return clone;
297
- } catch (CloneNotSupportedException e) {
298
- return new XmlAttr(runtime, klazz);
299
- }
300
- }
301
- };
302
-
303
- public static final ObjectAllocator XML_CDATA_ALLOCATOR = new ObjectAllocator() {
304
- private XmlCdata xmlCdata = null;
305
- public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
306
- if (xmlCdata == null) xmlCdata = new XmlCdata(runtime, klazz);
307
- try {
308
- XmlCdata clone = (XmlCdata) xmlCdata.clone();
309
- clone.setMetaClass(klazz);
310
- return clone;
311
- } catch (CloneNotSupportedException e) {
312
- return new XmlCdata(runtime, klazz);
313
- }
314
- }
315
- };
316
-
317
- public static final ObjectAllocator XML_COMMENT_ALLOCATOR = new ObjectAllocator() {
318
- private XmlComment xmlComment = null;
319
- public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
320
- if (xmlComment == null) xmlComment = new XmlComment(runtime, klazz);
321
- try {
322
- XmlComment clone = (XmlComment) xmlComment.clone();
323
- clone.setMetaClass(klazz);
324
- return clone;
325
- } catch (CloneNotSupportedException e) {
326
- return new XmlComment(runtime, klazz);
327
- }
328
- }
329
- };
330
-
331
- public static final ObjectAllocator XML_DOCUMENT_ALLOCATOR = new ObjectAllocator() {
332
- private XmlDocument xmlDocument = null;
333
- public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
334
- if (xmlDocument == null) xmlDocument = new XmlDocument(runtime, klazz);
335
- try {
336
- XmlDocument clone = (XmlDocument) xmlDocument.clone();
337
- clone.setMetaClass(klazz);
338
- return clone;
339
- } catch (CloneNotSupportedException e) {
340
- return new XmlDocument(runtime, klazz);
341
- }
342
- }
343
- };
344
-
345
- public static final ObjectAllocator XML_DOCUMENT_FRAGMENT_ALLOCATOR = new ObjectAllocator() {
346
- private XmlDocumentFragment xmlDocumentFragment = null;
347
- public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
348
- if (xmlDocumentFragment == null) xmlDocumentFragment = new XmlDocumentFragment(runtime, klazz);
349
- try {
350
- XmlDocumentFragment clone = (XmlDocumentFragment)xmlDocumentFragment.clone();
351
- clone.setMetaClass(klazz);
352
- return clone;
353
- } catch (CloneNotSupportedException e) {
354
- return new XmlDocumentFragment(runtime, klazz);
355
- }
356
- }
357
- };
358
-
359
- public static final ObjectAllocator XML_DTD_ALLOCATOR = new ObjectAllocator() {
360
- private XmlDtd xmlDtd = null;
361
- public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
362
- if (xmlDtd == null) xmlDtd = new XmlDtd(runtime, klazz);
363
- try {
364
- XmlDtd clone = (XmlDtd)xmlDtd.clone();
365
- clone.setMetaClass(klazz);
366
- return clone;
367
- } catch (CloneNotSupportedException e) {
368
- return new XmlDtd(runtime, klazz);
369
- }
370
- }
371
- };
372
-
373
- public static final ObjectAllocator XML_ELEMENT_ALLOCATOR = new ObjectAllocator() {
374
- private XmlElement xmlElement = null;
375
- public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
376
- if (xmlElement == null) xmlElement = new XmlElement(runtime, klazz);
377
- try {
378
- XmlElement clone = (XmlElement)xmlElement.clone();
379
- clone.setMetaClass(klazz);
380
- return clone;
381
- } catch (CloneNotSupportedException e) {
382
- return new XmlElement(runtime, klazz);
383
- }
384
- }
385
- };
386
-
387
- public static ObjectAllocator XML_ELEMENT_DECL_ALLOCATOR = new ObjectAllocator() {
388
- private XmlElementDecl xmlElementDecl = null;
389
- public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
390
- if (xmlElementDecl == null) xmlElementDecl = new XmlElementDecl(runtime, klazz);
391
- try {
392
- XmlElementDecl clone = (XmlElementDecl)xmlElementDecl.clone();
393
- clone.setMetaClass(klazz);
394
- return clone;
395
- } catch (CloneNotSupportedException e) {
396
- return new XmlElementDecl(runtime, klazz);
397
- }
398
- }
399
- };
400
-
401
- public static ObjectAllocator XML_ENTITY_REFERENCE_ALLOCATOR = new ObjectAllocator() {
402
- private XmlEntityReference xmlEntityRef = null;
403
- public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
404
- if (xmlEntityRef == null) xmlEntityRef = new XmlEntityReference(runtime, klazz);
405
- try {
406
- XmlEntityReference clone = (XmlEntityReference)xmlEntityRef.clone();
407
- clone.setMetaClass(klazz);
408
- return clone;
409
- } catch (CloneNotSupportedException e) {
410
- return new XmlEntityReference(runtime, klazz);
411
- }
412
- }
413
- };
414
-
415
- public static final ObjectAllocator XML_NAMESPACE_ALLOCATOR = new ObjectAllocator() {
416
- private XmlNamespace xmlNamespace = null;
417
- public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
418
- if (xmlNamespace == null) xmlNamespace = new XmlNamespace(runtime, klazz);
419
- try {
420
- XmlNamespace clone = (XmlNamespace) xmlNamespace.clone();
421
- clone.setMetaClass(klazz);
422
- return clone;
423
- } catch (CloneNotSupportedException e) {
424
- return new XmlNamespace(runtime, klazz);
425
- }
426
- }
427
- };
428
-
429
- public static final ObjectAllocator XML_NODE_ALLOCATOR = new ObjectAllocator() {
430
- private XmlNode xmlNode = null;
431
- public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
432
- if (xmlNode == null) xmlNode = new XmlNode(runtime, klazz);
433
- try {
434
- XmlNode clone = (XmlNode) xmlNode.clone();
435
- clone.setMetaClass(klazz);
436
- return clone;
437
- } catch (CloneNotSupportedException e) {
438
- return new XmlNode(runtime, klazz);
439
- }
440
- }
441
- };
442
-
443
- public static final ObjectAllocator XML_NODESET_ALLOCATOR = new ObjectAllocator() {
444
- private XmlNodeSet xmlNodeSet = null;
445
- public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
446
- if (xmlNodeSet == null) xmlNodeSet = new XmlNodeSet(runtime, klazz);
447
- try {
448
- XmlNodeSet clone = (XmlNodeSet) xmlNodeSet.clone();
449
- clone.setMetaClass(klazz);
450
- return clone;
451
- } catch (CloneNotSupportedException e) {
452
- return new XmlNodeSet(runtime, klazz);
453
- }
454
- }
455
- };
456
-
457
- public static ObjectAllocator XML_PROCESSING_INSTRUCTION_ALLOCATOR = new ObjectAllocator() {
458
- private XmlProcessingInstruction xmlProcessingInstruction = null;
459
- public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
460
- if (xmlProcessingInstruction == null) xmlProcessingInstruction = new XmlProcessingInstruction(runtime, klazz);
461
- try {
462
- XmlProcessingInstruction clone = (XmlProcessingInstruction)xmlProcessingInstruction.clone();
463
- clone.setMetaClass(klazz);
464
- return clone;
465
- } catch (CloneNotSupportedException e) {
466
- return new XmlProcessingInstruction(runtime, klazz);
467
- }
468
- }
469
- };
470
-
471
- public static ObjectAllocator XML_READER_ALLOCATOR = new ObjectAllocator() {
472
- private XmlReader xmlReader = null;
473
- public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
474
- if (xmlReader == null) xmlReader = new XmlReader(runtime, klazz);
475
- try {
476
- XmlReader clone = (XmlReader) xmlReader.clone();
477
- clone.setMetaClass(klazz);
478
- return clone;
479
- } catch (CloneNotSupportedException e) {
480
- xmlReader = new XmlReader(runtime, klazz);
481
- return xmlReader;
482
- }
483
- }
484
- };
485
-
486
- private static ObjectAllocator XML_ATTRIBUTE_DECL_ALLOCATOR = new ObjectAllocator() {
487
- public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
488
- return new XmlAttributeDecl(runtime, klazz);
489
- }
490
- };
491
-
492
- private static ObjectAllocator XML_ENTITY_DECL_ALLOCATOR = new ObjectAllocator() {
493
- public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
494
- return new XmlEntityDecl(runtime, klazz);
495
- }
496
- };
497
-
498
- private static ObjectAllocator XML_ELEMENT_CONTENT_ALLOCATOR = new ObjectAllocator() {
499
- public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
500
- throw runtime.newNotImplementedError("not implemented");
501
- }
502
- };
503
-
504
- public static final ObjectAllocator XML_RELAXNG_ALLOCATOR = new ObjectAllocator() {
505
- private XmlRelaxng xmlRelaxng = null;
506
- public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
507
- if (xmlRelaxng == null) xmlRelaxng = new XmlRelaxng(runtime, klazz);
508
- try {
509
- XmlRelaxng clone = (XmlRelaxng) xmlRelaxng.clone();
510
- clone.setMetaClass(klazz);
511
- return clone;
512
- } catch (CloneNotSupportedException e) {
513
- return new XmlRelaxng(runtime, klazz);
514
- }
515
- }
516
- };
517
-
518
- public static final ObjectAllocator XML_SAXPARSER_CONTEXT_ALLOCATOR = new ObjectAllocator() {
519
- private XmlSaxParserContext xmlSaxParserContext = null;
520
- public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
521
- if (xmlSaxParserContext == null) xmlSaxParserContext = new XmlSaxParserContext(runtime, klazz);
522
- try {
523
- XmlSaxParserContext clone = (XmlSaxParserContext) xmlSaxParserContext.clone();
524
- clone.setMetaClass(klazz);
525
- return clone;
526
- } catch (CloneNotSupportedException e) {
527
- return new XmlSaxParserContext(runtime, klazz);
528
- }
529
- }
530
- };
531
-
532
- private static final ObjectAllocator XML_SAXPUSHPARSER_ALLOCATOR = new ObjectAllocator() {
533
- public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
534
- return new XmlSaxPushParser(runtime, klazz);
535
- }
536
- };
537
-
538
- private static final ObjectAllocator HTML_SAXPUSHPARSER_ALLOCATOR = new ObjectAllocator() {
539
- public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
540
- return new HtmlSaxPushParser(runtime, klazz);
541
- }
542
- };
543
-
544
- public static final ObjectAllocator XML_SCHEMA_ALLOCATOR = new ObjectAllocator() {
545
- private XmlSchema xmlSchema = null;
546
- public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
547
- if (xmlSchema == null) xmlSchema = new XmlSchema(runtime, klazz);
548
- try {
549
- XmlSchema clone = (XmlSchema) xmlSchema.clone();
550
- clone.setMetaClass(klazz);
551
- return clone;
552
- } catch (CloneNotSupportedException e) {
553
- return new XmlSchema(runtime, klazz);
554
- }
555
- }
556
- };
557
-
558
- public static final ObjectAllocator XML_SYNTAXERROR_ALLOCATOR = new ObjectAllocator() {
559
- public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
560
- return new XmlSyntaxError(runtime, klazz);
561
- }
562
- };
563
-
564
- public static final ObjectAllocator XML_TEXT_ALLOCATOR = new ObjectAllocator() {
565
- private XmlText xmlText = null;
566
- public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
567
- if (xmlText == null) xmlText = new XmlText(runtime, klazz);
568
- try {
569
- XmlText clone = (XmlText) xmlText.clone();
570
- clone.setMetaClass(klazz);
571
- return clone;
572
- } catch (CloneNotSupportedException e) {
573
- return new XmlText(runtime, klazz);
574
- }
575
- }
576
- };
577
-
578
- public static final ObjectAllocator XML_XPATHCONTEXT_ALLOCATOR = new ObjectAllocator() {
579
- public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
580
- return new XmlXpathContext(runtime, klazz);
581
- }
582
- };
583
-
584
- public static ObjectAllocator XSLT_STYLESHEET_ALLOCATOR = new ObjectAllocator() {
585
- private XsltStylesheet xsltStylesheet = null;
586
- public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
587
- if (xsltStylesheet == null) xsltStylesheet = new XsltStylesheet(runtime, klazz);
588
- try {
589
- XsltStylesheet clone = (XsltStylesheet) xsltStylesheet.clone();
590
- clone.setMetaClass(klazz);
591
- return clone;
592
- } catch (CloneNotSupportedException e) {
593
- return new XmlText(runtime, klazz);
594
- }
595
- }
596
- };
647
+ public static final ObjectAllocator XML_XPATHCONTEXT_ALLOCATOR = new ObjectAllocator()
648
+ {
649
+ public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
650
+ return new XmlXpathContext(runtime, klazz);
651
+ }
652
+ };
653
+
654
+ public static ObjectAllocator XSLT_STYLESHEET_ALLOCATOR = new ObjectAllocator()
655
+ {
656
+ private XsltStylesheet xsltStylesheet = null;
657
+ public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
658
+ if (xsltStylesheet == null) { xsltStylesheet = new XsltStylesheet(runtime, klazz); }
659
+ try {
660
+ XsltStylesheet clone = (XsltStylesheet) xsltStylesheet.clone();
661
+ clone.setMetaClass(klazz);
662
+ return clone;
663
+ } catch (CloneNotSupportedException e) {
664
+ return new XmlText(runtime, klazz);
665
+ }
666
+ }
667
+ };
597
668
  }