nokogiri 1.11.0.rc1-java → 1.11.2-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (188) 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 +171 -94
  6. data/ext/java/nokogiri/EncodingHandler.java +78 -59
  7. data/ext/java/nokogiri/HtmlDocument.java +137 -114
  8. data/ext/java/nokogiri/HtmlElementDescription.java +104 -87
  9. data/ext/java/nokogiri/HtmlEntityLookup.java +31 -26
  10. data/ext/java/nokogiri/HtmlSaxParserContext.java +220 -192
  11. data/ext/java/nokogiri/HtmlSaxPushParser.java +164 -139
  12. data/ext/java/nokogiri/NokogiriService.java +597 -526
  13. data/ext/java/nokogiri/XmlAttr.java +120 -96
  14. data/ext/java/nokogiri/XmlAttributeDecl.java +97 -76
  15. data/ext/java/nokogiri/XmlCdata.java +35 -26
  16. data/ext/java/nokogiri/XmlComment.java +48 -37
  17. data/ext/java/nokogiri/XmlDocument.java +642 -540
  18. data/ext/java/nokogiri/XmlDocumentFragment.java +127 -107
  19. data/ext/java/nokogiri/XmlDtd.java +450 -384
  20. data/ext/java/nokogiri/XmlElement.java +25 -18
  21. data/ext/java/nokogiri/XmlElementContent.java +345 -286
  22. data/ext/java/nokogiri/XmlElementDecl.java +126 -95
  23. data/ext/java/nokogiri/XmlEntityDecl.java +121 -97
  24. data/ext/java/nokogiri/XmlEntityReference.java +51 -42
  25. data/ext/java/nokogiri/XmlNamespace.java +177 -145
  26. data/ext/java/nokogiri/XmlNode.java +1843 -1590
  27. data/ext/java/nokogiri/XmlNodeSet.java +361 -299
  28. data/ext/java/nokogiri/XmlProcessingInstruction.java +49 -39
  29. data/ext/java/nokogiri/XmlReader.java +513 -418
  30. data/ext/java/nokogiri/XmlRelaxng.java +92 -72
  31. data/ext/java/nokogiri/XmlSaxParserContext.java +330 -280
  32. data/ext/java/nokogiri/XmlSaxPushParser.java +229 -190
  33. data/ext/java/nokogiri/XmlSchema.java +335 -210
  34. data/ext/java/nokogiri/XmlSyntaxError.java +113 -87
  35. data/ext/java/nokogiri/XmlText.java +57 -46
  36. data/ext/java/nokogiri/XmlXpathContext.java +242 -178
  37. data/ext/java/nokogiri/XsltStylesheet.java +282 -239
  38. data/ext/java/nokogiri/internals/ClosedStreamException.java +5 -2
  39. data/ext/java/nokogiri/internals/HtmlDomParserContext.java +203 -160
  40. data/ext/java/nokogiri/internals/IgnoreSchemaErrorsErrorHandler.java +17 -10
  41. data/ext/java/nokogiri/internals/NokogiriBlockingQueueInputStream.java +43 -16
  42. data/ext/java/nokogiri/internals/NokogiriDomParser.java +65 -50
  43. data/ext/java/nokogiri/internals/NokogiriEntityResolver.java +107 -88
  44. data/ext/java/nokogiri/internals/NokogiriErrorHandler.java +25 -18
  45. data/ext/java/nokogiri/internals/NokogiriHandler.java +316 -254
  46. data/ext/java/nokogiri/internals/NokogiriHelpers.java +738 -622
  47. data/ext/java/nokogiri/internals/NokogiriNamespaceCache.java +186 -143
  48. data/ext/java/nokogiri/internals/NokogiriNamespaceContext.java +81 -59
  49. data/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler.java +66 -49
  50. data/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler4NekoHtml.java +86 -69
  51. data/ext/java/nokogiri/internals/NokogiriStrictErrorHandler.java +44 -29
  52. data/ext/java/nokogiri/internals/NokogiriXPathFunction.java +121 -48
  53. data/ext/java/nokogiri/internals/NokogiriXPathFunctionResolver.java +34 -22
  54. data/ext/java/nokogiri/internals/NokogiriXPathVariableResolver.java +25 -17
  55. data/ext/java/nokogiri/internals/NokogiriXsltErrorListener.java +57 -42
  56. data/ext/java/nokogiri/internals/ParserContext.java +206 -179
  57. data/ext/java/nokogiri/internals/ReaderNode.java +478 -371
  58. data/ext/java/nokogiri/internals/SaveContextVisitor.java +822 -707
  59. data/ext/java/nokogiri/internals/SchemaErrorHandler.java +28 -19
  60. data/ext/java/nokogiri/internals/XalanDTMManagerPatch.java +129 -123
  61. data/ext/java/nokogiri/internals/XmlDeclHandler.java +5 -4
  62. data/ext/java/nokogiri/internals/XmlDomParserContext.java +208 -177
  63. data/ext/java/nokogiri/internals/XmlSaxParser.java +24 -17
  64. data/ext/java/nokogiri/internals/c14n/AttrCompare.java +71 -68
  65. data/ext/java/nokogiri/internals/c14n/C14nHelper.java +137 -118
  66. data/ext/java/nokogiri/internals/c14n/CanonicalFilter.java +27 -21
  67. data/ext/java/nokogiri/internals/c14n/CanonicalizationException.java +74 -61
  68. data/ext/java/nokogiri/internals/c14n/Canonicalizer.java +230 -205
  69. data/ext/java/nokogiri/internals/c14n/Canonicalizer11.java +572 -547
  70. data/ext/java/nokogiri/internals/c14n/Canonicalizer11_OmitComments.java +17 -10
  71. data/ext/java/nokogiri/internals/c14n/Canonicalizer11_WithComments.java +17 -10
  72. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315.java +323 -302
  73. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315Excl.java +232 -219
  74. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315ExclOmitComments.java +22 -15
  75. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315ExclWithComments.java +23 -16
  76. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315OmitComments.java +23 -16
  77. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315WithComments.java +22 -15
  78. data/ext/java/nokogiri/internals/c14n/CanonicalizerBase.java +575 -545
  79. data/ext/java/nokogiri/internals/c14n/CanonicalizerPhysical.java +141 -120
  80. data/ext/java/nokogiri/internals/c14n/CanonicalizerSpi.java +39 -38
  81. data/ext/java/nokogiri/internals/c14n/Constants.java +13 -10
  82. data/ext/java/nokogiri/internals/c14n/ElementProxy.java +279 -247
  83. data/ext/java/nokogiri/internals/c14n/HelperNodeList.java +66 -53
  84. data/ext/java/nokogiri/internals/c14n/IgnoreAllErrorHandler.java +44 -37
  85. data/ext/java/nokogiri/internals/c14n/InclusiveNamespaces.java +135 -120
  86. data/ext/java/nokogiri/internals/c14n/InvalidCanonicalizerException.java +59 -48
  87. data/ext/java/nokogiri/internals/c14n/NameSpaceSymbTable.java +384 -334
  88. data/ext/java/nokogiri/internals/c14n/NodeFilter.java +25 -24
  89. data/ext/java/nokogiri/internals/c14n/UtfHelpper.java +151 -140
  90. data/ext/java/nokogiri/internals/c14n/XMLUtils.java +456 -423
  91. data/ext/java/nokogiri/internals/dom2dtm/DOM2DTM.java +1466 -1500
  92. data/ext/java/nokogiri/internals/dom2dtm/DOM2DTMdefaultNamespaceDeclarationNode.java +626 -570
  93. data/ext/nokogiri/depend +37 -358
  94. data/ext/nokogiri/extconf.rb +585 -374
  95. data/ext/nokogiri/html_document.c +78 -82
  96. data/ext/nokogiri/html_element_description.c +84 -71
  97. data/ext/nokogiri/html_entity_lookup.c +21 -16
  98. data/ext/nokogiri/html_sax_parser_context.c +69 -66
  99. data/ext/nokogiri/html_sax_push_parser.c +42 -34
  100. data/ext/nokogiri/libxml2_backwards_compat.c +121 -0
  101. data/ext/nokogiri/nokogiri.c +192 -93
  102. data/ext/nokogiri/test_global_handlers.c +40 -0
  103. data/ext/nokogiri/xml_attr.c +15 -15
  104. data/ext/nokogiri/xml_attribute_decl.c +18 -18
  105. data/ext/nokogiri/xml_cdata.c +13 -18
  106. data/ext/nokogiri/xml_comment.c +19 -26
  107. data/ext/nokogiri/xml_document.c +225 -163
  108. data/ext/nokogiri/xml_document_fragment.c +13 -15
  109. data/ext/nokogiri/xml_dtd.c +54 -48
  110. data/ext/nokogiri/xml_element_content.c +30 -27
  111. data/ext/nokogiri/xml_element_decl.c +22 -22
  112. data/ext/nokogiri/xml_encoding_handler.c +17 -11
  113. data/ext/nokogiri/xml_entity_decl.c +32 -30
  114. data/ext/nokogiri/xml_entity_reference.c +16 -18
  115. data/ext/nokogiri/xml_namespace.c +56 -49
  116. data/ext/nokogiri/xml_node.c +338 -286
  117. data/ext/nokogiri/xml_node_set.c +168 -156
  118. data/ext/nokogiri/xml_processing_instruction.c +17 -19
  119. data/ext/nokogiri/xml_reader.c +195 -172
  120. data/ext/nokogiri/xml_relax_ng.c +52 -28
  121. data/ext/nokogiri/xml_sax_parser.c +118 -118
  122. data/ext/nokogiri/xml_sax_parser_context.c +103 -86
  123. data/ext/nokogiri/xml_sax_push_parser.c +36 -27
  124. data/ext/nokogiri/xml_schema.c +111 -34
  125. data/ext/nokogiri/xml_syntax_error.c +42 -21
  126. data/ext/nokogiri/xml_text.c +13 -17
  127. data/ext/nokogiri/xml_xpath_context.c +206 -123
  128. data/ext/nokogiri/xslt_stylesheet.c +158 -161
  129. data/lib/nokogiri.rb +4 -8
  130. data/lib/nokogiri/css/parser.rb +62 -62
  131. data/lib/nokogiri/css/parser.y +2 -2
  132. data/lib/nokogiri/css/parser_extras.rb +38 -36
  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 -148
  139. data/lib/nokogiri/version/constant.rb +5 -0
  140. data/lib/nokogiri/version/info.rb +205 -0
  141. data/lib/nokogiri/xml/builder.rb +2 -2
  142. data/lib/nokogiri/xml/document.rb +48 -18
  143. data/lib/nokogiri/xml/document_fragment.rb +4 -6
  144. data/lib/nokogiri/xml/node.rb +599 -279
  145. data/lib/nokogiri/xml/parse_options.rb +6 -0
  146. data/lib/nokogiri/xml/reader.rb +2 -9
  147. data/lib/nokogiri/xml/relax_ng.rb +6 -2
  148. data/lib/nokogiri/xml/schema.rb +12 -4
  149. data/lib/nokogiri/xml/searchable.rb +24 -16
  150. data/lib/nokogiri/xml/xpath.rb +1 -3
  151. data/lib/nokogiri/xml/xpath/syntax_error.rb +1 -1
  152. metadata +87 -158
  153. data/ext/nokogiri/html_document.h +0 -10
  154. data/ext/nokogiri/html_element_description.h +0 -10
  155. data/ext/nokogiri/html_entity_lookup.h +0 -8
  156. data/ext/nokogiri/html_sax_parser_context.h +0 -11
  157. data/ext/nokogiri/html_sax_push_parser.h +0 -9
  158. data/ext/nokogiri/nokogiri.h +0 -122
  159. data/ext/nokogiri/xml_attr.h +0 -9
  160. data/ext/nokogiri/xml_attribute_decl.h +0 -9
  161. data/ext/nokogiri/xml_cdata.h +0 -9
  162. data/ext/nokogiri/xml_comment.h +0 -9
  163. data/ext/nokogiri/xml_document.h +0 -23
  164. data/ext/nokogiri/xml_document_fragment.h +0 -10
  165. data/ext/nokogiri/xml_dtd.h +0 -10
  166. data/ext/nokogiri/xml_element_content.h +0 -10
  167. data/ext/nokogiri/xml_element_decl.h +0 -9
  168. data/ext/nokogiri/xml_encoding_handler.h +0 -8
  169. data/ext/nokogiri/xml_entity_decl.h +0 -10
  170. data/ext/nokogiri/xml_entity_reference.h +0 -9
  171. data/ext/nokogiri/xml_io.c +0 -61
  172. data/ext/nokogiri/xml_io.h +0 -11
  173. data/ext/nokogiri/xml_libxml2_hacks.c +0 -112
  174. data/ext/nokogiri/xml_libxml2_hacks.h +0 -12
  175. data/ext/nokogiri/xml_namespace.h +0 -14
  176. data/ext/nokogiri/xml_node.h +0 -13
  177. data/ext/nokogiri/xml_node_set.h +0 -12
  178. data/ext/nokogiri/xml_processing_instruction.h +0 -9
  179. data/ext/nokogiri/xml_reader.h +0 -10
  180. data/ext/nokogiri/xml_relax_ng.h +0 -9
  181. data/ext/nokogiri/xml_sax_parser.h +0 -39
  182. data/ext/nokogiri/xml_sax_parser_context.h +0 -10
  183. data/ext/nokogiri/xml_sax_push_parser.h +0 -9
  184. data/ext/nokogiri/xml_schema.h +0 -9
  185. data/ext/nokogiri/xml_syntax_error.h +0 -13
  186. data/ext/nokogiri/xml_text.h +0 -9
  187. data/ext/nokogiri/xml_xpath_context.h +0 -10
  188. data/ext/nokogiri/xslt_stylesheet.h +0 -14
