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.

Files changed (142) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE-DEPENDENCIES.md +12 -12
  3. data/LICENSE.md +1 -1
  4. data/README.md +20 -15
  5. data/ext/java/nokogiri/EncodingHandler.java +78 -59
  6. data/ext/java/nokogiri/HtmlDocument.java +137 -114
  7. data/ext/java/nokogiri/HtmlElementDescription.java +104 -87
  8. data/ext/java/nokogiri/HtmlEntityLookup.java +31 -26
  9. data/ext/java/nokogiri/HtmlSaxParserContext.java +220 -192
  10. data/ext/java/nokogiri/HtmlSaxPushParser.java +164 -139
  11. data/ext/java/nokogiri/NokogiriService.java +597 -526
  12. data/ext/java/nokogiri/XmlAttr.java +120 -96
  13. data/ext/java/nokogiri/XmlAttributeDecl.java +97 -76
  14. data/ext/java/nokogiri/XmlCdata.java +35 -26
  15. data/ext/java/nokogiri/XmlComment.java +48 -37
  16. data/ext/java/nokogiri/XmlDocument.java +642 -540
  17. data/ext/java/nokogiri/XmlDocumentFragment.java +127 -107
  18. data/ext/java/nokogiri/XmlDtd.java +450 -384
  19. data/ext/java/nokogiri/XmlElement.java +25 -18
  20. data/ext/java/nokogiri/XmlElementContent.java +345 -286
  21. data/ext/java/nokogiri/XmlElementDecl.java +126 -95
  22. data/ext/java/nokogiri/XmlEntityDecl.java +121 -97
  23. data/ext/java/nokogiri/XmlEntityReference.java +51 -42
  24. data/ext/java/nokogiri/XmlNamespace.java +177 -145
  25. data/ext/java/nokogiri/XmlNode.java +1843 -1588
  26. data/ext/java/nokogiri/XmlNodeSet.java +361 -299
  27. data/ext/java/nokogiri/XmlProcessingInstruction.java +49 -39
  28. data/ext/java/nokogiri/XmlReader.java +513 -418
  29. data/ext/java/nokogiri/XmlRelaxng.java +91 -78
  30. data/ext/java/nokogiri/XmlSaxParserContext.java +330 -285
  31. data/ext/java/nokogiri/XmlSaxPushParser.java +229 -190
  32. data/ext/java/nokogiri/XmlSchema.java +328 -263
  33. data/ext/java/nokogiri/XmlSyntaxError.java +113 -83
  34. data/ext/java/nokogiri/XmlText.java +57 -46
  35. data/ext/java/nokogiri/XmlXpathContext.java +240 -206
  36. data/ext/java/nokogiri/XsltStylesheet.java +282 -239
  37. data/ext/java/nokogiri/internals/ClosedStreamException.java +5 -2
  38. data/ext/java/nokogiri/internals/HtmlDomParserContext.java +199 -168
  39. data/ext/java/nokogiri/internals/IgnoreSchemaErrorsErrorHandler.java +17 -10
  40. data/ext/java/nokogiri/internals/NokogiriBlockingQueueInputStream.java +43 -16
  41. data/ext/java/nokogiri/internals/NokogiriDomParser.java +65 -50
  42. data/ext/java/nokogiri/internals/NokogiriEntityResolver.java +107 -88
  43. data/ext/java/nokogiri/internals/NokogiriErrorHandler.java +25 -18
  44. data/ext/java/nokogiri/internals/NokogiriHandler.java +316 -254
  45. data/ext/java/nokogiri/internals/NokogiriHelpers.java +738 -622
  46. data/ext/java/nokogiri/internals/NokogiriNamespaceCache.java +186 -143
  47. data/ext/java/nokogiri/internals/NokogiriNamespaceContext.java +83 -68
  48. data/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler.java +66 -49
  49. data/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler4NekoHtml.java +86 -69
  50. data/ext/java/nokogiri/internals/NokogiriStrictErrorHandler.java +44 -29
  51. data/ext/java/nokogiri/internals/NokogiriXPathFunction.java +118 -101
  52. data/ext/java/nokogiri/internals/NokogiriXPathFunctionResolver.java +34 -24
  53. data/ext/java/nokogiri/internals/NokogiriXPathVariableResolver.java +25 -17
  54. data/ext/java/nokogiri/internals/NokogiriXsltErrorListener.java +57 -42
  55. data/ext/java/nokogiri/internals/ParserContext.java +206 -179
  56. data/ext/java/nokogiri/internals/ReaderNode.java +478 -371
  57. data/ext/java/nokogiri/internals/SaveContextVisitor.java +822 -707
  58. data/ext/java/nokogiri/internals/SchemaErrorHandler.java +28 -19
  59. data/ext/java/nokogiri/internals/XalanDTMManagerPatch.java +129 -123
  60. data/ext/java/nokogiri/internals/XmlDeclHandler.java +5 -4
  61. data/ext/java/nokogiri/internals/XmlDomParserContext.java +208 -177
  62. data/ext/java/nokogiri/internals/XmlSaxParser.java +24 -17
  63. data/ext/java/nokogiri/internals/c14n/AttrCompare.java +71 -68
  64. data/ext/java/nokogiri/internals/c14n/C14nHelper.java +137 -118
  65. data/ext/java/nokogiri/internals/c14n/CanonicalFilter.java +27 -21
  66. data/ext/java/nokogiri/internals/c14n/CanonicalizationException.java +74 -61
  67. data/ext/java/nokogiri/internals/c14n/Canonicalizer.java +230 -205
  68. data/ext/java/nokogiri/internals/c14n/Canonicalizer11.java +572 -547
  69. data/ext/java/nokogiri/internals/c14n/Canonicalizer11_OmitComments.java +17 -10
  70. data/ext/java/nokogiri/internals/c14n/Canonicalizer11_WithComments.java +17 -10
  71. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315.java +323 -302
  72. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315Excl.java +232 -219
  73. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315ExclOmitComments.java +22 -15
  74. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315ExclWithComments.java +23 -16
  75. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315OmitComments.java +23 -16
  76. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315WithComments.java +22 -15
  77. data/ext/java/nokogiri/internals/c14n/CanonicalizerBase.java +575 -545
  78. data/ext/java/nokogiri/internals/c14n/CanonicalizerPhysical.java +141 -120
  79. data/ext/java/nokogiri/internals/c14n/CanonicalizerSpi.java +39 -38
  80. data/ext/java/nokogiri/internals/c14n/Constants.java +13 -10
  81. data/ext/java/nokogiri/internals/c14n/ElementProxy.java +279 -247
  82. data/ext/java/nokogiri/internals/c14n/HelperNodeList.java +66 -53
  83. data/ext/java/nokogiri/internals/c14n/IgnoreAllErrorHandler.java +44 -37
  84. data/ext/java/nokogiri/internals/c14n/InclusiveNamespaces.java +135 -120
  85. data/ext/java/nokogiri/internals/c14n/InvalidCanonicalizerException.java +59 -48
  86. data/ext/java/nokogiri/internals/c14n/NameSpaceSymbTable.java +384 -334
  87. data/ext/java/nokogiri/internals/c14n/NodeFilter.java +25 -24
  88. data/ext/java/nokogiri/internals/c14n/UtfHelpper.java +151 -140
  89. data/ext/java/nokogiri/internals/c14n/XMLUtils.java +456 -423
  90. data/ext/java/nokogiri/internals/dom2dtm/DOM2DTM.java +1466 -1500
  91. data/ext/java/nokogiri/internals/dom2dtm/DOM2DTMdefaultNamespaceDeclarationNode.java +626 -570
  92. data/ext/nokogiri/depend +34 -474
  93. data/ext/nokogiri/extconf.rb +253 -183
  94. data/ext/nokogiri/html_document.c +10 -15
  95. data/ext/nokogiri/html_element_description.c +84 -71
  96. data/ext/nokogiri/html_entity_lookup.c +21 -16
  97. data/ext/nokogiri/html_sax_parser_context.c +66 -65
  98. data/ext/nokogiri/html_sax_push_parser.c +29 -27
  99. data/ext/nokogiri/libxml2_backwards_compat.c +121 -0
  100. data/ext/nokogiri/nokogiri.c +171 -63
  101. data/ext/nokogiri/test_global_handlers.c +3 -4
  102. data/ext/nokogiri/xml_attr.c +15 -15
  103. data/ext/nokogiri/xml_attribute_decl.c +18 -18
  104. data/ext/nokogiri/xml_cdata.c +13 -18
  105. data/ext/nokogiri/xml_comment.c +19 -26
  106. data/ext/nokogiri/xml_document.c +221 -164
  107. data/ext/nokogiri/xml_document_fragment.c +13 -15
  108. data/ext/nokogiri/xml_dtd.c +54 -48
  109. data/ext/nokogiri/xml_element_content.c +30 -27
  110. data/ext/nokogiri/xml_element_decl.c +22 -22
  111. data/ext/nokogiri/xml_encoding_handler.c +17 -11
  112. data/ext/nokogiri/xml_entity_decl.c +32 -30
  113. data/ext/nokogiri/xml_entity_reference.c +16 -18
  114. data/ext/nokogiri/xml_namespace.c +56 -49
  115. data/ext/nokogiri/xml_node.c +338 -286
  116. data/ext/nokogiri/xml_node_set.c +168 -156
  117. data/ext/nokogiri/xml_processing_instruction.c +17 -19
  118. data/ext/nokogiri/xml_reader.c +191 -157
  119. data/ext/nokogiri/xml_relax_ng.c +29 -23
  120. data/ext/nokogiri/xml_sax_parser.c +117 -112
  121. data/ext/nokogiri/xml_sax_parser_context.c +100 -85
  122. data/ext/nokogiri/xml_sax_push_parser.c +34 -27
  123. data/ext/nokogiri/xml_schema.c +48 -42
  124. data/ext/nokogiri/xml_syntax_error.c +21 -23
  125. data/ext/nokogiri/xml_text.c +13 -17
  126. data/ext/nokogiri/xml_xpath_context.c +134 -127
  127. data/ext/nokogiri/xslt_stylesheet.c +157 -157
  128. data/lib/nokogiri.rb +1 -22
  129. data/lib/nokogiri/css/parser.rb +1 -1
  130. data/lib/nokogiri/extension.rb +26 -0
  131. data/lib/nokogiri/html/document_fragment.rb +15 -15
  132. data/lib/nokogiri/nokogiri.jar +0 -0
  133. data/lib/nokogiri/version/constant.rb +1 -1
  134. data/lib/nokogiri/version/info.rb +31 -8
  135. data/lib/nokogiri/xml/document.rb +31 -11
  136. data/lib/nokogiri/xml/node.rb +38 -42
  137. data/lib/nokogiri/xml/reader.rb +2 -9
  138. data/lib/nokogiri/xml/xpath.rb +1 -3
  139. data/lib/nokogiri/xml/xpath/syntax_error.rb +1 -1
  140. metadata +7 -8
  141. data/ext/nokogiri/xml_io.c +0 -63
  142. 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
