nokogiri 1.5.0.beta.1 → 1.5.0.beta.2

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 (114) hide show
  1. data/CHANGELOG.ja.rdoc +28 -8
  2. data/CHANGELOG.rdoc +23 -0
  3. data/Manifest.txt +63 -1
  4. data/README.ja.rdoc +1 -1
  5. data/README.rdoc +22 -4
  6. data/Rakefile +6 -2
  7. data/ext/java/nokogiri/EncodingHandler.java +92 -0
  8. data/ext/java/nokogiri/HtmlDocument.java +116 -0
  9. data/ext/java/nokogiri/HtmlElementDescription.java +111 -0
  10. data/ext/java/nokogiri/HtmlEntityLookup.java +45 -0
  11. data/ext/java/nokogiri/HtmlSaxParserContext.java +218 -0
  12. data/ext/java/nokogiri/NokogiriService.java +370 -0
  13. data/ext/java/nokogiri/XmlAttr.java +147 -0
  14. data/ext/java/nokogiri/XmlAttributeDecl.java +98 -0
  15. data/ext/java/nokogiri/XmlCdata.java +50 -0
  16. data/ext/java/nokogiri/XmlComment.java +47 -0
  17. data/ext/java/nokogiri/XmlDocument.java +463 -0
  18. data/ext/java/nokogiri/XmlDocumentFragment.java +207 -0
  19. data/ext/java/nokogiri/XmlDtd.java +427 -0
  20. data/ext/java/nokogiri/XmlElement.java +172 -0
  21. data/ext/java/nokogiri/XmlElementContent.java +350 -0
  22. data/ext/java/nokogiri/XmlElementDecl.java +115 -0
  23. data/ext/java/nokogiri/XmlEntityDecl.java +129 -0
  24. data/ext/java/nokogiri/XmlEntityReference.java +42 -0
  25. data/ext/java/nokogiri/XmlNamespace.java +77 -0
  26. data/ext/java/nokogiri/XmlNode.java +1399 -0
  27. data/ext/java/nokogiri/XmlNodeSet.java +248 -0
  28. data/ext/java/nokogiri/XmlProcessingInstruction.java +70 -0
  29. data/ext/java/nokogiri/XmlReader.java +373 -0
  30. data/ext/java/nokogiri/XmlRelaxng.java +166 -0
  31. data/ext/java/nokogiri/XmlSaxParserContext.java +308 -0
  32. data/ext/java/nokogiri/XmlSaxPushParser.java +146 -0
  33. data/ext/java/nokogiri/XmlSchema.java +142 -0
  34. data/ext/java/nokogiri/XmlSyntaxError.java +84 -0
  35. data/ext/java/nokogiri/XmlText.java +96 -0
  36. data/ext/java/nokogiri/XmlXpathContext.java +130 -0
  37. data/ext/java/nokogiri/XsltStylesheet.java +126 -0
  38. data/ext/java/nokogiri/internals/HtmlDomParserContext.java +181 -0
  39. data/ext/java/nokogiri/internals/NokogiriDocumentCache.java +39 -0
  40. data/ext/java/nokogiri/internals/NokogiriErrorHandler.java +42 -0
  41. data/ext/java/nokogiri/internals/NokogiriHandler.java +251 -0
  42. data/ext/java/nokogiri/internals/NokogiriHelpers.java +526 -0
  43. data/ext/java/nokogiri/internals/NokogiriNamespaceCache.java +136 -0
  44. data/ext/java/nokogiri/internals/NokogiriNamespaceContext.java +80 -0
  45. data/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler.java +37 -0
  46. data/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler4NekoHtml.java +54 -0
  47. data/ext/java/nokogiri/internals/NokogiriStrictErrorHandler.java +49 -0
  48. data/ext/java/nokogiri/internals/NokogiriXPathFunction.java +88 -0
  49. data/ext/java/nokogiri/internals/NokogiriXPathFunctionResolver.java +23 -0
  50. data/ext/java/nokogiri/internals/ParserContext.java +235 -0
  51. data/ext/java/nokogiri/internals/PushInputStream.java +381 -0
  52. data/ext/java/nokogiri/internals/ReaderNode.java +431 -0
  53. data/ext/java/nokogiri/internals/SaveContext.java +249 -0
  54. data/ext/java/nokogiri/internals/SchemaErrorHandler.java +35 -0
  55. data/ext/java/nokogiri/internals/XmlDeclHandler.java +10 -0
  56. data/ext/java/nokogiri/internals/XmlDomParser.java +45 -0
  57. data/ext/java/nokogiri/internals/XmlDomParserContext.java +201 -0
  58. data/ext/java/nokogiri/internals/XmlSaxParser.java +33 -0
  59. data/ext/nokogiri/depend +32 -0
  60. data/ext/nokogiri/extconf.rb +61 -32
  61. data/ext/nokogiri/nokogiri.c +0 -5
  62. data/ext/nokogiri/nokogiri.h +2 -2
  63. data/ext/nokogiri/xml_document.c +5 -0
  64. data/ext/nokogiri/xml_libxml2_hacks.c +112 -0
  65. data/ext/nokogiri/xml_libxml2_hacks.h +12 -0
  66. data/ext/nokogiri/xml_node.c +56 -16
  67. data/ext/nokogiri/xml_node_set.c +7 -7
  68. data/ext/nokogiri/xml_reader.c +20 -1
  69. data/ext/nokogiri/xml_relax_ng.c +0 -7
  70. data/ext/nokogiri/xml_xpath_context.c +2 -0
  71. data/lib/isorelax.jar +0 -0
  72. data/lib/jing.jar +0 -0
  73. data/lib/nekodtd.jar +0 -0
  74. data/lib/nekohtml.jar +0 -0
  75. data/lib/nokogiri.rb +1 -2
  76. data/lib/nokogiri/css/generated_parser.rb +155 -148
  77. data/lib/nokogiri/css/generated_tokenizer.rb +2 -1
  78. data/lib/nokogiri/css/parser.y +3 -0
  79. data/lib/nokogiri/css/xpath_visitor.rb +1 -7
  80. data/lib/nokogiri/html.rb +2 -2
  81. data/lib/nokogiri/html/document_fragment.rb +7 -4
  82. data/lib/nokogiri/nokogiri.jar +0 -0
  83. data/lib/nokogiri/version.rb +3 -6
  84. data/lib/nokogiri/xml/builder.rb +1 -1
  85. data/lib/nokogiri/xml/document.rb +1 -2
  86. data/lib/nokogiri/xml/document_fragment.rb +7 -0
  87. data/lib/nokogiri/xml/node.rb +5 -3
  88. data/lib/nokogiri/xml/node_set.rb +25 -0
  89. data/lib/nokogiri/xml/reader.rb +2 -0
  90. data/lib/nokogiri/xml/sax/document.rb +3 -1
  91. data/lib/xercesImpl.jar +0 -0
  92. data/spec/helper.rb +3 -0
  93. data/spec/xml/reader_spec.rb +307 -0
  94. data/tasks/test.rb +1 -1
  95. data/test/css/test_parser.rb +11 -1
  96. data/test/html/sax/test_parser_context.rb +2 -2
  97. data/test/html/test_document.rb +2 -2
  98. data/test/html/test_document_fragment.rb +34 -6
  99. data/test/test_memory_leak.rb +2 -2
  100. data/test/test_reader.rb +28 -6
  101. data/test/test_xslt_transforms.rb +2 -3
  102. data/test/xml/test_attr.rb +31 -4
  103. data/test/xml/test_builder.rb +5 -5
  104. data/test/xml/test_cdata.rb +3 -3
  105. data/test/xml/test_document.rb +8 -8
  106. data/test/xml/test_document_fragment.rb +4 -12
  107. data/test/xml/test_node.rb +1 -1
  108. data/test/xml/test_node_reparenting.rb +26 -11
  109. data/test/xml/test_node_set.rb +38 -2
  110. data/test/xml/test_text.rb +11 -2
  111. data/test/xml/test_unparented_node.rb +1 -1
  112. data/test/xml/test_xpath.rb +11 -7
  113. metadata +68 -5
  114. data/lib/nokogiri/version_warning.rb +0 -14
