nokogiri 1.5.0.beta.2 → 1.5.0.beta.3

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 (107) hide show
  1. data/CHANGELOG.ja.rdoc +63 -0
  2. data/CHANGELOG.rdoc +44 -1
  3. data/Manifest.txt +3 -3
  4. data/README.ja.rdoc +4 -4
  5. data/README.rdoc +4 -4
  6. data/Rakefile +3 -0
  7. data/bin/nokogiri +6 -1
  8. data/ext/java/nokogiri/EncodingHandler.java +32 -0
  9. data/ext/java/nokogiri/HtmlDocument.java +36 -0
  10. data/ext/java/nokogiri/HtmlElementDescription.java +34 -0
  11. data/ext/java/nokogiri/HtmlEntityLookup.java +34 -0
  12. data/ext/java/nokogiri/HtmlSaxParserContext.java +41 -3
  13. data/ext/java/nokogiri/NokogiriService.java +109 -13
  14. data/ext/java/nokogiri/XmlAttr.java +40 -4
  15. data/ext/java/nokogiri/XmlAttributeDecl.java +32 -0
  16. data/ext/java/nokogiri/XmlCdata.java +41 -2
  17. data/ext/java/nokogiri/XmlComment.java +38 -1
  18. data/ext/java/nokogiri/XmlDocument.java +56 -11
  19. data/ext/java/nokogiri/XmlDocumentFragment.java +39 -30
  20. data/ext/java/nokogiri/XmlDtd.java +37 -0
  21. data/ext/java/nokogiri/XmlElement.java +51 -2
  22. data/ext/java/nokogiri/XmlElementContent.java +32 -0
  23. data/ext/java/nokogiri/XmlElementDecl.java +32 -0
  24. data/ext/java/nokogiri/XmlEntityDecl.java +32 -0
  25. data/ext/java/nokogiri/XmlEntityReference.java +35 -2
  26. data/ext/java/nokogiri/XmlNamespace.java +55 -5
  27. data/ext/java/nokogiri/XmlNode.java +129 -136
  28. data/ext/java/nokogiri/XmlNodeSet.java +36 -0
  29. data/ext/java/nokogiri/XmlProcessingInstruction.java +34 -1
  30. data/ext/java/nokogiri/XmlReader.java +36 -0
  31. data/ext/java/nokogiri/XmlRelaxng.java +34 -1
  32. data/ext/java/nokogiri/XmlSaxParserContext.java +52 -7
  33. data/ext/java/nokogiri/XmlSaxPushParser.java +36 -0
  34. data/ext/java/nokogiri/XmlSchema.java +34 -1
  35. data/ext/java/nokogiri/XmlSyntaxError.java +48 -18
  36. data/ext/java/nokogiri/XmlText.java +45 -6
  37. data/ext/java/nokogiri/XmlXpathContext.java +45 -0
  38. data/ext/java/nokogiri/XsltStylesheet.java +58 -3
  39. data/ext/java/nokogiri/internals/HtmlDomParserContext.java +50 -26
  40. data/ext/java/nokogiri/internals/NokogiriDocumentCache.java +35 -1
  41. data/ext/java/nokogiri/internals/NokogiriErrorHandler.java +51 -13
  42. data/ext/java/nokogiri/internals/NokogiriHandler.java +70 -21
  43. data/ext/java/nokogiri/internals/NokogiriHelpers.java +95 -38
  44. data/ext/java/nokogiri/internals/NokogiriNamespaceCache.java +37 -3
  45. data/ext/java/nokogiri/internals/NokogiriNamespaceContext.java +39 -1
  46. data/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler.java +43 -7
  47. data/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler4NekoHtml.java +77 -10
  48. data/ext/java/nokogiri/internals/NokogiriStrictErrorHandler.java +49 -20
  49. data/ext/java/nokogiri/internals/NokogiriXPathFunction.java +34 -2
  50. data/ext/java/nokogiri/internals/NokogiriXPathFunctionResolver.java +34 -1
  51. data/ext/java/nokogiri/internals/ParserContext.java +32 -0
  52. data/ext/java/nokogiri/internals/PushInputStream.java +33 -3
  53. data/ext/java/nokogiri/internals/ReaderNode.java +50 -8
  54. data/ext/java/nokogiri/internals/SaveContext.java +35 -2
  55. data/ext/java/nokogiri/internals/SchemaErrorHandler.java +34 -1
  56. data/ext/java/nokogiri/internals/XmlDeclHandler.java +32 -0
  57. data/ext/java/nokogiri/internals/XmlDomParser.java +32 -0
  58. data/ext/java/nokogiri/internals/XmlDomParserContext.java +43 -11
  59. data/ext/java/nokogiri/internals/XmlSaxParser.java +32 -0
  60. data/ext/java/nokogiri/internals/XsltExtensionFunction.java +72 -0
  61. data/ext/nokogiri/depend +358 -32
  62. data/ext/nokogiri/extconf.rb +1 -3
  63. data/ext/nokogiri/nokogiri.c +2 -0
  64. data/ext/nokogiri/nokogiri.h +7 -0
  65. data/ext/nokogiri/xml_dtd.c +2 -2
  66. data/ext/nokogiri/xml_io.c +2 -2
  67. data/ext/nokogiri/xml_node.c +31 -6
  68. data/ext/nokogiri/xml_node_set.c +1 -1
  69. data/ext/nokogiri/xml_sax_parser.c +1 -1
  70. data/ext/nokogiri/xml_sax_parser_context.c +40 -0
  71. data/ext/nokogiri/xml_xpath_context.c +33 -2
  72. data/ext/nokogiri/xslt_stylesheet.c +122 -6
  73. data/lib/nokogiri.rb +12 -5
  74. data/lib/nokogiri/css/generated_tokenizer.rb +1 -2
  75. data/lib/nokogiri/css/xpath_visitor.rb +15 -7
  76. data/lib/nokogiri/decorators/slop.rb +5 -3
  77. data/lib/nokogiri/html/document.rb +3 -3
  78. data/lib/nokogiri/html/document_fragment.rb +19 -17
  79. data/lib/nokogiri/version.rb +1 -1
  80. data/lib/nokogiri/xml/document.rb +26 -1
  81. data/lib/nokogiri/xml/document_fragment.rb +2 -2
  82. data/lib/nokogiri/xml/dtd.rb +11 -0
  83. data/lib/nokogiri/xml/node.rb +156 -45
  84. data/lib/nokogiri/xml/node_set.rb +2 -2
  85. data/lib/nokogiri/xml/reader.rb +36 -0
  86. data/lib/nokogiri/xml/sax/document.rb +4 -2
  87. data/lib/nokogiri/xslt.rb +9 -5
  88. data/lib/nokogiri/xslt/stylesheet.rb +1 -1
  89. data/tasks/cross_compile.rb +27 -8
  90. data/test/css/test_parser.rb +29 -18
  91. data/test/decorators/test_slop.rb +16 -0
  92. data/test/html/test_document_fragment.rb +46 -3
  93. data/test/html/test_node.rb +9 -0
  94. data/test/xml/sax/test_parser.rb +11 -3
  95. data/test/xml/sax/test_parser_context.rb +50 -0
  96. data/test/xml/sax/test_push_parser.rb +18 -1
  97. data/test/xml/test_document_fragment.rb +15 -8
  98. data/test/xml/test_dtd.rb +15 -0
  99. data/test/xml/test_node.rb +31 -2
  100. data/test/xml/test_node_reparenting.rb +59 -31
  101. data/test/xml/test_node_set.rb +13 -0
  102. data/test/xml/test_xpath.rb +32 -0
  103. data/test/xslt/test_custom_functions.rb +94 -0
  104. metadata +83 -81
  105. data/lib/nokogiri/nokogiri.jar +0 -0
  106. data/spec/helper.rb +0 -3
  107. data/spec/xml/reader_spec.rb +0 -307
