nokogiri-maven 1.5.0-java
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.ja.rdoc +544 -0
- data/CHANGELOG.rdoc +532 -0
- data/Manifest.txt +283 -0
- data/README.ja.rdoc +106 -0
- data/README.rdoc +174 -0
- data/Rakefile +164 -0
- data/bin/nokogiri +53 -0
- data/ext/java/nokogiri/EncodingHandler.java +124 -0
- data/ext/java/nokogiri/HtmlDocument.java +119 -0
- data/ext/java/nokogiri/HtmlElementDescription.java +145 -0
- data/ext/java/nokogiri/HtmlEntityLookup.java +79 -0
- data/ext/java/nokogiri/HtmlSaxParserContext.java +259 -0
- data/ext/java/nokogiri/NokogiriService.java +590 -0
- data/ext/java/nokogiri/XmlAttr.java +180 -0
- data/ext/java/nokogiri/XmlAttributeDecl.java +130 -0
- data/ext/java/nokogiri/XmlCdata.java +84 -0
- data/ext/java/nokogiri/XmlComment.java +86 -0
- data/ext/java/nokogiri/XmlDocument.java +519 -0
- data/ext/java/nokogiri/XmlDocumentFragment.java +223 -0
- data/ext/java/nokogiri/XmlDtd.java +469 -0
- data/ext/java/nokogiri/XmlElement.java +195 -0
- data/ext/java/nokogiri/XmlElementContent.java +382 -0
- data/ext/java/nokogiri/XmlElementDecl.java +152 -0
- data/ext/java/nokogiri/XmlEntityDecl.java +162 -0
- data/ext/java/nokogiri/XmlEntityReference.java +97 -0
- data/ext/java/nokogiri/XmlNamespace.java +183 -0
- data/ext/java/nokogiri/XmlNode.java +1378 -0
- data/ext/java/nokogiri/XmlNodeSet.java +267 -0
- data/ext/java/nokogiri/XmlProcessingInstruction.java +99 -0
- data/ext/java/nokogiri/XmlReader.java +408 -0
- data/ext/java/nokogiri/XmlRelaxng.java +144 -0
- data/ext/java/nokogiri/XmlSaxParserContext.java +367 -0
- data/ext/java/nokogiri/XmlSaxPushParser.java +184 -0
- data/ext/java/nokogiri/XmlSchema.java +324 -0
- data/ext/java/nokogiri/XmlSyntaxError.java +119 -0
- data/ext/java/nokogiri/XmlText.java +119 -0
- data/ext/java/nokogiri/XmlXpathContext.java +199 -0
- data/ext/java/nokogiri/XsltStylesheet.java +197 -0
- data/ext/java/nokogiri/internals/HtmlDomParserContext.java +204 -0
- data/ext/java/nokogiri/internals/NokogiriDocumentCache.java +73 -0
- data/ext/java/nokogiri/internals/NokogiriErrorHandler.java +86 -0
- data/ext/java/nokogiri/internals/NokogiriHandler.java +327 -0
- data/ext/java/nokogiri/internals/NokogiriHelpers.java +639 -0
- data/ext/java/nokogiri/internals/NokogiriNamespaceCache.java +167 -0
- data/ext/java/nokogiri/internals/NokogiriNamespaceContext.java +130 -0
- data/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler.java +74 -0
- data/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler4NekoHtml.java +121 -0
- data/ext/java/nokogiri/internals/NokogiriStrictErrorHandler.java +79 -0
- data/ext/java/nokogiri/internals/NokogiriXPathFunction.java +141 -0
- data/ext/java/nokogiri/internals/NokogiriXPathFunctionResolver.java +73 -0
- data/ext/java/nokogiri/internals/NokogiriXPathVariableResolver.java +67 -0
- data/ext/java/nokogiri/internals/NokogiriXsltErrorListener.java +86 -0
- data/ext/java/nokogiri/internals/ParserContext.java +276 -0
- data/ext/java/nokogiri/internals/PushInputStream.java +411 -0
- data/ext/java/nokogiri/internals/ReaderNode.java +531 -0
- data/ext/java/nokogiri/internals/SaveContextVisitor.java +567 -0
- data/ext/java/nokogiri/internals/SchemaErrorHandler.java +76 -0
- data/ext/java/nokogiri/internals/XmlDeclHandler.java +42 -0
- data/ext/java/nokogiri/internals/XmlDomParser.java +76 -0
- data/ext/java/nokogiri/internals/XmlDomParserContext.java +244 -0
- data/ext/java/nokogiri/internals/XmlSaxParser.java +65 -0
- data/ext/java/nokogiri/internals/XsltExtensionFunction.java +72 -0
- data/ext/nokogiri/depend +358 -0
- data/ext/nokogiri/extconf.rb +124 -0
- data/ext/nokogiri/html_document.c +154 -0
- data/ext/nokogiri/html_document.h +10 -0
- data/ext/nokogiri/html_element_description.c +276 -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 +94 -0
- data/ext/nokogiri/html_sax_parser_context.h +11 -0
- data/ext/nokogiri/nokogiri.c +115 -0
- data/ext/nokogiri/nokogiri.h +160 -0
- data/ext/nokogiri/xml_attr.c +94 -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 +56 -0
- data/ext/nokogiri/xml_cdata.h +9 -0
- data/ext/nokogiri/xml_comment.c +54 -0
- data/ext/nokogiri/xml_comment.h +9 -0
- data/ext/nokogiri/xml_document.c +478 -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 +56 -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 +84 -0
- data/ext/nokogiri/xml_namespace.h +13 -0
- data/ext/nokogiri/xml_node.c +1385 -0
- data/ext/nokogiri/xml_node.h +13 -0
- data/ext/nokogiri/xml_node_set.c +418 -0
- data/ext/nokogiri/xml_node_set.h +9 -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 +684 -0
- data/ext/nokogiri/xml_reader.h +10 -0
- data/ext/nokogiri/xml_relax_ng.c +161 -0
- data/ext/nokogiri/xml_relax_ng.h +9 -0
- data/ext/nokogiri/xml_sax_parser.c +293 -0
- data/ext/nokogiri/xml_sax_parser.h +39 -0
- data/ext/nokogiri/xml_sax_parser_context.c +199 -0
- data/ext/nokogiri/xml_sax_parser_context.h +10 -0
- data/ext/nokogiri/xml_sax_push_parser.c +115 -0
- data/ext/nokogiri/xml_sax_push_parser.h +9 -0
- data/ext/nokogiri/xml_schema.c +205 -0
- data/ext/nokogiri/xml_schema.h +9 -0
- data/ext/nokogiri/xml_syntax_error.c +58 -0
- data/ext/nokogiri/xml_syntax_error.h +13 -0
- data/ext/nokogiri/xml_text.c +50 -0
- data/ext/nokogiri/xml_text.h +9 -0
- data/ext/nokogiri/xml_xpath_context.c +309 -0
- data/ext/nokogiri/xml_xpath_context.h +9 -0
- data/ext/nokogiri/xslt_stylesheet.c +264 -0
- data/ext/nokogiri/xslt_stylesheet.h +9 -0
- data/lib/nokogiri.rb +127 -0
- data/lib/nokogiri/css.rb +27 -0
- data/lib/nokogiri/css/node.rb +99 -0
- data/lib/nokogiri/css/parser.rb +677 -0
- data/lib/nokogiri/css/parser.y +237 -0
- data/lib/nokogiri/css/parser_extras.rb +91 -0
- data/lib/nokogiri/css/syntax_error.rb +7 -0
- data/lib/nokogiri/css/tokenizer.rb +152 -0
- data/lib/nokogiri/css/tokenizer.rex +55 -0
- data/lib/nokogiri/css/xpath_visitor.rb +171 -0
- data/lib/nokogiri/decorators/slop.rb +35 -0
- data/lib/nokogiri/html.rb +36 -0
- data/lib/nokogiri/html/builder.rb +35 -0
- data/lib/nokogiri/html/document.rb +213 -0
- data/lib/nokogiri/html/document_fragment.rb +41 -0
- data/lib/nokogiri/html/element_description.rb +23 -0
- data/lib/nokogiri/html/element_description_defaults.rb +671 -0
- data/lib/nokogiri/html/entity_lookup.rb +13 -0
- data/lib/nokogiri/html/sax/parser.rb +52 -0
- data/lib/nokogiri/html/sax/parser_context.rb +16 -0
- data/lib/nokogiri/nokogiri.jar +0 -0
- data/lib/nokogiri/syntax_error.rb +4 -0
- data/lib/nokogiri/version.rb +88 -0
- data/lib/nokogiri/xml.rb +67 -0
- data/lib/nokogiri/xml/attr.rb +14 -0
- data/lib/nokogiri/xml/attribute_decl.rb +18 -0
- data/lib/nokogiri/xml/builder.rb +425 -0
- data/lib/nokogiri/xml/cdata.rb +11 -0
- data/lib/nokogiri/xml/character_data.rb +7 -0
- data/lib/nokogiri/xml/document.rb +234 -0
- data/lib/nokogiri/xml/document_fragment.rb +98 -0
- data/lib/nokogiri/xml/dtd.rb +22 -0
- data/lib/nokogiri/xml/element_content.rb +36 -0
- data/lib/nokogiri/xml/element_decl.rb +13 -0
- data/lib/nokogiri/xml/entity_decl.rb +19 -0
- data/lib/nokogiri/xml/namespace.rb +13 -0
- data/lib/nokogiri/xml/node.rb +915 -0
- data/lib/nokogiri/xml/node/save_options.rb +61 -0
- data/lib/nokogiri/xml/node_set.rb +357 -0
- data/lib/nokogiri/xml/notation.rb +6 -0
- data/lib/nokogiri/xml/parse_options.rb +93 -0
- data/lib/nokogiri/xml/pp.rb +2 -0
- data/lib/nokogiri/xml/pp/character_data.rb +18 -0
- data/lib/nokogiri/xml/pp/node.rb +56 -0
- data/lib/nokogiri/xml/processing_instruction.rb +8 -0
- data/lib/nokogiri/xml/reader.rb +112 -0
- data/lib/nokogiri/xml/relax_ng.rb +32 -0
- data/lib/nokogiri/xml/sax.rb +4 -0
- data/lib/nokogiri/xml/sax/document.rb +164 -0
- data/lib/nokogiri/xml/sax/parser.rb +115 -0
- data/lib/nokogiri/xml/sax/parser_context.rb +16 -0
- data/lib/nokogiri/xml/sax/push_parser.rb +60 -0
- data/lib/nokogiri/xml/schema.rb +63 -0
- data/lib/nokogiri/xml/syntax_error.rb +47 -0
- data/lib/nokogiri/xml/text.rb +9 -0
- data/lib/nokogiri/xml/xpath.rb +10 -0
- data/lib/nokogiri/xml/xpath/syntax_error.rb +11 -0
- data/lib/nokogiri/xml/xpath_context.rb +16 -0
- data/lib/nokogiri/xslt.rb +52 -0
- data/lib/nokogiri/xslt/stylesheet.rb +25 -0
- data/lib/xsd/xmlparser/nokogiri.rb +90 -0
- data/nokogiri_help_responses.md +40 -0
- data/tasks/cross_compile.rb +152 -0
- data/tasks/nokogiri.org.rb +18 -0
- data/tasks/test.rb +94 -0
- data/test/css/test_nthiness.rb +159 -0
- data/test/css/test_parser.rb +303 -0
- data/test/css/test_tokenizer.rb +198 -0
- data/test/css/test_xpath_visitor.rb +85 -0
- data/test/decorators/test_slop.rb +16 -0
- data/test/files/2ch.html +108 -0
- data/test/files/address_book.rlx +12 -0
- data/test/files/address_book.xml +10 -0
- data/test/files/bar/bar.xsd +4 -0
- data/test/files/dont_hurt_em_why.xml +422 -0
- data/test/files/encoding.html +82 -0
- data/test/files/encoding.xhtml +84 -0
- data/test/files/exslt.xml +8 -0
- data/test/files/exslt.xslt +35 -0
- data/test/files/foo/foo.xsd +4 -0
- data/test/files/metacharset.html +10 -0
- data/test/files/noencoding.html +47 -0
- data/test/files/po.xml +32 -0
- data/test/files/po.xsd +66 -0
- data/test/files/shift_jis.html +10 -0
- data/test/files/shift_jis.xml +5 -0
- data/test/files/snuggles.xml +3 -0
- data/test/files/staff.dtd +10 -0
- data/test/files/staff.xml +59 -0
- data/test/files/staff.xslt +32 -0
- data/test/files/tlm.html +850 -0
- data/test/files/valid_bar.xml +2 -0
- data/test/helper.rb +173 -0
- data/test/html/sax/test_parser.rb +136 -0
- data/test/html/sax/test_parser_context.rb +48 -0
- data/test/html/test_builder.rb +164 -0
- data/test/html/test_document.rb +472 -0
- data/test/html/test_document_encoding.rb +138 -0
- data/test/html/test_document_fragment.rb +255 -0
- data/test/html/test_element_description.rb +100 -0
- data/test/html/test_named_characters.rb +14 -0
- data/test/html/test_node.rb +190 -0
- data/test/html/test_node_encoding.rb +27 -0
- data/test/test_convert_xpath.rb +135 -0
- data/test/test_css_cache.rb +45 -0
- data/test/test_encoding_handler.rb +46 -0
- data/test/test_memory_leak.rb +72 -0
- data/test/test_nokogiri.rb +132 -0
- data/test/test_reader.rb +425 -0
- data/test/test_soap4r_sax.rb +52 -0
- data/test/test_xslt_transforms.rb +193 -0
- data/test/xml/node/test_save_options.rb +28 -0
- data/test/xml/node/test_subclass.rb +44 -0
- data/test/xml/sax/test_parser.rb +338 -0
- data/test/xml/sax/test_parser_context.rb +113 -0
- data/test/xml/sax/test_push_parser.rb +156 -0
- data/test/xml/test_attr.rb +65 -0
- data/test/xml/test_attribute_decl.rb +86 -0
- data/test/xml/test_builder.rb +227 -0
- data/test/xml/test_cdata.rb +50 -0
- data/test/xml/test_comment.rb +29 -0
- data/test/xml/test_document.rb +697 -0
- data/test/xml/test_document_encoding.rb +26 -0
- data/test/xml/test_document_fragment.rb +192 -0
- data/test/xml/test_dtd.rb +107 -0
- data/test/xml/test_dtd_encoding.rb +33 -0
- data/test/xml/test_element_content.rb +56 -0
- data/test/xml/test_element_decl.rb +73 -0
- data/test/xml/test_entity_decl.rb +122 -0
- data/test/xml/test_entity_reference.rb +21 -0
- data/test/xml/test_namespace.rb +70 -0
- data/test/xml/test_node.rb +917 -0
- data/test/xml/test_node_attributes.rb +34 -0
- data/test/xml/test_node_encoding.rb +107 -0
- data/test/xml/test_node_reparenting.rb +334 -0
- data/test/xml/test_node_set.rb +742 -0
- data/test/xml/test_parse_options.rb +52 -0
- data/test/xml/test_processing_instruction.rb +30 -0
- data/test/xml/test_reader_encoding.rb +126 -0
- data/test/xml/test_relax_ng.rb +60 -0
- data/test/xml/test_schema.rb +94 -0
- data/test/xml/test_syntax_error.rb +12 -0
- data/test/xml/test_text.rb +47 -0
- data/test/xml/test_unparented_node.rb +381 -0
- data/test/xml/test_xpath.rb +237 -0
- data/test/xslt/test_custom_functions.rb +94 -0
- data/test/xslt/test_exception_handling.rb +37 -0
- metadata +552 -0
@@ -0,0 +1,119 @@
|
|
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.stringOrNil;
|
37
|
+
|
38
|
+
import org.jruby.Ruby;
|
39
|
+
import org.jruby.RubyClass;
|
40
|
+
import org.jruby.RubyException;
|
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
|
+
private Exception exception;
|
56
|
+
|
57
|
+
public XmlSyntaxError(Ruby runtime, RubyClass klazz) {
|
58
|
+
super(runtime, klazz);
|
59
|
+
}
|
60
|
+
|
61
|
+
/**
|
62
|
+
* Create and return a copy of this object.
|
63
|
+
*
|
64
|
+
* @return a clone of this object
|
65
|
+
*/
|
66
|
+
@Override
|
67
|
+
public Object clone() throws CloneNotSupportedException {
|
68
|
+
return super.clone();
|
69
|
+
}
|
70
|
+
|
71
|
+
public XmlSyntaxError(Ruby runtime, RubyClass rubyClass, Exception ex) {
|
72
|
+
super(runtime, rubyClass, ex.getMessage());
|
73
|
+
this.exception = ex;
|
74
|
+
}
|
75
|
+
|
76
|
+
public static XmlSyntaxError createWarning(Ruby runtime, SAXParseException e) {
|
77
|
+
XmlSyntaxError xmlSyntaxError = (XmlSyntaxError) NokogiriService.XML_SYNTAXERROR_ALLOCATOR.allocate(runtime, getNokogiriClass(runtime, "Nokogiri::XML::SyntaxError"));
|
78
|
+
xmlSyntaxError.setException(runtime, e, 1);
|
79
|
+
return xmlSyntaxError;
|
80
|
+
}
|
81
|
+
|
82
|
+
public static XmlSyntaxError createError(Ruby runtime, SAXParseException e) {
|
83
|
+
XmlSyntaxError xmlSyntaxError = (XmlSyntaxError) NokogiriService.XML_SYNTAXERROR_ALLOCATOR.allocate(runtime, getNokogiriClass(runtime, "Nokogiri::XML::SyntaxError"));
|
84
|
+
xmlSyntaxError.setException(runtime, e, 2);
|
85
|
+
return xmlSyntaxError;
|
86
|
+
}
|
87
|
+
|
88
|
+
public static XmlSyntaxError createFatalError(Ruby runtime, SAXParseException e) {
|
89
|
+
XmlSyntaxError xmlSyntaxError = (XmlSyntaxError) NokogiriService.XML_SYNTAXERROR_ALLOCATOR.allocate(runtime, getNokogiriClass(runtime, "Nokogiri::XML::SyntaxError"));
|
90
|
+
xmlSyntaxError.setException(runtime, e, 3);
|
91
|
+
return xmlSyntaxError;
|
92
|
+
}
|
93
|
+
|
94
|
+
public void setException(Exception exception) {
|
95
|
+
this.exception = exception;
|
96
|
+
}
|
97
|
+
|
98
|
+
public void setException(Ruby runtime, Exception exception, int level) {
|
99
|
+
this.exception = exception;
|
100
|
+
setInstanceVariable("@level", runtime.newFixnum(level));
|
101
|
+
setInstanceVariable("@line", runtime.newFixnum(((SAXParseException)exception).getLineNumber()));
|
102
|
+
setInstanceVariable("@column", runtime.newFixnum(((SAXParseException)exception).getColumnNumber()));
|
103
|
+
setInstanceVariable("@file", stringOrNil(runtime, ((SAXParseException)exception).getSystemId()));
|
104
|
+
}
|
105
|
+
|
106
|
+
public static RubyException createXPathSyntaxError(Ruby runtime, Exception e) {
|
107
|
+
RubyClass klazz = (RubyClass)runtime.getClassFromPath("Nokogiri::XML::XPath::SyntaxError");
|
108
|
+
return new XmlSyntaxError(runtime, klazz, e);
|
109
|
+
}
|
110
|
+
|
111
|
+
@Override
|
112
|
+
@JRubyMethod(name = "to_s")
|
113
|
+
public IRubyObject to_s(ThreadContext context) {
|
114
|
+
if (exception != null && exception.getMessage() != null)
|
115
|
+
return context.getRuntime().newString(exception.getMessage());
|
116
|
+
else
|
117
|
+
return super.to_s(context);
|
118
|
+
}
|
119
|
+
}
|
@@ -0,0 +1,119 @@
|
|
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 static nokogiri.internals.NokogiriHelpers.stringOrNil;
|
38
|
+
import nokogiri.internals.SaveContextVisitor;
|
39
|
+
|
40
|
+
import org.jruby.Ruby;
|
41
|
+
import org.jruby.RubyClass;
|
42
|
+
import org.jruby.anno.JRubyClass;
|
43
|
+
import org.jruby.anno.JRubyMethod;
|
44
|
+
import org.jruby.runtime.ThreadContext;
|
45
|
+
import org.jruby.runtime.builtin.IRubyObject;
|
46
|
+
import org.w3c.dom.Document;
|
47
|
+
import org.w3c.dom.Node;
|
48
|
+
import org.w3c.dom.Text;
|
49
|
+
|
50
|
+
/**
|
51
|
+
* Class for Nokogiri::XML::Text
|
52
|
+
*
|
53
|
+
* @author sergio
|
54
|
+
* @author Yoko Harada <yokolet@gmail.com>
|
55
|
+
*/
|
56
|
+
@JRubyClass(name="Nokogiri::XML::Text", parent="Nokogiri::XML::CharacterData")
|
57
|
+
public class XmlText extends XmlNode {
|
58
|
+
|
59
|
+
public XmlText(Ruby runtime, RubyClass rubyClass, Node node) {
|
60
|
+
super(runtime, rubyClass, node);
|
61
|
+
}
|
62
|
+
|
63
|
+
public XmlText(Ruby runtime, RubyClass klass) {
|
64
|
+
super(runtime, klass);
|
65
|
+
}
|
66
|
+
|
67
|
+
@Override
|
68
|
+
protected void init(ThreadContext context, IRubyObject[] args) {
|
69
|
+
if (args.length < 2) {
|
70
|
+
throw getRuntime().newArgumentError(args.length, 2);
|
71
|
+
}
|
72
|
+
|
73
|
+
content = args[0];
|
74
|
+
IRubyObject xNode = args[1];
|
75
|
+
|
76
|
+
XmlNode xmlNode = asXmlNode(context, xNode);
|
77
|
+
XmlDocument xmlDoc = (XmlDocument)xmlNode.document(context);
|
78
|
+
doc = xmlDoc;
|
79
|
+
Document document = xmlDoc.getDocument();
|
80
|
+
// text node content should not be encoded when it is created by Text node.
|
81
|
+
// while content should be encoded when it is created by Element node.
|
82
|
+
Node node = document.createTextNode(rubyStringToString(content));
|
83
|
+
setNode(context, node);
|
84
|
+
}
|
85
|
+
|
86
|
+
@Override
|
87
|
+
protected IRubyObject getNodeName(ThreadContext context) {
|
88
|
+
if (name == null) name = context.getRuntime().newString("text");
|
89
|
+
return name;
|
90
|
+
}
|
91
|
+
|
92
|
+
@Override
|
93
|
+
@JRubyMethod(name = {"content", "text", "inner_text"})
|
94
|
+
public IRubyObject content(ThreadContext context) {
|
95
|
+
if (content == null || content.isNil()) {
|
96
|
+
return stringOrNil(context.getRuntime(), node.getTextContent());
|
97
|
+
} else {
|
98
|
+
return content;
|
99
|
+
}
|
100
|
+
}
|
101
|
+
|
102
|
+
@Override
|
103
|
+
public void accept(ThreadContext context, SaveContextVisitor visitor) {
|
104
|
+
visitor.enter((Text)node);
|
105
|
+
Node child = node.getFirstChild();
|
106
|
+
while (child != null) {
|
107
|
+
IRubyObject nokoNode = getCachedNodeOrCreate(context.getRuntime(), child);
|
108
|
+
if (nokoNode instanceof XmlNode) {
|
109
|
+
XmlNode cur = (XmlNode) nokoNode;
|
110
|
+
cur.accept(context, visitor);
|
111
|
+
} else if (nokoNode instanceof XmlNamespace) {
|
112
|
+
XmlNamespace cur = (XmlNamespace) nokoNode;
|
113
|
+
cur.accept(context, visitor);
|
114
|
+
}
|
115
|
+
child = child.getNextSibling();
|
116
|
+
}
|
117
|
+
visitor.leave((Text)node);
|
118
|
+
}
|
119
|
+
}
|
@@ -0,0 +1,199 @@
|
|
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 java.util.Set;
|
38
|
+
import java.util.regex.Matcher;
|
39
|
+
import java.util.regex.Pattern;
|
40
|
+
|
41
|
+
import javax.xml.xpath.XPath;
|
42
|
+
import javax.xml.xpath.XPathConstants;
|
43
|
+
import javax.xml.xpath.XPathExpression;
|
44
|
+
import javax.xml.xpath.XPathExpressionException;
|
45
|
+
import javax.xml.xpath.XPathFactory;
|
46
|
+
|
47
|
+
import nokogiri.internals.NokogiriNamespaceContext;
|
48
|
+
import nokogiri.internals.NokogiriXPathFunctionResolver;
|
49
|
+
import nokogiri.internals.NokogiriXPathVariableResolver;
|
50
|
+
|
51
|
+
import org.jruby.Ruby;
|
52
|
+
import org.jruby.RubyBoolean;
|
53
|
+
import org.jruby.RubyClass;
|
54
|
+
import org.jruby.RubyException;
|
55
|
+
import org.jruby.RubyNumeric;
|
56
|
+
import org.jruby.RubyObject;
|
57
|
+
import org.jruby.RubyString;
|
58
|
+
import org.jruby.anno.JRubyClass;
|
59
|
+
import org.jruby.anno.JRubyMethod;
|
60
|
+
import org.jruby.exceptions.RaiseException;
|
61
|
+
import org.jruby.runtime.ThreadContext;
|
62
|
+
import org.jruby.runtime.builtin.IRubyObject;
|
63
|
+
import org.w3c.dom.NodeList;
|
64
|
+
|
65
|
+
/**
|
66
|
+
* Class for Nokogiri::XML::XpathContext
|
67
|
+
*
|
68
|
+
* @author sergio
|
69
|
+
* @author Yoko Harada <yokolet@gmail.com>
|
70
|
+
*/
|
71
|
+
@JRubyClass(name="Nokogiri::XML::XPathContext")
|
72
|
+
public class XmlXpathContext extends RubyObject {
|
73
|
+
private XmlNode context;
|
74
|
+
private static final XPath xpath = XPathFactory.newInstance().newXPath();;
|
75
|
+
|
76
|
+
public XmlXpathContext(Ruby ruby, RubyClass rubyClass) {
|
77
|
+
super(ruby, rubyClass);
|
78
|
+
}
|
79
|
+
|
80
|
+
public void setNode(XmlNode node) {
|
81
|
+
context = node;
|
82
|
+
xpath.setNamespaceContext(NokogiriNamespaceContext.create());
|
83
|
+
xpath.setXPathVariableResolver(NokogiriXPathVariableResolver.create());
|
84
|
+
}
|
85
|
+
|
86
|
+
/**
|
87
|
+
* Create and return a copy of this object.
|
88
|
+
*
|
89
|
+
* @return a clone of this object
|
90
|
+
*/
|
91
|
+
@Override
|
92
|
+
public Object clone() throws CloneNotSupportedException {
|
93
|
+
return super.clone();
|
94
|
+
}
|
95
|
+
|
96
|
+
@JRubyMethod(name = "new", meta = true)
|
97
|
+
public static IRubyObject rbNew(ThreadContext context, IRubyObject klazz, IRubyObject node) {
|
98
|
+
XmlNode xmlNode = (XmlNode)node;
|
99
|
+
XmlXpathContext xmlXpathContext = (XmlXpathContext) NokogiriService.XML_XPATHCONTEXT_ALLOCATOR.allocate(context.getRuntime(), (RubyClass)klazz);
|
100
|
+
xmlXpathContext.setNode(xmlNode);
|
101
|
+
return xmlXpathContext;
|
102
|
+
}
|
103
|
+
|
104
|
+
@JRubyMethod
|
105
|
+
public IRubyObject evaluate(ThreadContext context, IRubyObject expr, IRubyObject handler) {
|
106
|
+
String src = (String) expr.toJava(String.class);
|
107
|
+
try {
|
108
|
+
if(!handler.isNil()) {
|
109
|
+
if (!isContainsPrefix(src)) {
|
110
|
+
Set<String> methodNames = handler.getMetaClass().getMethods().keySet();
|
111
|
+
for (String name : methodNames) {
|
112
|
+
src = src.replaceAll(name, NokogiriNamespaceContext.NOKOGIRI_PREFIX+":"+name);
|
113
|
+
}
|
114
|
+
}
|
115
|
+
xpath.setXPathFunctionResolver(NokogiriXPathFunctionResolver.create(handler));
|
116
|
+
}
|
117
|
+
XPathExpression xpathExpression = xpath.compile(src);
|
118
|
+
return node_set(context, xpathExpression);
|
119
|
+
} catch (XPathExpressionException xpee) {
|
120
|
+
xpee = new XPathExpressionException(src);
|
121
|
+
RubyException e = XmlSyntaxError.createXPathSyntaxError(getRuntime(), xpee);
|
122
|
+
throw new RaiseException(e);
|
123
|
+
}
|
124
|
+
}
|
125
|
+
|
126
|
+
protected IRubyObject node_set(ThreadContext rbctx, XPathExpression xpathExpression) {
|
127
|
+
XmlNodeSet result = null;
|
128
|
+
try {
|
129
|
+
result = tryGetNodeSet(xpathExpression);
|
130
|
+
return result;
|
131
|
+
} catch (XPathExpressionException xpee) {
|
132
|
+
try {
|
133
|
+
return tryGetOpaqueValue(xpathExpression);
|
134
|
+
} catch (XPathExpressionException xpee_opaque) {
|
135
|
+
RubyException e = XmlSyntaxError.createXPathSyntaxError(getRuntime(), xpee_opaque);
|
136
|
+
throw new RaiseException(e);
|
137
|
+
}
|
138
|
+
}
|
139
|
+
}
|
140
|
+
|
141
|
+
private XmlNodeSet tryGetNodeSet(XPathExpression xpathExpression) throws XPathExpressionException {
|
142
|
+
NodeList nodeList = (NodeList)xpathExpression.evaluate(context.node, XPathConstants.NODESET);
|
143
|
+
XmlNodeSet xmlNodeSet = (XmlNodeSet) NokogiriService.XML_NODESET_ALLOCATOR.allocate(getRuntime(), getNokogiriClass(getRuntime(), "Nokogiri::XML::NodeSet"));
|
144
|
+
xmlNodeSet.setNodeList(nodeList);
|
145
|
+
return xmlNodeSet;
|
146
|
+
}
|
147
|
+
|
148
|
+
private static Pattern boolean_pattern = Pattern.compile("true|false");
|
149
|
+
|
150
|
+
private IRubyObject tryGetOpaqueValue(XPathExpression xpathExpression) throws XPathExpressionException {
|
151
|
+
String string = (String)xpathExpression.evaluate(context.node, XPathConstants.STRING);
|
152
|
+
Double value = null;
|
153
|
+
if ((value = getDoubleValue(string)) != null) return RubyNumeric.dbl2num(getRuntime(), value);
|
154
|
+
if (doesMatch(boolean_pattern, string.toLowerCase())) return RubyBoolean.newBoolean(getRuntime(), Boolean.parseBoolean(string));
|
155
|
+
return RubyString.newString(getRuntime(), string);
|
156
|
+
}
|
157
|
+
|
158
|
+
private Double getDoubleValue(String value) {
|
159
|
+
try {
|
160
|
+
return Double.valueOf(value);
|
161
|
+
} catch (NumberFormatException e) {
|
162
|
+
return null;
|
163
|
+
}
|
164
|
+
}
|
165
|
+
|
166
|
+
private boolean doesMatch(Pattern pattern, String string) {
|
167
|
+
Matcher m = pattern.matcher(string);
|
168
|
+
return m.matches();
|
169
|
+
}
|
170
|
+
|
171
|
+
private boolean isContainsPrefix(String str) {
|
172
|
+
Set<String> prefixes = ((NokogiriNamespaceContext)xpath.getNamespaceContext()).getAllPrefixes();
|
173
|
+
for (String prefix : prefixes) {
|
174
|
+
if (str.contains(prefix + ":")) {
|
175
|
+
return true;
|
176
|
+
}
|
177
|
+
}
|
178
|
+
return false;
|
179
|
+
}
|
180
|
+
|
181
|
+
|
182
|
+
@JRubyMethod
|
183
|
+
public IRubyObject evaluate(ThreadContext context, IRubyObject expr) {
|
184
|
+
return this.evaluate(context, expr, context.getRuntime().getNil());
|
185
|
+
}
|
186
|
+
|
187
|
+
@JRubyMethod
|
188
|
+
public IRubyObject register_ns(ThreadContext context, IRubyObject prefix, IRubyObject uri) {
|
189
|
+
((NokogiriNamespaceContext) xpath.getNamespaceContext()).registerNamespace((String)prefix.toJava(String.class), (String)uri.toJava(String.class));
|
190
|
+
return this;
|
191
|
+
}
|
192
|
+
|
193
|
+
@JRubyMethod
|
194
|
+
public IRubyObject register_variable(ThreadContext context, IRubyObject name, IRubyObject value) {
|
195
|
+
((NokogiriXPathVariableResolver) xpath.getXPathVariableResolver()).
|
196
|
+
registerVariable((String)name.toJava(String.class), (String)value.toJava(String.class));
|
197
|
+
return this;
|
198
|
+
}
|
199
|
+
}
|
@@ -0,0 +1,197 @@
|
|
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 java.util.HashMap;
|
38
|
+
import java.util.Map;
|
39
|
+
import java.util.regex.Matcher;
|
40
|
+
import java.util.regex.Pattern;
|
41
|
+
|
42
|
+
import javax.xml.transform.ErrorListener;
|
43
|
+
import javax.xml.transform.Templates;
|
44
|
+
import javax.xml.transform.Transformer;
|
45
|
+
import javax.xml.transform.TransformerConfigurationException;
|
46
|
+
import javax.xml.transform.TransformerException;
|
47
|
+
import javax.xml.transform.TransformerFactory;
|
48
|
+
import javax.xml.transform.dom.DOMResult;
|
49
|
+
import javax.xml.transform.dom.DOMSource;
|
50
|
+
|
51
|
+
import nokogiri.internals.NokogiriXsltErrorListener;
|
52
|
+
|
53
|
+
import org.jruby.Ruby;
|
54
|
+
import org.jruby.RubyArray;
|
55
|
+
import org.jruby.RubyClass;
|
56
|
+
import org.jruby.RubyObject;
|
57
|
+
import org.jruby.anno.JRubyClass;
|
58
|
+
import org.jruby.anno.JRubyMethod;
|
59
|
+
import org.jruby.javasupport.util.RuntimeHelpers;
|
60
|
+
import org.jruby.runtime.ThreadContext;
|
61
|
+
import org.jruby.runtime.builtin.IRubyObject;
|
62
|
+
import org.w3c.dom.Document;
|
63
|
+
|
64
|
+
/**
|
65
|
+
* Class for Nokogiri::XSLT::Stylesheet
|
66
|
+
*
|
67
|
+
* @author sergio
|
68
|
+
* @author Yoko Harada <yokolet@gmail.com>
|
69
|
+
*/
|
70
|
+
@JRubyClass(name="Nokogiri::XSLT::Stylesheet")
|
71
|
+
public class XsltStylesheet extends RubyObject {
|
72
|
+
private static Map<String, Object> registry = new HashMap<String, Object>();
|
73
|
+
private static TransformerFactory factory = null;
|
74
|
+
private Templates sheet;
|
75
|
+
|
76
|
+
public static Map<String, Object> getRegistry() {
|
77
|
+
return registry;
|
78
|
+
}
|
79
|
+
|
80
|
+
public XsltStylesheet(Ruby ruby, RubyClass rubyClass) {
|
81
|
+
super(ruby, rubyClass);
|
82
|
+
}
|
83
|
+
|
84
|
+
private void addParametersToTransformer(ThreadContext context, Transformer transf, IRubyObject parameters) {
|
85
|
+
Ruby ruby = context.getRuntime();
|
86
|
+
RubyArray params = parameters.convertToArray();
|
87
|
+
int limit = params.getLength();
|
88
|
+
if(limit % 2 == 1) limit--;
|
89
|
+
|
90
|
+
for(int i = 0; i < limit; i+=2) {
|
91
|
+
String name = params.aref(ruby.newFixnum(i)).asJavaString();
|
92
|
+
String value = params.aref(ruby.newFixnum(i+1)).asJavaString();
|
93
|
+
transf.setParameter(name, unparseValue(value));
|
94
|
+
}
|
95
|
+
}
|
96
|
+
|
97
|
+
private Pattern p = Pattern.compile("'.{1,}'");
|
98
|
+
|
99
|
+
private String unparseValue(String orig) {
|
100
|
+
Matcher m = p.matcher(orig);
|
101
|
+
if ((orig.startsWith("\"") && orig.endsWith("\"")) || m.matches()) {
|
102
|
+
orig = orig.substring(1, orig.length()-1);
|
103
|
+
}
|
104
|
+
|
105
|
+
return orig;
|
106
|
+
}
|
107
|
+
|
108
|
+
@JRubyMethod(meta = true)
|
109
|
+
public static IRubyObject parse_stylesheet_doc(ThreadContext context, IRubyObject cls, IRubyObject document) {
|
110
|
+
|
111
|
+
Ruby ruby = context.getRuntime();
|
112
|
+
|
113
|
+
if(!(document instanceof XmlDocument)) {
|
114
|
+
throw ruby.newArgumentError("doc must be a Nokogiri::XML::Document instance");
|
115
|
+
}
|
116
|
+
|
117
|
+
XmlDocument xmlDoc = (XmlDocument) document;
|
118
|
+
|
119
|
+
RubyArray errors = (RubyArray) xmlDoc.getInstanceVariable("@errors");
|
120
|
+
|
121
|
+
if(!errors.isEmpty()) {
|
122
|
+
throw ruby.newRuntimeError(errors.first().asJavaString());
|
123
|
+
}
|
124
|
+
|
125
|
+
Document doc = ((XmlDocument) xmlDoc.dup_implementation(context, true)).getDocument();
|
126
|
+
|
127
|
+
XsltStylesheet xslt = new XsltStylesheet(ruby, (RubyClass) cls);
|
128
|
+
|
129
|
+
try {
|
130
|
+
if (factory == null) factory = TransformerFactory.newInstance();
|
131
|
+
xslt.sheet = factory.newTemplates(new DOMSource(doc));
|
132
|
+
} catch (TransformerConfigurationException ex) {
|
133
|
+
ruby.newRuntimeError("could not parse xslt stylesheet");
|
134
|
+
}
|
135
|
+
|
136
|
+
return xslt;
|
137
|
+
}
|
138
|
+
|
139
|
+
@JRubyMethod
|
140
|
+
public IRubyObject serialize(ThreadContext context, IRubyObject doc) {
|
141
|
+
return RuntimeHelpers.invoke(context,
|
142
|
+
RuntimeHelpers.invoke(context, doc, "root"),
|
143
|
+
"to_s");
|
144
|
+
}
|
145
|
+
|
146
|
+
@JRubyMethod(rest = true, required=1, optional=2)
|
147
|
+
public IRubyObject transform(ThreadContext context, IRubyObject[] args) {
|
148
|
+
Ruby runtime = context.getRuntime();
|
149
|
+
|
150
|
+
DOMSource docSource = new DOMSource(((XmlDocument) args[0]).getDocument());
|
151
|
+
DOMResult result = new DOMResult();
|
152
|
+
|
153
|
+
NokogiriXsltErrorListener elistener = new NokogiriXsltErrorListener();
|
154
|
+
try{
|
155
|
+
Transformer transf = this.sheet.newTransformer();
|
156
|
+
transf.setErrorListener(elistener);
|
157
|
+
if(args.length > 1) {
|
158
|
+
addParametersToTransformer(context, transf, args[1]);
|
159
|
+
}
|
160
|
+
transf.transform(docSource, result);
|
161
|
+
} catch(TransformerConfigurationException ex) {
|
162
|
+
// processes later
|
163
|
+
} catch(TransformerException ex) {
|
164
|
+
// processes later
|
165
|
+
}
|
166
|
+
|
167
|
+
switch (elistener.getErrorType()) {
|
168
|
+
case ERROR:
|
169
|
+
case FATAL:
|
170
|
+
throw runtime.newRuntimeError(elistener.getErrorMessage());
|
171
|
+
case WARNING:
|
172
|
+
default:
|
173
|
+
// no-op
|
174
|
+
}
|
175
|
+
|
176
|
+
if ("html".equals(result.getNode().getFirstChild().getNodeName())) {
|
177
|
+
HtmlDocument htmlDocument = (HtmlDocument) getNokogiriClass(runtime, "Nokogiri::HTML::Document").allocate();
|
178
|
+
htmlDocument.setNode(context, (Document) result.getNode());
|
179
|
+
return htmlDocument;
|
180
|
+
} else {
|
181
|
+
XmlDocument xmlDocument = (XmlDocument) NokogiriService.XML_DOCUMENT_ALLOCATOR.allocate(runtime, getNokogiriClass(runtime, "Nokogiri::XML::Document"));
|
182
|
+
xmlDocument.setNode(context, (Document) result.getNode());
|
183
|
+
return xmlDocument;
|
184
|
+
}
|
185
|
+
}
|
186
|
+
|
187
|
+
@JRubyMethod(name = {"registr", "register"}, meta = true)
|
188
|
+
public static IRubyObject register(ThreadContext context, IRubyObject cls, IRubyObject uri, IRubyObject receiver) {
|
189
|
+
throw context.getRuntime().newNotImplementedError("Nokogiri::XSLT.register method is not implemented");
|
190
|
+
/* When API conflict is solved, this method should be below:
|
191
|
+
// ThreadContext is used while executing xslt extension function
|
192
|
+
registry.put("context", context);
|
193
|
+
registry.put("receiver", receiver);
|
194
|
+
return context.getRuntime().getNil();
|
195
|
+
*/
|
196
|
+
}
|
197
|
+
}
|