@@ -1,8 +1,28 @@
1
- === 1.4.2 2010年5月22日
1
+ === 1.4.3 2010年7月28日
2
2
 
3
3
  * 新しい機能
4
4
 
5
- * XML::Node#parse 定義されたコンテキストノードで、XML 又はHTMLのフレグメント
5
+ * XML::Reader#empty_element? - 子の無いエレメントにtrueを返す  #262
6
+ * Node#remove_namespaces! - 1.4.2では 名前空間のみを取り除いていたが、
7
+ 1.4.3 では名前空間及び、名前空間宣言も取り除く #294
8
+
9
+ * バグの修正
10
+
11
+ * XML::NodeSet#{include?,delete,push} はXML::Namespaceを受入れる
12
+ * XML::Document#parse - 1.4.3より文書内の文脈を解析する機能を追加
13
+ * XML::DocumentFragment#inner_html= 文脈解析を共に実行する #298, #281
14
+ * lib/nokogiri/css/parser.y はCSSと疑似選別の両方を機能
15
+ * 演算によって近隣に存在する併合型ノードへの遊離問題の有無に関わらず、一切の
16
+ 弊害なしにテキストノードの繰り返しが実行可能  #283
17
+ * xmlFirstElementChild et al.による libxml2バージョンでの不適合性を修正 #303
18
+ * XML::Attr#add_namespace (!)文字通りの機能実現!  #252
19
+ * HTML::DocumentFragment が文字列に存在するエンコードを使用 #305
20
+
21
+ === 1.4.2 2010年5月22日
22
+
23
+ * 新機能
24
+
25
+ * XML::Node#parse 定義されたコンテキストノードでXML 又はHTMLのフレグメント
6
26
  を解析する
