nokogiri 1.5.0.beta.4 → 1.5.0

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/.gemtest +0 -0
  2. data/CHANGELOG.ja.rdoc +34 -0
  3. data/CHANGELOG.rdoc +40 -1
  4. data/Manifest.txt +11 -2
  5. data/README.rdoc +1 -1
  6. data/Rakefile +100 -104
  7. data/bin/nokogiri +1 -2
  8. data/ext/nokogiri/nokogiri.c +24 -1
  9. data/ext/nokogiri/xml_io.c +32 -7
  10. data/ext/nokogiri/xml_node.c +14 -13
  11. data/ext/nokogiri/xml_sax_parser.c +9 -4
  12. data/ext/nokogiri/xslt_stylesheet.c +7 -1
  13. data/lib/nokogiri.rb +3 -22
  14. data/lib/nokogiri/css.rb +4 -0
  15. data/lib/nokogiri/html/document.rb +10 -14
  16. data/lib/nokogiri/version.rb +76 -23
  17. data/lib/nokogiri/xml/builder.rb +7 -0
  18. data/lib/nokogiri/xml/document.rb +17 -1
  19. data/lib/nokogiri/xml/document_fragment.rb +14 -0
  20. data/lib/nokogiri/xml/node.rb +36 -28
  21. data/lib/nokogiri/xml/node/save_options.rb +17 -1
  22. data/lib/nokogiri/xml/node_set.rb +7 -0
  23. data/lib/nokogiri/xml/parse_options.rb +8 -0
  24. data/lib/nokogiri/xml/reader.rb +6 -6
  25. data/lib/nokogiri/xml/schema.rb +7 -1
  26. data/nokogiri_help_responses.md +40 -0
  27. data/tasks/cross_compile.rb +134 -159
  28. data/tasks/nokogiri.org.rb +18 -0
  29. data/tasks/test.rb +1 -1
  30. data/test/files/encoding.html +82 -0
  31. data/test/files/encoding.xhtml +84 -0
  32. data/test/files/metacharset.html +10 -0
  33. data/test/files/noencoding.html +47 -0
  34. data/test/helper.rb +2 -0
  35. data/test/html/test_document.rb +15 -0
  36. data/test/html/test_document_encoding.rb +13 -0
  37. data/test/test_memory_leak.rb +20 -0
  38. data/test/test_reader.rb +22 -0
  39. data/test/test_xslt_transforms.rb +6 -2
  40. data/test/xml/node/test_save_options.rb +10 -2
  41. data/test/xml/test_builder.rb +17 -0
  42. data/test/xml/test_document.rb +22 -0
  43. data/test/xml/test_node.rb +19 -1
  44. data/test/xml/test_node_reparenting.rb +16 -3
  45. data/test/xml/test_node_set.rb +34 -0
  46. data/test/xml/test_schema.rb +5 -0
  47. data/test/xslt/test_exception_handling.rb +37 -0
  48. metadata +185 -157
  49. data/deps.rip +0 -5
  50. data/ext/java/nokogiri/EncodingHandler.java +0 -124
  51. data/ext/java/nokogiri/HtmlDocument.java +0 -149
  52. data/ext/java/nokogiri/HtmlElementDescription.java +0 -145
  53. data/ext/java/nokogiri/HtmlEntityLookup.java +0 -79
  54. data/ext/java/nokogiri/HtmlSaxParserContext.java +0 -259
  55. data/ext/java/nokogiri/NokogiriService.java +0 -535
  56. data/ext/java/nokogiri/XmlAttr.java +0 -191
  57. data/ext/java/nokogiri/XmlAttributeDecl.java +0 -130
  58. data/ext/java/nokogiri/XmlCdata.java +0 -91
  59. data/ext/java/nokogiri/XmlComment.java +0 -86
  60. data/ext/java/nokogiri/XmlDocument.java +0 -529
  61. data/ext/java/nokogiri/XmlDocumentFragment.java +0 -217
  62. data/ext/java/nokogiri/XmlDtd.java +0 -467
  63. data/ext/java/nokogiri/XmlElement.java +0 -222
  64. data/ext/java/nokogiri/XmlElementContent.java +0 -382
  65. data/ext/java/nokogiri/XmlElementDecl.java +0 -148
  66. data/ext/java/nokogiri/XmlEntityDecl.java +0 -162
  67. data/ext/java/nokogiri/XmlEntityReference.java +0 -75
  68. data/ext/java/nokogiri/XmlNamespace.java +0 -128
  69. data/ext/java/nokogiri/XmlNode.java +0 -1399
  70. data/ext/java/nokogiri/XmlNodeSet.java +0 -311
  71. data/ext/java/nokogiri/XmlProcessingInstruction.java +0 -103
  72. data/ext/java/nokogiri/XmlReader.java +0 -411
  73. data/ext/java/nokogiri/XmlRelaxng.java +0 -144
  74. data/ext/java/nokogiri/XmlSaxParserContext.java +0 -367
  75. data/ext/java/nokogiri/XmlSaxPushParser.java +0 -184
  76. data/ext/java/nokogiri/XmlSchema.java +0 -319
  77. data/ext/java/nokogiri/XmlSyntaxError.java +0 -119
  78. data/ext/java/nokogiri/XmlText.java +0 -136
  79. data/ext/java/nokogiri/XmlXpathContext.java +0 -179
  80. data/ext/java/nokogiri/XsltStylesheet.java +0 -183
  81. data/ext/java/nokogiri/internals/HtmlDomParserContext.java +0 -206
  82. data/ext/java/nokogiri/internals/NokogiriDocumentCache.java +0 -73
  83. data/ext/java/nokogiri/internals/NokogiriErrorHandler.java +0 -86
  84. data/ext/java/nokogiri/internals/NokogiriHandler.java +0 -327
  85. data/ext/java/nokogiri/internals/NokogiriHelpers.java +0 -582
  86. data/ext/java/nokogiri/internals/NokogiriNamespaceCache.java +0 -171
  87. data/ext/java/nokogiri/internals/NokogiriNamespaceContext.java +0 -118
  88. data/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler.java +0 -74
  89. data/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler4NekoHtml.java +0 -121
  90. data/ext/java/nokogiri/internals/NokogiriStrictErrorHandler.java +0 -79
  91. data/ext/java/nokogiri/internals/NokogiriXPathFunction.java +0 -126
  92. data/ext/java/nokogiri/internals/NokogiriXPathFunctionResolver.java +0 -56
  93. data/ext/java/nokogiri/internals/ParserContext.java +0 -278
  94. data/ext/java/nokogiri/internals/PushInputStream.java +0 -411
  95. data/ext/java/nokogiri/internals/ReaderNode.java +0 -474
  96. data/ext/java/nokogiri/internals/SaveContext.java +0 -288
  97. data/ext/java/nokogiri/internals/SchemaErrorHandler.java +0 -76
  98. data/ext/java/nokogiri/internals/XmlDeclHandler.java +0 -42
  99. data/ext/java/nokogiri/internals/XmlDomParser.java +0 -77
  100. data/ext/java/nokogiri/internals/XmlDomParserContext.java +0 -238
  101. data/ext/java/nokogiri/internals/XmlSaxParser.java +0 -65
  102. data/ext/java/nokogiri/internals/XsltExtensionFunction.java +0 -72
  103. data/lib/isorelax.jar +0 -0
  104. data/lib/jing.jar +0 -0
  105. data/lib/nekodtd.jar +0 -0
  106. data/lib/nekohtml.jar +0 -0
  107. data/lib/xercesImpl.jar +0 -0
