nokogiri 1.11.0.rc3-java → 1.11.4-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 (187) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +3 -0
  3. data/LICENSE-DEPENDENCIES.md +1015 -947
  4. data/LICENSE.md +1 -1
  5. data/README.md +168 -91
  6. data/dependencies.yml +12 -12
  7. data/ext/java/nokogiri/EncodingHandler.java +76 -89
  8. data/ext/java/nokogiri/HtmlDocument.java +135 -144
  9. data/ext/java/nokogiri/HtmlElementDescription.java +102 -117
  10. data/ext/java/nokogiri/HtmlEntityLookup.java +33 -60
  11. data/ext/java/nokogiri/HtmlSaxParserContext.java +218 -222
  12. data/ext/java/nokogiri/HtmlSaxPushParser.java +162 -169
  13. data/ext/java/nokogiri/NokogiriService.java +595 -556
  14. data/ext/java/nokogiri/XmlAttr.java +118 -126
  15. data/ext/java/nokogiri/XmlAttributeDecl.java +95 -106
  16. data/ext/java/nokogiri/XmlCdata.java +35 -58
  17. data/ext/java/nokogiri/XmlComment.java +46 -67
  18. data/ext/java/nokogiri/XmlDocument.java +645 -572
  19. data/ext/java/nokogiri/XmlDocumentFragment.java +125 -137
  20. data/ext/java/nokogiri/XmlDtd.java +448 -414
  21. data/ext/java/nokogiri/XmlElement.java +23 -48
  22. data/ext/java/nokogiri/XmlElementContent.java +343 -316
  23. data/ext/java/nokogiri/XmlElementDecl.java +124 -125
  24. data/ext/java/nokogiri/XmlEntityDecl.java +119 -127
  25. data/ext/java/nokogiri/XmlEntityReference.java +49 -72
  26. data/ext/java/nokogiri/XmlNamespace.java +175 -175
  27. data/ext/java/nokogiri/XmlNode.java +1843 -1622
  28. data/ext/java/nokogiri/XmlNodeSet.java +361 -331
  29. data/ext/java/nokogiri/XmlProcessingInstruction.java +47 -69
  30. data/ext/java/nokogiri/XmlReader.java +513 -450
  31. data/ext/java/nokogiri/XmlRelaxng.java +89 -101
  32. data/ext/java/nokogiri/XmlSaxParserContext.java +328 -310
  33. data/ext/java/nokogiri/XmlSaxPushParser.java +227 -220
  34. data/ext/java/nokogiri/XmlSchema.java +335 -242
  35. data/ext/java/nokogiri/XmlSyntaxError.java +113 -119
  36. data/ext/java/nokogiri/XmlText.java +55 -76
  37. data/ext/java/nokogiri/XmlXpathContext.java +242 -210
  38. data/ext/java/nokogiri/XsltStylesheet.java +280 -269
  39. data/ext/java/nokogiri/internals/ClosedStreamException.java +5 -2
  40. data/ext/java/nokogiri/internals/HtmlDomParserContext.java +201 -190
  41. data/ext/java/nokogiri/internals/IgnoreSchemaErrorsErrorHandler.java +17 -10
  42. data/ext/java/nokogiri/internals/NokogiriBlockingQueueInputStream.java +43 -16
  43. data/ext/java/nokogiri/internals/NokogiriDomParser.java +63 -80
  44. data/ext/java/nokogiri/internals/NokogiriEntityResolver.java +107 -88
  45. data/ext/java/nokogiri/internals/NokogiriErrorHandler.java +27 -52
  46. data/ext/java/nokogiri/internals/NokogiriHandler.java +316 -286
  47. data/ext/java/nokogiri/internals/NokogiriHelpers.java +736 -652
  48. data/ext/java/nokogiri/internals/NokogiriNamespaceCache.java +184 -173
  49. data/ext/java/nokogiri/internals/NokogiriNamespaceContext.java +79 -89
  50. data/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler.java +64 -79
  51. data/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler4NekoHtml.java +84 -99
  52. data/ext/java/nokogiri/internals/NokogiriStrictErrorHandler.java +48 -65
  53. data/ext/java/nokogiri/internals/NokogiriXPathFunction.java +119 -78
  54. data/ext/java/nokogiri/internals/NokogiriXPathFunctionResolver.java +34 -54
  55. data/ext/java/nokogiri/internals/NokogiriXPathVariableResolver.java +23 -46
  56. data/ext/java/nokogiri/internals/NokogiriXsltErrorListener.java +55 -72
  57. data/ext/java/nokogiri/internals/ParserContext.java +206 -211
  58. data/ext/java/nokogiri/internals/ReaderNode.java +478 -403
  59. data/ext/java/nokogiri/internals/SaveContextVisitor.java +822 -739
  60. data/ext/java/nokogiri/internals/SchemaErrorHandler.java +31 -54
  61. data/ext/java/nokogiri/internals/XalanDTMManagerPatch.java +129 -123
  62. data/ext/java/nokogiri/internals/XmlDeclHandler.java +3 -34
  63. data/ext/java/nokogiri/internals/XmlDomParserContext.java +206 -207
  64. data/ext/java/nokogiri/internals/XmlSaxParser.java +22 -47
  65. data/ext/java/nokogiri/internals/c14n/AttrCompare.java +71 -68
  66. data/ext/java/nokogiri/internals/c14n/C14nHelper.java +137 -118
  67. data/ext/java/nokogiri/internals/c14n/CanonicalFilter.java +27 -21
  68. data/ext/java/nokogiri/internals/c14n/CanonicalizationException.java +74 -61
  69. data/ext/java/nokogiri/internals/c14n/Canonicalizer.java +230 -205
  70. data/ext/java/nokogiri/internals/c14n/Canonicalizer11.java +572 -547
  71. data/ext/java/nokogiri/internals/c14n/Canonicalizer11_OmitComments.java +17 -10
  72. data/ext/java/nokogiri/internals/c14n/Canonicalizer11_WithComments.java +17 -10
  73. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315.java +323 -302
  74. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315Excl.java +232 -219
  75. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315ExclOmitComments.java +22 -15
  76. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315ExclWithComments.java +23 -16
  77. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315OmitComments.java +23 -16
  78. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315WithComments.java +22 -15
  79. data/ext/java/nokogiri/internals/c14n/CanonicalizerBase.java +575 -545
  80. data/ext/java/nokogiri/internals/c14n/CanonicalizerPhysical.java +141 -120
  81. data/ext/java/nokogiri/internals/c14n/CanonicalizerSpi.java +39 -38
  82. data/ext/java/nokogiri/internals/c14n/Constants.java +13 -10
  83. data/ext/java/nokogiri/internals/c14n/ElementProxy.java +279 -247
  84. data/ext/java/nokogiri/internals/c14n/HelperNodeList.java +66 -53
  85. data/ext/java/nokogiri/internals/c14n/IgnoreAllErrorHandler.java +44 -37
  86. data/ext/java/nokogiri/internals/c14n/InclusiveNamespaces.java +135 -120
  87. data/ext/java/nokogiri/internals/c14n/InvalidCanonicalizerException.java +59 -48
  88. data/ext/java/nokogiri/internals/c14n/NameSpaceSymbTable.java +384 -334
  89. data/ext/java/nokogiri/internals/c14n/NodeFilter.java +25 -24
  90. data/ext/java/nokogiri/internals/c14n/UtfHelpper.java +151 -140
  91. data/ext/java/nokogiri/internals/c14n/XMLUtils.java +456 -423
  92. data/ext/java/nokogiri/internals/dom2dtm/DOM2DTM.java +1466 -1500
  93. data/ext/java/nokogiri/internals/dom2dtm/DOM2DTMdefaultNamespaceDeclarationNode.java +626 -574
  94. data/ext/nokogiri/depend +37 -358
  95. data/ext/nokogiri/extconf.rb +581 -374
  96. data/ext/nokogiri/html_document.c +78 -82
  97. data/ext/nokogiri/html_element_description.c +84 -71
  98. data/ext/nokogiri/html_entity_lookup.c +21 -16
  99. data/ext/nokogiri/html_sax_parser_context.c +69 -66
  100. data/ext/nokogiri/html_sax_push_parser.c +42 -34
  101. data/ext/nokogiri/libxml2_backwards_compat.c +121 -0
  102. data/ext/nokogiri/nokogiri.c +192 -93
  103. data/ext/nokogiri/test_global_handlers.c +40 -0
  104. data/ext/nokogiri/xml_attr.c +15 -15
  105. data/ext/nokogiri/xml_attribute_decl.c +18 -18
  106. data/ext/nokogiri/xml_cdata.c +13 -18
  107. data/ext/nokogiri/xml_comment.c +19 -26
  108. data/ext/nokogiri/xml_document.c +246 -188
  109. data/ext/nokogiri/xml_document_fragment.c +13 -15
  110. data/ext/nokogiri/xml_dtd.c +54 -48
  111. data/ext/nokogiri/xml_element_content.c +30 -27
  112. data/ext/nokogiri/xml_element_decl.c +22 -22
  113. data/ext/nokogiri/xml_encoding_handler.c +17 -11
  114. data/ext/nokogiri/xml_entity_decl.c +32 -30
  115. data/ext/nokogiri/xml_entity_reference.c +16 -18
  116. data/ext/nokogiri/xml_namespace.c +56 -49
  117. data/ext/nokogiri/xml_node.c +371 -320
  118. data/ext/nokogiri/xml_node_set.c +168 -156
  119. data/ext/nokogiri/xml_processing_instruction.c +17 -19
  120. data/ext/nokogiri/xml_reader.c +191 -157
  121. data/ext/nokogiri/xml_relax_ng.c +52 -28
  122. data/ext/nokogiri/xml_sax_parser.c +118 -118
  123. data/ext/nokogiri/xml_sax_parser_context.c +103 -86
  124. data/ext/nokogiri/xml_sax_push_parser.c +36 -27
  125. data/ext/nokogiri/xml_schema.c +95 -47
  126. data/ext/nokogiri/xml_syntax_error.c +42 -21
  127. data/ext/nokogiri/xml_text.c +13 -17
  128. data/ext/nokogiri/xml_xpath_context.c +206 -123
  129. data/ext/nokogiri/xslt_stylesheet.c +158 -161
  130. data/lib/nokogiri.rb +3 -7
  131. data/lib/nokogiri/css/parser.rb +3 -3
  132. data/lib/nokogiri/css/parser.y +2 -2
  133. data/lib/nokogiri/css/xpath_visitor.rb +70 -42
  134. data/lib/nokogiri/extension.rb +26 -0
  135. data/lib/nokogiri/html/document.rb +12 -26
  136. data/lib/nokogiri/html/document_fragment.rb +15 -15
  137. data/lib/nokogiri/nokogiri.jar +0 -0
  138. data/lib/nokogiri/version.rb +2 -149
  139. data/lib/nokogiri/version/constant.rb +5 -0
  140. data/lib/nokogiri/version/info.rb +205 -0
  141. data/lib/nokogiri/xml/document.rb +91 -35
  142. data/lib/nokogiri/xml/document_fragment.rb +4 -6
  143. data/lib/nokogiri/xml/node.rb +89 -69
  144. data/lib/nokogiri/xml/parse_options.rb +6 -0
  145. data/lib/nokogiri/xml/reader.rb +2 -9
  146. data/lib/nokogiri/xml/relax_ng.rb +6 -2
  147. data/lib/nokogiri/xml/schema.rb +12 -4
  148. data/lib/nokogiri/xml/searchable.rb +3 -1
  149. data/lib/nokogiri/xml/xpath.rb +1 -3
  150. data/lib/nokogiri/xml/xpath/syntax_error.rb +1 -1
  151. metadata +86 -177
  152. data/ext/nokogiri/html_document.h +0 -10
  153. data/ext/nokogiri/html_element_description.h +0 -10
  154. data/ext/nokogiri/html_entity_lookup.h +0 -8
  155. data/ext/nokogiri/html_sax_parser_context.h +0 -11
  156. data/ext/nokogiri/html_sax_push_parser.h +0 -9
  157. data/ext/nokogiri/nokogiri.h +0 -134
  158. data/ext/nokogiri/xml_attr.h +0 -9
  159. data/ext/nokogiri/xml_attribute_decl.h +0 -9
  160. data/ext/nokogiri/xml_cdata.h +0 -9
  161. data/ext/nokogiri/xml_comment.h +0 -9
  162. data/ext/nokogiri/xml_document.h +0 -23
  163. data/ext/nokogiri/xml_document_fragment.h +0 -10
  164. data/ext/nokogiri/xml_dtd.h +0 -10
  165. data/ext/nokogiri/xml_element_content.h +0 -10
  166. data/ext/nokogiri/xml_element_decl.h +0 -9
  167. data/ext/nokogiri/xml_encoding_handler.h +0 -8
  168. data/ext/nokogiri/xml_entity_decl.h +0 -10
  169. data/ext/nokogiri/xml_entity_reference.h +0 -9
  170. data/ext/nokogiri/xml_io.c +0 -63
  171. data/ext/nokogiri/xml_io.h +0 -11
  172. data/ext/nokogiri/xml_libxml2_hacks.c +0 -112
  173. data/ext/nokogiri/xml_libxml2_hacks.h +0 -12
  174. data/ext/nokogiri/xml_namespace.h +0 -14
  175. data/ext/nokogiri/xml_node.h +0 -13
  176. data/ext/nokogiri/xml_node_set.h +0 -12
  177. data/ext/nokogiri/xml_processing_instruction.h +0 -9
  178. data/ext/nokogiri/xml_reader.h +0 -10
  179. data/ext/nokogiri/xml_relax_ng.h +0 -9
  180. data/ext/nokogiri/xml_sax_parser.h +0 -39
  181. data/ext/nokogiri/xml_sax_parser_context.h +0 -10
  182. data/ext/nokogiri/xml_sax_push_parser.h +0 -9
  183. data/ext/nokogiri/xml_schema.h +0 -9
  184. data/ext/nokogiri/xml_syntax_error.h +0 -13
  185. data/ext/nokogiri/xml_text.h +0 -9
  186. data/ext/nokogiri/xml_xpath_context.h +0 -10
  187. data/ext/nokogiri/xslt_stylesheet.h +0 -14