7
27
  * XML::Node#namespacesが子ノードとその祖先ノード内で定義された全ての名前空間
8
28
  を返すようになった(以前は祖先ノードの名前空間は返されなかった)
@@ -30,18 +50,18 @@
30
50
  * XML::Node#xpath はNodeSetのオブジェクト以外のオブジェクトを返す GH #208
31
51
  * XSLT::StyleSheet#transformはパラメーターのハッシュを受け入れる GH #223
32
52
  * CSSのnot()の疑似セレクタの修正  GH #205
33
- * XML::Builder はノード達が切り離されても破壊しない(vihaiの協力に感謝)
53
+ * XML::Builder はノードらが切り離されても破壊しない(vihaiの協力に感謝)
34
54
  GH #228
35
55
  * SAX parser経由でエンコードを強制することが出来る  Eugene Pimenovに感謝!
36
56
  GH #204
37
- * XML::DocumentFragment はML::Node#parse を使用して子供を限定する
38
- * XML Reader内のメモリリークを修正  sdorさん、ありがとう! GH#244
57
+ * XML::DocumentFragment はML::Node#parse を使用して子を限定する
58
+ * XML Reader内のメモリリーク修正  sdorさん、ありがとう! GH#244
39
59
 
40
60
  * ノート
41
61
 
42
- * 今日4月18日現在、Windows gems は libxml 2.7.6 とlibxslt
43
- 1.1.26にDLLsを正規装備しています。このリリース以前にも既にDLLsはlibxml
44
- 2.7.3 と libxslt 1.1.24に正規装備されています。
62
+ * 今日4月18日現在、Windows gems は libxml 2.7.7 とlibxslt
63
+ 1.1.26にDLLsを標準装備しています。このリリース以前にも既にDLLsはlibxml
64
+ 2.7.3 と libxslt 1.1.24に標準装備済み。
45
65
 
46
66
  === 1.4.1 2009年12月10日
47
67
 