@@ -1,9 +1,42 @@
1
+ /**
2
+ * (The MIT License)
3
+ *
4
+ * Copyright (c) 2008 - 2010:
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
+
1
33
  package nokogiri;
2
34
 
3
35
  import static nokogiri.internals.NokogiriHelpers.getCachedNodeOrCreate;
4
36
  import static nokogiri.internals.NokogiriHelpers.getLocalNameForNamespace;
5
37
  import static nokogiri.internals.NokogiriHelpers.getNokogiriClass;
6
38
  import static nokogiri.internals.NokogiriHelpers.isNamespace;
39
+ import static nokogiri.internals.NokogiriHelpers.rubyStringToString;
7
40
  import static nokogiri.internals.NokogiriHelpers.stringOrNil;
8
41
 
9
42
  import javax.xml.parsers.DocumentBuilderFactory;
@@ -20,7 +53,6 @@ import org.jruby.RubyFixnum;
20
53
  import org.jruby.RubyNil;
21
54
  import org.jruby.anno.JRubyClass;
22
55
  import org.jruby.anno.JRubyMethod;
23
- import org.jruby.javasupport.JavaUtil;
24
56
  import org.jruby.javasupport.util.RuntimeHelpers;
25
57
  import org.jruby.runtime.Arity;
26
58
  import org.jruby.runtime.ThreadContext;
@@ -31,6 +63,11 @@ import org.w3c.dom.NamedNodeMap;
31
63
  import org.w3c.dom.Node;
32
64
  import org.w3c.dom.NodeList;
33
65
 
66
+ /**
67
+ * Class for Nokogiri::XML::Document
68
+ *
69
+ */
70
+
34
71
  @JRubyClass(name="Nokogiri::XML::Document", parent="Nokogiri::XML::Node")
