nokogiri 1.5.0-java → 1.5.1-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 (81) hide show
  1. data/CHANGELOG.ja.rdoc +56 -12
  2. data/CHANGELOG.rdoc +45 -0
  3. data/C_CODING_STYLE.rdoc +27 -0
  4. data/Manifest.txt +4 -0
  5. data/README.rdoc +11 -7
  6. data/Rakefile +44 -26
  7. data/bin/nokogiri +10 -2
  8. data/ext/java/nokogiri/HtmlDocument.java +37 -2
  9. data/ext/java/nokogiri/NokogiriService.java +10 -2
  10. data/ext/java/nokogiri/XmlAttr.java +1 -1
  11. data/ext/java/nokogiri/XmlDocument.java +68 -11
  12. data/ext/java/nokogiri/XmlDocumentFragment.java +16 -5
  13. data/ext/java/nokogiri/XmlElement.java +0 -40
  14. data/ext/java/nokogiri/XmlNamespace.java +8 -1
  15. data/ext/java/nokogiri/XmlNode.java +131 -27
  16. data/ext/java/nokogiri/XmlNodeSet.java +4 -1
  17. data/ext/java/nokogiri/XmlSaxParserContext.java +2 -13
  18. data/ext/java/nokogiri/XmlXpathContext.java +4 -1
  19. data/ext/java/nokogiri/XsltStylesheet.java +198 -37
  20. data/ext/java/nokogiri/internals/HtmlDomParserContext.java +40 -2
  21. data/ext/java/nokogiri/internals/NokogiriHelpers.java +82 -9
  22. data/ext/java/nokogiri/internals/NokogiriXsltErrorListener.java +4 -3
  23. data/ext/java/nokogiri/internals/ParserContext.java +33 -3
  24. data/ext/java/nokogiri/internals/SaveContextVisitor.java +203 -12
  25. data/ext/java/nokogiri/internals/XmlDomParser.java +33 -2
  26. data/ext/java/nokogiri/internals/XmlDomParserContext.java +32 -12
  27. data/ext/nokogiri/extconf.rb +11 -3
  28. data/ext/nokogiri/html_document.c +16 -0
  29. data/ext/nokogiri/html_sax_parser_context.c +59 -37
  30. data/ext/nokogiri/html_sax_push_parser.c +87 -0
  31. data/ext/nokogiri/html_sax_push_parser.h +9 -0
  32. data/ext/nokogiri/nokogiri.c +6 -8
  33. data/ext/nokogiri/nokogiri.h +3 -0
  34. data/ext/nokogiri/xml_document.c +101 -3
  35. data/ext/nokogiri/xml_document.h +3 -3
  36. data/ext/nokogiri/xml_node.c +150 -58
  37. data/ext/nokogiri/xml_node_set.c +169 -120
  38. data/ext/nokogiri/xml_node_set.h +5 -0
  39. data/ext/nokogiri/xml_sax_parser_context.c +64 -41
  40. data/ext/nokogiri/xml_text.c +2 -0
  41. data/ext/nokogiri/xml_xpath_context.c +30 -24
  42. data/ext/nokogiri/xslt_stylesheet.c +62 -16
  43. data/ext/nokogiri/xslt_stylesheet.h +5 -0
  44. data/lib/nokogiri/css/parser.rb +163 -157
  45. data/lib/nokogiri/css/parser.y +6 -3
  46. data/lib/nokogiri/css/tokenizer.rb +1 -1
  47. data/lib/nokogiri/css/tokenizer.rex +1 -1
  48. data/lib/nokogiri/html.rb +1 -0
  49. data/lib/nokogiri/html/document.rb +82 -42
  50. data/lib/nokogiri/html/sax/push_parser.rb +16 -0
  51. data/lib/nokogiri/nokogiri.jar +0 -0
  52. data/lib/nokogiri/version.rb +1 -1
  53. data/lib/nokogiri/xml.rb +6 -0
  54. data/lib/nokogiri/xml/builder.rb +7 -1
  55. data/lib/nokogiri/xml/document.rb +32 -17
  56. data/lib/nokogiri/xml/document_fragment.rb +6 -1
  57. data/lib/nokogiri/xml/node.rb +40 -9
  58. data/lib/nokogiri/xslt.rb +5 -1
  59. data/tasks/cross_compile.rb +1 -0
  60. data/tasks/nokogiri.org.rb +6 -0
  61. data/tasks/test.rb +1 -0
  62. data/test/css/test_xpath_visitor.rb +6 -0
  63. data/test/helper.rb +1 -0
  64. data/test/html/test_document.rb +26 -0
  65. data/test/html/test_document_fragment.rb +1 -2
  66. data/test/test_memory_leak.rb +81 -1
  67. data/test/test_xslt_transforms.rb +152 -123
  68. data/test/xml/test_builder.rb +24 -2
  69. data/test/xml/test_c14n.rb +151 -0
  70. data/test/xml/test_document.rb +48 -0
  71. data/test/xml/test_namespace.rb +5 -0
  72. data/test/xml/test_node.rb +82 -1
  73. data/test/xml/test_node_attributes.rb +19 -0
  74. data/test/xml/test_node_inheritance.rb +32 -0
  75. data/test/xml/test_node_reparenting.rb +32 -0
  76. data/test/xml/test_node_set.rb +16 -8
  77. data/test/xml/test_reader_encoding.rb +16 -0
  78. data/test/xml/test_unparented_node.rb +32 -0
  79. data/test/xml/test_xinclude.rb +83 -0
  80. data/test/xml/test_xpath.rb +22 -0
  81. metadata +147 -123