@@ -10,6 +10,29 @@
10
10
  * LibXML 2.6.16 and earlier are deprecated. Nokogiri will refuse to install.
11
11
  * FFI support is removed.
12
12
 
13
+ === 1.4.3 / 2010/07/28
14
+
15
+ * New Features
16
+
17
+ * XML::Reader#empty_element? returns true for empty elements. #262
18
+ * Node#remove_namespaces! now removes namespace *declarations* as well. #294
19
+ * NodeSet#at_xpath, NodeSet#at_css and NodeSet#> do what the corresponding
20
+ methods of Node do.
21
+
22
+ * Bugfixes
23
+
24
+ * XML::NodeSet#{include?,delete,push} accept an XML::Namespace
25
+ * XML::Document#parse added for parsing in the context of a document
26
+ * XML::DocumentFragment#inner_html= works with contextual parsing! #298, #281
27
+ * lib/nokogiri/css/parser.y Combined CSS functions + pseudo selectors fixed
28
+ * Reparenting text nodes is safe, even when the operation frees adjacent merged nodes. #283
29
+ * Fixed libxml2 versionitis issue with xmlFirstElementChild et al. #303
30
+ * XML::Attr#add_namespace now works as expected. #252
31
+ * HTML::DocumentFragment uses the string's encoding. #305
32
+ * Fix the CSS3 selector translation rule for the general sibling combinator
33
+ (a.k.a. preceding selector) that incorrectly converted "E + F G" to
34
+ "//F//G[preceding-sibling::E]".
35
+
13
36
  === 1.4.2 / 2010/05/22
14
37
 
15
38
  * New Features
@@ -7,6 +7,59 @@ README.rdoc
7
7
  Rakefile
8
8
  bin/nokogiri
9
9
  deps.rip
10
+ ext/java/nokogiri/EncodingHandler.java
11
+ ext/java/nokogiri/HtmlDocument.java
12
+ ext/java/nokogiri/HtmlElementDescription.java
13
+ ext/java/nokogiri/HtmlEntityLookup.java
14
+ ext/java/nokogiri/HtmlSaxParserContext.java
15
+ ext/java/nokogiri/NokogiriService.java
16
+ ext/java/nokogiri/XmlAttr.java
17
+ ext/java/nokogiri/XmlAttributeDecl.java
18
+ ext/java/nokogiri/XmlCdata.java
19
+ ext/java/nokogiri/XmlComment.java
20
+ ext/java/nokogiri/XmlDocument.java
21
+ ext/java/nokogiri/XmlDocumentFragment.java
22
+ ext/java/nokogiri/XmlDtd.java
23
+ ext/java/nokogiri/XmlElement.java
24
+ ext/java/nokogiri/XmlElementContent.java
25
+ ext/java/nokogiri/XmlElementDecl.java
26
+ ext/java/nokogiri/XmlEntityDecl.java
27
+ ext/java/nokogiri/XmlEntityReference.java
28
+ ext/java/nokogiri/XmlNamespace.java
29
+ ext/java/nokogiri/XmlNode.java
30
+ ext/java/nokogiri/XmlNodeSet.java
31
+ ext/java/nokogiri/XmlProcessingInstruction.java
32
+ ext/java/nokogiri/XmlReader.java
33
+ ext/java/nokogiri/XmlRelaxng.java
34
+ ext/java/nokogiri/XmlSaxParserContext.java
35
+ ext/java/nokogiri/XmlSaxPushParser.java
36
+ ext/java/nokogiri/XmlSchema.java
37
+ ext/java/nokogiri/XmlSyntaxError.java
38
+ ext/java/nokogiri/XmlText.java
39
+ ext/java/nokogiri/XmlXpathContext.java
40
+ ext/java/nokogiri/XsltStylesheet.java
41
+ ext/java/nokogiri/internals/HtmlDomParserContext.java
42
+ ext/java/nokogiri/internals/NokogiriDocumentCache.java
43
+ ext/java/nokogiri/internals/NokogiriErrorHandler.java
44
+ ext/java/nokogiri/internals/NokogiriHandler.java
45
+ ext/java/nokogiri/internals/NokogiriHelpers.java
46
+ ext/java/nokogiri/internals/NokogiriNamespaceCache.java
47
+ ext/java/nokogiri/internals/NokogiriNamespaceContext.java
48
+ ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler.java
49
+ ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler4NekoHtml.java
50
+ ext/java/nokogiri/internals/NokogiriStrictErrorHandler.java
51
+ ext/java/nokogiri/internals/NokogiriXPathFunction.java
52
+ ext/java/nokogiri/internals/NokogiriXPathFunctionResolver.java
53
+ ext/java/nokogiri/internals/ParserContext.java
54
+ ext/java/nokogiri/internals/PushInputStream.java
55
+ ext/java/nokogiri/internals/ReaderNode.java
56
+ ext/java/nokogiri/internals/SaveContext.java
57
+ ext/java/nokogiri/internals/SchemaErrorHandler.java
58
+ ext/java/nokogiri/internals/XmlDeclHandler.java
59
+ ext/java/nokogiri/internals/XmlDomParser.java
60
+ ext/java/nokogiri/internals/XmlDomParserContext.java
61
+ ext/java/nokogiri/internals/XmlSaxParser.java
62
+ ext/nokogiri/depend
10
63
  ext/nokogiri/extconf.rb
11
64
  ext/nokogiri/html_document.c
12
65
  ext/nokogiri/html_document.h
@@ -44,6 +97,8 @@ ext/nokogiri/xml_entity_reference.c
44
97
  ext/nokogiri/xml_entity_reference.h
45
98
  ext/nokogiri/xml_io.c
46
99
  ext/nokogiri/xml_io.h
100
+ ext/nokogiri/xml_libxml2_hacks.c
101
+ ext/nokogiri/xml_libxml2_hacks.h
47
102
  ext/nokogiri/xml_namespace.c
48
103
  ext/nokogiri/xml_namespace.h
49
104
  ext/nokogiri/xml_node.c
@@ -72,6 +127,10 @@ ext/nokogiri/xml_xpath_context.c
72
127
  ext/nokogiri/xml_xpath_context.h
73
128
  ext/nokogiri/xslt_stylesheet.c
74
129
  ext/nokogiri/xslt_stylesheet.h
130
+ lib/isorelax.jar
131
+ lib/jing.jar
132
+ lib/nekodtd.jar
133
+ lib/nekohtml.jar
75
134
  lib/nokogiri.rb
76
135
  lib/nokogiri/css.rb
77
136
  lib/nokogiri/css/generated_parser.rb
@@ -93,9 +152,9 @@ lib/nokogiri/html/element_description_defaults.rb
93
152
  lib/nokogiri/html/entity_lookup.rb
94
153
  lib/nokogiri/html/sax/parser.rb
95
154
  lib/nokogiri/html/sax/parser_context.rb
155
+ lib/nokogiri/nokogiri.jar
96
156
  lib/nokogiri/syntax_error.rb
97
157
  lib/nokogiri/version.rb
98
- lib/nokogiri/version_warning.rb
99
158
  lib/nokogiri/xml.rb
100
159
  lib/nokogiri/xml/attr.rb
101
160
  lib/nokogiri/xml/attribute_decl.rb
@@ -133,7 +192,10 @@ lib/nokogiri/xml/xpath/syntax_error.rb
133
192
  lib/nokogiri/xml/xpath_context.rb
134
193
  lib/nokogiri/xslt.rb
135
194
  lib/nokogiri/xslt/stylesheet.rb
195
+ lib/xercesImpl.jar
136
196
  lib/xsd/xmlparser/nokogiri.rb
197
+ spec/helper.rb
198
+ spec/xml/reader_spec.rb
137
199
  tasks/cross_compile.rb
138
200
  tasks/test.rb
139
201
  test/css/test_nthiness.rb
@@ -3,7 +3,7 @@
3
3
  * http://nokogiri.org/
