nokogiri-backport 1.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +3 -0
- data/LICENSE-DEPENDENCIES.md +1682 -0
- data/LICENSE.md +9 -0
- data/README.md +272 -0
- data/bin/nokogiri +118 -0
- data/dependencies.yml +74 -0
- data/ext/java/nokogiri/EncodingHandler.java +124 -0
- data/ext/java/nokogiri/HtmlDocument.java +178 -0
- data/ext/java/nokogiri/HtmlElementDescription.java +148 -0
- data/ext/java/nokogiri/HtmlEntityLookup.java +79 -0
- data/ext/java/nokogiri/HtmlSaxParserContext.java +282 -0
- data/ext/java/nokogiri/HtmlSaxPushParser.java +222 -0
- data/ext/java/nokogiri/NokogiriService.java +597 -0
- data/ext/java/nokogiri/XmlAttr.java +162 -0
- data/ext/java/nokogiri/XmlAttributeDecl.java +129 -0
- data/ext/java/nokogiri/XmlCdata.java +82 -0
- data/ext/java/nokogiri/XmlComment.java +97 -0
- data/ext/java/nokogiri/XmlDocument.java +633 -0
- data/ext/java/nokogiri/XmlDocumentFragment.java +185 -0
- data/ext/java/nokogiri/XmlDtd.java +481 -0
- data/ext/java/nokogiri/XmlElement.java +68 -0
- data/ext/java/nokogiri/XmlElementContent.java +382 -0
- data/ext/java/nokogiri/XmlElementDecl.java +147 -0
- data/ext/java/nokogiri/XmlEntityDecl.java +157 -0
- data/ext/java/nokogiri/XmlEntityReference.java +101 -0
- data/ext/java/nokogiri/XmlNamespace.java +199 -0
- data/ext/java/nokogiri/XmlNode.java +1684 -0
- data/ext/java/nokogiri/XmlNodeSet.java +434 -0
- data/ext/java/nokogiri/XmlProcessingInstruction.java +100 -0
- data/ext/java/nokogiri/XmlReader.java +531 -0
- data/ext/java/nokogiri/XmlRelaxng.java +151 -0
- data/ext/java/nokogiri/XmlSaxParserContext.java +374 -0
- data/ext/java/nokogiri/XmlSaxPushParser.java +286 -0
- data/ext/java/nokogiri/XmlSchema.java +388 -0
- data/ext/java/nokogiri/XmlSyntaxError.java +138 -0
- data/ext/java/nokogiri/XmlText.java +110 -0
- data/ext/java/nokogiri/XmlXpathContext.java +301 -0
- data/ext/java/nokogiri/XsltStylesheet.java +347 -0
- data/ext/java/nokogiri/internals/ClosedStreamException.java +10 -0
- data/ext/java/nokogiri/internals/HtmlDomParserContext.java +252 -0
- data/ext/java/nokogiri/internals/IgnoreSchemaErrorsErrorHandler.java +20 -0
- data/ext/java/nokogiri/internals/NokogiriBlockingQueueInputStream.java +151 -0
- data/ext/java/nokogiri/internals/NokogiriDomParser.java +116 -0
- data/ext/java/nokogiri/internals/NokogiriEntityResolver.java +121 -0
- data/ext/java/nokogiri/internals/NokogiriErrorHandler.java +69 -0
- data/ext/java/nokogiri/internals/NokogiriHandler.java +327 -0
- data/ext/java/nokogiri/internals/NokogiriHelpers.java +734 -0
- data/ext/java/nokogiri/internals/NokogiriNamespaceCache.java +217 -0
- data/ext/java/nokogiri/internals/NokogiriNamespaceContext.java +127 -0
- data/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler.java +100 -0
- data/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler4NekoHtml.java +121 -0
- data/ext/java/nokogiri/internals/NokogiriStrictErrorHandler.java +78 -0
- data/ext/java/nokogiri/internals/NokogiriXPathFunction.java +180 -0
- data/ext/java/nokogiri/internals/NokogiriXPathFunctionResolver.java +72 -0
- data/ext/java/nokogiri/internals/NokogiriXPathVariableResolver.java +60 -0
- data/ext/java/nokogiri/internals/NokogiriXsltErrorListener.java +87 -0
- data/ext/java/nokogiri/internals/ParserContext.java +259 -0
- data/ext/java/nokogiri/internals/ReaderNode.java +488 -0
- data/ext/java/nokogiri/internals/SaveContextVisitor.java +778 -0
- data/ext/java/nokogiri/internals/SchemaErrorHandler.java +73 -0
- data/ext/java/nokogiri/internals/XalanDTMManagerPatch.java +168 -0
- data/ext/java/nokogiri/internals/XmlDeclHandler.java +42 -0
- data/ext/java/nokogiri/internals/XmlDomParserContext.java +274 -0
- data/ext/java/nokogiri/internals/XmlSaxParser.java +65 -0
- data/ext/java/nokogiri/internals/c14n/AttrCompare.java +119 -0
- data/ext/java/nokogiri/internals/c14n/C14nHelper.java +159 -0
- data/ext/java/nokogiri/internals/c14n/CanonicalFilter.java +37 -0
- data/ext/java/nokogiri/internals/c14n/CanonicalizationException.java +93 -0
- data/ext/java/nokogiri/internals/c14n/Canonicalizer.java +252 -0
- data/ext/java/nokogiri/internals/c14n/Canonicalizer11.java +639 -0
- data/ext/java/nokogiri/internals/c14n/Canonicalizer11_OmitComments.java +38 -0
- data/ext/java/nokogiri/internals/c14n/Canonicalizer11_WithComments.java +38 -0
- data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315.java +367 -0
- data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315Excl.java +295 -0
- data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315ExclOmitComments.java +40 -0
- data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315ExclWithComments.java +44 -0
- data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315OmitComments.java +44 -0
- data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315WithComments.java +43 -0
- data/ext/java/nokogiri/internals/c14n/CanonicalizerBase.java +630 -0
- data/ext/java/nokogiri/internals/c14n/CanonicalizerPhysical.java +173 -0
- data/ext/java/nokogiri/internals/c14n/CanonicalizerSpi.java +76 -0
- data/ext/java/nokogiri/internals/c14n/Constants.java +42 -0
- data/ext/java/nokogiri/internals/c14n/ElementProxy.java +293 -0
- data/ext/java/nokogiri/internals/c14n/HelperNodeList.java +93 -0
- data/ext/java/nokogiri/internals/c14n/IgnoreAllErrorHandler.java +79 -0
- data/ext/java/nokogiri/internals/c14n/InclusiveNamespaces.java +166 -0
- data/ext/java/nokogiri/internals/c14n/InvalidCanonicalizerException.java +76 -0
- data/ext/java/nokogiri/internals/c14n/NameSpaceSymbTable.java +402 -0
- data/ext/java/nokogiri/internals/c14n/NodeFilter.java +51 -0
- data/ext/java/nokogiri/internals/c14n/UtfHelpper.java +179 -0
- data/ext/java/nokogiri/internals/c14n/XMLUtils.java +507 -0
- data/ext/java/nokogiri/internals/dom2dtm/DOM2DTM.java +1745 -0
- data/ext/java/nokogiri/internals/dom2dtm/DOM2DTMdefaultNamespaceDeclarationNode.java +685 -0
- data/ext/nokogiri/depend +477 -0
- data/ext/nokogiri/extconf.rb +836 -0
- data/ext/nokogiri/html_document.c +171 -0
- data/ext/nokogiri/html_document.h +10 -0
- data/ext/nokogiri/html_element_description.c +279 -0
- data/ext/nokogiri/html_element_description.h +10 -0
- data/ext/nokogiri/html_entity_lookup.c +32 -0
- data/ext/nokogiri/html_entity_lookup.h +8 -0
- data/ext/nokogiri/html_sax_parser_context.c +116 -0
- data/ext/nokogiri/html_sax_parser_context.h +11 -0
- data/ext/nokogiri/html_sax_push_parser.c +87 -0
- data/ext/nokogiri/html_sax_push_parser.h +9 -0
- data/ext/nokogiri/nokogiri.c +135 -0
- data/ext/nokogiri/nokogiri.h +130 -0
- data/ext/nokogiri/xml_attr.c +103 -0
- data/ext/nokogiri/xml_attr.h +9 -0
- data/ext/nokogiri/xml_attribute_decl.c +70 -0
- data/ext/nokogiri/xml_attribute_decl.h +9 -0
- data/ext/nokogiri/xml_cdata.c +62 -0
- data/ext/nokogiri/xml_cdata.h +9 -0
- data/ext/nokogiri/xml_comment.c +69 -0
- data/ext/nokogiri/xml_comment.h +9 -0
- data/ext/nokogiri/xml_document.c +622 -0
- data/ext/nokogiri/xml_document.h +23 -0
- data/ext/nokogiri/xml_document_fragment.c +48 -0
- data/ext/nokogiri/xml_document_fragment.h +10 -0
- data/ext/nokogiri/xml_dtd.c +202 -0
- data/ext/nokogiri/xml_dtd.h +10 -0
- data/ext/nokogiri/xml_element_content.c +123 -0
- data/ext/nokogiri/xml_element_content.h +10 -0
- data/ext/nokogiri/xml_element_decl.c +69 -0
- data/ext/nokogiri/xml_element_decl.h +9 -0
- data/ext/nokogiri/xml_encoding_handler.c +79 -0
- data/ext/nokogiri/xml_encoding_handler.h +8 -0
- data/ext/nokogiri/xml_entity_decl.c +110 -0
- data/ext/nokogiri/xml_entity_decl.h +10 -0
- data/ext/nokogiri/xml_entity_reference.c +52 -0
- data/ext/nokogiri/xml_entity_reference.h +9 -0
- data/ext/nokogiri/xml_io.c +63 -0
- data/ext/nokogiri/xml_io.h +11 -0
- data/ext/nokogiri/xml_libxml2_hacks.c +112 -0
- data/ext/nokogiri/xml_libxml2_hacks.h +12 -0
- data/ext/nokogiri/xml_namespace.c +111 -0
- data/ext/nokogiri/xml_namespace.h +14 -0
- data/ext/nokogiri/xml_node.c +1773 -0
- data/ext/nokogiri/xml_node.h +13 -0
- data/ext/nokogiri/xml_node_set.c +486 -0
- data/ext/nokogiri/xml_node_set.h +12 -0
- data/ext/nokogiri/xml_processing_instruction.c +56 -0
- data/ext/nokogiri/xml_processing_instruction.h +9 -0
- data/ext/nokogiri/xml_reader.c +657 -0
- data/ext/nokogiri/xml_reader.h +10 -0
- data/ext/nokogiri/xml_relax_ng.c +179 -0
- data/ext/nokogiri/xml_relax_ng.h +9 -0
- data/ext/nokogiri/xml_sax_parser.c +305 -0
- data/ext/nokogiri/xml_sax_parser.h +39 -0
- data/ext/nokogiri/xml_sax_parser_context.c +262 -0
- data/ext/nokogiri/xml_sax_parser_context.h +10 -0
- data/ext/nokogiri/xml_sax_push_parser.c +159 -0
- data/ext/nokogiri/xml_sax_push_parser.h +9 -0
- data/ext/nokogiri/xml_schema.c +276 -0
- data/ext/nokogiri/xml_schema.h +9 -0
- data/ext/nokogiri/xml_syntax_error.c +64 -0
- data/ext/nokogiri/xml_syntax_error.h +13 -0
- data/ext/nokogiri/xml_text.c +52 -0
- data/ext/nokogiri/xml_text.h +9 -0
- data/ext/nokogiri/xml_xpath_context.c +374 -0
- data/ext/nokogiri/xml_xpath_context.h +10 -0
- data/ext/nokogiri/xslt_stylesheet.c +263 -0
- data/ext/nokogiri/xslt_stylesheet.h +14 -0
- data/lib/isorelax.jar +0 -0
- data/lib/jing.jar +0 -0
- data/lib/nekodtd.jar +0 -0
- data/lib/nekohtml.jar +0 -0
- data/lib/nokogiri/css/node.rb +53 -0
- data/lib/nokogiri/css/parser.rb +751 -0
- data/lib/nokogiri/css/parser.y +272 -0
- data/lib/nokogiri/css/parser_extras.rb +94 -0
- data/lib/nokogiri/css/syntax_error.rb +8 -0
- data/lib/nokogiri/css/tokenizer.rb +154 -0
- data/lib/nokogiri/css/tokenizer.rex +55 -0
- data/lib/nokogiri/css/xpath_visitor.rb +260 -0
- data/lib/nokogiri/css.rb +28 -0
- data/lib/nokogiri/decorators/slop.rb +43 -0
- data/lib/nokogiri/html/builder.rb +36 -0
- data/lib/nokogiri/html/document.rb +322 -0
- data/lib/nokogiri/html/document_fragment.rb +50 -0
- data/lib/nokogiri/html/element_description.rb +24 -0
- data/lib/nokogiri/html/element_description_defaults.rb +672 -0
- data/lib/nokogiri/html/entity_lookup.rb +14 -0
- data/lib/nokogiri/html/sax/parser.rb +63 -0
- data/lib/nokogiri/html/sax/parser_context.rb +17 -0
- data/lib/nokogiri/html/sax/push_parser.rb +37 -0
- data/lib/nokogiri/html.rb +38 -0
- data/lib/nokogiri/jruby/dependencies.rb +20 -0
- data/lib/nokogiri/syntax_error.rb +5 -0
- data/lib/nokogiri/version/constant.rb +5 -0
- data/lib/nokogiri/version/info.rb +182 -0
- data/lib/nokogiri/version.rb +3 -0
- data/lib/nokogiri/xml/attr.rb +15 -0
- data/lib/nokogiri/xml/attribute_decl.rb +19 -0
- data/lib/nokogiri/xml/builder.rb +447 -0
- data/lib/nokogiri/xml/cdata.rb +12 -0
- data/lib/nokogiri/xml/character_data.rb +8 -0
- data/lib/nokogiri/xml/document.rb +290 -0
- data/lib/nokogiri/xml/document_fragment.rb +159 -0
- data/lib/nokogiri/xml/dtd.rb +33 -0
- data/lib/nokogiri/xml/element_content.rb +37 -0
- data/lib/nokogiri/xml/element_decl.rb +14 -0
- data/lib/nokogiri/xml/entity_decl.rb +20 -0
- data/lib/nokogiri/xml/entity_reference.rb +19 -0
- data/lib/nokogiri/xml/namespace.rb +14 -0
- data/lib/nokogiri/xml/node/save_options.rb +62 -0
- data/lib/nokogiri/xml/node.rb +1240 -0
- data/lib/nokogiri/xml/node_set.rb +372 -0
- data/lib/nokogiri/xml/notation.rb +7 -0
- data/lib/nokogiri/xml/parse_options.rb +127 -0
- data/lib/nokogiri/xml/pp/character_data.rb +19 -0
- data/lib/nokogiri/xml/pp/node.rb +57 -0
- data/lib/nokogiri/xml/pp.rb +3 -0
- data/lib/nokogiri/xml/processing_instruction.rb +9 -0
- data/lib/nokogiri/xml/reader.rb +116 -0
- data/lib/nokogiri/xml/relax_ng.rb +37 -0
- data/lib/nokogiri/xml/sax/document.rb +172 -0
- data/lib/nokogiri/xml/sax/parser.rb +123 -0
- data/lib/nokogiri/xml/sax/parser_context.rb +17 -0
- data/lib/nokogiri/xml/sax/push_parser.rb +61 -0
- data/lib/nokogiri/xml/sax.rb +5 -0
- data/lib/nokogiri/xml/schema.rb +72 -0
- data/lib/nokogiri/xml/searchable.rb +239 -0
- data/lib/nokogiri/xml/syntax_error.rb +71 -0
- data/lib/nokogiri/xml/text.rb +10 -0
- data/lib/nokogiri/xml/xpath/syntax_error.rb +12 -0
- data/lib/nokogiri/xml/xpath.rb +11 -0
- data/lib/nokogiri/xml/xpath_context.rb +17 -0
- data/lib/nokogiri/xml.rb +76 -0
- data/lib/nokogiri/xslt/stylesheet.rb +26 -0
- data/lib/nokogiri/xslt.rb +57 -0
- data/lib/nokogiri.rb +144 -0
- data/lib/serializer.jar +0 -0
- data/lib/xalan.jar +0 -0
- data/lib/xercesImpl.jar +0 -0
- data/lib/xml-apis.jar +0 -0
- data/lib/xsd/xmlparser/nokogiri.rb +103 -0
- metadata +531 -0
@@ -0,0 +1,388 @@
|
|
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.adjustSystemIdIfNecessary;
|
36
|
+
import static nokogiri.internals.NokogiriHelpers.getNokogiriClass;
|
37
|
+
|
38
|
+
import java.io.IOException;
|
39
|
+
import java.io.InputStream;
|
40
|
+
import java.io.Reader;
|
41
|
+
import java.io.StringReader;
|
42
|
+
|
43
|
+
import javax.xml.XMLConstants;
|
44
|
+
import javax.xml.transform.Source;
|
45
|
+
import javax.xml.transform.dom.DOMSource;
|
46
|
+
import javax.xml.transform.stream.StreamSource;
|
47
|
+
import javax.xml.validation.Schema;
|
48
|
+
import javax.xml.validation.SchemaFactory;
|
49
|
+
import javax.xml.validation.Validator;
|
50
|
+
|
51
|
+
import nokogiri.internals.IgnoreSchemaErrorsErrorHandler;
|
52
|
+
import nokogiri.internals.SchemaErrorHandler;
|
53
|
+
import nokogiri.internals.XmlDomParserContext;
|
54
|
+
import nokogiri.internals.ParserContext;
|
55
|
+
import nokogiri.internals.ParserContext.Options;
|
56
|
+
|
57
|
+
import org.jruby.Ruby;
|
58
|
+
import org.jruby.RubyArray;
|
59
|
+
import org.jruby.RubyClass;
|
60
|
+
import org.jruby.RubyFixnum;
|
61
|
+
import org.jruby.RubyObject;
|
62
|
+
import org.jruby.anno.JRubyClass;
|
63
|
+
import org.jruby.anno.JRubyMethod;
|
64
|
+
import org.jruby.exceptions.RaiseException;
|
65
|
+
import org.jruby.runtime.ThreadContext;
|
66
|
+
import org.jruby.runtime.Visibility;
|
67
|
+
import org.jruby.runtime.builtin.IRubyObject;
|
68
|
+
import org.jruby.runtime.Helpers;
|
69
|
+
import org.w3c.dom.Document;
|
70
|
+
import org.w3c.dom.ls.LSInput;
|
71
|
+
import org.w3c.dom.ls.LSResourceResolver;
|
72
|
+
import org.xml.sax.ErrorHandler;
|
73
|
+
import org.xml.sax.SAXException;
|
74
|
+
import org.xml.sax.SAXParseException;
|
75
|
+
|
76
|
+
/**
|
77
|
+
* Class for Nokogiri::XML::Schema
|
78
|
+
*
|
79
|
+
* @author sergio
|
80
|
+
* @author Yoko Harada <yokolet@gmail.com>
|
81
|
+
*/
|
82
|
+
@JRubyClass(name="Nokogiri::XML::Schema")
|
83
|
+
public class XmlSchema extends RubyObject {
|
84
|
+
private Validator validator;
|
85
|
+
|
86
|
+
public XmlSchema(Ruby ruby, RubyClass klazz) {
|
87
|
+
super(ruby, klazz);
|
88
|
+
}
|
89
|
+
|
90
|
+
/**
|
91
|
+
* Create and return a copy of this object.
|
92
|
+
*
|
93
|
+
* @return a clone of this object
|
94
|
+
*/
|
95
|
+
@Override
|
96
|
+
public Object clone() throws CloneNotSupportedException {
|
97
|
+
return super.clone();
|
98
|
+
}
|
99
|
+
|
100
|
+
private Schema getSchema(Source source,
|
101
|
+
String currentDir,
|
102
|
+
String scriptFileName,
|
103
|
+
SchemaErrorHandler errorHandler,
|
104
|
+
long parseOptions) throws SAXException {
|
105
|
+
boolean noNet = new ParserContext.Options(parseOptions).noNet;
|
106
|
+
|
107
|
+
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
|
108
|
+
SchemaResourceResolver resourceResolver =
|
109
|
+
new SchemaResourceResolver(currentDir, scriptFileName, null, errorHandler, noNet);
|
110
|
+
|
111
|
+
schemaFactory.setResourceResolver(resourceResolver);
|
112
|
+
schemaFactory.setErrorHandler(errorHandler);
|
113
|
+
|
114
|
+
return schemaFactory.newSchema(source);
|
115
|
+
}
|
116
|
+
|
117
|
+
private void setValidator(Validator validator) {
|
118
|
+
this.validator = validator;
|
119
|
+
}
|
120
|
+
|
121
|
+
static XmlSchema createSchemaInstance(ThreadContext context, RubyClass klazz, Source source, IRubyObject parseOptions) {
|
122
|
+
Ruby runtime = context.getRuntime();
|
123
|
+
XmlSchema xmlSchema = (XmlSchema) NokogiriService.XML_SCHEMA_ALLOCATOR.allocate(runtime, klazz);
|
124
|
+
|
125
|
+
if (parseOptions == null) {
|
126
|
+
parseOptions = defaultParseOptions(context.getRuntime());
|
127
|
+
}
|
128
|
+
long intParseOptions = RubyFixnum.fix2long(Helpers.invoke(context, parseOptions, "to_i"));
|
129
|
+
|
130
|
+
xmlSchema.setInstanceVariable("@errors", runtime.newEmptyArray());
|
131
|
+
xmlSchema.setInstanceVariable("@parse_options", parseOptions);
|
132
|
+
|
133
|
+
try {
|
134
|
+
SchemaErrorHandler errorHandler =
|
135
|
+
new SchemaErrorHandler(context.getRuntime(), (RubyArray)xmlSchema.getInstanceVariable("@errors"));
|
136
|
+
Schema schema =
|
137
|
+
xmlSchema.getSchema(source,
|
138
|
+
context.getRuntime().getCurrentDirectory(),
|
139
|
+
context.getRuntime().getInstanceConfig().getScriptFileName(),
|
140
|
+
errorHandler,
|
141
|
+
intParseOptions);
|
142
|
+
xmlSchema.setValidator(schema.newValidator());
|
143
|
+
return xmlSchema;
|
144
|
+
} catch (SAXException ex) {
|
145
|
+
throw context.getRuntime().newRuntimeError("Could not parse document: " + ex.getMessage());
|
146
|
+
}
|
147
|
+
}
|
148
|
+
|
149
|
+
protected static IRubyObject defaultParseOptions(Ruby runtime) {
|
150
|
+
return ((RubyClass)runtime.getClassFromPath("Nokogiri::XML::ParseOptions")).getConstant("DEFAULT_SCHEMA");
|
151
|
+
}
|
152
|
+
|
153
|
+
/*
|
154
|
+
* call-seq:
|
155
|
+
* from_document(doc)
|
156
|
+
*
|
157
|
+
* Create a new Schema from the Nokogiri::XML::Document +doc+
|
158
|
+
*/
|
159
|
+
@JRubyMethod(meta=true, required=1, optional=1)
|
160
|
+
public static IRubyObject from_document(ThreadContext context, IRubyObject klazz, IRubyObject[] args) {
|
161
|
+
IRubyObject document = args[0];
|
162
|
+
IRubyObject parseOptions = null;
|
163
|
+
if (args.length > 1) {
|
164
|
+
parseOptions = args[1];
|
165
|
+
}
|
166
|
+
|
167
|
+
XmlDocument doc = ((XmlDocument) ((XmlNode) document).document(context));
|
168
|
+
|
169
|
+
RubyArray errors = (RubyArray) doc.getInstanceVariable("@errors");
|
170
|
+
if (!errors.isEmpty()) {
|
171
|
+
throw ((XmlSyntaxError) errors.first()).toThrowable();
|
172
|
+
}
|
173
|
+
|
174
|
+
DOMSource source = new DOMSource(doc.getDocument());
|
175
|
+
|
176
|
+
IRubyObject uri = doc.url(context);
|
177
|
+
|
178
|
+
if (!uri.isNil()) {
|
179
|
+
source.setSystemId(uri.convertToString().asJavaString());
|
180
|
+
}
|
181
|
+
|
182
|
+
return getSchema(context, (RubyClass)klazz, source, parseOptions);
|
183
|
+
}
|
184
|
+
|
185
|
+
@JRubyMethod(meta=true, required=1, optional=1)
|
186
|
+
public static IRubyObject read_memory(ThreadContext context, IRubyObject klazz, IRubyObject[] args) {
|
187
|
+
IRubyObject content = args[0];
|
188
|
+
IRubyObject parseOptions = null;
|
189
|
+
if (args.length > 1) {
|
190
|
+
parseOptions = args[1];
|
191
|
+
}
|
192
|
+
String data = content.convertToString().asJavaString();
|
193
|
+
return getSchema(context, (RubyClass) klazz, new StreamSource(new StringReader(data)), parseOptions);
|
194
|
+
}
|
195
|
+
|
196
|
+
private static IRubyObject getSchema(ThreadContext context, RubyClass klazz, Source source, IRubyObject parseOptions) {
|
197
|
+
String moduleName = klazz.getName();
|
198
|
+
if ("Nokogiri::XML::Schema".equals(moduleName)) {
|
199
|
+
return XmlSchema.createSchemaInstance(context, klazz, source, parseOptions);
|
200
|
+
} else if ("Nokogiri::XML::RelaxNG".equals(moduleName)) {
|
201
|
+
return XmlRelaxng.createSchemaInstance(context, klazz, source, parseOptions);
|
202
|
+
}
|
203
|
+
return context.getRuntime().getNil();
|
204
|
+
}
|
205
|
+
|
206
|
+
@JRubyMethod(visibility=Visibility.PRIVATE)
|
207
|
+
public IRubyObject validate_document(ThreadContext context, IRubyObject document) {
|
208
|
+
return validate_document_or_file(context, (XmlDocument)document);
|
209
|
+
}
|
210
|
+
|
211
|
+
@JRubyMethod(visibility=Visibility.PRIVATE)
|
212
|
+
public IRubyObject validate_file(ThreadContext context, IRubyObject file) {
|
213
|
+
Ruby runtime = context.runtime;
|
214
|
+
|
215
|
+
XmlDomParserContext ctx = new XmlDomParserContext(runtime, RubyFixnum.newFixnum(runtime, 1L));
|
216
|
+
ctx.setInputSourceFile(context, file);
|
217
|
+
XmlDocument xmlDocument = ctx.parse(context, getNokogiriClass(runtime, "Nokogiri::XML::Document"), context.nil);
|
218
|
+
return validate_document_or_file(context, xmlDocument);
|
219
|
+
}
|
220
|
+
|
221
|
+
IRubyObject validate_document_or_file(ThreadContext context, XmlDocument xmlDocument) {
|
222
|
+
RubyArray errors = (RubyArray) this.getInstanceVariable("@errors");
|
223
|
+
ErrorHandler errorHandler = new SchemaErrorHandler(context.runtime, errors);
|
224
|
+
setErrorHandler(errorHandler);
|
225
|
+
|
226
|
+
try {
|
227
|
+
validate(xmlDocument.getDocument());
|
228
|
+
}
|
229
|
+
catch (SAXException ex) {
|
230
|
+
XmlSyntaxError xmlSyntaxError = XmlSyntaxError.createXMLSyntaxError(context.runtime);
|
231
|
+
xmlSyntaxError.setException(ex);
|
232
|
+
errors.append(xmlSyntaxError);
|
233
|
+
}
|
234
|
+
catch (IOException ex) {
|
235
|
+
throw context.runtime.newIOError(ex.getMessage());
|
236
|
+
}
|
237
|
+
|
238
|
+
return errors;
|
239
|
+
}
|
240
|
+
|
241
|
+
protected void setErrorHandler(ErrorHandler errorHandler) {
|
242
|
+
validator.setErrorHandler(errorHandler);
|
243
|
+
}
|
244
|
+
|
245
|
+
protected void validate(Document document) throws SAXException, IOException {
|
246
|
+
DOMSource docSource = new DOMSource(document);
|
247
|
+
validator.validate(docSource);
|
248
|
+
}
|
249
|
+
|
250
|
+
private class SchemaResourceResolver implements LSResourceResolver {
|
251
|
+
SchemaLSInput lsInput = new SchemaLSInput();
|
252
|
+
String currentDir;
|
253
|
+
String scriptFileName;
|
254
|
+
SchemaErrorHandler errorHandler;
|
255
|
+
boolean noNet;
|
256
|
+
//String defaultURI;
|
257
|
+
|
258
|
+
SchemaResourceResolver(String currentDir, String scriptFileName, Object input, SchemaErrorHandler errorHandler, boolean noNet) {
|
259
|
+
this.currentDir = currentDir;
|
260
|
+
this.scriptFileName = scriptFileName;
|
261
|
+
this.errorHandler = errorHandler;
|
262
|
+
this.noNet = noNet;
|
263
|
+
if (input == null) return;
|
264
|
+
if (input instanceof String) {
|
265
|
+
lsInput.setStringData((String)input);
|
266
|
+
} else if (input instanceof Reader) {
|
267
|
+
lsInput.setCharacterStream((Reader)input);
|
268
|
+
} else if (input instanceof InputStream) {
|
269
|
+
lsInput.setByteStream((InputStream)input);
|
270
|
+
}
|
271
|
+
}
|
272
|
+
|
273
|
+
@Override
|
274
|
+
public LSInput resolveResource(String type,
|
275
|
+
String namespaceURI,
|
276
|
+
String publicId,
|
277
|
+
String systemId,
|
278
|
+
String baseURI) {
|
279
|
+
if (noNet && (systemId.startsWith("http://") || systemId.startsWith("ftp://"))) {
|
280
|
+
if (systemId.startsWith(XMLConstants.W3C_XML_SCHEMA_NS_URI)) {
|
281
|
+
return null; // use default resolver
|
282
|
+
}
|
283
|
+
try {
|
284
|
+
this.errorHandler.warning(new SAXParseException(String.format("Attempt to load network entity '%s'", systemId), null));
|
285
|
+
} catch (SAXException ex) {
|
286
|
+
}
|
287
|
+
} else {
|
288
|
+
String adjusted = adjustSystemIdIfNecessary(currentDir, scriptFileName, baseURI, systemId);
|
289
|
+
lsInput.setPublicId(publicId);
|
290
|
+
lsInput.setSystemId(adjusted != null? adjusted : systemId);
|
291
|
+
lsInput.setBaseURI(baseURI);
|
292
|
+
}
|
293
|
+
return lsInput;
|
294
|
+
}
|
295
|
+
}
|
296
|
+
|
297
|
+
private class SchemaLSInput implements LSInput {
|
298
|
+
protected String fPublicId;
|
299
|
+
protected String fSystemId;
|
300
|
+
protected String fBaseSystemId;
|
301
|
+
protected InputStream fByteStream;
|
302
|
+
protected Reader fCharStream;
|
303
|
+
protected String fData;
|
304
|
+
protected String fEncoding;
|
305
|
+
protected boolean fCertifiedText = false;
|
306
|
+
|
307
|
+
@Override
|
308
|
+
public String getBaseURI() {
|
309
|
+
return fBaseSystemId;
|
310
|
+
}
|
311
|
+
|
312
|
+
@Override
|
313
|
+
public InputStream getByteStream() {
|
314
|
+
return fByteStream;
|
315
|
+
}
|
316
|
+
|
317
|
+
@Override
|
318
|
+
public boolean getCertifiedText() {
|
319
|
+
return fCertifiedText;
|
320
|
+
}
|
321
|
+
|
322
|
+
@Override
|
323
|
+
public Reader getCharacterStream() {
|
324
|
+
return fCharStream;
|
325
|
+
}
|
326
|
+
|
327
|
+
@Override
|
328
|
+
public String getEncoding() {
|
329
|
+
return fEncoding;
|
330
|
+
}
|
331
|
+
|
332
|
+
@Override
|
333
|
+
public String getPublicId() {
|
334
|
+
return fPublicId;
|
335
|
+
}
|
336
|
+
|
337
|
+
@Override
|
338
|
+
public String getStringData() {
|
339
|
+
return fData;
|
340
|
+
}
|
341
|
+
|
342
|
+
@Override
|
343
|
+
public String getSystemId() {
|
344
|
+
return fSystemId;
|
345
|
+
}
|
346
|
+
|
347
|
+
@Override
|
348
|
+
public void setBaseURI(String baseURI) {
|
349
|
+
fBaseSystemId = baseURI;
|
350
|
+
}
|
351
|
+
|
352
|
+
@Override
|
353
|
+
public void setByteStream(InputStream byteStream) {
|
354
|
+
fByteStream = byteStream;
|
355
|
+
}
|
356
|
+
|
357
|
+
@Override
|
358
|
+
public void setCertifiedText(boolean certified) {
|
359
|
+
fCertifiedText = certified;
|
360
|
+
}
|
361
|
+
|
362
|
+
@Override
|
363
|
+
public void setCharacterStream(Reader charStream) {
|
364
|
+
fCharStream = charStream;
|
365
|
+
}
|
366
|
+
|
367
|
+
@Override
|
368
|
+
public void setEncoding(String encoding) {
|
369
|
+
fEncoding = encoding;
|
370
|
+
}
|
371
|
+
|
372
|
+
@Override
|
373
|
+
public void setPublicId(String pubId) {
|
374
|
+
fPublicId = pubId;
|
375
|
+
}
|
376
|
+
|
377
|
+
@Override
|
378
|
+
public void setStringData(String stringData) {
|
379
|
+
fData = stringData;
|
380
|
+
}
|
381
|
+
|
382
|
+
@Override
|
383
|
+
public void setSystemId(String sysId) {
|
384
|
+
fSystemId = sysId;
|
385
|
+
}
|
386
|
+
|
387
|
+
}
|
388
|
+
}
|
@@ -0,0 +1,138 @@
|
|
1
|
+
/**
|
2
|
+
* (The MIT License)
|
3
|
+
*
|
4
|
+
* Copyright (c) 2008 - 2012:
|
5
|
+
*
|
6
|
+
* * {Aaron Patterson}[http://tenderlovemaking.com]
|
7
|
+
* * {Mike Dalessio}[http://mike.daless.io]
|
8
|
+
* * {Charles Nutter}[http://blog.headius.com]
|
9
|
+
* * {Sergio Arbeo}[http://www.serabe.com]
|
10
|
+
* * {Patrick Mahoney}[http://polycrystal.org]
|
11
|
+
* * {Yoko Harada}[http://yokolet.blogspot.com]
|
12
|
+
*
|
13
|
+
* Permission is hereby granted, free of charge, to any person obtaining
|
14
|
+
* a copy of this software and associated documentation files (the
|
15
|
+
* 'Software'), to deal in the Software without restriction, including
|
16
|
+
* without limitation the rights to use, copy, modify, merge, publish,
|
17
|
+
* distribute, sublicense, and/or sell copies of the Software, and to
|
18
|
+
* permit persons to whom the Software is furnished to do so, subject to
|
19
|
+
* the following conditions:
|
20
|
+
*
|
21
|
+
* The above copyright notice and this permission notice shall be
|
22
|
+
* included in all copies or substantial portions of the Software.
|
23
|
+
*
|
24
|
+
* THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
25
|
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
26
|
+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
27
|
+
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
28
|
+
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
29
|
+
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
30
|
+
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
31
|
+
*/
|
32
|
+
|
33
|
+
package nokogiri;
|
34
|
+
|
35
|
+
import static nokogiri.internals.NokogiriHelpers.stringOrNil;
|
36
|
+
|
37
|
+
import org.jruby.Ruby;
|
38
|
+
import org.jruby.RubyClass;
|
39
|
+
import org.jruby.RubyException;
|
40
|
+
import org.jruby.RubyString;
|
41
|
+
import org.jruby.anno.JRubyClass;
|
42
|
+
import org.jruby.anno.JRubyMethod;
|
43
|
+
import org.jruby.runtime.ThreadContext;
|
44
|
+
import org.jruby.runtime.builtin.IRubyObject;
|
45
|
+
import org.xml.sax.SAXParseException;
|
46
|
+
|
47
|
+
/**
|
48
|
+
* Class for Nokogiri::XML::SyntaxError
|
49
|
+
*
|
50
|
+
* @author sergio
|
51
|
+
* @author Yoko Harada <yokolet@gmail.com>
|
52
|
+
*/
|
53
|
+
@JRubyClass(name="Nokogiri::XML::SyntaxError", parent="Nokogiri::SyntaxError")
|
54
|
+
public class XmlSyntaxError extends RubyException {
|
55
|
+
|
56
|
+
private Exception exception;
|
57
|
+
private boolean messageSet; // whether a custom error message was set
|
58
|
+
|
59
|
+
public XmlSyntaxError(Ruby runtime, RubyClass klazz) {
|
60
|
+
super(runtime, klazz);
|
61
|
+
}
|
62
|
+
|
63
|
+
public XmlSyntaxError(Ruby runtime, RubyClass rubyClass, Exception ex) {
|
64
|
+
super(runtime, rubyClass, ex.getMessage());
|
65
|
+
this.exception = ex;
|
66
|
+
}
|
67
|
+
|
68
|
+
public XmlSyntaxError(Ruby runtime, RubyClass rubyClass, String message, Exception ex) {
|
69
|
+
super(runtime, rubyClass, message);
|
70
|
+
this.exception = ex; this.messageSet = true;
|
71
|
+
}
|
72
|
+
|
73
|
+
public static XmlSyntaxError createXMLSyntaxError(final Ruby runtime) {
|
74
|
+
RubyClass klazz = (RubyClass) runtime.getClassFromPath("Nokogiri::XML::SyntaxError");
|
75
|
+
return new XmlSyntaxError(runtime, klazz);
|
76
|
+
}
|
77
|
+
|
78
|
+
public static XmlSyntaxError createXMLSyntaxError(final Ruby runtime, final Exception ex) {
|
79
|
+
RubyClass klazz = (RubyClass) runtime.getClassFromPath("Nokogiri::XML::SyntaxError");
|
80
|
+
return new XmlSyntaxError(runtime, klazz, ex);
|
81
|
+
}
|
82
|
+
|
83
|
+
public static XmlSyntaxError createHTMLSyntaxError(final Ruby runtime) {
|
84
|
+
RubyClass klazz = (RubyClass) runtime.getClassFromPath("Nokogiri::HTML::SyntaxError");
|
85
|
+
return new XmlSyntaxError(runtime, klazz);
|
86
|
+
}
|
87
|
+
|
88
|
+
public static RubyException createXMLXPathSyntaxError(final Ruby runtime, final String msg, final Exception ex) {
|
89
|
+
RubyClass klazz = (RubyClass) runtime.getClassFromPath("Nokogiri::XML::XPath::SyntaxError");
|
90
|
+
return new XmlSyntaxError(runtime, klazz, msg, ex);
|
91
|
+
}
|
92
|
+
|
93
|
+
public static XmlSyntaxError createWarning(Ruby runtime, SAXParseException e) {
|
94
|
+
XmlSyntaxError xmlSyntaxError = createXMLSyntaxError(runtime);
|
95
|
+
xmlSyntaxError.setException(runtime, e, 1);
|
96
|
+
return xmlSyntaxError;
|
97
|
+
}
|
98
|
+
|
99
|
+
public static XmlSyntaxError createError(Ruby runtime, SAXParseException e) {
|
100
|
+
XmlSyntaxError xmlSyntaxError = createXMLSyntaxError(runtime);
|
101
|
+
xmlSyntaxError.setException(runtime, e, 2);
|
102
|
+
return xmlSyntaxError;
|
103
|
+
}
|
104
|
+
|
105
|
+
public static XmlSyntaxError createFatalError(Ruby runtime, SAXParseException e) {
|
106
|
+
XmlSyntaxError xmlSyntaxError = createXMLSyntaxError(runtime);
|
107
|
+
xmlSyntaxError.setException(runtime, e, 3);
|
108
|
+
return xmlSyntaxError;
|
109
|
+
}
|
110
|
+
|
111
|
+
public void setException(Exception exception) {
|
112
|
+
this.exception = exception;
|
113
|
+
}
|
114
|
+
|
115
|
+
public void setException(Ruby runtime, SAXParseException exception, int level) {
|
116
|
+
this.exception = exception;
|
117
|
+
setInstanceVariable("@level", runtime.newFixnum(level));
|
118
|
+
setInstanceVariable("@line", runtime.newFixnum(exception.getLineNumber()));
|
119
|
+
setInstanceVariable("@column", runtime.newFixnum(exception.getColumnNumber()));
|
120
|
+
setInstanceVariable("@file", stringOrNil(runtime, exception.getSystemId()));
|
121
|
+
}
|
122
|
+
|
123
|
+
@JRubyMethod(name = "to_s")
|
124
|
+
@Override
|
125
|
+
public IRubyObject to_s(ThreadContext context) {
|
126
|
+
RubyString msg = msg(context.runtime);
|
127
|
+
return msg != null ? msg : super.to_s(context).asString();
|
128
|
+
}
|
129
|
+
|
130
|
+
private RubyString msg(final Ruby runtime) {
|
131
|
+
if (exception != null && exception.getMessage() != null) {
|
132
|
+
if (messageSet) return null;
|
133
|
+
return runtime.newString( exception.getMessage() );
|
134
|
+
}
|
135
|
+
return null;
|
136
|
+
}
|
137
|
+
|
138
|
+
}
|
@@ -0,0 +1,110 @@
|
|
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.getCachedNodeOrCreate;
|
36
|
+
import static nokogiri.internals.NokogiriHelpers.rubyStringToString;
|
37
|
+
import nokogiri.internals.SaveContextVisitor;
|
38
|
+
|
39
|
+
import org.jcodings.specific.USASCIIEncoding;
|
40
|
+
import org.jruby.Ruby;
|
41
|
+
import org.jruby.RubyClass;
|
42
|
+
import org.jruby.RubyString;
|
43
|
+
import org.jruby.anno.JRubyClass;
|
44
|
+
import org.jruby.runtime.ThreadContext;
|
45
|
+
import org.jruby.runtime.builtin.IRubyObject;
|
46
|
+
import org.jruby.util.ByteList;
|
47
|
+
import org.w3c.dom.Document;
|
48
|
+
import org.w3c.dom.Node;
|
49
|
+
import org.w3c.dom.Text;
|
50
|
+
|
51
|
+
/**
|
52
|
+
* Class for Nokogiri::XML::Text
|
53
|
+
*
|
54
|
+
* @author sergio
|
55
|
+
* @author Yoko Harada <yokolet@gmail.com>
|
56
|
+
*/
|
57
|
+
@JRubyClass(name="Nokogiri::XML::Text", parent="Nokogiri::XML::CharacterData")
|
58
|
+
public class XmlText extends XmlNode {
|
59
|
+
|
60
|
+
private static final ByteList TEXT = ByteList.create("text");
|
61
|
+
static { TEXT.setEncoding(USASCIIEncoding.INSTANCE); }
|
62
|
+
|
63
|
+
public XmlText(Ruby runtime, RubyClass rubyClass, Node node) {
|
64
|
+
super(runtime, rubyClass, node);
|
65
|
+
}
|
66
|
+
|
67
|
+
public XmlText(Ruby runtime, RubyClass klass) {
|
68
|
+
super(runtime, klass);
|
69
|
+
}
|
70
|
+
|
71
|
+
@Override
|
72
|
+
protected void init(ThreadContext context, IRubyObject[] args) {
|
73
|
+
if (args.length < 2) {
|
74
|
+
throw context.runtime.newArgumentError(args.length, 2);
|
75
|
+
}
|
76
|
+
|
77
|
+
content = args[0];
|
78
|
+
IRubyObject xNode = args[1];
|
79
|
+
|
80
|
+
Document document = asXmlNode(context, xNode).getOwnerDocument();
|
81
|
+
// text node content should not be encoded when it is created by Text node.
|
82
|
+
// while content should be encoded when it is created by Element node.
|
83
|
+
Node node = document.createTextNode(rubyStringToString(content));
|
84
|
+
setNode(context.runtime, node);
|
85
|
+
}
|
86
|
+
|
87
|
+
@Override
|
88
|
+
protected IRubyObject getNodeName(ThreadContext context) {
|
89
|
+
if (name == null) name = RubyString.newStringShared(context.runtime, TEXT);
|
90
|
+
return name;
|
91
|
+
}
|
92
|
+
|
93
|
+
@Override
|
94
|
+
public void accept(ThreadContext context, SaveContextVisitor visitor) {
|
95
|
+
visitor.enter((Text) node);
|
96
|
+
Node child = node.getFirstChild();
|
97
|
+
while (child != null) {
|
98
|
+
IRubyObject nokoNode = getCachedNodeOrCreate(context.runtime, child);
|
99
|
+
if (nokoNode instanceof XmlNode) {
|
100
|
+
XmlNode cur = (XmlNode) nokoNode;
|
101
|
+
cur.accept(context, visitor);
|
102
|
+
} else if (nokoNode instanceof XmlNamespace) {
|
103
|
+
XmlNamespace cur = (XmlNamespace) nokoNode;
|
104
|
+
cur.accept(context, visitor);
|
105
|
+
}
|
106
|
+
child = child.getNextSibling();
|
107
|
+
}
|
108
|
+
visitor.leave(node);
|
109
|
+
}
|
110
|
+
}
|