- private final Map<CacheKey, CacheEntry> cache; // pair of the index of a given key and entry
57
- private XmlNamespace defaultNamespace = null;
58
-
59
- public NokogiriNamespaceCache() {
60
- this.cache = new LinkedHashMap<CacheKey, CacheEntry>(4);
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
- public NokogiriNamespaceCache(NokogiriNamespaceCache cache) {
64
- this.cache = new LinkedHashMap<CacheKey, CacheEntry>(cache.size() + 2);
65
- this.cache.putAll(cache.cache);
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
- public XmlNamespace getDefault() {
69
- return defaultNamespace;
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
- public XmlNamespace get(String prefix, String href) {
73
- if (href == null) return null;
74
-
75
- CacheEntry value = cache.get(new CacheKey(prefix, href));
76
- return value == null ? null : value.namespace;
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
- public XmlNamespace get(Node node, String prefix) {
80
- if (prefix == null) return defaultNamespace;
81
- for (Map.Entry<CacheKey, CacheEntry> entry : cache.entrySet()) {
82
- if (entry.getKey().prefix.equals(prefix)) {
83
- if (entry.getValue().isOwner(node)) {
84
- return entry.getValue().namespace;
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
- return null;
170
+ }
89
171
  }
90
-
91
- public List<XmlNamespace> get(String prefix) {
92
- List<XmlNamespace> namespaces = new ArrayList<XmlNamespace>();
93
- if (prefix == null) {
94
- namespaces.add(defaultNamespace);
95
- return namespaces;
96
- }
97
- for (Map.Entry<CacheKey, CacheEntry> entry : cache.entrySet()) {
98
- if (entry.getKey().prefix.equals(prefix)) {
99
- namespaces.add(entry.getValue().namespace);
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
- public List<XmlNamespace> get(Node node) {
106
- List<XmlNamespace> namespaces = new ArrayList<XmlNamespace>();
107
- for (Map.Entry<CacheKey, CacheEntry> entry : cache.entrySet()) {
108
- if (entry.getValue().isOwner(node)) {
109
- namespaces.add(entry.getValue().namespace);
110
- }
111
- }
112
- return namespaces;
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
- public void put(XmlNamespace namespace, Node ownerNode) {
116
- String prefix = namespace.getPrefix();
117
- String href = namespace.getHref();
118
- if (href == null) return;
119
-
120
- CacheKey key = new CacheKey(prefix, href);
121
- if (cache.get(key) != null) return;
122
- cache.put(key, new CacheEntry(namespace, ownerNode));
123
- if ("".equals(prefix)) defaultNamespace = namespace;
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
- public void remove(Node ownerNode) {
127
- String prefix = ownerNode.getPrefix();
128
- String href = ownerNode.getNamespaceURI();
129
- if (href == null) return;
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
- public int size() {
135
- return cache.size();
222
+ @Override
223
+ public String
224
+ toString()
225
+ {
226
+ return '[' + prefix + ']' + href;
136
227
  }
228
+ }
137
229
 
138
- public void clear() {
139
- // removes namespace declarations from node
140
- for (CacheEntry entry : cache.values()) {
141
- NamedNodeMap attributes = entry.ownerNode.getAttributes();
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
- public void replaceNode(Node oldNode, Node newNode) {
154
- for (Map.Entry<CacheKey, CacheEntry> entry : cache.entrySet()) {
155
- if (entry.getValue().isOwner(oldNode)) {
156
- entry.getValue().replaceOwner(newNode);
157
- }
158
- }
235
+ CacheEntry(XmlNamespace namespace, Node ownerNode)
236
+ {
237
+ this.namespace = namespace;
238
+ this.ownerNode = ownerNode;
159
239
  }
160
240
 
161
- @Override
162
- public String toString() {
163
- return getClass().getName() + '@' + Integer.toHexString(hashCode()) + '(' + cache + "default=" + defaultNamespace + ')';
241
+ boolean
242
+ isOwner(Node node)
243
+ {
244
+ return ownerNode.isSameNode(node);
164
245
  }
165
246
 
166
- private static class CacheKey {
167
- final String prefix;
168
- final String href;
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
- private static class CacheEntry {
196
- final XmlNamespace namespace;
197
- private Node ownerNode;
198
-
199
- CacheEntry(XmlNamespace namespace, Node ownerNode) {
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
- * these constants have matching declarations in
55
- * ext/nokogiri/xml_xpath_context.c
56
- */
57
- public static final String NOKOGIRI_PREFIX = "nokogiri";
58
- public static final String NOKOGIRI_URI = "http://www.nokogiri.org/default_ns/ruby/extensions_functions";
59
-
60
- public static final String NOKOGIRI_BUILTIN_PREFIX = "nokogiri-builtin";
61
- public static final String NOKOGIRI_BUILTIN_URI = "https://www.nokogiri.org/default_ns/ruby/builtins";
62
-
63
- private final Map<String,String> register;
64
-
65
- public static NokogiriNamespaceContext create() {
66
- return new NokogiriNamespaceContext();
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
- private NokogiriNamespaceContext() {
70
- register = new HashMap<String, String>(6, 1);
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
- public String getNamespaceURI(String prefix) {
78
- if (prefix == null) {
79
- throw new IllegalArgumentException();
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
- public String getPrefix(String uri) {
95
- if (uri == null) {
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
- public Iterator<String> getPrefixes(String uri) {
108
- Set<Entry<String, String>> entries = register.entrySet();
109
- ArrayList<String> list = new ArrayList<String>(entries.size());
110
- for (Entry<String, String> entry : entries) {
111
- if (uri.equals(entry.getValue())) {
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
- public Set<String> getAllPrefixes() {
119
- return register.keySet();
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
- public void registerNamespace(String prefix, String uri) {
123
- if ("xmlns".equals(prefix)) prefix = "";
124
- register.put(prefix, uri);
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
  }