@@ -1,22 +1,66 @@
1
+ == 1.5.1 / 未リリース
2
+
3
+ * 新機能
4
+
5
+ * XML::Builder#comment はコメントノードを作れるようになった.
6
+ * CSS searches now support namespaced attributes. #593
7
+ * Java integration 機能が追加された. このバージョンから,
8
+ XML::Document.wrap と XML::Document#to_java メソッドが利用可能。
9
+ * RelaxNG validator support in the `nokogiri` cli utility. #591 (thanks, Dan Radez!)
10
+
11
+ * バグの修正
12
+
13
+ * エンコーディング自動認識において発生しうるメモリリークを修正.
14
+ Tim Elliottに感謝!
15
+ * homebrew はインストールしたら、extconf は homebrew のパスを読む。
16
+ * Inconsistent behavior of Nokogiri 1.5.0 Java #620
17
+ * Inheriting from Nokogiri::XML::Node on JRuby (1.6.4/5) fails #560
18
+ * XML::Attr nodes are not allowed to be added as node children, so an
19
+ exception is raised. #558
20
+ * No longer defensively "pickle" adjacent text nodes on
21
+ Node#add_next_sibling and Node#add_previous_sibling calls. #595.
22
+ * Java version inconsistency: it returns nil for empty attributes #589
23
+ * to_xhtml incorrectly generates <p /></p> when tag is empty #557
24
+ * Document#add_child now accepts a Node, NodeSet, DocumentFragment,
25
+ or String. #546.
26
+ * Document#create_element now recognizes namespaces containing
27
+ non-word characters (like "SOAP-ENV"). This is mostly relevant to
28
+ users of Builder, which calls Document#create_element for nearly
29
+ everything. #531.
30
+ * File encoding broken in 1.5.0 / jruby / windows #529
31
+ * Java version does not return namespace defs as attrs for ::HTML #542
32
+ * Bad file descriptor with Nokogiri 1.5.0 #495
33
+ * remove_namespace! doesn't work in pure java version #492
34
+ * The Nokogiri Java native build throws a null pointer exception when
35
+ ActiveSupport's .blank? method is called directly on a parsed object.
36
+ #489
37
+ * 1.5.0 Not using correct character encoding #488
38
+ * Raw XML string in XML Builder broken on JRuby #486
39
+ * Nokogiri 1.5.0 XML generation broken on JRuby #484
40
+ * Do not allow multiple root nodes. #550
41
+ * Fixes for custom XPath functions. #605, #606 (thanks, Juan Wajnerman!)
42
+ * Node#to_xml does not override :save_with if it is provided. #505
43
+ * Node#set is a private method [JRuby]. #564 (thanks, Nick Sieger!)
44
+ * C14n cleanup and Node#canonicalize (thanks, Ivan Pirlik!) #563
45
+
1
46
  == 1.5.0 / 2011年7月1日
2
47
 
3
- * Notes
48
+ *
4
49
 