@@ -1,191 +0,0 @@
1
- /**
2
- * (The MIT License)
3
- *
4
- * Copyright (c) 2008 - 2011:
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
- package nokogiri;
34
-
35
- import static nokogiri.internals.NokogiriHelpers.getNokogiriClass;
36
- import static nokogiri.internals.NokogiriHelpers.rubyStringToString;
37
- import nokogiri.internals.NokogiriHelpers;
38
- import nokogiri.internals.SaveContext;
39
-
40
- import org.jruby.Ruby;
41
- import org.jruby.RubyBoolean;
42
- import org.jruby.RubyClass;
43
- import org.jruby.RubyString;
44
- import org.jruby.anno.JRubyClass;
45
- import org.jruby.anno.JRubyMethod;
46
- import org.jruby.runtime.ThreadContext;
47
- import org.jruby.runtime.builtin.IRubyObject;
48
- import org.w3c.dom.Attr;
49
- import org.w3c.dom.Element;
50
- import org.w3c.dom.Node;
51
-
52
- /**
53
- * Class for Nokogiri::XML::Attr
54
- *
55
- * @author sergio
56
- * @author Yoko Harada <yokolet@gmail.com>
57
- */
58
-
59
- @JRubyClass(name="Nokogiri::XML::Attr", parent="Nokogiri::XML::Node")
60
- public class XmlAttr extends XmlNode{
61
-
62
- public static final String[] HTML_BOOLEAN_ATTRS = {
63
- "checked", "compact", "declare", "defer", "disabled", "ismap",
64
- "multiple", "nohref", "noresize", "noshade", "nowrap", "readonly",
65
- "selected"
66
- };
67
-
68
- public XmlAttr(Ruby ruby, Node attr){
69
- super(ruby, getNokogiriClass(ruby, "Nokogiri::XML::Attr"), attr);
70
- }
71
-
72
- public XmlAttr(Ruby ruby, RubyClass rubyClass) {
73
- super(ruby, rubyClass);
74
- }
75
-
76
- public XmlAttr(Ruby ruby, RubyClass rubyClass, Node attr){
77
- super(ruby, rubyClass, attr);
78
- }
79
-
80
- @Override
81
- protected void init(ThreadContext context, IRubyObject[] args) {
82
- if (args.length < 2) {
83
- throw getRuntime().newArgumentError(args.length, 2);
84
- }
85
-
86
- IRubyObject doc = args[0];
87
- IRubyObject content = args[1];
88
-
89
- if(!(doc instanceof XmlDocument)) {
90
- final String msg =
91
- "document must be an instance of Nokogiri::XML::Document";
92
- throw getRuntime().newArgumentError(msg);
93
- }
94
-
95
- XmlDocument xmlDoc = (XmlDocument)doc;
96
- String str = rubyStringToString(content);
97
- Node attr = xmlDoc.getDocument().createAttribute(str);
98
- setNode(context, attr);
99
- }
100
-
101
- public boolean isHtmlBooleanAttr() {
102
- String name = node.getNodeName().toLowerCase();
103
-
104
- for(String s : HTML_BOOLEAN_ATTRS) {
105
- if(s.equals(name)) return true;
106
- }
107
-
108
- return false;
109
- }
110
-
111
-
112
- private String serializeAttrTextContent(String s, boolean htmlDoc) {
113
- if (s == null) return "";
114
-
115
- char[] c = s.toCharArray();
116
- StringBuffer buffer = new StringBuffer(c.length);
117
-
118
- for(int i = 0; i < c.length; i++) {
119
- switch(c[i]){
120
- case '\n': buffer.append("&#10;"); break;
121
- case '\r': buffer.append("&#13;"); break;
122
- case '\t': buffer.append("&#9;"); break;
123
- case '"': if (htmlDoc) buffer.append("%22");
124
- else buffer.append("&quot;");
125
- break;
126
- case '<': buffer.append("&lt;"); break;
127
- case '>': buffer.append("&gt;"); break;
128
- case '&': buffer.append("&amp;"); break;
129
- default: buffer.append(c[i]);
130
- }
131
- }
132
-
133
- return buffer.toString();
134
- }
135
-
136
- @Override
137
- @JRubyMethod(name = {"content", "value", "to_s"})
138
- public IRubyObject content(ThreadContext context) {
139
- if (content != null && !content.isNil()) return content;
140
- if (node == null) return context.getRuntime().getNil();
141
- String attrValue = ((Attr)node).getValue();
142
- if (attrValue == null) return context.getRuntime().getNil();
143
- return RubyString.newString(context.getRuntime(), attrValue);
144
- }
145
-
146
- @JRubyMethod(name = {"value=", "content="})
147
- public IRubyObject value_set(ThreadContext context, IRubyObject content){
148
- Attr attr = (Attr) node;
149
- attr.setValue(rubyStringToString(XmlNode.encode_special_chars(context, content)));
150
- setContent(content);
151
- return content;
152
- }
153
-
154
- @Override
155
- protected IRubyObject getNodeName(ThreadContext context) {
156
- if (name != null) return name;
157
- String attrName = ((Attr)node).getName();
158
- attrName = NokogiriHelpers.getLocalPart(attrName);
159
- return attrName == null ? context.getRuntime().getNil() : RubyString.newString(context.getRuntime(), attrName);
160
- }
161
-
162
- @Override
163
- public void saveContent(ThreadContext context, SaveContext ctx) {
164
- boolean docType = isHtml(context);
165
- Attr attr = (Attr) node;
166
-
167
- ctx.maybeSpace();
168
- ctx.append(attr.getName());
169
-
170
- if (!ctx.asHtml() || !isHtmlBooleanAttr()) {
171
- ctx.append("=");
172
- ctx.append("\"");
173
- ctx.append(serializeAttrTextContent(attr.getValue(), docType));
174
- ctx.append("\"");
175
- }
176
- }
177
-
178
- private boolean isHtml(ThreadContext context) {
179
- return document(context).getMetaClass().isKindOfModule(getNokogiriClass(context.getRuntime(), "Nokogiri::HTML::Document"));
180
- }
181
-
182
- @Override
183
- public IRubyObject unlink(ThreadContext context) {
184
- Attr attr = (Attr) node;
185
- Element parent = attr.getOwnerElement();
186
- parent.removeAttributeNode(attr);
187
-
188
- return this;
189
- }
190
-
191
- }
@@ -1,130 +0,0 @@
1
- /**
2
- * (The MIT License)
3
- *
4
- * Copyright (c) 2008 - 2011:
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
- package nokogiri;
34
-
35
- import static nokogiri.internals.NokogiriHelpers.getNokogiriClass;
36
-
37
- import org.jruby.Ruby;
38
- import org.jruby.RubyArray;
39
- import org.jruby.RubyClass;
40
- import org.jruby.anno.JRubyClass;
41
- import org.jruby.anno.JRubyMethod;
42
- import org.jruby.runtime.ThreadContext;
43
- import org.jruby.runtime.builtin.IRubyObject;
44
- import org.w3c.dom.Element;
45
- import org.w3c.dom.Node;
46
-
47
- /**
48
- * DTD attribute declaration.
49
- *
50
- * @author Patrick Mahoney <pat@polycrystal.org>
51
- */
52
- @JRubyClass(name="Nokogiri::XML::AttributeDecl", parent="Nokogiri::XML::Node")
53
- public class XmlAttributeDecl extends XmlNode {
54
-
55
- public XmlAttributeDecl(Ruby ruby, RubyClass klass) {
56
- super(ruby, klass);
57
- throw ruby.newRuntimeError("node required");
58
- }
59
-
60
- /**
61
- * Initialize based on an attributeDecl node from a NekoDTD parsed
62
- * DTD.
63
- *
64
- * Internally, XmlAttributeDecl combines these into a single node.
65
- */
66
- public XmlAttributeDecl(Ruby ruby, RubyClass klass, Node attrDeclNode) {
67
- super(ruby, klass, attrDeclNode);
68
- }
69
-
70
- public static IRubyObject create(ThreadContext context, Node attrDeclNode) {
71
- XmlAttributeDecl self =
72
- new XmlAttributeDecl(context.getRuntime(),
73
- getNokogiriClass(context.getRuntime(), "Nokogiri::XML::AttributeDecl"),
74
- attrDeclNode);
75
- return self;
76
- }
77
-
78
- @Override
79
- @JRubyMethod
80
- public IRubyObject node_name(ThreadContext context) {
81
- return attribute_name(context);
82
- }
83
-
84
- @Override
85
- @JRubyMethod(name = "node_name=")
86
- public IRubyObject node_name_set(ThreadContext context, IRubyObject name) {
87
- throw context.getRuntime()
88
- .newRuntimeError("cannot change name of DTD decl");
89
- }
90
-
91
- public IRubyObject element_name(ThreadContext context) {
92
- return getAttribute(context, "ename");
93
- }
94
-
95
- public IRubyObject attribute_name(ThreadContext context) {
96
- return getAttribute(context, "aname");
97
- }
98
-
99
- @JRubyMethod
100
- public IRubyObject attribute_type(ThreadContext context) {
101
- return getAttribute(context, "atype");
102
- }
103
-
104
- @JRubyMethod(name="default")
105
- public IRubyObject default_value(ThreadContext context) {
106
- return getAttribute(context, "default");
107
- }
108
-
109
- /**
110
- * FIXME: will enumerations all be of the simple (val1|val2|val3)
111
- * type string?
112
- */
113
- @JRubyMethod
114
- public IRubyObject enumeration(ThreadContext context) {
115
- RubyArray enumVals = RubyArray.newArray(context.getRuntime());
116
- String atype = ((Element)node).getAttribute("atype");
117
-
118
- if (atype != null && atype.length() != 0 && atype.charAt(0) == '(') {
119
- // removed enclosing parens
120
- String valueStr = atype.substring(1, atype.length() - 1);
121
- String[] values = valueStr.split("\\|");
122
- for (int i = 0; i < values.length; i++) {
123
- enumVals.append(context.getRuntime().newString(values[i]));
124
- }
125
- }
126
-
127
- return enumVals;
128
- }
129
-
130
- }
@@ -1,91 +0,0 @@
1
- /**
2
- * (The MIT License)
3
- *
4
- * Copyright (c) 2008 - 2011:
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
- package nokogiri;
34
-
35
- import static nokogiri.internals.NokogiriHelpers.rubyStringToString;
36
-
37
- import nokogiri.internals.SaveContext;
38
-
39
- import org.jruby.Ruby;
40
- import org.jruby.RubyClass;
41
- import org.jruby.anno.JRubyClass;
42
- import org.jruby.runtime.ThreadContext;
43
- import org.jruby.runtime.builtin.IRubyObject;
44
- import org.w3c.dom.CDATASection;
45
- import org.w3c.dom.Document;
46
- import org.w3c.dom.Node;
47
-
48
- /**
49
- * Class for Nokogiri::XML::CDATA
50
- *
51
- * @author sergio
52
- * @author Yoko Harada <yokolet@gmail.com>
53
- */
54
-
55
- @JRubyClass(name="Nokogiri::XML::CDATA", parent="Nokogiri::XML::Text")
56
- public class XmlCdata extends XmlText {
57
- public XmlCdata(Ruby ruby, RubyClass rubyClass) {
58
- super(ruby, rubyClass);
59
- }
60
-
61
- public XmlCdata(Ruby ruby, RubyClass rubyClass, Node node) {
62
- super(ruby, rubyClass, node);
63
- }
64
-
65
- @Override
66
- protected void init(ThreadContext context, IRubyObject[] args) {
67
- if (args.length < 2) {
68
- throw getRuntime().newArgumentError(args.length, 2);
69
- }
70
- IRubyObject doc = args[0];
71
- content = args[1];
72
- XmlDocument xmlDoc =(XmlDocument) ((XmlNode) doc).document(context);
73
- doc = xmlDoc;
74
- Document document = xmlDoc.getDocument();
75
- Node node = document.createCDATASection((content.isNil()) ? null : rubyStringToString(content));
76
- setNode(context, node);
77
- }
78
-
79
- @Override
80
- public void saveContent(ThreadContext context, SaveContext ctx) {
81
- CDATASection cdata = (CDATASection) node;
82
-
83
- if(cdata.getData().length() == 0) {
84
- ctx.append("<![CDATA[]]>");
85
- } else {
86
- ctx.append("<![CDATA[");
87
- ctx.append(cdata.getData());
88
- ctx.append("]]>");
89
- }
90
- }
91
- }
@@ -1,86 +0,0 @@
1
- /**
2
- * (The MIT License)
3
- *
4
- * Copyright (c) 2008 - 2011:
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
- package nokogiri;
34
-
35
- import static nokogiri.internals.NokogiriHelpers.rubyStringToString;
36
- import nokogiri.internals.SaveContext;
37
-
38
- import org.jruby.Ruby;
39
- import org.jruby.RubyClass;
40
- import org.jruby.anno.JRubyClass;
41
- import org.jruby.runtime.ThreadContext;
42
- import org.jruby.runtime.builtin.IRubyObject;
43
- import org.w3c.dom.Document;
44
- import org.w3c.dom.Node;
45
-
46
- /**
47
- * Class for Nokogiri::XML::Comment
48
- *
49
- * @author sergio
50
- * @author Yoko Harada <yokolet@gmail.com>
51
- */
52
-
53
- @JRubyClass(name="Nokogiri::XML::Comment", parent="Nokogiri::XML::CharacterData")
54
- public class XmlComment extends XmlNode {
55
- public XmlComment(Ruby ruby, RubyClass rubyClass, Node node) {
56
- super(ruby, rubyClass, node);
57
- }
58
-
59
- public XmlComment(Ruby runtime, RubyClass klass) {
60
- super(runtime, klass);
61
- }
62
-
63
- @Override
64
- protected void init(ThreadContext context, IRubyObject[] args) {
65
- if (args.length < 2)
66
- throw getRuntime().newArgumentError(args.length, 2);
67
-
68
- IRubyObject doc = args[0];
69
- IRubyObject text = args[1];
70
-
71
- XmlDocument xmlDoc = (XmlDocument) doc;
72
- Document document = xmlDoc.getDocument();
73
- Node node = document.createComment(rubyStringToString(text));
74
- setNode(context, node);
75
- }
76
-
77
- @Override
78
- public boolean isComment() { return true; }
79
-
80
- @Override
81
- public void saveContent(ThreadContext context, SaveContext ctx) {
82
- ctx.append("<!--");
83
- ctx.append(content(context).convertToString().asJavaString());
84
- ctx.append("-->");
85
- }
86
- }