nokogiri 1.11.0.rc4-java → 1.11.5-java
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of nokogiri might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/Gemfile +3 -0
- data/LICENSE-DEPENDENCIES.md +12 -12
- data/LICENSE.md +1 -1
- data/README.md +168 -91
- data/dependencies.yml +12 -12
- data/ext/java/nokogiri/EncodingHandler.java +76 -89
- data/ext/java/nokogiri/HtmlDocument.java +135 -144
- data/ext/java/nokogiri/HtmlElementDescription.java +102 -117
- data/ext/java/nokogiri/HtmlEntityLookup.java +33 -60
- data/ext/java/nokogiri/HtmlSaxParserContext.java +218 -222
- data/ext/java/nokogiri/HtmlSaxPushParser.java +162 -169
- data/ext/java/nokogiri/NokogiriService.java +595 -556
- data/ext/java/nokogiri/XmlAttr.java +118 -126
- data/ext/java/nokogiri/XmlAttributeDecl.java +95 -106
- data/ext/java/nokogiri/XmlCdata.java +35 -58
- data/ext/java/nokogiri/XmlComment.java +46 -67
- data/ext/java/nokogiri/XmlDocument.java +645 -572
- data/ext/java/nokogiri/XmlDocumentFragment.java +125 -137
- data/ext/java/nokogiri/XmlDtd.java +448 -414
- data/ext/java/nokogiri/XmlElement.java +23 -48
- data/ext/java/nokogiri/XmlElementContent.java +343 -316
- data/ext/java/nokogiri/XmlElementDecl.java +124 -125
- data/ext/java/nokogiri/XmlEntityDecl.java +119 -127
- data/ext/java/nokogiri/XmlEntityReference.java +49 -72
- data/ext/java/nokogiri/XmlNamespace.java +175 -175
- data/ext/java/nokogiri/XmlNode.java +1843 -1620
- data/ext/java/nokogiri/XmlNodeSet.java +361 -331
- data/ext/java/nokogiri/XmlProcessingInstruction.java +47 -69
- data/ext/java/nokogiri/XmlReader.java +513 -450
- data/ext/java/nokogiri/XmlRelaxng.java +85 -104
- data/ext/java/nokogiri/XmlSaxParserContext.java +328 -315
- data/ext/java/nokogiri/XmlSaxPushParser.java +227 -220
- data/ext/java/nokogiri/XmlSchema.java +328 -295
- data/ext/java/nokogiri/XmlSyntaxError.java +113 -115
- data/ext/java/nokogiri/XmlText.java +55 -76
- data/ext/java/nokogiri/XmlXpathContext.java +240 -238
- data/ext/java/nokogiri/XsltStylesheet.java +280 -269
- data/ext/java/nokogiri/internals/ClosedStreamException.java +5 -2
- data/ext/java/nokogiri/internals/HtmlDomParserContext.java +201 -202
- data/ext/java/nokogiri/internals/IgnoreSchemaErrorsErrorHandler.java +17 -10
- data/ext/java/nokogiri/internals/NokogiriBlockingQueueInputStream.java +43 -16
- data/ext/java/nokogiri/internals/NokogiriDomParser.java +63 -80
- data/ext/java/nokogiri/internals/NokogiriEntityResolver.java +107 -88
- data/ext/java/nokogiri/internals/NokogiriErrorHandler.java +27 -52
- data/ext/java/nokogiri/internals/NokogiriHandler.java +316 -286
- data/ext/java/nokogiri/internals/NokogiriHelpers.java +736 -652
- data/ext/java/nokogiri/internals/NokogiriNamespaceCache.java +184 -173
- data/ext/java/nokogiri/internals/NokogiriNamespaceContext.java +81 -98
- data/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler.java +64 -79
- data/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler4NekoHtml.java +84 -99
- data/ext/java/nokogiri/internals/NokogiriStrictErrorHandler.java +48 -65
- data/ext/java/nokogiri/internals/NokogiriXPathFunction.java +116 -131
- data/ext/java/nokogiri/internals/NokogiriXPathFunctionResolver.java +34 -56
- data/ext/java/nokogiri/internals/NokogiriXPathVariableResolver.java +23 -46
- data/ext/java/nokogiri/internals/NokogiriXsltErrorListener.java +55 -72
- data/ext/java/nokogiri/internals/ParserContext.java +206 -211
- data/ext/java/nokogiri/internals/ReaderNode.java +478 -403
- data/ext/java/nokogiri/internals/SaveContextVisitor.java +822 -739
- data/ext/java/nokogiri/internals/SchemaErrorHandler.java +31 -54
- data/ext/java/nokogiri/internals/XalanDTMManagerPatch.java +129 -123
- data/ext/java/nokogiri/internals/XmlDeclHandler.java +3 -34
- data/ext/java/nokogiri/internals/XmlDomParserContext.java +206 -207
- data/ext/java/nokogiri/internals/XmlSaxParser.java +22 -47
- data/ext/java/nokogiri/internals/c14n/AttrCompare.java +71 -68
- data/ext/java/nokogiri/internals/c14n/C14nHelper.java +137 -118
- data/ext/java/nokogiri/internals/c14n/CanonicalFilter.java +27 -21
- data/ext/java/nokogiri/internals/c14n/CanonicalizationException.java +74 -61
- data/ext/java/nokogiri/internals/c14n/Canonicalizer.java +230 -205
- data/ext/java/nokogiri/internals/c14n/Canonicalizer11.java +572 -547
- data/ext/java/nokogiri/internals/c14n/Canonicalizer11_OmitComments.java +17 -10
- data/ext/java/nokogiri/internals/c14n/Canonicalizer11_WithComments.java +17 -10
- data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315.java +323 -302
- data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315Excl.java +232 -219
- data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315ExclOmitComments.java +22 -15
- data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315ExclWithComments.java +23 -16
- data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315OmitComments.java +23 -16
- data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315WithComments.java +22 -15
- data/ext/java/nokogiri/internals/c14n/CanonicalizerBase.java +575 -545
- data/ext/java/nokogiri/internals/c14n/CanonicalizerPhysical.java +141 -120
- data/ext/java/nokogiri/internals/c14n/CanonicalizerSpi.java +39 -38
- data/ext/java/nokogiri/internals/c14n/Constants.java +13 -10
- data/ext/java/nokogiri/internals/c14n/ElementProxy.java +279 -247
- data/ext/java/nokogiri/internals/c14n/HelperNodeList.java +66 -53
- data/ext/java/nokogiri/internals/c14n/IgnoreAllErrorHandler.java +44 -37
- data/ext/java/nokogiri/internals/c14n/InclusiveNamespaces.java +135 -120
- data/ext/java/nokogiri/internals/c14n/InvalidCanonicalizerException.java +59 -48
- data/ext/java/nokogiri/internals/c14n/NameSpaceSymbTable.java +384 -334
- data/ext/java/nokogiri/internals/c14n/NodeFilter.java +25 -24
- data/ext/java/nokogiri/internals/c14n/UtfHelpper.java +151 -140
- data/ext/java/nokogiri/internals/c14n/XMLUtils.java +456 -423
- data/ext/java/nokogiri/internals/dom2dtm/DOM2DTM.java +1466 -1500
- data/ext/java/nokogiri/internals/dom2dtm/DOM2DTMdefaultNamespaceDeclarationNode.java +626 -574
- data/ext/nokogiri/depend +34 -474
- data/ext/nokogiri/extconf.rb +270 -183
- data/ext/nokogiri/html_document.c +10 -15
- data/ext/nokogiri/html_element_description.c +84 -71
- data/ext/nokogiri/html_entity_lookup.c +21 -16
- data/ext/nokogiri/html_sax_parser_context.c +67 -64
- data/ext/nokogiri/html_sax_push_parser.c +42 -34
- data/ext/nokogiri/libxml2_backwards_compat.c +121 -0
- data/ext/nokogiri/nokogiri.c +190 -60
- data/ext/nokogiri/test_global_handlers.c +40 -0
- data/ext/nokogiri/xml_attr.c +15 -15
- data/ext/nokogiri/xml_attribute_decl.c +18 -18
- data/ext/nokogiri/xml_cdata.c +13 -18
- data/ext/nokogiri/xml_comment.c +19 -26
- data/ext/nokogiri/xml_document.c +246 -188
- data/ext/nokogiri/xml_document_fragment.c +13 -15
- data/ext/nokogiri/xml_dtd.c +54 -48
- data/ext/nokogiri/xml_element_content.c +30 -27
- data/ext/nokogiri/xml_element_decl.c +22 -22
- data/ext/nokogiri/xml_encoding_handler.c +17 -11
- data/ext/nokogiri/xml_entity_decl.c +32 -30
- data/ext/nokogiri/xml_entity_reference.c +16 -18
- data/ext/nokogiri/xml_namespace.c +56 -49
- data/ext/nokogiri/xml_node.c +371 -320
- data/ext/nokogiri/xml_node_set.c +168 -156
- data/ext/nokogiri/xml_processing_instruction.c +17 -19
- data/ext/nokogiri/xml_reader.c +191 -157
- data/ext/nokogiri/xml_relax_ng.c +29 -23
- data/ext/nokogiri/xml_sax_parser.c +117 -112
- data/ext/nokogiri/xml_sax_parser_context.c +101 -84
- data/ext/nokogiri/xml_sax_push_parser.c +36 -27
- data/ext/nokogiri/xml_schema.c +48 -42
- data/ext/nokogiri/xml_syntax_error.c +42 -21
- data/ext/nokogiri/xml_text.c +13 -17
- data/ext/nokogiri/xml_xpath_context.c +134 -127
- data/ext/nokogiri/xslt_stylesheet.c +157 -157
- data/lib/nokogiri.rb +2 -6
- data/lib/nokogiri/css/parser.rb +1 -1
- data/lib/nokogiri/extension.rb +26 -0
- data/lib/nokogiri/html/document_fragment.rb +15 -15
- data/lib/nokogiri/nokogiri.jar +0 -0
- data/lib/nokogiri/version/constant.rb +1 -1
- data/lib/nokogiri/version/info.rb +32 -8
- data/lib/nokogiri/xml/document.rb +74 -28
- data/lib/nokogiri/xml/node.rb +39 -42
- data/lib/nokogiri/xml/reader.rb +2 -9
- data/lib/nokogiri/xml/xpath.rb +1 -3
- data/lib/nokogiri/xml/xpath/syntax_error.rb +1 -1
- metadata +62 -127
- data/ext/nokogiri/xml_io.c +0 -63
- data/ext/nokogiri/xml_libxml2_hacks.c +0 -112
@@ -1,35 +1,3 @@
|
|
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
1
|
package nokogiri;
|
34
2
|
|
35
3
|
import static nokogiri.internals.NokogiriHelpers.stringOrNil;
|
@@ -50,89 +18,119 @@ import org.xml.sax.SAXParseException;
|
|
50
18
|
* @author sergio
|
51
19
|
* @author Yoko Harada <yokolet@gmail.com>
|
52
20
|
*/
|
53
|
-
@JRubyClass(name="Nokogiri::XML::SyntaxError", parent="Nokogiri::SyntaxError")
|
54
|
-
public class XmlSyntaxError extends RubyException
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
21
|
+
@JRubyClass(name = "Nokogiri::XML::SyntaxError", parent = "Nokogiri::SyntaxError")
|
22
|
+
public class XmlSyntaxError extends RubyException
|
23
|
+
{
|
24
|
+
|
25
|
+
private Exception exception;
|
26
|
+
private boolean messageSet; // whether a custom error message was set
|
27
|
+
|
28
|
+
public
|
29
|
+
XmlSyntaxError(Ruby runtime, RubyClass klazz)
|
30
|
+
{
|
31
|
+
super(runtime, klazz);
|
32
|
+
}
|
33
|
+
|
34
|
+
public
|
35
|
+
XmlSyntaxError(Ruby runtime, RubyClass rubyClass, Exception ex)
|
36
|
+
{
|
37
|
+
super(runtime, rubyClass, ex.getMessage());
|
38
|
+
this.exception = ex;
|
39
|
+
}
|
40
|
+
|
41
|
+
public
|
42
|
+
XmlSyntaxError(Ruby runtime, RubyClass rubyClass, String message, Exception ex)
|
43
|
+
{
|
44
|
+
super(runtime, rubyClass, message);
|
45
|
+
this.exception = ex;
|
46
|
+
this.messageSet = true;
|
47
|
+
}
|
48
|
+
|
49
|
+
public static XmlSyntaxError
|
50
|
+
createXMLSyntaxError(final Ruby runtime)
|
51
|
+
{
|
52
|
+
RubyClass klazz = (RubyClass) runtime.getClassFromPath("Nokogiri::XML::SyntaxError");
|
53
|
+
return new XmlSyntaxError(runtime, klazz);
|
54
|
+
}
|
55
|
+
|
56
|
+
public static XmlSyntaxError
|
57
|
+
createXMLSyntaxError(final Ruby runtime, final Exception ex)
|
58
|
+
{
|
59
|
+
RubyClass klazz = (RubyClass) runtime.getClassFromPath("Nokogiri::XML::SyntaxError");
|
60
|
+
return new XmlSyntaxError(runtime, klazz, ex);
|
61
|
+
}
|
62
|
+
|
63
|
+
public static XmlSyntaxError
|
64
|
+
createHTMLSyntaxError(final Ruby runtime)
|
65
|
+
{
|
66
|
+
RubyClass klazz = (RubyClass) runtime.getClassFromPath("Nokogiri::HTML::SyntaxError");
|
67
|
+
return new XmlSyntaxError(runtime, klazz);
|
68
|
+
}
|
69
|
+
|
70
|
+
public static RubyException
|
71
|
+
createXMLXPathSyntaxError(final Ruby runtime, final String msg, final Exception ex)
|
72
|
+
{
|
73
|
+
RubyClass klazz = (RubyClass) runtime.getClassFromPath("Nokogiri::XML::XPath::SyntaxError");
|
74
|
+
return new XmlSyntaxError(runtime, klazz, msg, ex);
|
75
|
+
}
|
76
|
+
|
77
|
+
public static XmlSyntaxError
|
78
|
+
createWarning(Ruby runtime, SAXParseException e)
|
79
|
+
{
|
80
|
+
XmlSyntaxError xmlSyntaxError = createXMLSyntaxError(runtime);
|
81
|
+
xmlSyntaxError.setException(runtime, e, 1);
|
82
|
+
return xmlSyntaxError;
|
83
|
+
}
|
84
|
+
|
85
|
+
public static XmlSyntaxError
|
86
|
+
createError(Ruby runtime, SAXParseException e)
|
87
|
+
{
|
88
|
+
XmlSyntaxError xmlSyntaxError = createXMLSyntaxError(runtime);
|
89
|
+
xmlSyntaxError.setException(runtime, e, 2);
|
90
|
+
return xmlSyntaxError;
|
91
|
+
}
|
92
|
+
|
93
|
+
public static XmlSyntaxError
|
94
|
+
createFatalError(Ruby runtime, SAXParseException e)
|
95
|
+
{
|
96
|
+
XmlSyntaxError xmlSyntaxError = createXMLSyntaxError(runtime);
|
97
|
+
xmlSyntaxError.setException(runtime, e, 3);
|
98
|
+
return xmlSyntaxError;
|
99
|
+
}
|
100
|
+
|
101
|
+
public void
|
102
|
+
setException(Exception exception)
|
103
|
+
{
|
104
|
+
this.exception = exception;
|
105
|
+
}
|
106
|
+
|
107
|
+
public void
|
108
|
+
setException(Ruby runtime, SAXParseException exception, int level)
|
109
|
+
{
|
110
|
+
this.exception = exception;
|
111
|
+
setInstanceVariable("@level", runtime.newFixnum(level));
|
112
|
+
setInstanceVariable("@line", runtime.newFixnum(exception.getLineNumber()));
|
113
|
+
setInstanceVariable("@column", runtime.newFixnum(exception.getColumnNumber()));
|
114
|
+
setInstanceVariable("@file", stringOrNil(runtime, exception.getSystemId()));
|
115
|
+
}
|
116
|
+
|
117
|
+
@JRubyMethod(name = "to_s")
|
118
|
+
@Override
|
119
|
+
public IRubyObject
|
120
|
+
to_s(ThreadContext context)
|
121
|
+
{
|
122
|
+
RubyString msg = msg(context.runtime);
|
123
|
+
return msg != null ? msg : super.to_s(context).asString();
|
124
|
+
}
|
125
|
+
|
126
|
+
private RubyString
|
127
|
+
msg(final Ruby runtime)
|
128
|
+
{
|
129
|
+
if (exception != null && exception.getMessage() != null) {
|
130
|
+
if (messageSet) { return null; }
|
131
|
+
return runtime.newString(exception.getMessage());
|
136
132
|
}
|
133
|
+
return null;
|
134
|
+
}
|
137
135
|
|
138
136
|
}
|
@@ -1,35 +1,3 @@
|
|
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
1
|
package nokogiri;
|
34
2
|
|
35
3
|
import static nokogiri.internals.NokogiriHelpers.getCachedNodeOrCreate;
|
@@ -54,57 +22,68 @@ import org.w3c.dom.Text;
|
|
54
22
|
* @author sergio
|
55
23
|
* @author Yoko Harada <yokolet@gmail.com>
|
56
24
|
*/
|
57
|
-
@JRubyClass(name="Nokogiri::XML::Text", parent="Nokogiri::XML::CharacterData")
|
58
|
-
public class XmlText extends XmlNode
|
25
|
+
@JRubyClass(name = "Nokogiri::XML::Text", parent = "Nokogiri::XML::CharacterData")
|
26
|
+
public class XmlText extends XmlNode
|
27
|
+
{
|
59
28
|
|
60
|
-
|
61
|
-
|
29
|
+
private static final ByteList TEXT = ByteList.create("text");
|
30
|
+
static { TEXT.setEncoding(USASCIIEncoding.INSTANCE); }
|
62
31
|
|
63
|
-
|
64
|
-
|
65
|
-
|
32
|
+
public
|
33
|
+
XmlText(Ruby runtime, RubyClass rubyClass, Node node)
|
34
|
+
{
|
35
|
+
super(runtime, rubyClass, node);
|
36
|
+
}
|
37
|
+
|
38
|
+
public
|
39
|
+
XmlText(Ruby runtime, RubyClass klass)
|
40
|
+
{
|
41
|
+
super(runtime, klass);
|
42
|
+
}
|
66
43
|
|
67
|
-
|
68
|
-
|
44
|
+
@Override
|
45
|
+
protected void
|
46
|
+
init(ThreadContext context, IRubyObject[] args)
|
47
|
+
{
|
48
|
+
if (args.length < 2) {
|
49
|
+
throw context.runtime.newArgumentError(args.length, 2);
|
69
50
|
}
|
70
51
|
|
71
|
-
|
72
|
-
|
73
|
-
if (args.length < 2) {
|
74
|
-
throw context.runtime.newArgumentError(args.length, 2);
|
75
|
-
}
|
52
|
+
content = args[0];
|
53
|
+
IRubyObject xNode = args[1];
|
76
54
|
|
77
|
-
|
78
|
-
|
55
|
+
Document document = asXmlNode(context, xNode).getOwnerDocument();
|
56
|
+
// text node content should not be encoded when it is created by Text node.
|
57
|
+
// while content should be encoded when it is created by Element node.
|
58
|
+
Node node = document.createTextNode(rubyStringToString(content));
|
59
|
+
setNode(context.runtime, node);
|
60
|
+
}
|
79
61
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
@Override
|
88
|
-
protected IRubyObject getNodeName(ThreadContext context) {
|
89
|
-
if (name == null) name = RubyString.newStringShared(context.runtime, TEXT);
|
90
|
-
return name;
|
91
|
-
}
|
62
|
+
@Override
|
63
|
+
protected IRubyObject
|
64
|
+
getNodeName(ThreadContext context)
|
65
|
+
{
|
66
|
+
if (name == null) { name = RubyString.newStringShared(context.runtime, TEXT); }
|
67
|
+
return name;
|
68
|
+
}
|
92
69
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
70
|
+
@Override
|
71
|
+
public void
|
72
|
+
accept(ThreadContext context, SaveContextVisitor visitor)
|
73
|
+
{
|
74
|
+
visitor.enter((Text) node);
|
75
|
+
Node child = node.getFirstChild();
|
76
|
+
while (child != null) {
|
77
|
+
IRubyObject nokoNode = getCachedNodeOrCreate(context.runtime, child);
|
78
|
+
if (nokoNode instanceof XmlNode) {
|
79
|
+
XmlNode cur = (XmlNode) nokoNode;
|
80
|
+
cur.accept(context, visitor);
|
81
|
+
} else if (nokoNode instanceof XmlNamespace) {
|
82
|
+
XmlNamespace cur = (XmlNamespace) nokoNode;
|
83
|
+
cur.accept(context, visitor);
|
84
|
+
}
|
85
|
+
child = child.getNextSibling();
|
109
86
|
}
|
87
|
+
visitor.leave(node);
|
88
|
+
}
|
110
89
|
}
|
@@ -1,35 +1,3 @@
|
|
1
|
-
/**
|
2
|
-
* (The MIT License)
|
3
|
-
*
|
4
|
-
* Copyright (c) 2008 - 2014:
|
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
1
|
package nokogiri;
|
34
2
|
|
35
3
|
import java.util.Set;
|
@@ -68,234 +36,268 @@ import static nokogiri.internals.NokogiriHelpers.nodeListToRubyArray;
|
|
68
36
|
* @author Yoko Harada <yokolet@gmail.com>
|
69
37
|
* @author John Shahid <jvshahid@gmail.com>
|
70
38
|
*/
|
71
|
-
@JRubyClass(name="Nokogiri::XML::XPathContext")
|
72
|
-
public class XmlXpathContext extends RubyObject
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
39
|
+
@JRubyClass(name = "Nokogiri::XML::XPathContext")
|
40
|
+
public class XmlXpathContext extends RubyObject
|
41
|
+
{
|
42
|
+
static
|
43
|
+
{
|
44
|
+
final String DTMManager = "org.apache.xml.dtm.DTMManager";
|
45
|
+
if (SafePropertyAccessor.getProperty(DTMManager) == null) {
|
46
|
+
try { // use patched "org.apache.xml.dtm.ref.DTMManagerDefault"
|
47
|
+
System.setProperty(DTMManager, nokogiri.internals.XalanDTMManagerPatch.class.getName());
|
48
|
+
} catch (SecurityException ex) { /* no-op - will work although might be slower */ }
|
81
49
|
}
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
50
|
+
}
|
51
|
+
|
52
|
+
/**
|
53
|
+
* user-data key for (cached) {@link XPathContext}
|
54
|
+
*/
|
55
|
+
public static final String XPATH_CONTEXT = "CACHED_XPATH_CONTEXT";
|
56
|
+
|
57
|
+
private XmlNode context;
|
58
|
+
|
59
|
+
public
|
60
|
+
XmlXpathContext(Ruby runtime, RubyClass klass)
|
61
|
+
{
|
62
|
+
super(runtime, klass);
|
63
|
+
}
|
64
|
+
|
65
|
+
public
|
66
|
+
XmlXpathContext(Ruby runtime, RubyClass klass, XmlNode node)
|
67
|
+
{
|
68
|
+
this(runtime, klass);
|
69
|
+
initNode(node);
|
70
|
+
}
|
71
|
+
|
72
|
+
private void
|
73
|
+
initNode(XmlNode node)
|
74
|
+
{
|
75
|
+
context = node;
|
76
|
+
}
|
77
|
+
|
78
|
+
@JRubyMethod(name = "new", meta = true)
|
79
|
+
public static IRubyObject
|
80
|
+
rbNew(ThreadContext context, IRubyObject klazz, IRubyObject node)
|
81
|
+
{
|
82
|
+
try {
|
83
|
+
return new XmlXpathContext(context.runtime, (RubyClass) klazz, (XmlNode) node);
|
84
|
+
} catch (IllegalArgumentException e) {
|
85
|
+
throw context.getRuntime().newRuntimeError(e.getMessage());
|
92
86
|
}
|
87
|
+
}
|
88
|
+
|
89
|
+
|
90
|
+
// see https://en.wikipedia.org/wiki/QName
|
91
|
+
private static final String NameStartCharStr =
|
92
|
+
"[_A-Za-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD]"
|
93
|
+
;
|
94
|
+
private static final String NameCharStr = "[-\\.0-9\u00B7\u0300-\u036F\u203F-\u2040]|" + NameStartCharStr ;
|
95
|
+
private static final String NCNameStr = "(?:" + NameStartCharStr + ")(?:" + NameCharStr + ")*";
|
96
|
+
private static final String XPathFunctionCaptureStr = "(" + NCNameStr + "(?=\\())";
|
97
|
+
private static final Pattern XPathFunctionCaptureRE = Pattern.compile(XPathFunctionCaptureStr);
|
98
|
+
|
99
|
+
@JRubyMethod
|
100
|
+
public IRubyObject
|
101
|
+
evaluate(ThreadContext context, IRubyObject rbQuery, IRubyObject handler)
|
102
|
+
{
|
103
|
+
String query = rbQuery.convertToString().asJavaString();
|
104
|
+
|
105
|
+
if (!handler.isNil() && !isContainsPrefix(query)) {
|
106
|
+
//
|
107
|
+
// The user has passed in a handler, but isn't using the `nokogiri:` prefix as
|
108
|
+
// instructed in JRuby land, so let's try to be clever and rewrite the query, inserting
|
109
|
+
// the nokogiri namespace where appropriate.
|
110
|
+
//
|
111
|
+
StringBuilder namespacedQuery = new StringBuilder();
|
112
|
+
int jchar = 0;
|
113
|
+
|
114
|
+
// Find the methods on the handler object
|
115
|
+
Set<String> methodNames = handler.getMetaClass().getMethods().keySet();
|
116
|
+
|
117
|
+
// Find the function calls in the xpath query
|
118
|
+
Matcher xpathFunctionCalls = XPathFunctionCaptureRE.matcher(query);
|
119
|
+
|
120
|
+
while (xpathFunctionCalls.find()) {
|
121
|
+
namespacedQuery.append(query.subSequence(jchar, xpathFunctionCalls.start()));
|
122
|
+
jchar = xpathFunctionCalls.start();
|
123
|
+
|
124
|
+
if (methodNames.contains(xpathFunctionCalls.group())) {
|
125
|
+
namespacedQuery.append(NokogiriNamespaceContext.NOKOGIRI_PREFIX);
|
126
|
+
namespacedQuery.append(":");
|
127
|
+
}
|
93
128
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
}
|
129
|
+
namespacedQuery.append(query.subSequence(xpathFunctionCalls.start(), xpathFunctionCalls.end()));
|
130
|
+
jchar = xpathFunctionCalls.end();
|
131
|
+
}
|
98
132
|
|
99
|
-
|
100
|
-
|
133
|
+
if (jchar < query.length() - 1) {
|
134
|
+
namespacedQuery.append(query.subSequence(jchar, query.length()));
|
135
|
+
}
|
136
|
+
query = namespacedQuery.toString();
|
101
137
|
}
|
102
138
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
139
|
+
return node_set(context, query, handler);
|
140
|
+
}
|
141
|
+
|
142
|
+
@JRubyMethod
|
143
|
+
public IRubyObject
|
144
|
+
evaluate(ThreadContext context, IRubyObject expr)
|
145
|
+
{
|
146
|
+
return this.evaluate(context, expr, context.getRuntime().getNil());
|
147
|
+
}
|
148
|
+
|
149
|
+
private final NokogiriNamespaceContext nsContext = NokogiriNamespaceContext.create();
|
150
|
+
|
151
|
+
@JRubyMethod
|
152
|
+
public IRubyObject
|
153
|
+
register_ns(IRubyObject prefix, IRubyObject uri)
|
154
|
+
{
|
155
|
+
nsContext.registerNamespace(prefix.asJavaString(), uri.asJavaString());
|
156
|
+
return this;
|
157
|
+
}
|
158
|
+
|
159
|
+
private NokogiriXPathVariableResolver variableResolver; // binds (if any)
|
160
|
+
|
161
|
+
@JRubyMethod
|
162
|
+
public IRubyObject
|
163
|
+
register_variable(IRubyObject name, IRubyObject value)
|
164
|
+
{
|
165
|
+
NokogiriXPathVariableResolver variableResolver = this.variableResolver;
|
166
|
+
if (variableResolver == null) {
|
167
|
+
variableResolver = NokogiriXPathVariableResolver.create();
|
168
|
+
this.variableResolver = variableResolver;
|
111
169
|
}
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
//
|
127
|
-
// The user has passed in a handler, but isn't using the `nokogiri:` prefix as
|
128
|
-
// instructed in JRuby land, so let's try to be clever and rewrite the query, inserting
|
129
|
-
// the nokogiri namespace where appropriate.
|
130
|
-
//
|
131
|
-
StringBuilder namespacedQuery = new StringBuilder();
|
132
|
-
int jchar = 0;
|
133
|
-
|
134
|
-
// Find the methods on the handler object
|
135
|
-
Set<String> methodNames = handler.getMetaClass().getMethods().keySet();
|
136
|
-
|
137
|
-
// Find the function calls in the xpath query
|
138
|
-
Matcher xpathFunctionCalls = XPathFunctionCaptureRE.matcher(query);
|
139
|
-
|
140
|
-
while (xpathFunctionCalls.find()) {
|
141
|
-
namespacedQuery.append(query.subSequence(jchar, xpathFunctionCalls.start()));
|
142
|
-
jchar = xpathFunctionCalls.start();
|
143
|
-
|
144
|
-
if (methodNames.contains(xpathFunctionCalls.group())) {
|
145
|
-
namespacedQuery.append(NokogiriNamespaceContext.NOKOGIRI_PREFIX);
|
146
|
-
namespacedQuery.append(":");
|
147
|
-
}
|
148
|
-
|
149
|
-
namespacedQuery.append(query.subSequence(xpathFunctionCalls.start(), xpathFunctionCalls.end()));
|
150
|
-
jchar = xpathFunctionCalls.end();
|
151
|
-
}
|
152
|
-
|
153
|
-
if (jchar < query.length()-1) {
|
154
|
-
namespacedQuery.append(query.subSequence(jchar, query.length()));
|
155
|
-
}
|
156
|
-
query = namespacedQuery.toString();
|
157
|
-
}
|
158
|
-
|
159
|
-
return node_set(context, query, handler);
|
170
|
+
variableResolver.registerVariable(name.asJavaString(), value.asJavaString());
|
171
|
+
return this;
|
172
|
+
}
|
173
|
+
|
174
|
+
private IRubyObject
|
175
|
+
node_set(ThreadContext context, String expr, IRubyObject handler)
|
176
|
+
{
|
177
|
+
final NokogiriXPathFunctionResolver fnResolver = NokogiriXPathFunctionResolver.create(handler);
|
178
|
+
try {
|
179
|
+
return tryGetNodeSet(context, expr, fnResolver);
|
180
|
+
} catch (TransformerException ex) {
|
181
|
+
throw XmlSyntaxError.createXMLXPathSyntaxError(context.runtime,
|
182
|
+
(expr + ": " + ex.toString()),
|
183
|
+
ex).toThrowable();
|
160
184
|
}
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
185
|
+
}
|
186
|
+
|
187
|
+
private IRubyObject
|
188
|
+
tryGetNodeSet(ThreadContext context, String expr, NokogiriXPathFunctionResolver fnResolver) throws TransformerException
|
189
|
+
{
|
190
|
+
final Node contextNode = this.context.node;
|
191
|
+
|
192
|
+
final JAXPPrefixResolver prefixResolver = new JAXPPrefixResolver(nsContext);
|
193
|
+
XPath xpathInternal = new XPath(expr, null, prefixResolver, XPath.SELECT);
|
194
|
+
|
195
|
+
// We always need to have a ContextNode with Xalan XPath implementation
|
196
|
+
// To allow simple expression evaluation like 1+1 we are setting
|
197
|
+
// dummy Document as Context Node
|
198
|
+
final XObject xobj;
|
199
|
+
if (contextNode == null) {
|
200
|
+
xobj = xpathInternal.execute(getXPathContext(fnResolver), DTM.NULL, prefixResolver);
|
201
|
+
} else {
|
202
|
+
xobj = xpathInternal.execute(getXPathContext(fnResolver), contextNode, prefixResolver);
|
165
203
|
}
|
166
204
|
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
205
|
+
switch (xobj.getType()) {
|
206
|
+
case XObject.CLASS_BOOLEAN :
|
207
|
+
return context.runtime.newBoolean(xobj.bool());
|
208
|
+
case XObject.CLASS_NUMBER :
|
209
|
+
return context.runtime.newFloat(xobj.num());
|
210
|
+
case XObject.CLASS_NODESET :
|
211
|
+
IRubyObject[] nodes = nodeListToRubyArray(context.runtime, xobj.nodelist());
|
212
|
+
return XmlNodeSet.newNodeSet(context.runtime, nodes, this.context);
|
213
|
+
default :
|
214
|
+
return context.runtime.newString(xobj.str());
|
173
215
|
}
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
216
|
+
}
|
217
|
+
|
218
|
+
private XPathContext
|
219
|
+
getXPathContext(final NokogiriXPathFunctionResolver fnResolver)
|
220
|
+
{
|
221
|
+
Node doc = context.getNode().getOwnerDocument();
|
222
|
+
if (doc == null) { doc = context.getNode(); }
|
223
|
+
|
224
|
+
XPathContext xpathContext = (XPathContext) doc.getUserData(XPATH_CONTEXT);
|
225
|
+
|
226
|
+
if (xpathContext == null) {
|
227
|
+
xpathContext = newXPathContext(fnResolver);
|
228
|
+
if (variableResolver == null) {
|
229
|
+
// NOTE: only caching without variables - could be improved by more sophisticated caching
|
230
|
+
doc.setUserData(XPATH_CONTEXT, xpathContext, null);
|
231
|
+
}
|
232
|
+
} else {
|
233
|
+
Object owner = xpathContext.getOwnerObject();
|
234
|
+
if ((owner == null && fnResolver == null) ||
|
235
|
+
(owner instanceof JAXPExtensionsProvider && ((JAXPExtensionsProvider) owner).hasSameResolver(fnResolver))) {
|
236
|
+
// can be re-used assuming it has the same variable-stack (for now only cached if no variables)
|
237
|
+
if (variableResolver == null) { return xpathContext; }
|
238
|
+
}
|
239
|
+
xpathContext = newXPathContext(fnResolver); // otherwise we can not use the cached xpath-context
|
186
240
|
}
|
187
241
|
|
188
|
-
|
189
|
-
|
190
|
-
try {
|
191
|
-
return tryGetNodeSet(context, expr, fnResolver);
|
192
|
-
}
|
193
|
-
catch (TransformerException ex) {
|
194
|
-
throw XmlSyntaxError.createXMLXPathSyntaxError(context.runtime,
|
195
|
-
(expr + ": " + ex.toString()),
|
196
|
-
ex).toThrowable();
|
197
|
-
}
|
242
|
+
if (variableResolver != null) {
|
243
|
+
xpathContext.setVarStack(new JAXPVariableStack(variableResolver));
|
198
244
|
}
|
199
245
|
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
default : return context.runtime.newString(xobj.str());
|
222
|
-
}
|
246
|
+
return xpathContext;
|
247
|
+
}
|
248
|
+
|
249
|
+
private static XPathContext
|
250
|
+
newXPathContext(final NokogiriXPathFunctionResolver functionResolver)
|
251
|
+
{
|
252
|
+
if (functionResolver == null) { return new XPathContext(false); }
|
253
|
+
return new XPathContext(new JAXPExtensionsProvider(functionResolver), false);
|
254
|
+
}
|
255
|
+
|
256
|
+
private boolean
|
257
|
+
isContainsPrefix(final String str)
|
258
|
+
{
|
259
|
+
final StringBuilder prefix_ = new StringBuilder();
|
260
|
+
for (String prefix : nsContext.getAllPrefixes()) {
|
261
|
+
prefix_.setLength(0);
|
262
|
+
prefix_.ensureCapacity(prefix.length() + 1);
|
263
|
+
prefix_.append(prefix).append(':');
|
264
|
+
if (str.contains(prefix_)) { // prefix + ':'
|
265
|
+
return true;
|
266
|
+
}
|
223
267
|
}
|
268
|
+
return false;
|
269
|
+
}
|
224
270
|
|
225
|
-
|
226
|
-
|
227
|
-
if (doc == null) doc = context.getNode();
|
271
|
+
private static final class JAXPExtensionsProvider extends org.apache.xpath.jaxp.JAXPExtensionsProvider
|
272
|
+
{
|
228
273
|
|
229
|
-
|
230
|
-
|
231
|
-
if ( xpathContext == null ) {
|
232
|
-
xpathContext = newXPathContext(fnResolver);
|
233
|
-
if ( variableResolver == null ) {
|
234
|
-
// NOTE: only caching without variables - could be improved by more sophisticated caching
|
235
|
-
doc.setUserData(XPATH_CONTEXT, xpathContext, null);
|
236
|
-
}
|
237
|
-
}
|
238
|
-
else {
|
239
|
-
Object owner = xpathContext.getOwnerObject();
|
240
|
-
if ( ( owner == null && fnResolver == null ) ||
|
241
|
-
( owner instanceof JAXPExtensionsProvider && ((JAXPExtensionsProvider) owner).hasSameResolver(fnResolver) ) ) {
|
242
|
-
// can be re-used assuming it has the same variable-stack (for now only cached if no variables)
|
243
|
-
if ( variableResolver == null ) return xpathContext;
|
244
|
-
}
|
245
|
-
xpathContext = newXPathContext(fnResolver); // otherwise we can not use the cached xpath-context
|
246
|
-
}
|
247
|
-
|
248
|
-
if ( variableResolver != null ) {
|
249
|
-
xpathContext.setVarStack(new JAXPVariableStack(variableResolver));
|
250
|
-
}
|
274
|
+
final NokogiriXPathFunctionResolver resolver;
|
251
275
|
|
252
|
-
|
276
|
+
JAXPExtensionsProvider(NokogiriXPathFunctionResolver resolver)
|
277
|
+
{
|
278
|
+
super(resolver, false);
|
279
|
+
this.resolver = resolver;
|
253
280
|
}
|
254
281
|
|
255
|
-
|
256
|
-
|
257
|
-
|
282
|
+
//@Override
|
283
|
+
//public boolean equals(Object obj) {
|
284
|
+
// if (obj instanceof JAXPExtensionsProvider) {
|
285
|
+
// return hasSameResolver(((JAXPExtensionsProvider) obj).resolver);
|
286
|
+
// }
|
287
|
+
// return false;
|
288
|
+
//}
|
289
|
+
|
290
|
+
final boolean
|
291
|
+
hasSameResolver(final NokogiriXPathFunctionResolver resolver)
|
292
|
+
{
|
293
|
+
return resolver == this.resolver || resolver != null && (
|
294
|
+
resolver.getHandler() == null ? this.resolver.getHandler() == null : (
|
295
|
+
resolver.getHandler() == this.resolver.getHandler()
|
296
|
+
// resolver.getHandler().eql( this.resolver.getHandler() )
|
297
|
+
)
|
298
|
+
);
|
258
299
|
}
|
259
300
|
|
260
|
-
|
261
|
-
final StringBuilder prefix_ = new StringBuilder();
|
262
|
-
for ( String prefix : nsContext.getAllPrefixes() ) {
|
263
|
-
prefix_.setLength(0);
|
264
|
-
prefix_.ensureCapacity(prefix.length() + 1);
|
265
|
-
prefix_.append(prefix).append(':');
|
266
|
-
if ( str.contains(prefix_) ) { // prefix + ':'
|
267
|
-
return true;
|
268
|
-
}
|
269
|
-
}
|
270
|
-
return false;
|
271
|
-
}
|
272
|
-
|
273
|
-
private static final class JAXPExtensionsProvider extends org.apache.xpath.jaxp.JAXPExtensionsProvider {
|
274
|
-
|
275
|
-
final NokogiriXPathFunctionResolver resolver;
|
276
|
-
|
277
|
-
JAXPExtensionsProvider(NokogiriXPathFunctionResolver resolver) {
|
278
|
-
super(resolver, false);
|
279
|
-
this.resolver = resolver;
|
280
|
-
}
|
281
|
-
|
282
|
-
//@Override
|
283
|
-
//public boolean equals(Object obj) {
|
284
|
-
// if (obj instanceof JAXPExtensionsProvider) {
|
285
|
-
// return hasSameResolver(((JAXPExtensionsProvider) obj).resolver);
|
286
|
-
// }
|
287
|
-
// return false;
|
288
|
-
//}
|
289
|
-
|
290
|
-
final boolean hasSameResolver(final NokogiriXPathFunctionResolver resolver) {
|
291
|
-
return resolver == this.resolver || resolver != null && (
|
292
|
-
resolver.getHandler() == null ? this.resolver.getHandler() == null : (
|
293
|
-
resolver.getHandler() == this.resolver.getHandler()
|
294
|
-
// resolver.getHandler().eql( this.resolver.getHandler() )
|
295
|
-
)
|
296
|
-
);
|
297
|
-
}
|
298
|
-
|
299
|
-
}
|
301
|
+
}
|
300
302
|
|
301
303
|
}
|