5
- * See changelog from 1.4.7
50
+ * 1.4.7からの変更点を参照
6
51
 
7
- * Features
52
+ * 新機能
8
53
 
9
- * extracted sets of Node::SaveOptions into Node::SaveOptions::DEFAULT_{X,H,XH}TML (refactor)
54
+ * 各文書形式用のデフォルトのNode::SaveOptionsの組合せを定数化.
55
+ (Node::SaveOptions::DEFAULT_{X,H,XH}TML)
10
56
 
11
- * Bugfixes
57
+ * バグの修正
12
58
 
13
- * default output of XML on JRuby is no longer formatted due to
14
- inconsistent whitespace handling. #415
15
- * (JRuby) making empty NodeSets with null `nodes` member safe to operate on. #443
16
- * Fix a bug in advanced encoding detection that leads to partially
17
- duplicated document when parsing an HTML file with unknown
18
- encoding.
19
- * Add support for <meta charset="...">.
59
+ * JRuby版ではホワイトスペースの扱いに難があるため、XML出力(to_xml)において
60
+ 自動整形をデフォルトでは行わないように変更. #415
61
+ * JRuby版でNodeのないNodeSetでNullPointerExceptionが発生するのを修正. #443
62
+ * エンコーディング宣言のないHTMLファイルで部分的に重複したドキュメントが生成される問題を修正した. #478
63
+ * <meta charset="..."> を認識するようになった.
20
64
 
21
65
 
22
66
  == 1.5.0 beta3 2010年12月2日
@@ -1,3 +1,48 @@
1
+ == 1.5.1 / unreleased
2
+
3
+ * Features
4
+
5
+ * XML::Builder#comment allows creation of comment nodes.
6
+ * CSS searches now support namespaced attributes. #593
7
+ * Java integration feature is added. Now, XML::Document.wrap
8
+ and XML::Document#to_java methods are available.
9
+ * RelaxNG validator support in the `nokogiri` cli utility. #591 (thanks, Dan Radez!)
10
+
11
+ * Bugfixes
12
+
13
+ * Fix many memory leaks and segfault opportunities. Thanks, Tim Elliott!
14
+ * extconf searches homebrew paths if homebrew is installed.
15
+ * Inconsistent behavior of Nokogiri 1.5.0 Java #620
16
+ * Inheriting from Nokogiri::XML::Node on JRuby (1.6.4/5) fails #560
17
+ * XML::Attr nodes are not allowed to be added as node children, so an
18
+ exception is raised. #558
19
+ * No longer defensively "pickle" adjacent text nodes on
20
+ Node#add_next_sibling and Node#add_previous_sibling calls. #595.
21
+ * Java version inconsistency: it returns nil for empty attributes #589
22
+ * to_xhtml incorrectly generates <p /></p> when tag is empty #557
23
+ * Document#add_child now accepts a Node, NodeSet, DocumentFragment,
24
+ or String. #546.
25
+ * Document#create_element now recognizes namespaces containing
26
+ non-word characters (like "SOAP-ENV"). This is mostly relevant to
27
+ users of Builder, which calls Document#create_element for nearly
28
+ everything. #531.
29
+ * File encoding broken in 1.5.0 / jruby / windows #529
30
+ * Java version does not return namespace defs as attrs for ::HTML #542
31
+ * Bad file descriptor with Nokogiri 1.5.0 #495
32
+ * remove_namespace! doesn't work in pure java version #492
33
+ * The Nokogiri Java native build throws a null pointer exception
34
+ when ActiveSupport's .blank? method is called directly on a parsed
35
+ object. #489
36
+ * 1.5.0 Not using correct character encoding #488
37
+ * Raw XML string in XML Builder broken on JRuby #486
38
+ * Nokogiri 1.5.0 XML generation broken on JRuby #484
39
+ * Do not allow multiple root nodes. #550
40
+ * Fixes for custom XPath functions. #605, #606 (thanks, Juan Wajnerman!)
41
+ * Node#to_xml does not override :save_with if it is provided. #505
42
+ * Node#set is a private method [JRuby]. #564 (thanks, Nick Sieger!)
43
+ * C14n cleanup and Node#canonicalize (thanks, Ivan Pirlik!) #563
44
+
45
+
1
46
  == 1.5.0 / 2011-07-01