4
4
  * http://github.com/tenderlove/nokogiri/wikis
5
5
  * http://github.com/tenderlove/nokogiri/tree/master
6
- * http://groups.google.com/group/nokogiri-talk
6
+ * http://groups.google.com/group/nokogiri-list
7
7
  * http://github.com/tenderlove/nokogiri/issues
8
8
 
9
9
  == DESCRIPTION:
@@ -81,9 +81,27 @@ The IRC channel is #nokogiri on freenode.
81
81
 
82
82
  == ENCODING:
83
83
 
84
- Strings are always stored as UTF-8 internally. Methods that return text values
85
- will always return UTF-8 encoded strings. Methods that return XML (like to_xml,
86
- to_html and inner_html) will return a string encoded like the source document.
84
+ Strings are always stored as UTF-8 internally. Methods that return
85
+ text values will always return UTF-8 encoded strings. Methods that
86
+ return XML (like to_xml, to_html and inner_html) will return a string
87
+ encoded like the source document.
88
+
89
+ *WARNING*
90
+
91
+ Some documents declare one particular encoding, but use a different
92
+ one. So, which encoding should the parser choose?
93
+
94
+ Remember that data is just a stream of bytes. Only us humans add
95
+ meaning to that stream. Any particular set of bytes could be valid
96
+ characters in multiple encodings, so detecting encoding with 100%
97
+ accuracy is not possible. libxml2 does its best, but it can't be right
98
+ 100% of the time.
99
+
100
+ If you want Nokogiri to handle the document encoding properly, your
101
+ best bet is to explicitly set the encoding. Here is an example of
102
+ explicitly setting the encoding to EUC-JP on the parser:
103
+
104
+ doc = Nokogiri.XML('<foo><bar /><foo>', nil, 'EUC-JP')
87
105
 
88
106
  == INSTALL:
89
107
 
@@ -94,7 +112,7 @@ to_html and inner_html) will return a string encoded like the source document.
94
112
  Binary packages are available for:
95
113
 
