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.

Files changed (107) hide show
  1. data/.gemtest +0 -0
  2. data/CHANGELOG.ja.rdoc +34 -0
  3. data/CHANGELOG.rdoc +40 -1
  4. data/Manifest.txt +11 -2
  5. data/README.rdoc +1 -1
  6. data/Rakefile +100 -104
  7. data/bin/nokogiri +1 -2
  8. data/ext/nokogiri/nokogiri.c +24 -1
  9. data/ext/nokogiri/xml_io.c +32 -7
  10. data/ext/nokogiri/xml_node.c +14 -13
  11. data/ext/nokogiri/xml_sax_parser.c +9 -4
  12. data/ext/nokogiri/xslt_stylesheet.c +7 -1
  13. data/lib/nokogiri.rb +3 -22
  14. data/lib/nokogiri/css.rb +4 -0
  15. data/lib/nokogiri/html/document.rb +10 -14
  16. data/lib/nokogiri/version.rb +76 -23
  17. data/lib/nokogiri/xml/builder.rb +7 -0
  18. data/lib/nokogiri/xml/document.rb +17 -1
  19. data/lib/nokogiri/xml/document_fragment.rb +14 -0
  20. data/lib/nokogiri/xml/node.rb +36 -28
  21. data/lib/nokogiri/xml/node/save_options.rb +17 -1
  22. data/lib/nokogiri/xml/node_set.rb +7 -0
  23. data/lib/nokogiri/xml/parse_options.rb +8 -0
  24. data/lib/nokogiri/xml/reader.rb +6 -6
  25. data/lib/nokogiri/xml/schema.rb +7 -1
  26. data/nokogiri_help_responses.md +40 -0
  27. data/tasks/cross_compile.rb +134 -159
  28. data/tasks/nokogiri.org.rb +18 -0
  29. data/tasks/test.rb +1 -1
  30. data/test/files/encoding.html +82 -0
  31. data/test/files/encoding.xhtml +84 -0
  32. data/test/files/metacharset.html +10 -0
  33. data/test/files/noencoding.html +47 -0
  34. data/test/helper.rb +2 -0
  35. data/test/html/test_document.rb +15 -0
  36. data/test/html/test_document_encoding.rb +13 -0
  37. data/test/test_memory_leak.rb +20 -0
  38. data/test/test_reader.rb +22 -0
  39. data/test/test_xslt_transforms.rb +6 -2
  40. data/test/xml/node/test_save_options.rb +10 -2
  41. data/test/xml/test_builder.rb +17 -0
  42. data/test/xml/test_document.rb +22 -0
  43. data/test/xml/test_node.rb +19 -1
  44. data/test/xml/test_node_reparenting.rb +16 -3
  45. data/test/xml/test_node_set.rb +34 -0
  46. data/test/xml/test_schema.rb +5 -0
  47. data/test/xslt/test_exception_handling.rb +37 -0
  48. metadata +185 -157
  49. data/deps.rip +0 -5
  50. data/ext/java/nokogiri/EncodingHandler.java +0 -124
  51. data/ext/java/nokogiri/HtmlDocument.java +0 -149
  52. data/ext/java/nokogiri/HtmlElementDescription.java +0 -145
  53. data/ext/java/nokogiri/HtmlEntityLookup.java +0 -79
  54. data/ext/java/nokogiri/HtmlSaxParserContext.java +0 -259
  55. data/ext/java/nokogiri/NokogiriService.java +0 -535
  56. data/ext/java/nokogiri/XmlAttr.java +0 -191
  57. data/ext/java/nokogiri/XmlAttributeDecl.java +0 -130
  58. data/ext/java/nokogiri/XmlCdata.java +0 -91
  59. data/ext/java/nokogiri/XmlComment.java +0 -86
  60. data/ext/java/nokogiri/XmlDocument.java +0 -529
  61. data/ext/java/nokogiri/XmlDocumentFragment.java +0 -217
  62. data/ext/java/nokogiri/XmlDtd.java +0 -467
  63. data/ext/java/nokogiri/XmlElement.java +0 -222
  64. data/ext/java/nokogiri/XmlElementContent.java +0 -382
  65. data/ext/java/nokogiri/XmlElementDecl.java +0 -148
  66. data/ext/java/nokogiri/XmlEntityDecl.java +0 -162
  67. data/ext/java/nokogiri/XmlEntityReference.java +0 -75
  68. data/ext/java/nokogiri/XmlNamespace.java +0 -128
  69. data/ext/java/nokogiri/XmlNode.java +0 -1399
  70. data/ext/java/nokogiri/XmlNodeSet.java +0 -311
  71. data/ext/java/nokogiri/XmlProcessingInstruction.java +0 -103
  72. data/ext/java/nokogiri/XmlReader.java +0 -411
  73. data/ext/java/nokogiri/XmlRelaxng.java +0 -144
  74. data/ext/java/nokogiri/XmlSaxParserContext.java +0 -367
  75. data/ext/java/nokogiri/XmlSaxPushParser.java +0 -184
  76. data/ext/java/nokogiri/XmlSchema.java +0 -319
  77. data/ext/java/nokogiri/XmlSyntaxError.java +0 -119
  78. data/ext/java/nokogiri/XmlText.java +0 -136
  79. data/ext/java/nokogiri/XmlXpathContext.java +0 -179
  80. data/ext/java/nokogiri/XsltStylesheet.java +0 -183
  81. data/ext/java/nokogiri/internals/HtmlDomParserContext.java +0 -206
  82. data/ext/java/nokogiri/internals/NokogiriDocumentCache.java +0 -73
  83. data/ext/java/nokogiri/internals/NokogiriErrorHandler.java +0 -86
  84. data/ext/java/nokogiri/internals/NokogiriHandler.java +0 -327
  85. data/ext/java/nokogiri/internals/NokogiriHelpers.java +0 -582
  86. data/ext/java/nokogiri/internals/NokogiriNamespaceCache.java +0 -171
  87. data/ext/java/nokogiri/internals/NokogiriNamespaceContext.java +0 -118
  88. data/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler.java +0 -74
  89. data/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler4NekoHtml.java +0 -121
  90. data/ext/java/nokogiri/internals/NokogiriStrictErrorHandler.java +0 -79
  91. data/ext/java/nokogiri/internals/NokogiriXPathFunction.java +0 -126
  92. data/ext/java/nokogiri/internals/NokogiriXPathFunctionResolver.java +0 -56
  93. data/ext/java/nokogiri/internals/ParserContext.java +0 -278
  94. data/ext/java/nokogiri/internals/PushInputStream.java +0 -411
  95. data/ext/java/nokogiri/internals/ReaderNode.java +0 -474
  96. data/ext/java/nokogiri/internals/SaveContext.java +0 -288
  97. data/ext/java/nokogiri/internals/SchemaErrorHandler.java +0 -76
  98. data/ext/java/nokogiri/internals/XmlDeclHandler.java +0 -42
  99. data/ext/java/nokogiri/internals/XmlDomParser.java +0 -77
  100. data/ext/java/nokogiri/internals/XmlDomParserContext.java +0 -238
  101. data/ext/java/nokogiri/internals/XmlSaxParser.java +0 -65
  102. data/ext/java/nokogiri/internals/XsltExtensionFunction.java +0 -72
  103. data/lib/isorelax.jar +0 -0
  104. data/lib/jing.jar +0 -0
  105. data/lib/nekodtd.jar +0 -0
  106. data/lib/nekohtml.jar +0 -0
  107. data/lib/xercesImpl.jar +0 -0