@@ -1,35 +1,3 @@
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
1
  package nokogiri;
34
2
 
35
3
  import static nokogiri.internals.NokogiriHelpers.getNokogiriClass;
@@ -56,89 +24,109 @@ import org.jruby.Ruby;
56
24
  import org.jruby.RubyClass;
57
25
  import org.jruby.anno.JRubyClass;
58
26
  import org.jruby.runtime.ThreadContext;
27
+ import org.jruby.runtime.builtin.IRubyObject;
59
28
  import org.w3c.dom.Document;
60
29
  import org.xml.sax.ErrorHandler;
61
30
  import org.xml.sax.SAXException;
62
31
 
63
32
  /**
64
33
  * Class for Nokogiri::XML::RelaxNG
65
- *
34
+ *
66
35
  * @author sergio
67
36
  * @author Yoko Harada <yokolet@gmail.com>
68
37
  */
69
- @JRubyClass(name="Nokogiri::XML::RelaxNG", parent="Nokogiri::XML::Schema")
70
- public class XmlRelaxng extends XmlSchema {
71
- private Verifier verifier;
38
+ @JRubyClass(name = "Nokogiri::XML::RelaxNG", parent = "Nokogiri::XML::Schema")
39
+ public class XmlRelaxng extends XmlSchema
40
+ {
41
+ private Verifier verifier;
72
42
 
73
- public XmlRelaxng(Ruby ruby, RubyClass klazz) {
74
- super(ruby, klazz);
75
- }
76
-
77
- private void setVerifier(Verifier verifier) {
78
- this.verifier = verifier;
79
- }
80
-
81
- static XmlSchema createSchemaInstance(ThreadContext context, RubyClass klazz, Source source) {
82
- Ruby runtime = context.getRuntime();
83
- XmlRelaxng xmlRelaxng = (XmlRelaxng) NokogiriService.XML_RELAXNG_ALLOCATOR.allocate(runtime, klazz);
84
- xmlRelaxng.setInstanceVariable("@errors", runtime.newEmptyArray());
85
-
86
- try {
87
- Schema schema = xmlRelaxng.getSchema(source, context);
88
- xmlRelaxng.setVerifier(schema.newVerifier());
89
- return xmlRelaxng;
90
- } catch (VerifierConfigurationException ex) {
91
- throw context.getRuntime().newRuntimeError("Could not parse document: " + ex.getMessage());
92
- }
43
+ public
44
+ XmlRelaxng(Ruby ruby, RubyClass klazz)
45
+ {
46
+ super(ruby, klazz);
47
+ }
48
+
49
+ private void
50
+ setVerifier(Verifier verifier)
51
+ {
52
+ this.verifier = verifier;
53
+ }
54
+
55
+ static XmlSchema
56
+ createSchemaInstance(ThreadContext context, RubyClass klazz, Source source, IRubyObject parseOptions)
57
+ {
58
+ Ruby runtime = context.getRuntime();
59
+ XmlRelaxng xmlRelaxng = (XmlRelaxng) NokogiriService.XML_RELAXNG_ALLOCATOR.allocate(runtime, klazz);
60
+
61
+ if (parseOptions == null) {
62
+ parseOptions = defaultParseOptions(context.getRuntime());
93
63
  }
94
64
 
95
- private Schema getSchema(Source source, ThreadContext context) {
96
- InputStream is;
97
- VerifierFactory factory = new com.thaiopensource.relaxng.jarv.VerifierFactoryImpl();
98
- if (source instanceof StreamSource) {
99
- StreamSource ss = (StreamSource)source;
100
- is = ss.getInputStream();
101
- } else { //if (this.source instanceof DOMSource)
102
- DOMSource ds = (DOMSource)source;
103
- StringWriter xmlAsWriter = new StringWriter();
104
- StreamResult result = new StreamResult(xmlAsWriter);
105
- try {
106
- TransformerFactory.newInstance().newTransformer().transform(ds, result);
107
- } catch (TransformerConfigurationException ex) {
108
- throw context.getRuntime()
109
- .newRuntimeError("Could not parse document: "+ex.getMessage());
110
- } catch (TransformerException ex) {
111
- throw context.getRuntime()
112
- .newRuntimeError("Could not parse document: "+ex.getMessage());
113
- }
114
- try {
115
- is = new ByteArrayInputStream(xmlAsWriter.toString().getBytes("UTF-8"));
116
- } catch (UnsupportedEncodingException ex) {
117
- throw context.getRuntime()
118
- .newRuntimeError("Could not parse document: "+ex.getMessage());
119
- }
120
- }
65
+ xmlRelaxng.setInstanceVariable("@errors", runtime.newEmptyArray());
66
+ xmlRelaxng.setInstanceVariable("@parse_options", parseOptions);
121
67
 
122
- try {
123
- return factory.compileSchema(is);
124
- } catch (VerifierConfigurationException ex) {
125
- throw context.getRuntime()
126
- .newRuntimeError("Could not parse document: "+ex.getMessage());
127
- } catch (SAXException ex) {
128
- throw context.getRuntime()
129
- .newRuntimeError("Could not parse document: "+ex.getMessage());
130
- } catch (IOException ex) {
131
- throw context.getRuntime().newIOError(ex.getMessage());
132
- }
68
+ try {
69
+ Schema schema = xmlRelaxng.getSchema(source, context);
70
+ xmlRelaxng.setVerifier(schema.newVerifier());
71
+ return xmlRelaxng;
72
+ } catch (VerifierConfigurationException ex) {
73
+ throw context.getRuntime().newRuntimeError("Could not parse document: " + ex.getMessage());
133
74
  }
134
-
135
- @Override
136
- protected void setErrorHandler(ErrorHandler errorHandler) {
137
- verifier.setErrorHandler(errorHandler);
75
+ }
76
+
77
+ private Schema
78
+ getSchema(Source source, ThreadContext context)
79
+ {
80
+ InputStream is;
81
+ VerifierFactory factory = new com.thaiopensource.relaxng.jarv.VerifierFactoryImpl();
82
+ if (source instanceof StreamSource) {
83
+ StreamSource ss = (StreamSource)source;
84
+ is = ss.getInputStream();
85
+ } else { //if (this.source instanceof DOMSource)
86
+ DOMSource ds = (DOMSource)source;
87
+ StringWriter xmlAsWriter = new StringWriter();
88
+ StreamResult result = new StreamResult(xmlAsWriter);
89
+ try {
90
+ TransformerFactory.newInstance().newTransformer().transform(ds, result);
91
+ } catch (TransformerConfigurationException ex) {
92
+ throw context.getRuntime()
93
+ .newRuntimeError("Could not parse document: " + ex.getMessage());
94
+ } catch (TransformerException ex) {
95
+ throw context.getRuntime()
96
+ .newRuntimeError("Could not parse document: " + ex.getMessage());
97
+ }
98
+ try {
99
+ is = new ByteArrayInputStream(xmlAsWriter.toString().getBytes("UTF-8"));
100
+ } catch (UnsupportedEncodingException ex) {
101
+ throw context.getRuntime()
102
+ .newRuntimeError("Could not parse document: " + ex.getMessage());
103
+ }
138
104
  }
139
-
140
- @Override
141
- protected void validate(Document document) throws SAXException, IOException {
142
- verifier.verify(document);
105
+
106
+ try {
107
+ return factory.compileSchema(is);
108
+ } catch (VerifierConfigurationException ex) {
109
+ throw context.getRuntime()
110
+ .newRuntimeError("Could not parse document: " + ex.getMessage());
111
+ } catch (SAXException ex) {
112
+ throw context.getRuntime()
113
+ .newRuntimeError("Could not parse document: " + ex.getMessage());
114
+ } catch (IOException ex) {
115
+ throw context.getRuntime().newIOError(ex.getClass() + ": " + ex.getMessage());
143
116
  }
117
+ }
118
+
119
+ @Override
120
+ protected void
121
+ setErrorHandler(ErrorHandler errorHandler)
122
+ {
123
+ verifier.setErrorHandler(errorHandler);
124
+ }
125
+
126
+ @Override
127
+ protected void
128
+ validate(Document document) throws SAXException, IOException
129
+ {
130
+ verifier.verify(document);
131
+ }
144
132
  }
@@ -1,35 +1,3 @@
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
1
  package nokogiri;
34
2
 
35
3
  import static org.jruby.runtime.Helpers.invoke;
@@ -67,303 +35,353 @@ import nokogiri.internals.XmlSaxParser;
67
35
  * @author Patrick Mahoney <pat@polycrystal.org>
68
36
  * @author Yoko Harada <yokolet@gmail.com>
69
37
  */
70
- @JRubyClass(name="Nokogiri::XML::SAX::ParserContext")
71
- public class XmlSaxParserContext extends ParserContext {
72
-
73
- protected static final String FEATURE_NAMESPACES =
74
- "http://xml.org/sax/features/namespaces";
75
- protected static final String FEATURE_NAMESPACE_PREFIXES =
76
- "http://xml.org/sax/features/namespace-prefixes";
77
- protected static final String FEATURE_LOAD_EXTERNAL_DTD =
78
- "http://apache.org/xml/features/nonvalidating/load-external-dtd";
79
- protected static final String FEATURE_CONTINUE_AFTER_FATAL_ERROR =
80
- "http://apache.org/xml/features/continue-after-fatal-error";
81
-
82
- protected AbstractSAXParser parser;
83
-
84
- protected NokogiriHandler handler;
85
- private boolean replaceEntities = true;
86
- private boolean recovery = false;
87
-
88
- public XmlSaxParserContext(final Ruby ruby, RubyClass rubyClass) {
89
- super(ruby, rubyClass);
90
- }
91
-
92
- protected void initialize(Ruby runtime) {
93
- try {
94
- parser = createParser();
95
- }
96
- catch (SAXException se) {
97
- throw RaiseException.createNativeRaiseException(runtime, se);
98
- }
99
- }
100
-
101
- /**
102
- * Create and return a copy of this object.
103
- *
104
- * @return a clone of this object
105
- */
106
- @Override
107
- public Object clone() throws CloneNotSupportedException {
108
- return super.clone();
109
- }
110
-
111
- protected AbstractSAXParser createParser() throws SAXException {
112
- XmlSaxParser parser = new XmlSaxParser();
113
- parser.setFeature(FEATURE_NAMESPACE_PREFIXES, true);
114
- parser.setFeature(FEATURE_LOAD_EXTERNAL_DTD, false);
115
- return parser;
38
+ @JRubyClass(name = "Nokogiri::XML::SAX::ParserContext")
39
+ public class XmlSaxParserContext extends ParserContext
40
+ {
41
+
42
+ protected static final String FEATURE_NAMESPACES =
43
+ "http://xml.org/sax/features/namespaces";
44
+ protected static final String FEATURE_NAMESPACE_PREFIXES =
45
+ "http://xml.org/sax/features/namespace-prefixes";
46
+ protected static final String FEATURE_LOAD_EXTERNAL_DTD =
47
+ "http://apache.org/xml/features/nonvalidating/load-external-dtd";
48
+ protected static final String FEATURE_CONTINUE_AFTER_FATAL_ERROR =
49
+ "http://apache.org/xml/features/continue-after-fatal-error";
50
+
51
+ protected AbstractSAXParser parser;
52
+
53
+ protected NokogiriHandler handler;
54
+ private boolean replaceEntities = true;
55
+ private boolean recovery = false;
56
+
57
+ public
58
+ XmlSaxParserContext(final Ruby ruby, RubyClass rubyClass)
59
+ {
60
+ super(ruby, rubyClass);
61
+ }
62
+
63
+ protected void
64
+ initialize(Ruby runtime)
65
+ {
66
+ try {
67
+ parser = createParser();
68
+ } catch (SAXException se) {
69
+ // Unexpected failure in XML subsystem
70
+ RaiseException ex = runtime.newRuntimeError(se.toString());
71
+ ex.initCause(se);
72
+ throw ex;
116
73
  }
117
-
118
- /**
119
- * Create a new parser context that will parse the string
120
- * <code>data</code>.
121
- */
122
- @JRubyMethod(name="memory", meta=true)
123
- public static IRubyObject parse_memory(ThreadContext context,
124
- IRubyObject klazz,
125
- IRubyObject data) {
126
- final Ruby runtime = context.runtime;
127
- XmlSaxParserContext ctx = newInstance(runtime, (RubyClass) klazz);
128
- ctx.initialize(runtime);
129
- ctx.setStringInputSource(context, data, runtime.getNil());
130
- return ctx;
74
+ }
75
+
76
+ /**
77
+ * Create and return a copy of this object.
78
+ *
79
+ * @return a clone of this object
80
+ */
81
+ @Override
82
+ public Object
83
+ clone() throws CloneNotSupportedException
84
+ {
85
+ return super.clone();
86
+ }
87
+
88
+ protected AbstractSAXParser
89
+ createParser() throws SAXException
90
+ {
91
+ XmlSaxParser parser = new XmlSaxParser();
92
+ parser.setFeature(FEATURE_NAMESPACE_PREFIXES, true);
93
+ parser.setFeature(FEATURE_LOAD_EXTERNAL_DTD, false);
94
+ return parser;
95
+ }
96
+
97
+ /**
98
+ * Create a new parser context that will parse the string
99
+ * <code>data</code>.
100
+ */
101
+ @JRubyMethod(name = "memory", meta = true)
102
+ public static IRubyObject
103
+ parse_memory(ThreadContext context,
104
+ IRubyObject klazz,
105
+ IRubyObject data)
106
+ {
107
+ final Ruby runtime = context.runtime;
108
+ XmlSaxParserContext ctx = newInstance(runtime, (RubyClass) klazz);
109
+ ctx.initialize(runtime);
110
+ ctx.setStringInputSource(context, data, runtime.getNil());
111
+ return ctx;
112
+ }
113
+
114
+ /**
115
+ * Create a new parser context that will read from the file
116
+ * <code>data</code> and parse.
117
+ */
118
+ @JRubyMethod(name = "file", meta = true)
119
+ public static IRubyObject
120
+ parse_file(ThreadContext context,
121
+ IRubyObject klazz,
122
+ IRubyObject data)
123
+ {
124
+ final Ruby runtime = context.runtime;
125
+ XmlSaxParserContext ctx = newInstance(runtime, (RubyClass) klazz);
126
+ ctx.initialize(context.getRuntime());
127
+ ctx.setInputSourceFile(context, data);
128
+ return ctx;
129
+ }
130
+
131
+ /**
132
+ * Create a new parser context that will read from the IO or
133
+ * StringIO <code>data</code> and parse.
134
+ *
135
+ * TODO: Currently ignores encoding <code>enc</code>.
136
+ */
137
+ @JRubyMethod(name = "io", meta = true)
138
+ public static IRubyObject
139
+ parse_io(ThreadContext context,
140
+ IRubyObject klazz,
141
+ IRubyObject data,
142
+ IRubyObject enc)
143
+ {
144
+ //int encoding = (int)enc.convertToInteger().getLongValue();
145
+ final Ruby runtime = context.runtime;
146
+ XmlSaxParserContext ctx = newInstance(runtime, (RubyClass) klazz);
147
+ ctx.initialize(runtime);
148
+ ctx.setIOInputSource(context, data, runtime.getNil());
149
+ return ctx;
150
+ }
151
+
152
+ /**
153
+ * Create a new parser context that will read from a raw input stream.
154
+ * Meant to be run in a separate thread by XmlSaxPushParser.
155
+ */
156
+ static XmlSaxParserContext
157
+ parse_stream(final Ruby runtime, RubyClass klazz, InputStream stream)
158
+ {
159
+ XmlSaxParserContext ctx = newInstance(runtime, klazz);
160
+ ctx.initialize(runtime);
161
+ ctx.setInputSource(stream);
162
+ return ctx;
163
+ }
164
+
165
+ private static XmlSaxParserContext
166
+ newInstance(final Ruby runtime, final RubyClass klazz)
167
+ {
168
+ return (XmlSaxParserContext) NokogiriService.XML_SAXPARSER_CONTEXT_ALLOCATOR.allocate(runtime, klazz);
169
+ }
170
+
171
+ /**
172
+ * Set a property of the underlying parser.
173
+ */
174
+ protected void
175
+ setProperty(String key, Object val)
176
+ throws SAXNotRecognizedException, SAXNotSupportedException
177
+ {
178
+ parser.setProperty(key, val);
179
+ }
180
+
181
+ protected void
182
+ setContentHandler(ContentHandler handler)
183
+ {
184
+ parser.setContentHandler(handler);
185
+ }
186
+
187
+ protected void
188
+ setErrorHandler(ErrorHandler handler)
189
+ {
190
+ parser.setErrorHandler(handler);
191
+ }
192
+
193
+ public final NokogiriHandler
194
+ getNokogiriHandler() { return handler; }
195
+
196
+ /**
197
+ * Perform any initialization prior to parsing with the handler
198
+ * <code>handlerRuby</code>. Convenience hook for subclasses.
199
+ */
200
+ protected void
201
+ preParse(Ruby runtime, IRubyObject handlerRuby, NokogiriHandler handler)
202
+ {
203
+ ((XmlSaxParser) parser).setXmlDeclHandler(handler);
204
+ if (recovery) {
205
+ try {
206
+ parser.setFeature(FEATURE_CONTINUE_AFTER_FATAL_ERROR, true);
207
+ } catch (Exception e) {
208
+ // Unexpected failure in XML subsystem
209
+ throw runtime.newRuntimeError(e.getMessage());
210
+ }
131
211
  }
132
-
133
- /**
134
- * Create a new parser context that will read from the file
135
- * <code>data</code> and parse.
136
- */
137
- @JRubyMethod(name="file", meta=true)
138
- public static IRubyObject parse_file(ThreadContext context,
139
- IRubyObject klazz,
140
- IRubyObject data) {
141
- final Ruby runtime = context.runtime;
142
- XmlSaxParserContext ctx = newInstance(runtime, (RubyClass) klazz);
143
- ctx.initialize(context.getRuntime());
144
- ctx.setInputSourceFile(context, data);
145
- return ctx;
212
+ }
213
+
214
+ protected void
215
+ postParse(Ruby runtime, IRubyObject handlerRuby, NokogiriHandler handler)
216
+ {
217
+ // noop
218
+ }
219
+
220
+ protected void
221
+ do_parse() throws SAXException, IOException
222
+ {
223
+ parser.parse(getInputSource());
224
+ }
225
+
226
+ @JRubyMethod
227
+ public IRubyObject
228
+ parse_with(ThreadContext context, IRubyObject handlerRuby)
229
+ {
230
+ final Ruby runtime = context.getRuntime();
231
+
232
+ if (!invoke(context, handlerRuby, "respond_to?", runtime.newSymbol("document")).isTrue()) {
233
+ throw runtime.newArgumentError("argument must respond_to document");
146
234
  }
147
235
 
148
- /**
149
- * Create a new parser context that will read from the IO or
150
- * StringIO <code>data</code> and parse.
151
- *
152
- * TODO: Currently ignores encoding <code>enc</code>.
153
- */
154
- @JRubyMethod(name="io", meta=true)
155
- public static IRubyObject parse_io(ThreadContext context,
156
- IRubyObject klazz,
157
- IRubyObject data,
158
- IRubyObject enc) {
159
- //int encoding = (int)enc.convertToInteger().getLongValue();
160
- final Ruby runtime = context.runtime;
161
- XmlSaxParserContext ctx = newInstance(runtime, (RubyClass) klazz);
162
- ctx.initialize(runtime);
163
- ctx.setIOInputSource(context, data, runtime.getNil());
164
- return ctx;
165
- }
236
+ NokogiriHandler handler = this.handler = new NokogiriHandler(runtime, handlerRuby);
237
+ preParse(runtime, handlerRuby, handler);
166
238
 
167
- /**
168
- * Create a new parser context that will read from a raw input stream.
169
- * Meant to be run in a separate thread by XmlSaxPushParser.
170
- */
171
- static XmlSaxParserContext parse_stream(final Ruby runtime, RubyClass klazz, InputStream stream) {
172
- XmlSaxParserContext ctx = newInstance(runtime, klazz);
173
- ctx.initialize(runtime);
174
- ctx.setInputSource(stream);
175
- return ctx;
176
- }
239
+ setContentHandler(handler);
240
+ setErrorHandler(handler);
177
241
 
178
- private static XmlSaxParserContext newInstance(final Ruby runtime, final RubyClass klazz) {
179
- return (XmlSaxParserContext) NokogiriService.XML_SAXPARSER_CONTEXT_ALLOCATOR.allocate(runtime, klazz);
242
+ try {
243
+ setProperty("http://xml.org/sax/properties/lexical-handler", handler);
244
+ } catch (Exception ex) {
245
+ throw runtime.newRuntimeError("Problem while creating XML SAX Parser: " + ex.toString());
180
246
  }
181
247
 
182
- /**
183
- * Set a property of the underlying parser.
184
- */
185
- protected void setProperty(String key, Object val)
186
- throws SAXNotRecognizedException, SAXNotSupportedException {
187
- parser.setProperty(key, val);
188
- }
189
-
190
- protected void setContentHandler(ContentHandler handler) {
191
- parser.setContentHandler(handler);
192
- }
193
-
194
- protected void setErrorHandler(ErrorHandler handler) {
195
- parser.setErrorHandler(handler);
196
- }
197
-
198
- public final NokogiriHandler getNokogiriHandler() { return handler; }
199
-
200
- /**
201
- * Perform any initialization prior to parsing with the handler
202
- * <code>handlerRuby</code>. Convenience hook for subclasses.
203
- */
204
- protected void preParse(Ruby runtime, IRubyObject handlerRuby, NokogiriHandler handler) {
205
- ((XmlSaxParser) parser).setXmlDeclHandler(handler);
206
- if (recovery) {
207
- try {
208
- parser.setFeature(FEATURE_CONTINUE_AFTER_FATAL_ERROR, true);
209
- }
210
- catch (Exception e) {
211
- throw RaiseException.createNativeRaiseException(runtime, e);
212
- }
248
+ try {
249
+ try {
250
+ do_parse();
251
+ } catch (SAXParseException ex) {
252
+ // A bad document (<foo><bar></foo>) should call the
253
+ // error handler instead of raising a SAX exception.
254
+
255
+ // However, an EMPTY document should raise a RuntimeError.
256
+ // This is a bit kludgy, but AFAIK SAX doesn't distinguish
257
+ // between empty and bad whereas Nokogiri does.
258
+ String message = ex.getMessage();
259
+ if (message != null && message.contains("Premature end of file.") && stringDataSize < 1) {
260
+ throw runtime.newRuntimeError("couldn't parse document: " + message);
213
261
  }
262
+ handler.error(ex);
263
+ }
264
+ } catch (SAXException ex) {
265
+ // Unexpected failure in XML subsystem
266
+ throw runtime.newRuntimeError(ex.getMessage());
267
+ } catch (IOException ex) {
268
+ throw runtime.newIOErrorFromException(ex);
214
269
  }
215
270
 
216
- protected void postParse(Ruby runtime, IRubyObject handlerRuby, NokogiriHandler handler) {
217
- // noop
271
+ postParse(runtime, handlerRuby, handler);
272
+
273
+ //maybeTrimLeadingAndTrailingWhitespace(context, handlerRuby);
274
+
275
+ return runtime.getNil();
276
+ }
277
+
278
+ /**
279
+ * Can take a boolean assignment.
280
+ *
281
+ * @param context
282
+ * @param value
283
+ * @return
284
+ */
285
+ @JRubyMethod(name = "replace_entities=")
286
+ public IRubyObject
287
+ set_replace_entities(ThreadContext context, IRubyObject value)
288
+ {
289
+ replaceEntities = value.isTrue();
290
+ return this;
291
+ }
292
+
293
+ @JRubyMethod(name = "replace_entities")
294
+ public IRubyObject
295
+ get_replace_entities(ThreadContext context)
296
+ {
297
+ return context.runtime.newBoolean(replaceEntities);
298
+ }
299
+
300
+ /**
301
+ * Can take a boolean assignment.
302
+ *
303
+ * @param context
304
+ * @param value
305
+ * @return
306
+ */
307
+ @JRubyMethod(name = "recovery=")
308
+ public IRubyObject
309
+ set_recovery(ThreadContext context, IRubyObject value)
310
+ {
311
+ recovery = value.isTrue();
312
+ return this;
313
+ }
314
+
315
+ @JRubyMethod(name = "recovery")
316
+ public IRubyObject
317
+ get_recovery(ThreadContext context)
318
+ {
319
+ return context.runtime.newBoolean(recovery);
320
+ }
321
+
322
+ /**
323
+ * If the handler's document is a FragmentHandler, attempt to trim
324
+ * leading and trailing whitespace.
325
+ *
326
+ * This is a bit hackish and depends heavily on the internals of
327
+ * FragmentHandler.
328
+ */
329
+ protected void
330
+ maybeTrimLeadingAndTrailingWhitespace(ThreadContext context, IRubyObject parser)
331
+ {
332
+ RubyObjectAdapter adapter = JavaEmbedUtils.newObjectAdapter();
333
+ RubyModule mod = context.getRuntime().getClassFromPath("Nokogiri::XML::FragmentHandler");
334
+
335
+ IRubyObject handler = adapter.getInstanceVariable(parser, "@document");
336
+ if (handler == null || handler.isNil() || !adapter.isKindOf(handler, mod)) {
337
+ return;
218
338
  }
219
-
220
- protected void do_parse() throws SAXException, IOException {
221
- parser.parse(getInputSource());
339
+ IRubyObject stack = adapter.getInstanceVariable(handler, "@stack");
340
+ if (stack == null || stack.isNil()) {
341
+ return;
222
342
  }
223
-
224
- @JRubyMethod
225
- public IRubyObject parse_with(ThreadContext context, IRubyObject handlerRuby) {
226
- final Ruby runtime = context.getRuntime();
227
-
228
- if(!invoke(context, handlerRuby, "respond_to?", runtime.newSymbol("document")).isTrue()) {
229
- throw runtime.newArgumentError("argument must respond_to document");
230
- }
231
-
232
- NokogiriHandler handler = this.handler = new NokogiriHandler(runtime, handlerRuby);
233
- preParse(runtime, handlerRuby, handler);
234
-
235
- setContentHandler(handler);
236
- setErrorHandler(handler);
237
-
238
- try{
239
- setProperty("http://xml.org/sax/properties/lexical-handler", handler);
240
- }
241
- catch (Exception ex) {
242
- throw runtime.newRuntimeError("Problem while creating XML SAX Parser: " + ex.toString());
243
- }
244
-
245
- try{
246
- try {
247
- do_parse();
248
- }
249
- catch (SAXParseException ex) {
250
- // A bad document (<foo><bar></foo>) should call the
251
- // error handler instead of raising a SAX exception.
252
-
253
- // However, an EMPTY document should raise a RuntimeError.
254
- // This is a bit kludgy, but AFAIK SAX doesn't distinguish
255
- // between empty and bad whereas Nokogiri does.
256
- String message = ex.getMessage();
257
- if (message != null && message.contains("Premature end of file.") && stringDataSize < 1) {
258
- throw runtime.newRuntimeError("couldn't parse document: " + message);
259
- }
260
- handler.error(ex);
261
- }
262
- }
263
- catch (SAXException ex) {
264
- throw RaiseException.createNativeRaiseException(runtime, ex);
265
- }
266
- catch (IOException ex) {
267
- throw runtime.newIOErrorFromException(ex);
268
- }
269
-
270
- postParse(runtime, handlerRuby, handler);
271
-
272
- //maybeTrimLeadingAndTrailingWhitespace(context, handlerRuby);
273
-
274
- return runtime.getNil();
343
+ // doc is finally a DocumentFragment whose nodes we can check
344
+ IRubyObject doc = adapter.callMethod(stack, "first");
345
+ if (doc == null || doc.isNil()) {
346
+ return;
275
347
  }
276
348
 
277
- /**
278
- * Can take a boolean assignment.
279
- *
280
- * @param context
281
- * @param value
282
- * @return
283
- */
284
- @JRubyMethod(name = "replace_entities=")
285
- public IRubyObject set_replace_entities(ThreadContext context, IRubyObject value) {
286
- replaceEntities = value.isTrue();
287
- return this;
288
- }
289
-
290
- @JRubyMethod(name="replace_entities")
291
- public IRubyObject get_replace_entities(ThreadContext context) {
292
- return context.runtime.newBoolean(replaceEntities);
293
- }
294
-
295
- /**
296
- * Can take a boolean assignment.
297
- *
298
- * @param context
299
- * @param value
300
- * @return
301
- */
302
- @JRubyMethod(name = "recovery=")
303
- public IRubyObject set_recovery(ThreadContext context, IRubyObject value) {
304
- recovery = value.isTrue();
305
- return this;
306
- }
307
-
308
- @JRubyMethod(name="recovery")
309
- public IRubyObject get_recovery(ThreadContext context) {
310
- return context.runtime.newBoolean(recovery);
311
- }
312
-
313
- /**
314
- * If the handler's document is a FragmentHandler, attempt to trim
315
- * leading and trailing whitespace.
316
- *
317
- * This is a bit hackish and depends heavily on the internals of
318
- * FragmentHandler.
319
- */
320
- protected void maybeTrimLeadingAndTrailingWhitespace(ThreadContext context, IRubyObject parser) {
321
- RubyObjectAdapter adapter = JavaEmbedUtils.newObjectAdapter();
322
- RubyModule mod = context.getRuntime().getClassFromPath("Nokogiri::XML::FragmentHandler");
323
-
324
- IRubyObject handler = adapter.getInstanceVariable(parser, "@document");
325
- if (handler == null || handler.isNil() || !adapter.isKindOf(handler, mod))
326
- return;
327
- IRubyObject stack = adapter.getInstanceVariable(handler, "@stack");
328
- if (stack == null || stack.isNil())
329
- return;
330
- // doc is finally a DocumentFragment whose nodes we can check
331
- IRubyObject doc = adapter.callMethod(stack, "first");
332
- if (doc == null || doc.isNil())
333
- return;
334
-
335
- IRubyObject children;
336
-
337
- for (;;) {
338
- children = adapter.callMethod(doc, "children");
339
- IRubyObject first = adapter.callMethod(children, "first");
340
- if (NokogiriHelpers.isBlank(first)) adapter.callMethod(first, "unlink");
341
- else break;
342
- }
349
+ IRubyObject children;
343
350
 
344
- for (;;) {
345
- children = adapter.callMethod(doc, "children");
346
- IRubyObject last = adapter.callMethod(children, "last");
347
- if (NokogiriHelpers.isBlank(last)) adapter.callMethod(last, "unlink");
348
- else break;
349
- }
350
-
351
- // While we have a document, normalize it.
352
- ((XmlNode) doc).normalize();
351
+ for (;;) {
352
+ children = adapter.callMethod(doc, "children");
353
+ IRubyObject first = adapter.callMethod(children, "first");
354
+ if (NokogiriHelpers.isBlank(first)) { adapter.callMethod(first, "unlink"); }
355
+ else { break; }
353
356
  }
354
357
 
355
- @JRubyMethod(name="column")
356
- public IRubyObject column(ThreadContext context) {
357
- final Integer number = handler.getColumn();
358
- if (number == null) return context.getRuntime().getNil();
359
- return RubyFixnum.newFixnum(context.getRuntime(), number.longValue());
358
+ for (;;) {
359
+ children = adapter.callMethod(doc, "children");
360
+ IRubyObject last = adapter.callMethod(children, "last");
361
+ if (NokogiriHelpers.isBlank(last)) { adapter.callMethod(last, "unlink"); }
362
+ else { break; }
360
363
  }
361
364
 
362
- @JRubyMethod(name="line")
363
- public IRubyObject line(ThreadContext context) {
364
- final Integer number = handler.getLine();
365
- if (number == null) return context.getRuntime().getNil();
366
- return RubyFixnum.newFixnum(context.getRuntime(), number.longValue());
367
- }
365
+ // While we have a document, normalize it.
366
+ ((XmlNode) doc).normalize();
367
+ }
368
+
369
+ @JRubyMethod(name = "column")
370
+ public IRubyObject
371
+ column(ThreadContext context)
372
+ {
373
+ final Integer number = handler.getColumn();
374
+ if (number == null) { return context.getRuntime().getNil(); }
375
+ return RubyFixnum.newFixnum(context.getRuntime(), number.longValue());
376
+ }
377
+
378
+ @JRubyMethod(name = "line")
379
+ public IRubyObject
380
+ line(ThreadContext context)
381
+ {
382
+ final Integer number = handler.getLine();
383
+ if (number == null) { return context.getRuntime().getNil(); }
384
+ return RubyFixnum.newFixnum(context.getRuntime(), number.longValue());
385
+ }
368
386
 
369
387
  }