2
47
 
3
48
  * Notes
@@ -0,0 +1,27 @@
1
+ = C/C++ mode style for Nokogiri
2
+
3
+ Please don't propose commits that only change whitespace. However, if your
4
+ commit touches a function or section that is not using MRI Ruby conventions,
5
+ feel free to update whitespace in the surrounding code.
6
+
7
+ = WHITESPACE:
8
+
9
+ indent level: 2
10
+ indent type: Always spaces
11
+ Line Breaks: LF
12
+
13
+ = FUNCTION DECLARATION:
14
+
15
+ ANSI C style:
16
+
17
+ type name(args)
18
+ {
19
+ declarations
20
+
21
+ code
22
+ }
23
+
24
+ = SOURCES:
25
+
26
+ * <3<3<3
27
+
@@ -72,6 +72,8 @@ ext/nokogiri/html_entity_lookup.c
72
72
  ext/nokogiri/html_entity_lookup.h
73
73
  ext/nokogiri/html_sax_parser_context.c
74
74
  ext/nokogiri/html_sax_parser_context.h
75
+ ext/nokogiri/html_sax_push_parser.c
76
+ ext/nokogiri/html_sax_push_parser.h
75
77
  ext/nokogiri/nokogiri.c
76
78
  ext/nokogiri/nokogiri.h
77
79
  ext/nokogiri/xml_attr.c
@@ -154,6 +156,7 @@ lib/nokogiri/html/element_description_defaults.rb
154
156
  lib/nokogiri/html/entity_lookup.rb
155
157
  lib/nokogiri/html/sax/parser.rb
156
158
  lib/nokogiri/html/sax/parser_context.rb
159
+ lib/nokogiri/html/sax/push_parser.rb
157
160
  lib/nokogiri/syntax_error.rb
158
161
  lib/nokogiri/version.rb
159
162
  lib/nokogiri/xml.rb
@@ -270,6 +273,7 @@ test/xml/test_node_attributes.rb
270
273
  test/xml/test_node_encoding.rb
271
274
  test/xml/test_node_reparenting.rb
272
275
  test/xml/test_node_set.rb
276
+ test/xml/test_node_inheritance.rb
273
277
  test/xml/test_parse_options.rb
274
278
  test/xml/test_processing_instruction.rb
275
279
  test/xml/test_reader_encoding.rb