@@ -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.
@@ -55,124 +55,147 @@ import static nokogiri.internals.NokogiriHelpers.getNokogiriClass;
55
55
  * @author sergio
56
56
  * @author Yoko Harada <yokolet@gmail.com>
57
57
  */
58
- @JRubyClass(name="Nokogiri::HTML::Document", parent="Nokogiri::XML::Document")
59
- public class HtmlDocument extends XmlDocument {
60
- private static final String DEFAULT_CONTENT_TYPE = "html";
61
- private static final String DEFAULT_PUBLIC_ID = "-//W3C//DTD HTML 4.01//EN";
62
- private static final String DEFAULT_SYTEM_ID = "http://www.w3.org/TR/html4/strict.dtd";
63
-
64
- private String parsed_encoding = null;
65
-
66
- public HtmlDocument(Ruby ruby, RubyClass klazz) {
67
- super(ruby, klazz);
68
- }
69
-
70
- public HtmlDocument(Ruby runtime, Document document) {
71
- this(runtime, getNokogiriClass(runtime, "Nokogiri::XML::Document"), document);
58
+ @JRubyClass(name = "Nokogiri::HTML::Document", parent = "Nokogiri::XML::Document")
59
+ public class HtmlDocument extends XmlDocument
60
+ {
61
+ private static final String DEFAULT_CONTENT_TYPE = "html";
62
+ private static final String DEFAULT_PUBLIC_ID = "-//W3C//DTD HTML 4.01//EN";
63
+ private static final String DEFAULT_SYTEM_ID = "http://www.w3.org/TR/html4/strict.dtd";
64
+
65
+ private String parsed_encoding = null;
66
+
67
+ public
68
+ HtmlDocument(Ruby ruby, RubyClass klazz)
69
+ {
70
+ super(ruby, klazz);
71
+ }
72
+
73
+ public
74
+ HtmlDocument(Ruby runtime, Document document)
75
+ {
76
+ this(runtime, getNokogiriClass(runtime, "Nokogiri::XML::Document"), document);
77
+ }
78
+
79
+ public
80
+ HtmlDocument(Ruby ruby, RubyClass klazz, Document doc)
81
+ {
82
+ super(ruby, klazz, doc);
83
+ }
84
+
85
+ @JRubyMethod(name = "new", meta = true, rest = true, required = 0)
86
+ public static IRubyObject
87
+ rbNew(ThreadContext context, IRubyObject klazz, IRubyObject[] args)
88
+ {
89
+ final Ruby runtime = context.runtime;
90
+ HtmlDocument htmlDocument;
91
+ try {
92
+ Document docNode = createNewDocument(runtime);
93
+ htmlDocument = (HtmlDocument) NokogiriService.HTML_DOCUMENT_ALLOCATOR.allocate(runtime, (RubyClass) klazz);
94
+ htmlDocument.setDocumentNode(context.runtime, docNode);
95
+ } catch (Exception ex) {
96
+ throw asRuntimeError(runtime, "couldn't create document: ", ex);
72
97
  }
73
98
 
74
- public HtmlDocument(Ruby ruby, RubyClass klazz, Document doc) {
75
- super(ruby, klazz, doc);
99
+ Helpers.invoke(context, htmlDocument, "initialize", args);
100
+
101
+ return htmlDocument;
102
+ }
103
+
104
+ public IRubyObject
105
+ getInternalSubset(ThreadContext context)
106
+ {
107
+ IRubyObject internalSubset = super.getInternalSubset(context);
108
+
109
+ // html documents are expected to have a default internal subset
110
+ // the default values are the same ones used when the following
111
+ // feature is turned on
112
+ // "http://cyberneko.org/html/features/insert-doctype"
113
+ // the reason we don't turn it on, is because it overrides the document's
114
+ // declared doctype declaration.
115
+
116
+ if (internalSubset.isNil()) {
117
+ internalSubset = XmlDtd.newEmpty(context.getRuntime(),
118
+ getDocument(),
119
+ context.getRuntime().newString(DEFAULT_CONTENT_TYPE),
120
+ context.getRuntime().newString(DEFAULT_PUBLIC_ID),
121
+ context.getRuntime().newString(DEFAULT_SYTEM_ID));
122
+ setInternalSubset(internalSubset);
76
123
  }
77
124
 
78
- @JRubyMethod(name="new", meta = true, rest = true, required=0)
79
- public static IRubyObject rbNew(ThreadContext context, IRubyObject klazz, IRubyObject[] args) {
80
- final Ruby runtime = context.runtime;
81
- HtmlDocument htmlDocument;
82
- try {
83
- Document docNode = createNewDocument(runtime);
84
- htmlDocument = (HtmlDocument) NokogiriService.HTML_DOCUMENT_ALLOCATOR.allocate(runtime, (RubyClass) klazz);
85
- htmlDocument.setDocumentNode(context.runtime, docNode);
86
- } catch (Exception ex) {
87
- throw asRuntimeError(runtime, "couldn't create document: ", ex);
88
- }
89
-
90
- Helpers.invoke(context, htmlDocument, "initialize", args);
91
-
92
- return htmlDocument;
125
+ return internalSubset;
126
+ }
127
+
128
+ @Override
129
+ void
130
+ init(Ruby runtime, Document document)
131
+ {
132
+ stabilizeTextContent(document);
133
+ document.normalize();
134
+ setInstanceVariable("@decorators", runtime.getNil());
135
+ if (document.getDocumentElement() != null) {
136
+ stabilizeAttrs(document.getDocumentElement());
93
137
  }
94
-
95
- public IRubyObject getInternalSubset(ThreadContext context) {
96
- IRubyObject internalSubset = super.getInternalSubset(context);
97
-
98
- // html documents are expected to have a default internal subset
99
- // the default values are the same ones used when the following
100
- // feature is turned on
101
- // "http://cyberneko.org/html/features/insert-doctype"
102
- // the reason we don't turn it on, is because it overrides the document's
103
- // declared doctype declaration.
104
-
105
- if (internalSubset.isNil()) {
106
- internalSubset = XmlDtd.newEmpty(context.getRuntime(),
107
- getDocument(),
108
- context.getRuntime().newString(DEFAULT_CONTENT_TYPE),
109
- context.getRuntime().newString(DEFAULT_PUBLIC_ID),
110
- context.getRuntime().newString(DEFAULT_SYTEM_ID));
111
- setInternalSubset(internalSubset);
138
+ }
139
+
140
+ private static void
141
+ stabilizeAttrs(Node node)
142
+ {
143
+ if (node.hasAttributes()) {
144
+ NamedNodeMap nodeMap = node.getAttributes();
145
+ for (int i = 0; i < nodeMap.getLength(); i++) {
146
+ Node n = nodeMap.item(i);
147
+ if (n instanceof Attr) {
148
+ stabilizeAttr((Attr) n);
112
149
  }
113
-
114
- return internalSubset;
150
+ }
115
151
  }
116
-
117
- @Override
118
- void init(Ruby runtime, Document document) {
119
- stabilizeTextContent(document);
120
- document.normalize();
121
- setInstanceVariable("@decorators", runtime.getNil());
122
- if (document.getDocumentElement() != null) {
123
- stabilizeAttrs(document.getDocumentElement());
124
- }
125
- }
126
-
127
- private static void stabilizeAttrs(Node node) {
128
- if (node.hasAttributes()) {
129
- NamedNodeMap nodeMap = node.getAttributes();
130
- for (int i=0; i<nodeMap.getLength(); i++) {
131
- Node n = nodeMap.item(i);
132
- if (n instanceof Attr) {
133
- stabilizeAttr((Attr) n);
134
- }
135
- }
136
- }
137
- NodeList children = node.getChildNodes();
138
- for (int i=0; i<children.getLength(); i++) {
139
- stabilizeAttrs(children.item(i));
140
- }
141
- }
142
-
143
- public void setParsedEncoding(String encoding) {
144
- parsed_encoding = encoding;
145
- }
146
-
147
- public String getPraedEncoding() {
148
- return parsed_encoding;
149
- }
150
-
151
- /*
152
- * call-seq:
153
- * read_io(io, url, encoding, options)
154
- *
155
- * Read the HTML document from +io+ with given +url+, +encoding+,
156
- * and +options+. See Nokogiri::HTML.parse
157
- */
158
- @JRubyMethod(meta = true, required = 4)
159
- public static IRubyObject read_io(ThreadContext context, IRubyObject klass, IRubyObject[] args) {
160
- HtmlDomParserContext ctx = new HtmlDomParserContext(context.runtime, args[2], args[3]);
161
- ctx.setIOInputSource(context, args[0], args[1]);
162
- return ctx.parse(context, (RubyClass) klass, args[1]);
163
- }
164
-
165
- /*
166
- * call-seq:
167
- * read_memory(string, url, encoding, options)
168
- *
169
- * Read the HTML document contained in +string+ with given +url+, +encoding+,
170
- * and +options+. See Nokogiri::HTML.parse
171
- */
172
- @JRubyMethod(meta = true, required = 4)
173
- public static IRubyObject read_memory(ThreadContext context, IRubyObject klass, IRubyObject[] args) {
174
- HtmlDomParserContext ctx = new HtmlDomParserContext(context.runtime, args[2], args[3]);
175
- ctx.setStringInputSource(context, args[0], args[1]);
176
- return ctx.parse(context, (RubyClass) klass, args[1]);
152
+ NodeList children = node.getChildNodes();
153
+ for (int i = 0; i < children.getLength(); i++) {
154
+ stabilizeAttrs(children.item(i));
177
155
  }
156
+ }
157
+
158
+ public void
159
+ setParsedEncoding(String encoding)
160
+ {
161
+ parsed_encoding = encoding;
162
+ }
163
+
164
+ public String
165
+ getPraedEncoding()
166
+ {
167
+ return parsed_encoding;
168
+ }
169
+
170
+ /*
171
+ * call-seq:
172
+ * read_io(io, url, encoding, options)
173
+ *
174
+ * Read the HTML document from +io+ with given +url+, +encoding+,
175
+ * and +options+. See Nokogiri::HTML.parse
176
+ */
177
+ @JRubyMethod(meta = true, required = 4)
178
+ public static IRubyObject
179
+ read_io(ThreadContext context, IRubyObject klass, IRubyObject[] args)
180
+ {
181
+ HtmlDomParserContext ctx = new HtmlDomParserContext(context.runtime, args[2], args[3]);
182
+ ctx.setIOInputSource(context, args[0], args[1]);
183
+ return ctx.parse(context, (RubyClass) klass, args[1]);
184
+ }
185
+
186
+ /*
187
+ * call-seq:
188
+ * read_memory(string, url, encoding, options)
189
+ *
190
+ * Read the HTML document contained in +string+ with given +url+, +encoding+,
191
+ * and +options+. See Nokogiri::HTML.parse
192
+ */
193
+ @JRubyMethod(meta = true, required = 4)
194
+ public static IRubyObject
195
+ read_memory(ThreadContext context, IRubyObject klass, IRubyObject[] args)
196
+ {
197
+ HtmlDomParserContext ctx = new HtmlDomParserContext(context.runtime, args[2], args[3]);
198
+ ctx.setStringInputSource(context, args[0], args[1]);
199
+ return ctx.parse(context, (RubyClass) klass, args[1]);
200
+ }
178
201
  }
@@ -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.
@@ -49,100 +49,117 @@ import org.jruby.runtime.builtin.IRubyObject;
49
49
 
50
50
  /**
51
51
  * Class for Nokogiri::HTML::ElementDescription.
52
- *
52
+ *
53
53
  * @author Patrick Mahoney <pat@polycrystal.org>
54
54
  */
55
- @JRubyClass(name="Nokogiri::HTML::ElementDescription")
56
- public class HtmlElementDescription extends RubyObject {
57
-
58
- /**
59
- * Stores memoized hash of element -> list of valid subelements.
60
- */
61
- static protected Map<Short, List<String>> subElements;
62
- static {
63
- Map<Short, List<String>> _subElements =
64
- new HashMap<Short, List<String>>();
65
- subElements = Collections.synchronizedMap(_subElements);
66
- }
67
-
68
- protected HTMLElements.Element element;
69
-
70
- public HtmlElementDescription(Ruby runtime, RubyClass rubyClass) {
71
- super(runtime, rubyClass);
72
- }
73
-
74
- /**
75
- * Lookup the list of sub elements of <code>code</code>. If not
76
- * already stored, iterate through all elements to find valid
77
- * subelements; save this list and return it.
78
- */
79
- protected static List<String> findSubElements(HTMLElements.Element elem) {
80
- List<String> subs = subElements.get(elem.code);
81
-
82
- if (subs == null) {
83
- subs = new ArrayList<String>();
84
-
85
- /*
86
- * A bit of a hack. NekoHtml source code shows that
87
- * UNKNOWN is the highest value element. We cannot access
88
- * the list of elements directly because it's protected.
89
- */
90
- for (short c = 0; c < HTMLElements.UNKNOWN; c++) {
91
- HTMLElements.Element maybe_sub =
92
- HTMLElements.getElement(c);
93
- if (maybe_sub.isParent(elem)) {
94
- subs.add(maybe_sub.name);
95
- }
96
- }
97
-
98
- subElements.put(elem.code, subs);
55
+ @JRubyClass(name = "Nokogiri::HTML::ElementDescription")
56
+ public class HtmlElementDescription extends RubyObject
57
+ {
58
+
59
+ /**
60
+ * Stores memoized hash of element -> list of valid subelements.
61
+ */
62
+ static protected Map<Short, List<String>> subElements;
63
+ static
64
+ {
65
+ Map<Short, List<String>> _subElements =
66
+ new HashMap<Short, List<String>>();
67
+ subElements = Collections.synchronizedMap(_subElements);
68
+ }
69
+
70
+ protected HTMLElements.Element element;
71
+
72
+ public
73
+ HtmlElementDescription(Ruby runtime, RubyClass rubyClass)
74
+ {
75
+ super(runtime, rubyClass);
76
+ }
77
+
78
+ /**
79
+ * Lookup the list of sub elements of <code>code</code>. If not
80
+ * already stored, iterate through all elements to find valid
81
+ * subelements; save this list and return it.
82
+ */
83
+ protected static List<String>
84
+ findSubElements(HTMLElements.Element elem)
85
+ {
86
+ List<String> subs = subElements.get(elem.code);
87
+
88
+ if (subs == null) {
89
+ subs = new ArrayList<String>();
90
+
91
+ /*
92
+ * A bit of a hack. NekoHtml source code shows that
93
+ * UNKNOWN is the highest value element. We cannot access
94
+ * the list of elements directly because it's protected.
95
+ */
96
+ for (short c = 0; c < HTMLElements.UNKNOWN; c++) {
97
+ HTMLElements.Element maybe_sub =
98
+ HTMLElements.getElement(c);
99
+ if (maybe_sub.isParent(elem)) {
100
+ subs.add(maybe_sub.name);
99
101
  }
102
+ }
100
103
 
101
- return subs;
104
+ subElements.put(elem.code, subs);
102
105
  }
103
106
 
104
- @JRubyMethod(name="[]", meta=true)
105
- public static IRubyObject get(ThreadContext context,
106
- IRubyObject klazz, IRubyObject name) {
107
-
108
- // nekohtml will return an element even for invalid names, see
109
- // http://sourceforge.net/p/nekohtml/code/HEAD/tree/trunk/src/org/cyberneko/html/HTMLElements.java#l514
110
- // which breaks `test_fetch_nonexistent'
111
- HTMLElements.Element elem = HTMLElements.getElement(name.asJavaString(), HTMLElements.NO_SUCH_ELEMENT);
112
- if (elem == HTMLElements.NO_SUCH_ELEMENT)
113
- return context.nil;
114
-
115
- HtmlElementDescription desc =
116
- new HtmlElementDescription(context.getRuntime(), (RubyClass)klazz);
117
- desc.element = elem;
118
- return desc;
107
+ return subs;
108
+ }
109
+
110
+ @JRubyMethod(name = "[]", meta = true)
111
+ public static IRubyObject
112
+ get(ThreadContext context,
113
+ IRubyObject klazz, IRubyObject name)
114
+ {
115
+
116
+ // nekohtml will return an element even for invalid names, see
117
+ // http://sourceforge.net/p/nekohtml/code/HEAD/tree/trunk/src/org/cyberneko/html/HTMLElements.java#l514
118
+ // which breaks `test_fetch_nonexistent'
119
+ HTMLElements.Element elem = HTMLElements.getElement(name.asJavaString(), HTMLElements.NO_SUCH_ELEMENT);
120
+ if (elem == HTMLElements.NO_SUCH_ELEMENT) {
121
+ return context.nil;
119
122
  }
120
123
 
121
- @JRubyMethod()
122
- public IRubyObject name(ThreadContext context) {
123
- return context.getRuntime().newString(element.name.toLowerCase());
124
+ HtmlElementDescription desc =
125
+ new HtmlElementDescription(context.getRuntime(), (RubyClass)klazz);
126
+ desc.element = elem;
127
+ return desc;
128
+ }
129
+
130
+ @JRubyMethod()
131
+ public IRubyObject
132
+ name(ThreadContext context)
133
+ {
134
+ return context.getRuntime().newString(element.name.toLowerCase());
135
+ }
136
+
137
+ @JRubyMethod(name = "inline?")
138
+ public IRubyObject
139
+ inline_eh(ThreadContext context)
140
+ {
141
+ return context.getRuntime().newBoolean(element.isInline());
142
+ }
143
+
144
+ @JRubyMethod(name = "empty?")
145
+ public IRubyObject
146
+ empty_eh(ThreadContext context)
147
+ {
148
+ return context.getRuntime().newBoolean(element.isEmpty());
149
+ }
150
+
151
+ @JRubyMethod()
152
+ public IRubyObject
153
+ sub_elements(ThreadContext context)
154
+ {
155
+ Ruby ruby = context.getRuntime();
156
+ List<String> subs = findSubElements(element);
157
+ IRubyObject[] ary = new IRubyObject[subs.size()];
158
+ for (int i = 0; i < subs.size(); ++i) {
159
+ ary[i] = ruby.newString(subs.get(i));
124
160
  }
125
161
 
126
- @JRubyMethod(name="inline?")
127
- public IRubyObject inline_eh(ThreadContext context) {
128
- return context.getRuntime().newBoolean(element.isInline());
129
- }
130
-
131
- @JRubyMethod(name="empty?")
132
- public IRubyObject empty_eh(ThreadContext context) {
133
- return context.getRuntime().newBoolean(element.isEmpty());
134
- }
135
-
136
- @JRubyMethod()
137
- public IRubyObject sub_elements(ThreadContext context) {
138
- Ruby ruby = context.getRuntime();
139
- List<String> subs = findSubElements(element);
140
- IRubyObject[] ary = new IRubyObject[subs.size()];
141
- for (int i = 0; i < subs.size(); ++i) {
142
- ary[i] = ruby.newString(subs.get(i));
143
- }
144
-
145
- return ruby.newArray(ary);
146
- }
162
+ return ruby.newArray(ary);
163
+ }
147
164
 
148
165
  }