35
72
  public class XmlDocument extends XmlNode {
36
73
  private NokogiriNamespaceCache nsCache;
@@ -48,7 +85,7 @@ public class XmlDocument extends XmlNode {
48
85
  protected IRubyObject url = null;
49
86
 
50
87
  public XmlDocument(Ruby ruby, RubyClass klazz) {
51
- super(ruby, klazz);
88
+ super(ruby, klazz, createNewDocument());
52
89
  nsCache = new NokogiriNamespaceCache();
53
90
  }
54
91
 
@@ -64,6 +101,18 @@ public class XmlDocument extends XmlNode {
64
101
  setInstanceVariable("@decorators", ruby.getNil());
65
102
  }
66
103
 
104
+ @Override
105
+ public void setNode(ThreadContext context, Node node) {
106
+ super.setNode(context, node);
107
+ Ruby runtime = context.getRuntime();
108
+ if (node != null) {
109
+ Document document = (Document)node;
110
+ stabilizeTextContent(document);
111
+ createAndCacheNamespaces(runtime, document.getDocumentElement());
112
+ }
113
+ setInstanceVariable("@decorators", runtime.getNil());
114
+ }
115
+
67
116
  public void setEncoding(IRubyObject encoding) {
68
117
  this.encoding = encoding;
69
118
  }
@@ -107,7 +156,7 @@ public class XmlDocument extends XmlNode {
107
156
  super(ruby, klass, document);
108
157
  nsCache = contextDoc.getNamespaceCache();
109
158
  XmlNamespace default_ns = nsCache.getDefault();
110
- String default_href = (String)(default_ns.href(ruby.getCurrentContext())).toJava(String.class);
159
+ String default_href = rubyStringToString(default_ns.href(ruby.getCurrentContext()));
111
160
  resolveNamespaceIfNecessary(ruby.getCurrentContext(), document.getDocumentElement(), default_href);
112
161
  }
113
162
 
@@ -118,7 +167,7 @@ public class XmlDocument extends XmlNode {
118
167
  node.getOwnerDocument().renameNode(node, default_href, node.getNodeName());
119
168
  } else {
120
169
  XmlNamespace xmlNamespace = nsCache.get(nodePrefix);
121
- String href = (String)xmlNamespace.href(context).toJava(String.class);
170
+ String href = rubyStringToString(xmlNamespace.href(context));
122
171
  node.getOwnerDocument().renameNode(node, href, node.getNodeName());
123
172
  }
124
173
  resolveNamespaceIfNecessary(context, node.getNextSibling(), default_href);
@@ -142,7 +191,8 @@ public class XmlDocument extends XmlNode {
142
191
 
143
192
  @Override
144
193
  protected IRubyObject getNodeName(ThreadContext context) {
145
- return JavaUtil.convertJavaToUsableRubyObject(context.getRuntime(), "document");
194
+ if (name == null) name = context.getRuntime().newString("document");
195
+ return name;
146
196
  }
147
197
 
148
198
  public void setUrl(IRubyObject url) {
@@ -193,7 +243,7 @@ public class XmlDocument extends XmlNode {
193
243
  // this impl passes tests, but entity doesn't exists in DTD, which
194
244
  // would cause validation failure.
195
245
  if (argv.length == 0) throw context.getRuntime().newRuntimeError("Could not create entity");
196
- String tagName = (String) argv[0].toJava(String.class);
246
+ String tagName = rubyStringToString(argv[0]);
197
247
  Node n = this.getOwnerDocument().createElement(tagName);
198
248
  return XmlEntityDecl.create(context, n, argv);
199
249
  }
@@ -342,11 +392,6 @@ public class XmlDocument extends XmlNode {
342
392
  return stringOrNil(context.getRuntime(), getDocument().getXmlVersion());
343
393
  }
344
394
 
345
- @JRubyMethod
346
- public IRubyObject in_context(ThreadContext context) {
347
- throw getRuntime().newNotImplementedError("not implemented");
348
- }
349
-
350
395
  @JRubyMethod(meta = true)
351
396
  public static IRubyObject substitute_entities_set(ThreadContext context, IRubyObject cls, IRubyObject value) {
352
397
  XmlDocument.substituteEntities = value.isTrue();
@@ -1,3 +1,35 @@
1
+ /**
2
+ * (The MIT License)
3
+ *
4
+ * Copyright (c) 2008 - 2010:
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
+
1
33
  package nokogiri;
2
34
 
3
35
  import static nokogiri.internals.NokogiriHelpers.getLocalNameForNamespace;
@@ -5,6 +37,7 @@ import static nokogiri.internals.NokogiriHelpers.getLocalPart;
5
37
  import static nokogiri.internals.NokogiriHelpers.getNokogiriClass;
6
38
  import static nokogiri.internals.NokogiriHelpers.getPrefix;
7
39
  import static nokogiri.internals.NokogiriHelpers.isNamespace;
40
+ import static nokogiri.internals.NokogiriHelpers.rubyStringToString;
8
41
 
9
42
  import java.util.HashMap;
10
43
  import java.util.Map;
@@ -12,17 +45,14 @@ import java.util.Set;
12
45
  import java.util.regex.Matcher;
13
46
  import java.util.regex.Pattern;
14
47
 
15
- import nokogiri.internals.NokogiriNamespaceContext;
16
48
  import nokogiri.internals.SaveContext;
17
49
 
18
50
  import org.jruby.Ruby;
19
51
  import org.jruby.RubyArray;
20
- import org.jruby.RubyBoolean;
21
52
  import org.jruby.RubyClass;
22
53
  import org.jruby.RubyString;
23
54
  import org.jruby.anno.JRubyClass;
24
55
  import org.jruby.anno.JRubyMethod;
25
- import org.jruby.javasupport.JavaUtil;
26
56
  import org.jruby.javasupport.util.RuntimeHelpers;
27
57
  import org.jruby.runtime.ThreadContext;
28
58
  import org.jruby.runtime.builtin.IRubyObject;
@@ -30,7 +60,8 @@ import org.w3c.dom.Attr;
30
60
  import org.w3c.dom.NamedNodeMap;
31
61
 
32
62
  /**
33
- *
63
+ * Class for Nokogiri::XML::DocumentFragment
64
+ *
34
65
  * @author sergio
35
66
  */
36
67
  @JRubyClass(name="Nokogiri::XML::DocumentFragment", parent="Nokogiri::XML::Node")
@@ -45,13 +76,6 @@ public class XmlDocumentFragment extends XmlNode {
45
76
  super(ruby, klazz);
46
77
  }
47
78
 
48
- // @JRubyMethod(name="new", meta = true)
49
- // public static IRubyObject rbNew(ThreadContext context, IRubyObject cls, IRubyObject doc) {
50
- // IRubyObject[] argc = new IRubyObject[1];
51
- // argc[0] = doc;
52
- // return rbNew(context, cls, argc);
53
- // }
54
-
55
79
  @JRubyMethod(name="new", meta = true, required=1, optional=2)
56
80
  public static IRubyObject rbNew(ThreadContext context, IRubyObject cls, IRubyObject[] argc) {
57
81
 
@@ -67,14 +91,13 @@ public class XmlDocumentFragment extends XmlNode {
67
91
 
68
92
  // make wellformed fragment, ignore invalid namespace, or add appropriate namespace to parse
69
93
  if (argc.length > 1 && argc[1] instanceof RubyString) {
70
- argc[1] = JavaUtil.convertJavaToRuby(context.getRuntime(), addRootTagIfNeeded(context, doc, (String)argc[1].toJava(String.class)));
71
- argc[1] = JavaUtil.convertJavaToRuby(context.getRuntime(), ignoreNamespaceIfNeeded(doc, (String)argc[1].toJava(String.class)));
72
- argc[1] = JavaUtil.convertJavaToRuby(context.getRuntime(), addNamespaceDeclIfNeeded(doc, (String)argc[1].toJava(String.class)));
94
+ argc[1] = RubyString.newString(context.getRuntime(), ignoreNamespaceIfNeeded(doc, rubyStringToString(argc[1])));
95
+ argc[1] = RubyString.newString(context.getRuntime(), addNamespaceDeclIfNeeded(doc, rubyStringToString(argc[1])));
73
96
  }
74
97
 
75
98
  XmlDocumentFragment fragment = (XmlDocumentFragment) ((RubyClass)cls).allocate();
76
- fragment.setDocument(doc);
77
- fragment.setNode(doc.getDocument().createDocumentFragment());
99
+ fragment.setDocument(context, doc);
100
+ fragment.setNode(context, doc.getDocument().createDocumentFragment());
78
101
 
79
102
  //TODO: Get namespace definitions from doc.
80
103
  if (argc.length == 3 && argc[2] != null && argc[2] instanceof XmlElement) {
@@ -86,20 +109,6 @@ public class XmlDocumentFragment extends XmlNode {
86
109
 
87
110
  private static Pattern qname_pattern = Pattern.compile("[^</:>\\s]+:[^</:>=\\s]+");
88
111
  private static Pattern starttag_pattern = Pattern.compile("<[^</>]+>");
89
- // welformed_pattern is also used in XmlNode#in_context() method.
90
- public static Pattern wellformed_pattern = Pattern.compile("<(.*)>(()|[^>]*)</\\1>|<[^</>]+/>");
91
-
92
- private static String addRootTagIfNeeded(ThreadContext context, XmlDocument doc, String tags) {
93
- IRubyObject isHtml = RuntimeHelpers.invoke(context, doc, "html?");
94
- if (isHtml instanceof RubyBoolean && ((RubyBoolean)isHtml).isTrue()) return tags;
95
- Matcher matcher = wellformed_pattern.matcher(tags);
96
- while(matcher.find()) {
97
- if (matcher.start() == 0 && matcher.end() == tags.length()) return tags;
98
- break;
99
- }
100
- tags = "<"+ NokogiriNamespaceContext.NOKOGIRI_TEMPORARY_ROOT_TAG + ">" + tags + "</" + NokogiriNamespaceContext.NOKOGIRI_TEMPORARY_ROOT_TAG + ">";
101
- return tags;
102
- }
103
112
 
104
113
  private static String ignoreNamespaceIfNeeded(XmlDocument doc, String tags) {
105
114
  if (doc.getDocument() == null) return tags;
@@ -1,3 +1,35 @@
1
+ /**
2
+ * (The MIT License)
3
+ *
4
+ * Copyright (c) 2008 - 2010:
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
+
1
33
  package nokogiri;
2
34
 
3
35
  import static nokogiri.internals.NokogiriHelpers.getNokogiriClass;
@@ -22,6 +54,11 @@ import org.w3c.dom.DocumentType;
22
54
  import org.w3c.dom.Element;
23
55
  import org.w3c.dom.Node;
24
56
 
57
+ /**
58
+ * Class for Nokogiri::XML::DTD
59
+ *
60
+ */
61
+
25
62
  @JRubyClass(name="Nokogiri::XML::DTD", parent="Nokogiri::XML::Node")
26
63
  public class XmlDtd extends XmlNode {
27
64
  protected RubyArray allDecls = null;
@@ -1,3 +1,35 @@
1
+ /**
2
+ * (The MIT License)
3
+ *
4
+ * Copyright (c) 2008 - 2010:
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
+
1
33
  package nokogiri;
2
34
 
3
35
  import static nokogiri.internals.NokogiriHelpers.namedNodeMapToRubyArray;
@@ -9,6 +41,7 @@ import org.jruby.RubyArray;
9
41
  import org.jruby.RubyClass;
10
42
  import org.jruby.anno.JRubyClass;
11
43
  import org.jruby.anno.JRubyMethod;
44
+ import org.jruby.javasupport.util.RuntimeHelpers;
12
45
  import org.jruby.runtime.ThreadContext;
13
46
  import org.jruby.runtime.Visibility;
14
47
  import org.jruby.runtime.builtin.IRubyObject;
@@ -18,7 +51,8 @@ import org.w3c.dom.NamedNodeMap;
18
51
  import org.w3c.dom.Node;
19
52
 
20
53
  /**
21
- *
54
+ * Class for Nokogiri::XML::Element
55
+ *
22
56
  * @author sergio
23
57
  */
24
58
  @JRubyClass(name="Nokogiri::XML::Element", parent="Nokogiri::XML::Node")
@@ -31,6 +65,21 @@ public class XmlElement extends XmlNode {
31
65
  public XmlElement(Ruby runtime, RubyClass klazz, Node element) {
32
66
  super(runtime, klazz, element);
33
67
  }
68
+
69
+ @Override
70
+ public void setNode(ThreadContext context, Node node) {
71
+ this.node = node;
72
+ if (node != null) {
73
+ resetCache();
74
+ if (node.getNodeType() != Node.DOCUMENT_NODE) {
75
+ doc = document(context);
76
+ setInstanceVariable("@document", doc);
77
+ if (doc != null) {
78
+ RuntimeHelpers.invoke(context, doc, "decorate", this);
79
+ }
80
+ }
81
+ }
82
+ }
34
83
 
35
84
  @Override
36
85
  @JRubyMethod(name = {"add_namespace_definition", "add_namespace"})
@@ -58,7 +107,7 @@ public class XmlElement extends XmlNode {
58
107
  @JRubyMethod(visibility = Visibility.PRIVATE)
59
108
  public IRubyObject get(ThreadContext context, IRubyObject rbkey) {
60
109
  if (rbkey == null || rbkey.isNil()) context.getRuntime().getNil();
61
- String key = (String)rbkey.toJava(String.class);
110
+ String key = rubyStringToString(rbkey);
62
111
  Element element = (Element) node;
63
112
  String value = element.getAttribute(key);
64
113
  if(!value.equals("")){
@@ -1,3 +1,35 @@
1
+ /**
2
+ * (The MIT License)
3
+ *
4
+ * Copyright (c) 2008 - 2010:
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
+
1
33
  package nokogiri;
2
34
 
3
35
  import static nokogiri.internals.NokogiriHelpers.getLocalPart;
@@ -1,3 +1,35 @@
1
+ /**
2
+ * (The MIT License)
3
+ *
4
+ * Copyright (c) 2008 - 2010:
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
+
1
33
  package nokogiri;
2
34
 
3
35
  import static nokogiri.internals.NokogiriHelpers.getLocalPart;