@@ -1,288 +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.internals;
34
-
35
- import static nokogiri.internals.NokogiriHelpers.getNokogiriClass;
36
-
37
- import java.nio.charset.Charset;
38
-
39
- import org.jruby.Ruby;
40
- import org.jruby.RubyClass;
41
- import org.jruby.RubyEncoding;
42
- import org.jruby.RubyString;
43
- import org.jruby.javasupport.util.RuntimeHelpers;
44
- import org.jruby.runtime.ThreadContext;
45
- import org.jruby.runtime.builtin.IRubyObject;
46
- import org.jruby.util.ByteList;
47
-
48
- /**
49
- * A class for serializing a document.
50
- *
51
- * @author sergio
52
- * @author Patrick Mahoney <pat@polycrystal.org>
53
- * @author Yoko Harada <yokolet@gmail.com>
54
- */
55
- public class SaveContext {
56
-
57
- private final ThreadContext context;
58
- private final RubyClass elementDescription;
59
- private StringBuffer buffer;
60
- private int options;
61
- private int level=0;
62
- private String encoding, indentString;
63
- private boolean format, noDecl, noEmpty, noXhtml, xhtml, asXml, asHtml;
64
-
65
- /*
66
- * U can't touch this.
67
- * http://www.youtube.com/watch?v=WJ2ZFVx6A4Q
68
- *
69
- * Taken from libxml save options.
70
- */
71
-
72
- public static final int FORMAT = 1;
73
- public static final int NO_DECL = 2;
74
- public static final int NO_EMPTY = 4;
75
- public static final int NO_XHTML = 8;
76
- public static final int XHTML = 16;
77
- public static final int AS_XML = 32;
78
- public static final int AS_HTML = 64;
79
-
80
- public SaveContext(ThreadContext context, int options, String indentString, String encoding) {
81
- this.context = context;
82
- this.elementDescription = (RubyClass)getNokogiriClass(context.getRuntime(), "Nokogiri::HTML::ElementDescription");
83
- this.options = options;
84
- this.encoding = encoding;
85
- this.indentString = indentString;
86
- this.buffer = new StringBuffer();
87
- format = (options & FORMAT) == FORMAT;
88
- noDecl = (options & NO_DECL) == NO_DECL;
89
- noEmpty = (options & NO_EMPTY) == NO_EMPTY;
90
- noXhtml = (options & NO_XHTML) == NO_XHTML;
91
- xhtml = (options & XHTML) == XHTML;
92
- asXml = (options & AS_XML) == AS_XML;
93
- asHtml = (options & AS_HTML) == AS_HTML;
94
- }
95
-
96
- public void append(String s) {
97
- this.buffer.append(s);
98
- }
99
-
100
- public void append(char c) {
101
- buffer.append(c);
102
- }
103
-
104
- public void append(StringBuffer sb) {
105
- this.buffer.append(sb);
106
- }
107
-
108
- public void appendQuoted(String s) {
109
- this.append("\"");
110
- this.append(s);
111
- this.append("\"");
112
- }
113
-
114
- public void appendQuoted(StringBuffer sb) {
115
- this.append("\"");
116
- this.append(sb);
117
- this.append("\"");
118
- }
119
-
120
- public void emptyTag(String name) {
121
- emptyTagStart(name);
122
- emptyTagEnd(name);
123
- }
124
-
125
- public void emptyTagStart(String name) {
126
- openTagInlineStart(name);
127
- }
128
-
129
- public void emptyTagEnd(String name) {
130
- if (asHtml) {
131
- if (isEmpty(name) && noEmpty()) {
132
- append(">");
133
- } else {
134
- openTagInlineEnd();
135
- closeTagInline(name);
136
- }
137
- } else if (xhtml) {
138
- append(" />");
139
- } else {
140
- append("/>");
141
- }
142
- }
143
-
144
- public void openTag(String name) {
145
- openTagStart(name);
146
- openTagEnd();
147
- }
148
-
149
- public void openTagStart(String name) {
150
- maybeBreak();
151
- indent();
152
- append("<");
153
- append(name);
154
- }
155
-
156
- public void openTagEnd() {
157
- append(">");
158
- maybeBreak();
159
- increaseLevel();
160
- }
161
-
162
- public void closeTag(String name) {
163
- decreaseLevel();
164
- maybeBreak();
165
- indent();
166
- append("</");
167
- append(name);
168
- append(">");
169
- maybeBreak();
170
- }
171
-
172
- public void openTagInline(String name) {
173
- openTagInlineStart(name);
174
- openTagInlineEnd();
175
- }
176
-
177
- public void openTagInlineStart(String name) {
178
- maybeIndent();
179
- append("<");
180
- append(name);
181
- }
182
-
183
- public void openTagInlineEnd() {
184
- append(">");
185
- }
186
-
187
- public void closeTagInline(String name) {
188
- append("</");
189
- append(name);
190
- append(">");
191
- }
192
-
193
- public void maybeBreak() {
194
- if (format && !endsInNewline()) append('\n');
195
- }
196
-
197
- public void maybeSpace() {
198
- if (!endsInWhitespace()) append(' ');
199
- }
200
-
201
- /**
202
- * Indent if this is the start of a fresh line.
203
- */
204
- public void maybeIndent() {
205
- if (format && endsInNewline()) indent();
206
- }
207
-
208
- public void indent() {
209
- if (format) append(getCurrentIndentString());
210
- }
211
-
212
- public boolean endsInWhitespace() {
213
- return (Character.isWhitespace(lastChar()));
214
- }
215
-
216
- public boolean endsInNewline() {
217
- return (lastChar() == '\n');
218
- }
219
-
220
- public char lastChar() {
221
- if (buffer.length() == 0) return '\n'; // logically, the char
222
- // *before* a text file
223
- // is a newline
224
- return buffer.charAt(buffer.length() - 1);
225
- }
226
-
227
- public boolean asHtml() { return this.asHtml; }
228
-
229
- public boolean asXml() { return this.asXml; }
230
-
231
- public void decreaseLevel() {
232
- if(this.level > 0) this.level--;
233
- }
234
-
235
- public String encoding() { return this.encoding; }
236
-
237
- public boolean format() { return this.format; }
238
-
239
- public String getCurrentIndentString() {
240
- StringBuffer res = new StringBuffer();
241
- for(int i = 0; i < this.level; i++) {
242
- res.append(this.indentString());
243
- }
244
- return res.toString();
245
- }
246
-
247
- public String getEncoding() { return this.encoding; }
248
-
249
- public void increaseLevel() {
250
- if(this.level >= 0) this.level++;
251
- }
252
-
253
- public String indentString() { return this.indentString; }
254
-
255
- public boolean noDecl() { return this.noDecl; }
256
-
257
- public boolean noEmpty() { return this.noEmpty; }
258
-
259
- public boolean noXhtml() { return this.noXhtml; }
260
-
261
- public void setFormat(boolean format) { this.format = format; }
262
-
263
- public void setLevel(int level) { this.level = level; }
264
-
265
- @Override
266
- public String toString() { return this.buffer.toString(); }
267
-
268
- public RubyString toRubyString(Ruby runtime) {
269
- ByteList bytes;
270
- if (encoding == null) bytes = new ByteList(buffer.toString().getBytes());
271
- else bytes = new ByteList(RubyEncoding.encode(buffer.toString(), Charset.forName(encoding)), false);
272
- return RubyString.newString(runtime, bytes);
273
- }
274
-
275
- public boolean Xhtml() { return this.xhtml; }
276
-
277
- /**
278
- * Looks up the HTML ElementDescription and tests if it is an
279
- * empty element.
280
- */
281
- protected boolean isEmpty(String name) {
282
- IRubyObject desc =
283
- RuntimeHelpers.invoke(context,
284
- elementDescription, "[]",
285
- context.getRuntime().newString(name));
286
- return RuntimeHelpers.invoke(context, desc, "empty?").isTrue();
287
- }
288
- }
@@ -1,76 +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.internals;
34
-
35
- import static nokogiri.internals.NokogiriHelpers.getNokogiriClass;
36
- import nokogiri.NokogiriService;
37
- import nokogiri.XmlSyntaxError;
38
-
39
- import org.jruby.Ruby;
40
- import org.jruby.RubyArray;
41
- import org.xml.sax.ErrorHandler;
42
- import org.xml.sax.SAXException;
43
- import org.xml.sax.SAXParseException;
44
-
45
- /**
46
- * Error handler for Relax and W3C XML Schema.
47
- *
48
- * @author sergio
49
- * @author Yoko Harada <yokolet@gmail.com>
50
- */
51
- public class SchemaErrorHandler implements ErrorHandler{
52
- private RubyArray errors;
53
- private Ruby runtime;
54
-
55
- public SchemaErrorHandler(Ruby ruby, RubyArray array) {
56
- this.runtime = ruby;
57
- this.errors = array;
58
- }
59
-
60
- public void warning(SAXParseException ex) throws SAXException {
61
- XmlSyntaxError xmlSyntaxError = (XmlSyntaxError) NokogiriService.XML_SYNTAXERROR_ALLOCATOR.allocate(runtime, getNokogiriClass(runtime, "Nokogiri::XML::SyntaxError"));
62
- xmlSyntaxError.setException(ex);
63
- this.errors.append(xmlSyntaxError);
64
- }
65
-
66
- public void error(SAXParseException ex) throws SAXException {
67
- XmlSyntaxError xmlSyntaxError = (XmlSyntaxError) NokogiriService.XML_SYNTAXERROR_ALLOCATOR.allocate(runtime, getNokogiriClass(runtime, "Nokogiri::XML::SyntaxError"));
68
- xmlSyntaxError.setException(ex);
69
- this.errors.append(xmlSyntaxError);
70
- }
71
-
72
- public void fatalError(SAXParseException ex) throws SAXException {
73
- throw ex;
74
- }
75
-
76
- }
@@ -1,42 +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.internals;
34
-
35
- /**
36
- * Interface for receiving xmlDecl information.
37
- *
38
- * @author Patrick Mahoney <pat@polycrystal.org>
39
- */
40
- public interface XmlDeclHandler {
41
- public void xmlDecl(String version, String encoding, String standalone);
42
- }
@@ -1,77 +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.internals;
34
-
35
- import java.io.IOException;
36
-
37
- import nokogiri.XmlDocument;
38
-
39
- import org.apache.xerces.parsers.DOMParser;
40
- import org.apache.xerces.xni.parser.XMLParserConfiguration;
41
- import org.cyberneko.dtd.DTDConfiguration;
42
- import org.w3c.dom.Document;
43
- import org.xml.sax.InputSource;
44
- import org.xml.sax.SAXException;
45
-
46
- /**
47
- * Sets up a Xerces/XNI DOM Parser for use with Nokogiri. Uses
48
- * NekoDTD to parse the DTD into a tree of Nodes.
49
- *
50
- * @author Patrick Mahoney <pat@polycrystal.org>
51
- */
52
- public class XmlDomParser extends DOMParser {
53
- DOMParser dtd;
54
-
55
- public XmlDomParser() {
56
- super();
57
-
58
- DTDConfiguration dtdConfig = new DTDConfiguration();
59
- dtd = new DOMParser(dtdConfig);
60
-
61
- XMLParserConfiguration config = getXMLParserConfiguration();
62
- config.setDTDHandler(dtdConfig);
63
- config.setDTDContentModelHandler(dtdConfig);
64
- }
65
-
66
- @Override
67
- public void parse(InputSource source) throws SAXException, IOException {
68
- dtd.reset();
69
- super.parse(source);
70
- Document doc = getDocument();
71
- if (doc == null)
72
- throw new RuntimeException("null document");
73
-
74
- doc.setUserData(XmlDocument.DTD_RAW_DOCUMENT, dtd.getDocument(),
75
- null);
76
- }
77
- }