96
114
  * SuSE[http://download.opensuse.org/repositories/devel:/languages:/ruby:/extensions/]
97
- * Fedora[https://admin.fedoraproject.org/pkgdb/packages/name/rubygem-nokogiri]
115
+ * Fedora[http://s390.koji.fedoraproject.org/koji/packageinfo?packageID=6756]
98
116
 
99
117
  == DEVELOPMENT:
100
118
 
data/Rakefile CHANGED
@@ -140,7 +140,7 @@ end
140
140
 
141
141
  file GENERATED_PARSER => "lib/nokogiri/css/parser.y" do |t|
142
142
  begin
143
- racc = `which racc`.strip
143
+ racc = Config::CONFIG['target_os'] =~ /mswin32/ ? '' : `which racc`.strip
144
144
  racc = "#{::Config::CONFIG['bindir']}/racc" if racc.empty?
145
145
  sh "#{racc} -l -o #{t.name} #{t.prerequisites.first}"
146
146
  rescue
@@ -157,7 +157,11 @@ file GENERATED_TOKENIZER => "lib/nokogiri/css/tokenizer.rex" do |t|
157
157
  end
158
158
 
159
159
  require 'tasks/test'
160
- require 'tasks/cross_compile' unless RUBY_PLATFORM =~ /java/
160
+ begin
161
+ require 'tasks/cross_compile' unless java
162
+ rescue RuntimeError => e
163
+ warn "WARNING: Could not perform some cross-compiling: #{e}"
164
+ end
161
165
 
162
166
  desc "set environment variables to build and/or test with debug options"
163
167
  task :debug do
@@ -0,0 +1,92 @@
1
+ package nokogiri;
2
+
3
+ import static nokogiri.internals.NokogiriHelpers.getNokogiriClass;
4
+
5
+ import java.util.HashMap;
6
+
7
+ import org.jruby.Ruby;
8
+ import org.jruby.RubyClass;
9
+ import org.jruby.RubyObject;
10
+ import org.jruby.anno.JRubyClass;
11
+ import org.jruby.anno.JRubyMethod;
12
+ import org.jruby.runtime.ThreadContext;
13
+ import org.jruby.runtime.builtin.IRubyObject;
14
+
15
+ /**
16
+ * Stub class to satisfy unit tests. I'm not sure where this class is
17
+ * meant to be used. As coded it won't really interact with any other
18
+ * classes and will have no effect on character encodings reported by
19
+ * documents being parsed.
20
+ *
21
+ * @author Patrick Mahoney <pat@polycrstal.org>
22
+ */
23
+ @JRubyClass(name="Nokogiri::EncodingHandler")
24
+ public class EncodingHandler extends RubyObject {
25
+ protected static HashMap<String,String> map = new HashMap<String,String>();
26
+ static {
27
+ addInitial();
28
+ }
29
+
30
+ protected String name;
31
+
32
+ protected static void addInitial() {
33
+ map.put("UTF-8", "UTF-8");
34
+ }
35
+
36
+ public EncodingHandler(Ruby ruby, RubyClass klass, String value) {
37
+ super(ruby, klass);
38
+ name = value;
39
+ }
40
+
41
+ @JRubyMethod(name="[]", meta=true)
42
+ public static IRubyObject get(ThreadContext context,
43
+ IRubyObject _klass,
44
+ IRubyObject keyObj) {
45
+ Ruby ruby = context.getRuntime();
46
+ String key = keyObj.toString();
47
+ String value = map.get(key);
48
+ if (value == null)
49
+ return ruby.getNil();
50
+
51
+ return new EncodingHandler(
52
+ ruby,
53
+ getNokogiriClass(ruby, "Nokogiri::EncodingHandler"),
54
+ value);
55
+ }
56
+
57
+ @JRubyMethod(meta=true)
58
+ public static IRubyObject delete(ThreadContext context,
59
+ IRubyObject _klass,
60
+ IRubyObject keyObj) {
61
+ String key = keyObj.toString();
62
+ String value = map.remove(key);
63
+ if (value == null)
64
+ return context.getRuntime().getNil();
65
+ return context.getRuntime().newString(value);
66
+ }
67
+
68
+ @JRubyMethod(name="clear_aliases!", meta=true)
69
+ public static IRubyObject clear_aliases(ThreadContext context,
70
+ IRubyObject _klass) {
71
+ map.clear();
72
+ addInitial();
73
+ return context.getRuntime().getNil();
74
+ }
75
+
76
+ @JRubyMethod(meta=true)
77
+ public static IRubyObject alias(ThreadContext context,
78
+ IRubyObject _klass,
79
+ IRubyObject orig,
80
+ IRubyObject alias) {
81
+ String value = map.get(orig.toString());
82
+ if (value != null)
83
+ map.put(alias.toString(), value);
84
+
85
+ return context.getRuntime().getNil();
86
+ }
87
+
88
+ @JRubyMethod
89
+ public IRubyObject name(ThreadContext context) {
90
+ return context.getRuntime().newString(name);
91
+ }
92
+ }
@@ -0,0 +1,116 @@
1
+ package nokogiri;
2
+
3
+ import nokogiri.internals.HtmlDomParserContext;
4
+ import nokogiri.internals.SaveContext;
5
+
6
+ import org.jruby.Ruby;
7
+ import org.jruby.RubyClass;
8
+ import org.jruby.anno.JRubyClass;
9
+ import org.jruby.anno.JRubyMethod;
10
+ import org.jruby.javasupport.util.RuntimeHelpers;
11
+ import org.jruby.runtime.Arity;
12
+ import org.jruby.runtime.ThreadContext;
13
+ import org.jruby.runtime.builtin.IRubyObject;
14
+ import org.w3c.dom.Document;
15
+ import org.w3c.dom.DocumentType;
16
+
17
+ @JRubyClass(name="Nokogiri::HTML::Document", parent="Nokogiri::XML::Document")
18
+ public class HtmlDocument extends XmlDocument {
19
+
20
+ public HtmlDocument(Ruby ruby, RubyClass klazz) {
21
+ super(ruby, klazz);
22
+ }
23
+
24
+ public HtmlDocument(Ruby ruby, RubyClass klazz, Document doc) {
25
+ super(ruby, klazz, doc);
26
+ }
27
+
28
+ @JRubyMethod(name="new", meta = true, rest = true, required=0)
29
+ public static IRubyObject rbNew(ThreadContext context, IRubyObject cls,
30
+ IRubyObject[] args) {
31
+ HtmlDocument doc = null;
32
+ try {
33
+ Document docNode = createNewDocument();
34
+ doc = new HtmlDocument(context.getRuntime(), (RubyClass) cls, docNode);
35
+ } catch (Exception ex) {
36
+ throw context.getRuntime()
37
+ .newRuntimeError("couldn't create document: "+ex.toString());
38
+ }
39
+
40
+ RuntimeHelpers.invoke(context, doc, "initialize", args);
41
+
42
+ return doc;
43
+ }
44
+
45
+ public static IRubyObject do_parse(ThreadContext context,
46
+ IRubyObject klass,
47
+ IRubyObject[] args) {
48
+ Ruby ruby = context.getRuntime();
49
+ Arity.checkArgumentCount(ruby, args, 4, 4);
50
+ HtmlDomParserContext ctx =
51
+ new HtmlDomParserContext(ruby, args[2], args[3]);
52
+ ctx.setInputSource(context, args[0]);
53
+ return ctx.parse(context, klass, args[1]);
54
+ }
55
+
56
+ /*
57
+ * call-seq:
58
+ * read_io(io, url, encoding, options)
59
+ *
60
+ * Read the HTML document from +io+ with given +url+, +encoding+,
61
+ * and +options+. See Nokogiri::HTML.parse
62
+ */
63
+ @JRubyMethod(meta = true, rest = true)
64
+ public static IRubyObject read_io(ThreadContext context,
65
+ IRubyObject cls,
66
+ IRubyObject[] args) {
67
+ return do_parse(context, cls, args);
68
+ }
69
+
70
+ /*
71
+ * call-seq:
72
+ * read_memory(string, url, encoding, options)
73
+ *
74
+ * Read the HTML document contained in +string+ with given +url+, +encoding+,
75
+ * and +options+. See Nokogiri::HTML.parse
76
+ */
77
+ @JRubyMethod(meta = true, rest = true)
78
+ public static IRubyObject read_memory(ThreadContext context,
79
+ IRubyObject cls,
80
+ IRubyObject[] args) {
81
+ return do_parse(context, cls, args);
82
+ }
83
+
84
+
85
+ @JRubyMethod
86
+ public static IRubyObject serialize(ThreadContext context, IRubyObject htmlDoc) {
87
+ throw context.getRuntime().newNotImplementedError("not implemented");
88
+ }
89
+
90
+ @Override
91
+ public void saveContent(ThreadContext context, SaveContext ctx) {
92
+ Document doc = getDocument();
93
+ DocumentType dtd = doc.getDoctype();
94
+
95
+ if(dtd != null) {
96
+ ctx.append("<!DOCTYPE ");
97
+ ctx.append(dtd.getName());
98
+ if(dtd.getPublicId() != null) {
99
+ ctx.append(" PUBLIC ");
100
+ ctx.appendQuoted(dtd.getPublicId());
101
+ if(dtd.getSystemId() != null) {
102
+ ctx.append(" ");
103
+ ctx.appendQuoted(dtd.getSystemId());
104
+ }
105
+ } else if(dtd.getSystemId() != null) {
106
+ ctx.append(" SYSTEM ");
107
+ ctx.appendQuoted(dtd.getSystemId());
108
+ }
109
+ ctx.append(">\n");
110
+ }
111
+
112
+ this.saveNodeListContent(context,
113
+ (XmlNodeSet) this.children(context), ctx);
114
+ ctx.append("\n");
115
+ }
116
+ }