nokogiri 1.11.1-java → 1.11.2-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/LICENSE-DEPENDENCIES.md +12 -12
- data/LICENSE.md +1 -1
- data/README.md +20 -15
- data/ext/java/nokogiri/EncodingHandler.java +78 -59
- data/ext/java/nokogiri/HtmlDocument.java +137 -114
- data/ext/java/nokogiri/HtmlElementDescription.java +104 -87
- data/ext/java/nokogiri/HtmlEntityLookup.java +31 -26
- data/ext/java/nokogiri/HtmlSaxParserContext.java +220 -192
- data/ext/java/nokogiri/HtmlSaxPushParser.java +164 -139
- data/ext/java/nokogiri/NokogiriService.java +597 -526
- data/ext/java/nokogiri/XmlAttr.java +120 -96
- data/ext/java/nokogiri/XmlAttributeDecl.java +97 -76
- data/ext/java/nokogiri/XmlCdata.java +35 -26
- data/ext/java/nokogiri/XmlComment.java +48 -37
- data/ext/java/nokogiri/XmlDocument.java +642 -540
- data/ext/java/nokogiri/XmlDocumentFragment.java +127 -107
- data/ext/java/nokogiri/XmlDtd.java +450 -384
- data/ext/java/nokogiri/XmlElement.java +25 -18
- data/ext/java/nokogiri/XmlElementContent.java +345 -286
- data/ext/java/nokogiri/XmlElementDecl.java +126 -95
- data/ext/java/nokogiri/XmlEntityDecl.java +121 -97
- data/ext/java/nokogiri/XmlEntityReference.java +51 -42
- data/ext/java/nokogiri/XmlNamespace.java +177 -145
- data/ext/java/nokogiri/XmlNode.java +1843 -1588
- data/ext/java/nokogiri/XmlNodeSet.java +361 -299
- data/ext/java/nokogiri/XmlProcessingInstruction.java +49 -39
- data/ext/java/nokogiri/XmlReader.java +513 -418
- data/ext/java/nokogiri/XmlRelaxng.java +91 -78
- data/ext/java/nokogiri/XmlSaxParserContext.java +330 -285
- data/ext/java/nokogiri/XmlSaxPushParser.java +229 -190
- data/ext/java/nokogiri/XmlSchema.java +328 -263
- data/ext/java/nokogiri/XmlSyntaxError.java +113 -83
- data/ext/java/nokogiri/XmlText.java +57 -46
- data/ext/java/nokogiri/XmlXpathContext.java +240 -206
- data/ext/java/nokogiri/XsltStylesheet.java +282 -239
- data/ext/java/nokogiri/internals/ClosedStreamException.java +5 -2
- data/ext/java/nokogiri/internals/HtmlDomParserContext.java +199 -168
- 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 +65 -50
- data/ext/java/nokogiri/internals/NokogiriEntityResolver.java +107 -88
- data/ext/java/nokogiri/internals/NokogiriErrorHandler.java +25 -18
- data/ext/java/nokogiri/internals/NokogiriHandler.java +316 -254
- data/ext/java/nokogiri/internals/NokogiriHelpers.java +738 -622
- data/ext/java/nokogiri/internals/NokogiriNamespaceCache.java +186 -143
- data/ext/java/nokogiri/internals/NokogiriNamespaceContext.java +83 -68
- data/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler.java +66 -49
- data/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler4NekoHtml.java +86 -69
- data/ext/java/nokogiri/internals/NokogiriStrictErrorHandler.java +44 -29
- data/ext/java/nokogiri/internals/NokogiriXPathFunction.java +118 -101
- data/ext/java/nokogiri/internals/NokogiriXPathFunctionResolver.java +34 -24
- data/ext/java/nokogiri/internals/NokogiriXPathVariableResolver.java +25 -17
- data/ext/java/nokogiri/internals/NokogiriXsltErrorListener.java +57 -42
- data/ext/java/nokogiri/internals/ParserContext.java +206 -179
- data/ext/java/nokogiri/internals/ReaderNode.java +478 -371
- data/ext/java/nokogiri/internals/SaveContextVisitor.java +822 -707
- data/ext/java/nokogiri/internals/SchemaErrorHandler.java +28 -19
- data/ext/java/nokogiri/internals/XalanDTMManagerPatch.java +129 -123
- data/ext/java/nokogiri/internals/XmlDeclHandler.java +5 -4
- data/ext/java/nokogiri/internals/XmlDomParserContext.java +208 -177
- data/ext/java/nokogiri/internals/XmlSaxParser.java +24 -17
- 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 -570
- data/ext/nokogiri/depend +34 -474
- data/ext/nokogiri/extconf.rb +253 -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 +66 -65
- data/ext/nokogiri/html_sax_push_parser.c +29 -27
- data/ext/nokogiri/libxml2_backwards_compat.c +121 -0
- data/ext/nokogiri/nokogiri.c +171 -63
- data/ext/nokogiri/test_global_handlers.c +3 -4
- 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 +221 -164
- 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 +338 -286
- 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 +100 -85
- data/ext/nokogiri/xml_sax_push_parser.c +34 -27
- data/ext/nokogiri/xml_schema.c +48 -42
- data/ext/nokogiri/xml_syntax_error.c +21 -23
- 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 +1 -22
- 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 +31 -8
- data/lib/nokogiri/xml/document.rb +31 -11
- data/lib/nokogiri/xml/node.rb +38 -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 +7 -8
- data/ext/nokogiri/xml_io.c +0 -63
- data/ext/nokogiri/xml_libxml2_hacks.c +0 -112
@@ -17,10 +17,10 @@
|
|
17
17
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
18
18
|
* permit persons to whom the Software is furnished to do so, subject to
|
19
19
|
* the following conditions:
|
20
|
-
*
|
20
|
+
*
|
21
21
|
* The above copyright notice and this permission notice shall be
|
22
22
|
* included in all copies or substantial portions of the Software.
|
23
|
-
*
|
23
|
+
*
|
24
24
|
* THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
25
25
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
26
26
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
@@ -47,171 +47,214 @@ import org.w3c.dom.Node;
|
|
47
47
|
|
48
48
|
/**
|
49
49
|
* Cache of namespaces of each node. XmlDocument has one cache of this class.
|
50
|
-
*
|
50
|
+
*
|
51
51
|
* @author sergio
|
52
52
|
* @author Yoko Harada <yokolet@gmail.com>
|
53
53
|
*/
|
54
|
-
public class NokogiriNamespaceCache
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
54
|
+
public class NokogiriNamespaceCache
|
55
|
+
{
|
56
|
+
|
57
|
+
private final Map<CacheKey, CacheEntry> cache; // pair of the index of a given key and entry
|
58
|
+
private XmlNamespace defaultNamespace = null;
|
59
|
+
|
60
|
+
public
|
61
|
+
NokogiriNamespaceCache()
|
62
|
+
{
|
63
|
+
this.cache = new LinkedHashMap<CacheKey, CacheEntry>(4);
|
64
|
+
}
|
65
|
+
|
66
|
+
public
|
67
|
+
NokogiriNamespaceCache(NokogiriNamespaceCache cache)
|
68
|
+
{
|
69
|
+
this.cache = new LinkedHashMap<CacheKey, CacheEntry>(cache.size() + 2);
|
70
|
+
this.cache.putAll(cache.cache);
|
71
|
+
}
|
72
|
+
|
73
|
+
public XmlNamespace
|
74
|
+
getDefault()
|
75
|
+
{
|
76
|
+
return defaultNamespace;
|
77
|
+
}
|
78
|
+
|
79
|
+
public XmlNamespace
|
80
|
+
get(String prefix, String href)
|
81
|
+
{
|
82
|
+
if (href == null) { return null; }
|
83
|
+
|
84
|
+
CacheEntry value = cache.get(new CacheKey(prefix, href));
|
85
|
+
return value == null ? null : value.namespace;
|
86
|
+
}
|
87
|
+
|
88
|
+
public XmlNamespace
|
89
|
+
get(Node node, String prefix)
|
90
|
+
{
|
91
|
+
if (prefix == null) { return defaultNamespace; }
|
92
|
+
for (Map.Entry<CacheKey, CacheEntry> entry : cache.entrySet()) {
|
93
|
+
if (entry.getKey().prefix.equals(prefix)) {
|
94
|
+
if (entry.getValue().isOwner(node)) {
|
95
|
+
return entry.getValue().namespace;
|
96
|
+
}
|
97
|
+
}
|
61
98
|
}
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
99
|
+
return null;
|
100
|
+
}
|
101
|
+
|
102
|
+
public List<XmlNamespace>
|
103
|
+
get(String prefix)
|
104
|
+
{
|
105
|
+
List<XmlNamespace> namespaces = new ArrayList<XmlNamespace>();
|
106
|
+
if (prefix == null) {
|
107
|
+
namespaces.add(defaultNamespace);
|
108
|
+
return namespaces;
|
66
109
|
}
|
67
|
-
|
68
|
-
|
69
|
-
|
110
|
+
for (Map.Entry<CacheKey, CacheEntry> entry : cache.entrySet()) {
|
111
|
+
if (entry.getKey().prefix.equals(prefix)) {
|
112
|
+
namespaces.add(entry.getValue().namespace);
|
113
|
+
}
|
70
114
|
}
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
115
|
+
return namespaces;
|
116
|
+
}
|
117
|
+
|
118
|
+
public List<XmlNamespace>
|
119
|
+
get(Node node)
|
120
|
+
{
|
121
|
+
List<XmlNamespace> namespaces = new ArrayList<XmlNamespace>();
|
122
|
+
for (Map.Entry<CacheKey, CacheEntry> entry : cache.entrySet()) {
|
123
|
+
if (entry.getValue().isOwner(node)) {
|
124
|
+
namespaces.add(entry.getValue().namespace);
|
125
|
+
}
|
77
126
|
}
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
127
|
+
return namespaces;
|
128
|
+
}
|
129
|
+
|
130
|
+
public void
|
131
|
+
put(XmlNamespace namespace, Node ownerNode)
|
132
|
+
{
|
133
|
+
String prefix = namespace.getPrefix();
|
134
|
+
String href = namespace.getHref();
|
135
|
+
if (href == null) { return; }
|
136
|
+
|
137
|
+
CacheKey key = new CacheKey(prefix, href);
|
138
|
+
if (cache.get(key) != null) { return; }
|
139
|
+
cache.put(key, new CacheEntry(namespace, ownerNode));
|
140
|
+
if ("".equals(prefix)) { defaultNamespace = namespace; }
|
141
|
+
}
|
142
|
+
|
143
|
+
public void
|
144
|
+
remove(Node ownerNode)
|
145
|
+
{
|
146
|
+
String prefix = ownerNode.getPrefix();
|
147
|
+
String href = ownerNode.getNamespaceURI();
|
148
|
+
if (href == null) { return; }
|
149
|
+
|
150
|
+
cache.remove(new CacheKey(prefix, href));
|
151
|
+
}
|
152
|
+
|
153
|
+
public int
|
154
|
+
size()
|
155
|
+
{
|
156
|
+
return cache.size();
|
157
|
+
}
|
158
|
+
|
159
|
+
public void
|
160
|
+
clear()
|
161
|
+
{
|
162
|
+
// removes namespace declarations from node
|
163
|
+
for (CacheEntry entry : cache.values()) {
|
164
|
+
NamedNodeMap attributes = entry.ownerNode.getAttributes();
|
165
|
+
for (int j = 0; j < attributes.getLength(); j++) {
|
166
|
+
String name = ((Attr) attributes.item(j)).getName();
|
167
|
+
if (isNamespace(name)) {
|
168
|
+
attributes.removeNamedItem(name);
|
87
169
|
}
|
88
|
-
|
170
|
+
}
|
89
171
|
}
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
}
|
102
|
-
return namespaces;
|
172
|
+
cache.clear();
|
173
|
+
defaultNamespace = null;
|
174
|
+
}
|
175
|
+
|
176
|
+
public void
|
177
|
+
replaceNode(Node oldNode, Node newNode)
|
178
|
+
{
|
179
|
+
for (Map.Entry<CacheKey, CacheEntry> entry : cache.entrySet()) {
|
180
|
+
if (entry.getValue().isOwner(oldNode)) {
|
181
|
+
entry.getValue().replaceOwner(newNode);
|
182
|
+
}
|
103
183
|
}
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
184
|
+
}
|
185
|
+
|
186
|
+
@Override
|
187
|
+
public String
|
188
|
+
toString()
|
189
|
+
{
|
190
|
+
return getClass().getName() + '@' + Integer.toHexString(hashCode()) + '(' + cache + "default=" + defaultNamespace + ')';
|
191
|
+
}
|
192
|
+
|
193
|
+
private static class CacheKey
|
194
|
+
{
|
195
|
+
final String prefix;
|
196
|
+
final String href;
|
197
|
+
|
198
|
+
CacheKey(String prefix, String href)
|
199
|
+
{
|
200
|
+
this.prefix = prefix;
|
201
|
+
this.href = href;
|
113
202
|
}
|
114
203
|
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
CacheKey
|
121
|
-
|
122
|
-
|
123
|
-
|
204
|
+
@Override
|
205
|
+
public boolean
|
206
|
+
equals(final Object obj)
|
207
|
+
{
|
208
|
+
if (obj instanceof CacheKey) {
|
209
|
+
CacheKey that = (CacheKey) obj;
|
210
|
+
return prefix == null ? that.prefix == null : prefix.equals(that.prefix) && href.equals(that.href);
|
211
|
+
}
|
212
|
+
return false;
|
124
213
|
}
|
125
214
|
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
cache.remove(new CacheKey(prefix, href));
|
215
|
+
@Override
|
216
|
+
public int
|
217
|
+
hashCode()
|
218
|
+
{
|
219
|
+
return (prefix == null ? 0 : prefix.hashCode()) + 37 * href.hashCode();
|
132
220
|
}
|
133
221
|
|
134
|
-
|
135
|
-
|
222
|
+
@Override
|
223
|
+
public String
|
224
|
+
toString()
|
225
|
+
{
|
226
|
+
return '[' + prefix + ']' + href;
|
136
227
|
}
|
228
|
+
}
|
137
229
|
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
for (int j=0; j<attributes.getLength(); j++) {
|
143
|
-
String name = ((Attr) attributes.item(j)).getName();
|
144
|
-
if (isNamespace(name)) {
|
145
|
-
attributes.removeNamedItem(name);
|
146
|
-
}
|
147
|
-
}
|
148
|
-
}
|
149
|
-
cache.clear();
|
150
|
-
defaultNamespace = null;
|
151
|
-
}
|
230
|
+
private static class CacheEntry
|
231
|
+
{
|
232
|
+
final XmlNamespace namespace;
|
233
|
+
private Node ownerNode;
|
152
234
|
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
}
|
158
|
-
}
|
235
|
+
CacheEntry(XmlNamespace namespace, Node ownerNode)
|
236
|
+
{
|
237
|
+
this.namespace = namespace;
|
238
|
+
this.ownerNode = ownerNode;
|
159
239
|
}
|
160
240
|
|
161
|
-
|
162
|
-
|
163
|
-
|
241
|
+
boolean
|
242
|
+
isOwner(Node node)
|
243
|
+
{
|
244
|
+
return ownerNode.isSameNode(node);
|
164
245
|
}
|
165
246
|
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
CacheKey(String prefix, String href) {
|
171
|
-
this.prefix = prefix;
|
172
|
-
this.href = href;
|
173
|
-
}
|
174
|
-
|
175
|
-
@Override
|
176
|
-
public boolean equals(final Object obj) {
|
177
|
-
if (obj instanceof CacheKey) {
|
178
|
-
CacheKey that = (CacheKey) obj;
|
179
|
-
return prefix == null ? that.prefix == null : prefix.equals(that.prefix) && href.equals(that.href);
|
180
|
-
}
|
181
|
-
return false;
|
182
|
-
}
|
183
|
-
|
184
|
-
@Override
|
185
|
-
public int hashCode() {
|
186
|
-
return (prefix == null ? 0 : prefix.hashCode()) + 37 * href.hashCode();
|
187
|
-
}
|
188
|
-
|
189
|
-
@Override
|
190
|
-
public String toString() {
|
191
|
-
return '[' + prefix + ']' + href;
|
192
|
-
}
|
247
|
+
void
|
248
|
+
replaceOwner(Node newNode)
|
249
|
+
{
|
250
|
+
this.ownerNode = newNode;
|
193
251
|
}
|
194
252
|
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
this.namespace = namespace;
|
201
|
-
this.ownerNode = ownerNode;
|
202
|
-
}
|
203
|
-
|
204
|
-
boolean isOwner(Node node) {
|
205
|
-
return ownerNode.isSameNode(node);
|
206
|
-
}
|
207
|
-
|
208
|
-
void replaceOwner(Node newNode) {
|
209
|
-
this.ownerNode = newNode;
|
210
|
-
}
|
211
|
-
|
212
|
-
@Override
|
213
|
-
public String toString() {
|
214
|
-
return namespace.toString();
|
215
|
-
}
|
253
|
+
@Override
|
254
|
+
public String
|
255
|
+
toString()
|
256
|
+
{
|
257
|
+
return namespace.toString();
|
216
258
|
}
|
259
|
+
}
|
217
260
|
}
|
@@ -17,10 +17,10 @@
|
|
17
17
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
18
18
|
* permit persons to whom the Software is furnished to do so, subject to
|
19
19
|
* the following conditions:
|
20
|
-
*
|
20
|
+
*
|
21
21
|
* The above copyright notice and this permission notice shall be
|
22
22
|
* included in all copies or substantial portions of the Software.
|
23
|
-
*
|
23
|
+
*
|
24
24
|
* THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
25
25
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
26
26
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
@@ -44,84 +44,99 @@ import javax.xml.namespace.NamespaceContext;
|
|
44
44
|
|
45
45
|
/**
|
46
46
|
* Holder of each node's namespace.
|
47
|
-
*
|
47
|
+
*
|
48
48
|
* @author Yoko Harada <yokolet@gmail.com>
|
49
49
|
*
|
50
50
|
*/
|
51
|
-
public final class NokogiriNamespaceContext implements NamespaceContext
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
51
|
+
public final class NokogiriNamespaceContext implements NamespaceContext
|
52
|
+
{
|
53
|
+
|
54
|
+
/*
|
55
|
+
* these constants have matching declarations in
|
56
|
+
* ext/nokogiri/xml_xpath_context.c
|
57
|
+
*/
|
58
|
+
public static final String NOKOGIRI_PREFIX = "nokogiri";
|
59
|
+
public static final String NOKOGIRI_URI = "http://www.nokogiri.org/default_ns/ruby/extensions_functions";
|
60
|
+
|
61
|
+
public static final String NOKOGIRI_BUILTIN_PREFIX = "nokogiri-builtin";
|
62
|
+
public static final String NOKOGIRI_BUILTIN_URI = "https://www.nokogiri.org/default_ns/ruby/builtins";
|
63
|
+
|
64
|
+
private final Map<String, String> register;
|
65
|
+
|
66
|
+
public static NokogiriNamespaceContext
|
67
|
+
create()
|
68
|
+
{
|
69
|
+
return new NokogiriNamespaceContext();
|
70
|
+
}
|
71
|
+
|
72
|
+
private
|
73
|
+
NokogiriNamespaceContext()
|
74
|
+
{
|
75
|
+
register = new HashMap<String, String>(6, 1);
|
76
|
+
register.put(NOKOGIRI_PREFIX, NOKOGIRI_URI);
|
77
|
+
register.put(NOKOGIRI_BUILTIN_PREFIX, NOKOGIRI_BUILTIN_URI);
|
78
|
+
register.put("xml", "http://www.w3.org/XML/1998/namespace");
|
79
|
+
register.put("xhtml", "http://www.w3.org/1999/xhtml");
|
80
|
+
}
|
81
|
+
|
82
|
+
public String
|
83
|
+
getNamespaceURI(String prefix)
|
84
|
+
{
|
85
|
+
if (prefix == null) {
|
86
|
+
throw new IllegalArgumentException();
|
67
87
|
}
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
register.put(NOKOGIRI_PREFIX, NOKOGIRI_URI);
|
72
|
-
register.put(NOKOGIRI_BUILTIN_PREFIX, NOKOGIRI_BUILTIN_URI);
|
73
|
-
register.put("xml", "http://www.w3.org/XML/1998/namespace");
|
74
|
-
register.put("xhtml", "http://www.w3.org/1999/xhtml");
|
88
|
+
String uri = this.register.get(prefix);
|
89
|
+
if (uri != null) {
|
90
|
+
return uri;
|
75
91
|
}
|
76
92
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
}
|
81
|
-
String uri = this.register.get(prefix);
|
82
|
-
if (uri != null) {
|
83
|
-
return uri;
|
84
|
-
}
|
85
|
-
|
86
|
-
if (prefix.equals(XMLConstants.XMLNS_ATTRIBUTE)) {
|
87
|
-
uri = this.register.get(XMLConstants.XMLNS_ATTRIBUTE);
|
88
|
-
return (uri == null) ? XMLConstants.XMLNS_ATTRIBUTE_NS_URI : uri;
|
89
|
-
}
|
90
|
-
|
91
|
-
return XMLConstants.NULL_NS_URI;
|
93
|
+
if (prefix.equals(XMLConstants.XMLNS_ATTRIBUTE)) {
|
94
|
+
uri = this.register.get(XMLConstants.XMLNS_ATTRIBUTE);
|
95
|
+
return (uri == null) ? XMLConstants.XMLNS_ATTRIBUTE_NS_URI : uri;
|
92
96
|
}
|
93
97
|
|
94
|
-
|
95
|
-
|
96
|
-
throw new IllegalArgumentException("uri is null");
|
97
|
-
}
|
98
|
-
Set<Entry<String, String>> entries = register.entrySet();
|
99
|
-
for (Entry<String, String> entry : entries) {
|
100
|
-
if (uri.equals(entry.getValue())) {
|
101
|
-
return entry.getKey();
|
102
|
-
}
|
103
|
-
}
|
104
|
-
return null;
|
105
|
-
}
|
98
|
+
return XMLConstants.NULL_NS_URI;
|
99
|
+
}
|
106
100
|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
list.add(entry.getKey());
|
113
|
-
}
|
114
|
-
}
|
115
|
-
return list.iterator();
|
101
|
+
public String
|
102
|
+
getPrefix(String uri)
|
103
|
+
{
|
104
|
+
if (uri == null) {
|
105
|
+
throw new IllegalArgumentException("uri is null");
|
116
106
|
}
|
117
|
-
|
118
|
-
|
119
|
-
|
107
|
+
Set<Entry<String, String>> entries = register.entrySet();
|
108
|
+
for (Entry<String, String> entry : entries) {
|
109
|
+
if (uri.equals(entry.getValue())) {
|
110
|
+
return entry.getKey();
|
111
|
+
}
|
120
112
|
}
|
113
|
+
return null;
|
114
|
+
}
|
121
115
|
|
122
|
-
|
123
|
-
|
124
|
-
|
116
|
+
public Iterator<String>
|
117
|
+
getPrefixes(String uri)
|
118
|
+
{
|
119
|
+
Set<Entry<String, String>> entries = register.entrySet();
|
120
|
+
ArrayList<String> list = new ArrayList<String>(entries.size());
|
121
|
+
for (Entry<String, String> entry : entries) {
|
122
|
+
if (uri.equals(entry.getValue())) {
|
123
|
+
list.add(entry.getKey());
|
124
|
+
}
|
125
125
|
}
|
126
|
+
return list.iterator();
|
127
|
+
}
|
128
|
+
|
129
|
+
public Set<String>
|
130
|
+
getAllPrefixes()
|
131
|
+
{
|
132
|
+
return register.keySet();
|
133
|
+
}
|
134
|
+
|
135
|
+
public void
|
136
|
+
registerNamespace(String prefix, String uri)
|
137
|
+
{
|
138
|
+
if ("xmlns".equals(prefix)) { prefix = ""; }
|
139
|
+
register.put(prefix, uri);
|
140
|
+
}
|
126
141
|
|
127
142
|
}
|