@@ -1,4 +1,4 @@
1
- = Nokogiri
1
+ = Nokogiri {<img src="https://secure.travis-ci.org/tenderlove/nokogiri.png?rvm=1.9.3" />}[http://travis-ci.org/tenderlove/nokogiri]
2
2
 
3
3
  * http://nokogiri.org
4
4
  * http://github.com/tenderlove/nokogiri/wikis
@@ -25,6 +25,10 @@ correctly implemented CSS3 selector support as well as XPath support.
25
25
 
26
26
  == SUPPORT:
27
27
 
28
+ Before filing a bug report, please read our {submission guidelines}[http://nokogiri.org/tutorials/getting_help.html] at:
29
+
30
+ * http://nokogiri.org/tutorials/getting_help.html
31
+
28
32
  The Nokogiri {mailing list}[http://groups.google.com/group/nokogiri-talk]
29
33
  is available here:
30
34
 
@@ -50,19 +54,19 @@ The IRC channel is #nokogiri on freenode.
50
54
 
51
55
  ####
52
56
  # Search for nodes by css
53
- doc.css('h3.r a.l').each do |link|
57
+ doc.css('h3.r a').each do |link|
54
58
  puts link.content
55
59
  end
56
60
 
57
61
  ####
58
62
  # Search for nodes by xpath
59
- doc.xpath('//h3/a[@class="l"]').each do |link|
63
+ doc.xpath('//h3/a').each do |link|
60
64
  puts link.content
61
65
  end
62
66
 
63
67
  ####
64
68
  # Or mix and match.
65
- doc.search('h3.r a.l', '//h3/a[@class="l"]').each do |link|
69
+ doc.search('h3.r a.l', '//h3/a').each do |link|
66
70
  puts link.content
67
71
  end
68
72
 
@@ -128,8 +132,8 @@ Then run rake:
128
132
 
129
133
  === Developing on JRuby
130
134
 
131
- Currently, development with JRuby depends on C Ruby being installed. With
132
- normal C Ruby, install racc and rexical:
135
+ Currently, development with JRuby depends on CRuby being installed. With
136
+ CRuby, install racc and rexical:
133
137
 
134
138
  $ gem install racc rexical
135
139
 
@@ -145,7 +149,7 @@ Then run rake:
145
149
 
146
150
  (The MIT License)
147
151
 
148
- Copyright (c) 2008 - 2010:
152
+ Copyright (c) 2008 - 2012:
149
153
 
150
154
  * {Aaron Patterson}[http://tenderlovemaking.com]
151
155
  * {Mike Dalessio}[http://mike.daless.io]
data/Rakefile CHANGED
@@ -31,24 +31,22 @@ HOE = Hoe.spec 'nokogiri' do
31
31
 
32
32
  self.clean_globs += [
33
33
  'nokogiri.gemspec',
34
- 'lib/nokogiri/*.{o,so,bundle,a,log,dll}',
35
- 'lib/nokogiri/nokogiri.{so,dylib,rb,bundle}',
36
- 'lib/nokogiri/nokogiri.rb',
34
+ 'lib/nokogiri/nokogiri.{bundle,jar,rb,so}',
37
35
  'lib/nokogiri/1.{8,9}',
38
36
  GENERATED_PARSER,
39
37
  GENERATED_TOKENIZER
40
38
  ]
41
39
 
42
40
  self.extra_dev_deps += [
41
+ ["hoe-bundler", ">= 1.1"],
42
+ ["hoe-debugging", ">= 1.0.3"],
43
+ ["hoe-gemspec", ">= 1.0"],
44
+ ["hoe-git", ">= 1.4"],
45
+ ["mini_portile", ">= 0.2.2"],
46
+ ["minitest", "~> 2.2.2"],
43
47
  ["racc", ">= 1.4.6"],
48
+ ["rake-compiler", "= 0.8.0"],
44
49
  ["rexical", ">= 1.0.5"],
45
- ["rake-compiler", ">= 0.7.9"],
46
- ["minitest", "~> 2.2.2"],
47
- ["mini_portile", ">= 0.2.2"],
48
- ["hoe-debugging", ">= 0"],
49
- ["hoe-git", ">= 0"],
50
- ["hoe-gemspec", ">= 0"],
51
- ["hoe-bundler", ">= 0"]
52
50
  ]
53
51
 
54
52
  if java?
@@ -83,18 +81,28 @@ if java?
83
81
  HOE.spec.files += ['lib/nokogiri/nokogiri.jar']
84
82
  end
85
83
  else
86
- require 'tasks/cross_compile'
84
+ mingw_available = true
85
+ begin
86
+ require 'tasks/cross_compile'
87
+ rescue
88
+ mingw_available = false
89
+ end
87
90
  require "rake/extensiontask"
91
+
92
+ HOE.spec.files.reject! { |f| f =~ %r{\.(java|jar)$} }
93
+
88
94
  Rake::ExtensionTask.new("nokogiri", HOE.spec) do |ext|
89
95
  ext.lib_dir = File.join(*['lib', 'nokogiri', ENV['FAT_DIR']].compact)
90
96
  ext.config_options << ENV['EXTOPTS']
91
- ext.cross_compile = true
92
- ext.cross_platform = ["x86-mswin32-60", "x86-mingw32"]
93
- ext.cross_config_options << "--with-xml2-include=#{File.join($recipes[:libxml2].path, 'include', 'libxml2')}"
94
- ext.cross_config_options << "--with-xml2-lib=#{File.join($recipes[:libxml2].path, 'lib')}"
95
- ext.cross_config_options << "--with-iconv-dir=#{$recipes[:libiconv].path}"
96
- ext.cross_config_options << "--with-xslt-dir=#{$recipes[:libxslt].path}"
97
- ext.cross_config_options << "--with-zlib-dir=#{CROSS_DIR}"
97
+ if mingw_available
98
+ ext.cross_compile = true
99
+ ext.cross_platform = ["x86-mswin32-60", "x86-mingw32"]
100
+ ext.cross_config_options << "--with-xml2-include=#{File.join($recipes[:libxml2].path, 'include', 'libxml2')}"
101
+ ext.cross_config_options << "--with-xml2-lib=#{File.join($recipes[:libxml2].path, 'lib')}"
102
+ ext.cross_config_options << "--with-iconv-dir=#{$recipes[:libiconv].path}"
103
+ ext.cross_config_options << "--with-xslt-dir=#{$recipes[:libxslt].path}"
104
+ ext.cross_config_options << "--with-zlib-dir=#{CROSS_DIR}"
105
+ end
98
106
  end
99
107
  end
100
108
 
@@ -107,6 +115,7 @@ task 'gem:spec' => 'generate' if Rake::Task.task_defined?("gem:spec")
107
115
  file GENERATED_PARSER => "lib/nokogiri/css/parser.y" do |t|
108
116
  racc = RbConfig::CONFIG['target_os'] =~ /mswin32/ ? '' : `which racc`.strip
109
117
  racc = "#{::RbConfig::CONFIG['bindir']}/racc" if racc.empty?
118
+ racc = %x{command -v racc}.strip if racc.empty?
110
119
  sh "#{racc} -l -o #{t.name} #{t.prerequisites.first}"
111
120
  end
112
121
 
@@ -141,11 +150,20 @@ end
141
150
  # ----------------------------------------
142
151
 
143
152
  desc "build a windows gem without all the ceremony."
144
- task "gem:windows" do
145
- rake_compiler_config = YAML.load_file("#{ENV['HOME']}/.rake-compiler/config.yml")
153
+ task "gem:windows" => "gem" do
154
+ cross_rubies = ["1.8.7-p330", "1.9.2-p136"]
155
+ ruby_cc_version = cross_rubies.collect { |_| _.split("-").first }.join(":") # e.g., "1.8.7:1.9.2"
156
+ rake_compiler_config_path = "#{ENV['HOME']}/.rake-compiler/config.yml"
157
+
158
+ unless File.exists? rake_compiler_config_path
159
+ raise "rake-compiler has not installed any cross rubies. try running 'env --unset=HOST rake-compiler cross-ruby VERSION=#{cross_rubies.first}'"
160
+ end
161
+ rake_compiler_config = YAML.load_file(rake_compiler_config_path)
146
162
 
147
- # check that rake-compiler config contains the right patchlevels of 1.8.6 and 1.9.1. see #279.
148
- ["1.8.6-p383", "1.9.1-p243"].each do |version|
163
+ # check that rake-compiler config contains the right patchlevels. see #279 for background,
164
+ # and http://blog.mmediasys.com/2011/01/22/rake-compiler-updated-list-of-supported-ruby-versions-for-cross-compilation/
165
+ # for more up-to-date docs.
166
+ cross_rubies.each do |version|
149
167
  majmin, patchlevel = version.split("-")
150
168
  rbconfig = "rbconfig-#{majmin}"
151
169
  unless rake_compiler_config.key?(rbconfig) && rake_compiler_config[rbconfig] =~ /-#{patchlevel}/
@@ -153,12 +171,12 @@ task "gem:windows" do
153
171
  end
154
172
  end
155
173
 
156
- # verify that --export-all is in the 1.9.1 rbconfig. see #279,#374,#375.
157
- rbconfig_191 = rake_compiler_config["rbconfig-1.9.1"]
158
- raise "rbconfig #{rbconfig_191} needs --export-all in its DLDFLAGS value" if File.read(rbconfig_191).grep(/CONFIG\["DLDFLAGS"\].*--export-all/).empty?
174
+ # verify that --export-all is in the 1.9 rbconfig. see #279,#374,#375.
175
+ rbconfig_19 = rake_compiler_config["rbconfig-1.9.2"]
176
+ raise "rbconfig #{rbconfig_19} needs --export-all in its DLDFLAGS value" if File.read(rbconfig_19).split("\n").grep(/CONFIG\["DLDFLAGS"\].*--export-all/).empty?
159
177
 
160
178
  pkg_config_path = [:libxslt, :libxml2].collect { |pkg| File.join($recipes[pkg].path, "lib/pkgconfig") }.join(":")
161
- sh("env PKG_CONFIG_PATH=#{pkg_config_path} RUBY_CC_VERSION=1.8.6:1.9.1 rake cross native gem") || raise("build failed!")
179
+ sh("env PKG_CONFIG_PATH=#{pkg_config_path} RUBY_CC_VERSION=#{ruby_cc_version} rake cross native gem") || raise("build failed!")
162
180
  end
163
181
 
164
182
  # vim: syntax=Ruby
@@ -27,6 +27,10 @@ opts = OptionParser.new do |opts|
27
27
  encoding = v
28
28
  end
29
29
 
30
+ opts.on("--rng <uri|path>", "Validate using this rng file.") do |v|
31
+ @rng = open(v) {|f| Nokogiri::XML::RelaxNG(f)}
32
+ end
33
+
30
34
  opts.on_tail("-?", "--help", "Show this message") do
31
35
  puts opts
32
36
  exit
@@ -48,6 +52,10 @@ end
48
52
 
49
53
  @doc = parse_class.parse(open(uri).read, nil, encoding)
50
54
 
51
- puts "Your document is stored in @doc..."
52
- IRB.start
55
+ if @rng
56
+ puts @rng.validate(@doc)
57
+ else
58
+ puts "Your document is stored in @doc..."
59
+ IRB.start
60
+ end
53
61
 
@@ -33,7 +33,6 @@
33
33
  package nokogiri;
34
34
 
35
35
  import nokogiri.internals.HtmlDomParserContext;
36
-
37
36
  import org.jruby.Ruby;
38
37
  import org.jruby.RubyClass;
39
38
  import org.jruby.anno.JRubyClass;
@@ -42,7 +41,11 @@ import org.jruby.javasupport.util.RuntimeHelpers;
42
41
  import org.jruby.runtime.Arity;
43
42
  import org.jruby.runtime.ThreadContext;
44
43
  import org.jruby.runtime.builtin.IRubyObject;
44
+ import org.w3c.dom.Attr;
45
45
  import org.w3c.dom.Document;
46
+ import org.w3c.dom.NamedNodeMap;
47
+ import org.w3c.dom.Node;
48
+ import org.w3c.dom.NodeList;
46
49
 
47
50
  /**
48
51
  * Class for Nokogiri::HTML::Document.
@@ -68,7 +71,7 @@ public class HtmlDocument extends XmlDocument {
68
71
  try {
69
72
  Document docNode = createNewDocument();
70
73
  htmlDocument = (HtmlDocument) NokogiriService.HTML_DOCUMENT_ALLOCATOR.allocate(context.getRuntime(), (RubyClass) klazz);
71
- htmlDocument.setNode(context, docNode);
74
+ htmlDocument.setDocumentNode(context, docNode);
72
75
  } catch (Exception ex) {
73
76
  throw context.getRuntime().newRuntimeError("couldn't create document: "+ex.toString());
74
77
  }
@@ -88,6 +91,38 @@ public class HtmlDocument extends XmlDocument {
88
91
  ctx.setInputSource(context, args[0], args[1]);
89
92
  return ctx.parse(context, klass, args[1]);
90
93
  }
94
+
95
+ public void setDocumentNode(ThreadContext context, Node node) {
96
+ super.setNode(context, node);
97
+ Ruby runtime = context.getRuntime();
98
+ if (node != null) {
99
+ Document document = (Document)node;
100
+ document.normalize();
101
+ stabilzeAttrValue(document.getDocumentElement());
102
+ }
103
+ setInstanceVariable("@decorators", runtime.getNil());
104
+ }
105
+
106
+ private void stabilzeAttrValue(Node node) {
107
+ if (node == null) return;
108
+ if (node.hasAttributes()) {
109
+ NamedNodeMap nodeMap = node.getAttributes();
110
+ for (int i=0; i<nodeMap.getLength(); i++) {
111
+ Node n = nodeMap.item(i);
112
+ if (n instanceof Attr) {
113
+ Attr attr = (Attr)n;
114
+ String attrName = attr.getName();
115
+ // not sure, but need to get value always before document is referred.
116
+ // or lose attribute value
117
+ String attrValue = attr.getValue(); // don't delete this line
118
+ }
119
+ }
120
+ }
121
+ NodeList children = node.getChildNodes();
122
+ for (int i=0; i<children.getLength(); i++) {
123
+ stabilzeAttrValue(children.item(i));
124
+ }
125
+ }
91
126
 
92
127
  /*
93
128
  * call-seq: