nokogiri 1.11.0.rc4-java → 1.11.5-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 (144) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +3 -0
  3. data/LICENSE-DEPENDENCIES.md +12 -12
  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 -1620
  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 +85 -104
  32. data/ext/java/nokogiri/XmlSaxParserContext.java +328 -315
  33. data/ext/java/nokogiri/XmlSaxPushParser.java +227 -220
  34. data/ext/java/nokogiri/XmlSchema.java +328 -295
  35. data/ext/java/nokogiri/XmlSyntaxError.java +113 -115
  36. data/ext/java/nokogiri/XmlText.java +55 -76
  37. data/ext/java/nokogiri/XmlXpathContext.java +240 -238
  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 -202
  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 +81 -98
  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 +116 -131
  54. data/ext/java/nokogiri/internals/NokogiriXPathFunctionResolver.java +34 -56
  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 +34 -474
  95. data/ext/nokogiri/extconf.rb +270 -183
  96. data/ext/nokogiri/html_document.c +10 -15
  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 +67 -64
  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 +190 -60
  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 +29 -23
  122. data/ext/nokogiri/xml_sax_parser.c +117 -112
  123. data/ext/nokogiri/xml_sax_parser_context.c +101 -84
  124. data/ext/nokogiri/xml_sax_push_parser.c +36 -27
  125. data/ext/nokogiri/xml_schema.c +48 -42
  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 +134 -127
  129. data/ext/nokogiri/xslt_stylesheet.c +157 -157
  130. data/lib/nokogiri.rb +2 -6
  131. data/lib/nokogiri/css/parser.rb +1 -1
  132. data/lib/nokogiri/extension.rb +26 -0
  133. data/lib/nokogiri/html/document_fragment.rb +15 -15
  134. data/lib/nokogiri/nokogiri.jar +0 -0
  135. data/lib/nokogiri/version/constant.rb +1 -1
  136. data/lib/nokogiri/version/info.rb +32 -8
  137. data/lib/nokogiri/xml/document.rb +74 -28
  138. data/lib/nokogiri/xml/node.rb +39 -42
  139. data/lib/nokogiri/xml/reader.rb +2 -9
  140. data/lib/nokogiri/xml/xpath.rb +1 -3
  141. data/lib/nokogiri/xml/xpath/syntax_error.rb +1 -1
  142. metadata +62 -127
  143. data/ext/nokogiri/xml_io.c +0 -63
  144. data/ext/nokogiri/xml_libxml2_hacks.c +0 -112
@@ -1,35 +1,3 @@
1
- /**
2
- * (The MIT License)
3
- *
4
- * Copyright (c) 2008 - 2012:
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 org.jruby.Ruby;
@@ -55,124 +23,147 @@ import static nokogiri.internals.NokogiriHelpers.getNokogiriClass;
55
23
  * @author sergio
56
24
  * @author Yoko Harada <yokolet@gmail.com>
57
25
  */
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);
26
+ @JRubyClass(name = "Nokogiri::HTML::Document", parent = "Nokogiri::XML::Document")
27
+ public class HtmlDocument extends XmlDocument
28
+ {
29
+ private static final String DEFAULT_CONTENT_TYPE = "html";
30
+ private static final String DEFAULT_PUBLIC_ID = "-//W3C//DTD HTML 4.01//EN";
31
+ private static final String DEFAULT_SYTEM_ID = "http://www.w3.org/TR/html4/strict.dtd";
32
+
33
+ private String parsed_encoding = null;
34
+
35
+ public
36
+ HtmlDocument(Ruby ruby, RubyClass klazz)
37
+ {
38
+ super(ruby, klazz);
39
+ }
40
+
41
+ public
42
+ HtmlDocument(Ruby runtime, Document document)
43
+ {
44
+ this(runtime, getNokogiriClass(runtime, "Nokogiri::XML::Document"), document);
45
+ }
46
+
47
+ public
48
+ HtmlDocument(Ruby ruby, RubyClass klazz, Document doc)
49
+ {
50
+ super(ruby, klazz, doc);
51
+ }
52
+
53
+ @JRubyMethod(name = "new", meta = true, rest = true, required = 0)
54
+ public static IRubyObject
55
+ rbNew(ThreadContext context, IRubyObject klazz, IRubyObject[] args)
56
+ {
57
+ final Ruby runtime = context.runtime;
58
+ HtmlDocument htmlDocument;
59
+ try {
60
+ Document docNode = createNewDocument(runtime);
61
+ htmlDocument = (HtmlDocument) NokogiriService.HTML_DOCUMENT_ALLOCATOR.allocate(runtime, (RubyClass) klazz);
62
+ htmlDocument.setDocumentNode(context.runtime, docNode);
63
+ } catch (Exception ex) {
64
+ throw asRuntimeError(runtime, "couldn't create document: ", ex);
68
65
  }
69
66
 
70
- public HtmlDocument(Ruby runtime, Document document) {
71
- this(runtime, getNokogiriClass(runtime, "Nokogiri::XML::Document"), document);
67
+ Helpers.invoke(context, htmlDocument, "initialize", args);
68
+
69
+ return htmlDocument;
70
+ }
71
+
72
+ public IRubyObject
73
+ getInternalSubset(ThreadContext context)
74
+ {
75
+ IRubyObject internalSubset = super.getInternalSubset(context);
76
+
77
+ // html documents are expected to have a default internal subset
78
+ // the default values are the same ones used when the following
79
+ // feature is turned on
80
+ // "http://cyberneko.org/html/features/insert-doctype"
81
+ // the reason we don't turn it on, is because it overrides the document's
82
+ // declared doctype declaration.
83
+
84
+ if (internalSubset.isNil()) {
85
+ internalSubset = XmlDtd.newEmpty(context.getRuntime(),
86
+ getDocument(),
87
+ context.getRuntime().newString(DEFAULT_CONTENT_TYPE),
88
+ context.getRuntime().newString(DEFAULT_PUBLIC_ID),
89
+ context.getRuntime().newString(DEFAULT_SYTEM_ID));
90
+ setInternalSubset(internalSubset);
72
91
  }
73
92
 
74
- public HtmlDocument(Ruby ruby, RubyClass klazz, Document doc) {
75
- super(ruby, klazz, doc);
93
+ return internalSubset;
94
+ }
95
+
96
+ @Override
97
+ void
98
+ init(Ruby runtime, Document document)
99
+ {
100
+ stabilizeTextContent(document);
101
+ document.normalize();
102
+ setInstanceVariable("@decorators", runtime.getNil());
103
+ if (document.getDocumentElement() != null) {
104
+ stabilizeAttrs(document.getDocumentElement());
76
105
  }
77
-
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);
106
+ }
107
+
108
+ private static void
109
+ stabilizeAttrs(Node node)
110
+ {
111
+ if (node.hasAttributes()) {
112
+ NamedNodeMap nodeMap = node.getAttributes();
113
+ for (int i = 0; i < nodeMap.getLength(); i++) {
114
+ Node n = nodeMap.item(i);
115
+ if (n instanceof Attr) {
116
+ stabilizeAttr((Attr) n);
88
117
  }
89
-
90
- Helpers.invoke(context, htmlDocument, "initialize", args);
91
-
92
- return htmlDocument;
118
+ }
93
119
  }
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);
112
- }
113
-
114
- return internalSubset;
115
- }
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]);
120
+ NodeList children = node.getChildNodes();
121
+ for (int i = 0; i < children.getLength(); i++) {
122
+ stabilizeAttrs(children.item(i));
177
123
  }
124
+ }
125
+
126
+ public void
127
+ setParsedEncoding(String encoding)
128
+ {
129
+ parsed_encoding = encoding;
130
+ }
131
+
132
+ public String
133
+ getPraedEncoding()
134
+ {
135
+ return parsed_encoding;
136
+ }
137
+
138
+ /*
139
+ * call-seq:
140
+ * read_io(io, url, encoding, options)
141
+ *
142
+ * Read the HTML document from +io+ with given +url+, +encoding+,
143
+ * and +options+. See Nokogiri::HTML.parse
144
+ */
145
+ @JRubyMethod(meta = true, required = 4)
146
+ public static IRubyObject
147
+ read_io(ThreadContext context, IRubyObject klass, IRubyObject[] args)
148
+ {
149
+ HtmlDomParserContext ctx = new HtmlDomParserContext(context.runtime, args[2], args[3]);
150
+ ctx.setIOInputSource(context, args[0], args[1]);
151
+ return ctx.parse(context, (RubyClass) klass, args[1]);
152
+ }
153
+
154
+ /*
155
+ * call-seq:
156
+ * read_memory(string, url, encoding, options)
157
+ *
158
+ * Read the HTML document contained in +string+ with given +url+, +encoding+,
159
+ * and +options+. See Nokogiri::HTML.parse
160
+ */
161
+ @JRubyMethod(meta = true, required = 4)
162
+ public static IRubyObject
163
+ read_memory(ThreadContext context, IRubyObject klass, IRubyObject[] args)
164
+ {
165
+ HtmlDomParserContext ctx = new HtmlDomParserContext(context.runtime, args[2], args[3]);
166
+ ctx.setStringInputSource(context, args[0], args[1]);
167
+ return ctx.parse(context, (RubyClass) klass, args[1]);
168
+ }
178
169
  }
@@ -1,35 +1,3 @@
1
- /**
2
- * (The MIT License)
3
- *
4
- * Copyright (c) 2008 - 2012:
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 java.util.ArrayList;
@@ -49,100 +17,117 @@ import org.jruby.runtime.builtin.IRubyObject;
49
17
 
50
18
  /**
51
19
  * Class for Nokogiri::HTML::ElementDescription.
52
- *
20
+ *
53
21
  * @author Patrick Mahoney <pat@polycrystal.org>
54
22
  */
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);
23
+ @JRubyClass(name = "Nokogiri::HTML::ElementDescription")
24
+ public class HtmlElementDescription extends RubyObject
25
+ {
26
+
27
+ /**
28
+ * Stores memoized hash of element -> list of valid subelements.
29
+ */
30
+ static protected Map<Short, List<String>> subElements;
31
+ static
32
+ {
33
+ Map<Short, List<String>> _subElements =
34
+ new HashMap<Short, List<String>>();
35
+ subElements = Collections.synchronizedMap(_subElements);
36
+ }
37
+
38
+ protected HTMLElements.Element element;
39
+
40
+ public
41
+ HtmlElementDescription(Ruby runtime, RubyClass rubyClass)
42
+ {
43
+ super(runtime, rubyClass);
44
+ }
45
+
46
+ /**
47
+ * Lookup the list of sub elements of <code>code</code>. If not
48
+ * already stored, iterate through all elements to find valid
49
+ * subelements; save this list and return it.
50
+ */
51
+ protected static List<String>
52
+ findSubElements(HTMLElements.Element elem)
53
+ {
54
+ List<String> subs = subElements.get(elem.code);
55
+
56
+ if (subs == null) {
57
+ subs = new ArrayList<String>();
58
+
59
+ /*
60
+ * A bit of a hack. NekoHtml source code shows that
61
+ * UNKNOWN is the highest value element. We cannot access
62
+ * the list of elements directly because it's protected.
63
+ */
64
+ for (short c = 0; c < HTMLElements.UNKNOWN; c++) {
65
+ HTMLElements.Element maybe_sub =
66
+ HTMLElements.getElement(c);
67
+ if (maybe_sub.isParent(elem)) {
68
+ subs.add(maybe_sub.name);
99
69
  }
70
+ }
100
71
 
101
- return subs;
72
+ subElements.put(elem.code, subs);
102
73
  }
103
74
 
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;
75
+ return subs;
76
+ }
77
+
78
+ @JRubyMethod(name = "[]", meta = true)
79
+ public static IRubyObject
80
+ get(ThreadContext context,
81
+ IRubyObject klazz, IRubyObject name)
82
+ {
83
+
84
+ // nekohtml will return an element even for invalid names, see
85
+ // http://sourceforge.net/p/nekohtml/code/HEAD/tree/trunk/src/org/cyberneko/html/HTMLElements.java#l514
86
+ // which breaks `test_fetch_nonexistent'
87
+ HTMLElements.Element elem = HTMLElements.getElement(name.asJavaString(), HTMLElements.NO_SUCH_ELEMENT);
88
+ if (elem == HTMLElements.NO_SUCH_ELEMENT) {
89
+ return context.nil;
119
90
  }
120
91
 
121
- @JRubyMethod()
122
- public IRubyObject name(ThreadContext context) {
123
- return context.getRuntime().newString(element.name.toLowerCase());
92
+ HtmlElementDescription desc =
93
+ new HtmlElementDescription(context.getRuntime(), (RubyClass)klazz);
94
+ desc.element = elem;
95
+ return desc;
96
+ }
97
+
98
+ @JRubyMethod()
99
+ public IRubyObject
100
+ name(ThreadContext context)
101
+ {
102
+ return context.getRuntime().newString(element.name.toLowerCase());
103
+ }
104
+
105
+ @JRubyMethod(name = "inline?")
106
+ public IRubyObject
107
+ inline_eh(ThreadContext context)
108
+ {
109
+ return context.getRuntime().newBoolean(element.isInline());
110
+ }
111
+
112
+ @JRubyMethod(name = "empty?")
113
+ public IRubyObject
114
+ empty_eh(ThreadContext context)
115
+ {
116
+ return context.getRuntime().newBoolean(element.isEmpty());
117
+ }
118
+
119
+ @JRubyMethod()
120
+ public IRubyObject
121
+ sub_elements(ThreadContext context)
122
+ {
123
+ Ruby ruby = context.getRuntime();
124
+ List<String> subs = findSubElements(element);
125
+ IRubyObject[] ary = new IRubyObject[subs.size()];
126
+ for (int i = 0; i < subs.size(); ++i) {
127
+ ary[i] = ruby.newString(subs.get(i));
124
128
  }
125
129
 
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
- }
130
+ return ruby.newArray(ary);
131
+ }
147
132
 
148
133
  }