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
@@ -62,427 +62,534 @@ import static nokogiri.internals.NokogiriHelpers.*;
|
|
62
62
|
* @author Yoko Harada <yokolet@gmail.com>
|
63
63
|
*
|
64
64
|
*/
|
65
|
-
public abstract class ReaderNode
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
65
|
+
public abstract class ReaderNode
|
66
|
+
{
|
67
|
+
|
68
|
+
final Ruby ruby;
|
69
|
+
public ReaderAttributeList attributeList;
|
70
|
+
public Map<String, String> namespaces;
|
71
|
+
public int depth, nodeType;
|
72
|
+
public String lang, localName, xmlBase, prefix, name, uri, value, xmlVersion = "1.0";
|
73
|
+
public int startOffset, endOffset;
|
74
|
+
public boolean hasChildren = false;
|
75
|
+
private Document document = null;
|
76
|
+
|
77
|
+
protected
|
78
|
+
ReaderNode(final Ruby runtime)
|
79
|
+
{
|
80
|
+
this.ruby = runtime;
|
81
|
+
}
|
82
|
+
|
83
|
+
public abstract String getString();
|
84
|
+
|
85
|
+
public IRubyObject
|
86
|
+
getAttributeByIndex(IRubyObject index)
|
87
|
+
{
|
88
|
+
if (index.isNil()) { return index; }
|
89
|
+
|
90
|
+
long i = index.convertToInteger().getLongValue();
|
91
|
+
if (i > Integer.MAX_VALUE) {
|
92
|
+
throw ruby.newArgumentError("value too long to be an array index");
|
78
93
|
}
|
79
94
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
95
|
+
if (attributeList == null) { return ruby.getNil(); }
|
96
|
+
if (i < 0 || attributeList.length <= i) { return ruby.getNil(); }
|
97
|
+
return stringOrBlank(ruby, attributeList.values.get(((Long)i).intValue()));
|
98
|
+
}
|
99
|
+
|
100
|
+
public IRubyObject
|
101
|
+
getAttributeByName(IRubyObject name)
|
102
|
+
{
|
103
|
+
if (attributeList == null) { return ruby.getNil(); }
|
104
|
+
String value = attributeList.getByName(rubyStringToString(name));
|
105
|
+
return stringOrNil(ruby, value);
|
106
|
+
}
|
107
|
+
|
108
|
+
public IRubyObject
|
109
|
+
getAttributeByName(String name)
|
110
|
+
{
|
111
|
+
if (attributeList == null) { return ruby.getNil(); }
|
112
|
+
String value = attributeList.getByName(name);
|
113
|
+
return stringOrNil(ruby, value);
|
114
|
+
}
|
115
|
+
|
116
|
+
public IRubyObject
|
117
|
+
getAttributeCount()
|
118
|
+
{
|
119
|
+
if (attributeList == null) { return ruby.newFixnum(0); }
|
120
|
+
return ruby.newFixnum(attributeList.length);
|
121
|
+
}
|
122
|
+
|
123
|
+
public IRubyObject
|
124
|
+
getAttributesNodes()
|
125
|
+
{
|
126
|
+
RubyArray array = RubyArray.newArray(ruby);
|
127
|
+
if (attributeList != null && attributeList.length > 0) {
|
128
|
+
if (document == null) {
|
129
|
+
document = XmlDocument.createNewDocument(ruby);
|
130
|
+
}
|
131
|
+
for (int i = 0; i < attributeList.length; i++) {
|
132
|
+
if (!isNamespace(attributeList.names.get(i))) {
|
133
|
+
Attr attr = document.createAttributeNS(attributeList.namespaces.get(i), attributeList.names.get(i));
|
134
|
+
attr.setValue(attributeList.values.get(i));
|
135
|
+
XmlAttr xmlAttr = new XmlAttr(ruby, attr);
|
136
|
+
array.append(xmlAttr);
|
88
137
|
}
|
89
|
-
|
90
|
-
if (attributeList == null) return ruby.getNil();
|
91
|
-
if (i<0 || attributeList.length <= i) return ruby.getNil();
|
92
|
-
return stringOrBlank(ruby, attributeList.values.get(((Long)i).intValue()));
|
138
|
+
}
|
93
139
|
}
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
140
|
+
return array;
|
141
|
+
}
|
142
|
+
|
143
|
+
public IRubyObject
|
144
|
+
getAttributes(ThreadContext context)
|
145
|
+
{
|
146
|
+
final Ruby runtime = context.runtime;
|
147
|
+
if (attributeList == null) { return runtime.getNil(); }
|
148
|
+
RubyHash hash = RubyHash.newHash(runtime);
|
149
|
+
for (int i = 0; i < attributeList.length; i++) {
|
150
|
+
IRubyObject k = stringOrBlank(runtime, attributeList.names.get(i));
|
151
|
+
IRubyObject v = stringOrBlank(runtime, attributeList.values.get(i));
|
152
|
+
hash.fastASetCheckString(runtime, k, v); // hash.op_aset(context, k, v)
|
99
153
|
}
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
154
|
+
return hash;
|
155
|
+
}
|
156
|
+
|
157
|
+
public IRubyObject
|
158
|
+
getDepth()
|
159
|
+
{
|
160
|
+
return ruby.newFixnum(depth);
|
161
|
+
}
|
162
|
+
|
163
|
+
public IRubyObject
|
164
|
+
getLang()
|
165
|
+
{
|
166
|
+
return stringOrNil(ruby, lang);
|
167
|
+
}
|
168
|
+
|
169
|
+
public IRubyObject
|
170
|
+
getLocalName()
|
171
|
+
{
|
172
|
+
return stringOrNil(ruby, localName);
|
173
|
+
}
|
174
|
+
|
175
|
+
public IRubyObject
|
176
|
+
getName()
|
177
|
+
{
|
178
|
+
return stringOrNil(ruby, name);
|
179
|
+
}
|
180
|
+
|
181
|
+
public IRubyObject
|
182
|
+
getNamespaces(ThreadContext context)
|
183
|
+
{
|
184
|
+
final Ruby runtime = context.runtime;
|
185
|
+
if (namespaces == null) { return runtime.getNil(); }
|
186
|
+
RubyHash hash = RubyHash.newHash(runtime);
|
187
|
+
for (Map.Entry<String, String> entry : namespaces.entrySet()) {
|
188
|
+
IRubyObject k = stringOrBlank(runtime, entry.getKey());
|
189
|
+
IRubyObject v = stringOrBlank(runtime, entry.getValue());
|
190
|
+
hash.fastASetCheckString(runtime, k, v); // hash.op_aset(context, k, v)
|
105
191
|
}
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
192
|
+
return hash;
|
193
|
+
}
|
194
|
+
|
195
|
+
public IRubyObject
|
196
|
+
getXmlBase()
|
197
|
+
{
|
198
|
+
return stringOrNil(ruby, xmlBase);
|
199
|
+
}
|
200
|
+
|
201
|
+
public IRubyObject
|
202
|
+
getPrefix()
|
203
|
+
{
|
204
|
+
return stringOrNil(ruby, prefix);
|
205
|
+
}
|
206
|
+
|
207
|
+
public IRubyObject
|
208
|
+
getUri()
|
209
|
+
{
|
210
|
+
return stringOrNil(ruby, uri);
|
211
|
+
}
|
212
|
+
|
213
|
+
public IRubyObject
|
214
|
+
getValue()
|
215
|
+
{
|
216
|
+
return stringOrNil(ruby, value);
|
217
|
+
}
|
218
|
+
|
219
|
+
public IRubyObject
|
220
|
+
getXmlVersion()
|
221
|
+
{
|
222
|
+
return ruby.newString(xmlVersion);
|
223
|
+
}
|
224
|
+
|
225
|
+
public RubyBoolean
|
226
|
+
hasAttributes()
|
227
|
+
{
|
228
|
+
if (attributeList == null || attributeList.length == 0) { return ruby.getFalse(); }
|
229
|
+
return ruby.getTrue();
|
230
|
+
}
|
231
|
+
|
232
|
+
public abstract RubyBoolean hasValue();
|
233
|
+
|
234
|
+
public RubyBoolean
|
235
|
+
isDefault()
|
236
|
+
{
|
237
|
+
// TODO Implement.
|
238
|
+
return ruby.getFalse();
|
239
|
+
}
|
240
|
+
|
241
|
+
public boolean
|
242
|
+
isError() { return false; }
|
243
|
+
|
244
|
+
protected void
|
245
|
+
parsePrefix(String qName)
|
246
|
+
{
|
247
|
+
int index = qName.indexOf(':');
|
248
|
+
if (index != -1) { prefix = qName.substring(0, index); }
|
249
|
+
}
|
250
|
+
|
251
|
+
public void
|
252
|
+
setLang(String lang)
|
253
|
+
{
|
254
|
+
this.lang = lang;
|
255
|
+
}
|
256
|
+
|
257
|
+
public IRubyObject
|
258
|
+
toSyntaxError() { return ruby.getNil(); }
|
259
|
+
|
260
|
+
public IRubyObject
|
261
|
+
getNodeType() { return ruby.newFixnum(nodeType); }
|
262
|
+
|
263
|
+
public static enum ReaderNodeType {
|
264
|
+
NODE(0),
|
265
|
+
ELEMENT(1),
|
266
|
+
ATTRIBUTE(2),
|
267
|
+
TEXT(3),
|
268
|
+
CDATA(4),
|
269
|
+
ENTITY_REFERENCE(5),
|
270
|
+
ENTITY(6),
|
271
|
+
PROCESSING_INSTRUCTION(7),
|
272
|
+
COMMENT(8),
|
273
|
+
DOCUMENT(9),
|
274
|
+
DOCUMENT_TYPE(10),
|
275
|
+
DOCUMENTFRAGMENT(11),
|
276
|
+
NOTATION(12),
|
277
|
+
WHITESPACE(13),
|
278
|
+
SIGNIFICANT_WHITESPACE(14),
|
279
|
+
END_ELEMENT(15),
|
280
|
+
END_ENTITY(16),
|
281
|
+
XML_DECLARATION(17);
|
282
|
+
|
283
|
+
private final int value;
|
284
|
+
ReaderNodeType(int value)
|
285
|
+
{
|
286
|
+
this.value = value;
|
110
287
|
}
|
111
288
|
|
112
|
-
public
|
113
|
-
|
114
|
-
|
115
|
-
if (document == null) {
|
116
|
-
document = XmlDocument.createNewDocument(ruby);
|
117
|
-
}
|
118
|
-
for (int i=0; i<attributeList.length; i++) {
|
119
|
-
if (!isNamespace(attributeList.names.get(i))) {
|
120
|
-
Attr attr = document.createAttributeNS(attributeList.namespaces.get(i), attributeList.names.get(i));
|
121
|
-
attr.setValue(attributeList.values.get(i));
|
122
|
-
XmlAttr xmlAttr = new XmlAttr(ruby, attr);
|
123
|
-
array.append(xmlAttr);
|
124
|
-
}
|
125
|
-
}
|
126
|
-
}
|
127
|
-
return array;
|
289
|
+
public int getValue()
|
290
|
+
{
|
291
|
+
return value;
|
128
292
|
}
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
293
|
+
}
|
294
|
+
|
295
|
+
public static ClosingNode
|
296
|
+
createClosingNode(Ruby ruby, String uri, String localName, String qName, int depth, Stack<String> langStack,
|
297
|
+
Stack<String> xmlBaseStack)
|
298
|
+
{
|
299
|
+
return new ClosingNode(ruby, uri, localName, qName, depth, langStack, xmlBaseStack);
|
300
|
+
}
|
301
|
+
|
302
|
+
public static class ClosingNode extends ReaderNode
|
303
|
+
{
|
304
|
+
|
305
|
+
// public ClosingNode() {}
|
306
|
+
|
307
|
+
ClosingNode(Ruby runtime, String uri, String localName, String qName, int depth, Stack<String> langStack,
|
308
|
+
Stack<String> xmlBaseStack)
|
309
|
+
{
|
310
|
+
super(runtime);
|
311
|
+
nodeType = ReaderNodeType.END_ELEMENT.getValue();
|
312
|
+
this.uri = "".equals(uri) ? null : uri;
|
313
|
+
this.localName = ! isBlank(localName) ? localName : qName;
|
314
|
+
this.name = qName;
|
315
|
+
parsePrefix(qName);
|
316
|
+
this.depth = depth;
|
317
|
+
if (!langStack.isEmpty()) { this.lang = langStack.peek(); }
|
318
|
+
if (!xmlBaseStack.isEmpty()) { this.xmlBase = xmlBaseStack.peek(); }
|
140
319
|
}
|
141
320
|
|
142
|
-
|
143
|
-
|
321
|
+
@Override
|
322
|
+
public IRubyObject
|
323
|
+
getAttributeCount()
|
324
|
+
{
|
325
|
+
return ruby.newFixnum(0);
|
144
326
|
}
|
145
327
|
|
146
|
-
|
147
|
-
|
328
|
+
@Override
|
329
|
+
public RubyBoolean
|
330
|
+
hasValue()
|
331
|
+
{
|
332
|
+
return ruby.getFalse();
|
148
333
|
}
|
149
334
|
|
150
|
-
|
151
|
-
|
335
|
+
@Override
|
336
|
+
public String
|
337
|
+
getString()
|
338
|
+
{
|
339
|
+
return "</" + name + '>';
|
340
|
+
}
|
341
|
+
}
|
342
|
+
|
343
|
+
public static ElementNode
|
344
|
+
createElementNode(Ruby ruby, String uri, String localName, String qName, XMLAttributes attrs, int depth,
|
345
|
+
Stack<String> langStack, Stack<String> xmlBaseStack)
|
346
|
+
{
|
347
|
+
return new ElementNode(ruby, uri, localName, qName, attrs, depth, langStack, xmlBaseStack);
|
348
|
+
}
|
349
|
+
|
350
|
+
public static class ElementNode extends ReaderNode
|
351
|
+
{
|
352
|
+
|
353
|
+
// public ElementNode() {}
|
354
|
+
|
355
|
+
ElementNode(Ruby runtime, String uri, String localName, String qName, XMLAttributes attrs, int depth,
|
356
|
+
Stack<String> langStack, Stack<String> xmlBaseStack)
|
357
|
+
{
|
358
|
+
super(runtime);
|
359
|
+
this.nodeType = ReaderNodeType.ELEMENT.getValue();
|
360
|
+
this.uri = "".equals(uri) ? null : uri;
|
361
|
+
this.localName = ! isBlank(localName) ? localName : qName;
|
362
|
+
this.name = qName;
|
363
|
+
parsePrefix(qName);
|
364
|
+
this.depth = depth;
|
365
|
+
parseAttributes(attrs, langStack, xmlBaseStack);
|
152
366
|
}
|
153
367
|
|
154
|
-
|
155
|
-
|
368
|
+
@Override
|
369
|
+
public RubyBoolean
|
370
|
+
hasValue()
|
371
|
+
{
|
372
|
+
return ruby.getFalse();
|
156
373
|
}
|
157
374
|
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
375
|
+
private void
|
376
|
+
parseAttributes(XMLAttributes attrs, Stack<String> langStack, Stack<String> xmlBaseStack)
|
377
|
+
{
|
378
|
+
if (attrs.getLength() > 0) { attributeList = new ReaderAttributeList(); }
|
379
|
+
String u, n, v;
|
380
|
+
for (int i = 0; i < attrs.getLength(); i++) {
|
381
|
+
u = attrs.getURI(i);
|
382
|
+
n = attrs.getQName(i);
|
383
|
+
v = attrs.getValue(i);
|
384
|
+
if (isNamespace(n)) {
|
385
|
+
if (namespaces == null) { namespaces = new HashMap<String, String>(); }
|
386
|
+
namespaces.put(n, v);
|
387
|
+
} else {
|
388
|
+
if (lang == null) { lang = resolveLang(n, v, langStack); }
|
389
|
+
if (xmlBase == null) { xmlBase = resolveXmlBase(n, v, xmlBaseStack); }
|
166
390
|
}
|
167
|
-
|
391
|
+
attributeList.add(u, n, v);
|
392
|
+
}
|
168
393
|
}
|
169
394
|
|
170
|
-
|
171
|
-
|
395
|
+
private String
|
396
|
+
resolveLang(String n, String v, Stack<String> langStack)
|
397
|
+
{
|
398
|
+
if ("xml:lang".equals(n)) {
|
399
|
+
return v;
|
400
|
+
} else if (!langStack.isEmpty()) {
|
401
|
+
return langStack.peek();
|
402
|
+
} else {
|
403
|
+
return null;
|
404
|
+
}
|
172
405
|
}
|
173
406
|
|
174
|
-
|
175
|
-
|
407
|
+
private String
|
408
|
+
resolveXmlBase(String n, String v, Stack<String> xmlBaseStack)
|
409
|
+
{
|
410
|
+
if (isXmlBase(n)) {
|
411
|
+
return getXmlBaseUri(n, v, xmlBaseStack);
|
412
|
+
} else if (!xmlBaseStack.isEmpty()) {
|
413
|
+
return xmlBaseStack.peek();
|
414
|
+
} else {
|
415
|
+
return null;
|
416
|
+
}
|
176
417
|
}
|
177
418
|
|
178
|
-
|
179
|
-
|
419
|
+
private String
|
420
|
+
getXmlBaseUri(String n, String v, Stack<String> xmlBaseStack)
|
421
|
+
{
|
422
|
+
if ("xml:base".equals(n)) {
|
423
|
+
if (v.startsWith("http://")) {
|
424
|
+
return v;
|
425
|
+
} else if (v.startsWith("/") && v.endsWith("/")) {
|
426
|
+
String sub = v.substring(1, v.length() - 2);
|
427
|
+
String base = xmlBaseStack.peek();
|
428
|
+
if (base.endsWith("/")) {
|
429
|
+
base = base.substring(0, base.length() - 1);
|
430
|
+
}
|
431
|
+
int pos = base.lastIndexOf("/");
|
432
|
+
return base.substring(0, pos).concat(sub);
|
433
|
+
} else {
|
434
|
+
String base = xmlBaseStack.peek();
|
435
|
+
if (base.endsWith("/")) { return base.concat(v); }
|
436
|
+
else { return base.concat("/").concat(v); }
|
437
|
+
}
|
438
|
+
} else if ("xlink:href".equals(n)) {
|
439
|
+
if (v.startsWith("http://")) {
|
440
|
+
return v;
|
441
|
+
} else if (!xmlBaseStack.isEmpty()) {
|
442
|
+
String base = xmlBaseStack.peek();
|
443
|
+
return base;
|
444
|
+
}
|
445
|
+
}
|
446
|
+
return null;
|
180
447
|
}
|
181
448
|
|
182
|
-
|
183
|
-
|
449
|
+
@Override
|
450
|
+
public String
|
451
|
+
getString()
|
452
|
+
{
|
453
|
+
StringBuffer sb = new StringBuffer(24);
|
454
|
+
sb.append('<').append(name);
|
455
|
+
if (attributeList != null) {
|
456
|
+
for (int i = 0; i < attributeList.length; i++) {
|
457
|
+
String n = attributeList.names.get(i);
|
458
|
+
String v = attributeList.values.get(i);
|
459
|
+
sb.append(' ').append(n).append('=')
|
460
|
+
.append('"').append(v).append('"');
|
461
|
+
}
|
462
|
+
}
|
463
|
+
if (hasChildren) { sb.append('>'); }
|
464
|
+
else { sb.append("/>"); }
|
465
|
+
return sb.toString();
|
184
466
|
}
|
185
|
-
|
186
|
-
|
187
|
-
|
467
|
+
}
|
468
|
+
|
469
|
+
private static class ReaderAttributeList
|
470
|
+
{
|
471
|
+
final List<String> namespaces = new ArrayList<String>();
|
472
|
+
final List<String> names = new ArrayList<String>();
|
473
|
+
final List<String> values = new ArrayList<String>();
|
474
|
+
int length = 0;
|
475
|
+
|
476
|
+
void
|
477
|
+
add(String namespace, String name, String value)
|
478
|
+
{
|
479
|
+
namespaces.add(namespace != null ? namespace : "");
|
480
|
+
names.add(name != null ? name : "");
|
481
|
+
values.add(value != null ? value : "");
|
482
|
+
length++;
|
188
483
|
}
|
189
484
|
|
190
|
-
|
191
|
-
|
192
|
-
|
485
|
+
String
|
486
|
+
getByName(String name)
|
487
|
+
{
|
488
|
+
for (int i = 0; i < names.size(); i++) {
|
489
|
+
if (name.equals(names.get(i))) {
|
490
|
+
return values.get(i);
|
491
|
+
}
|
492
|
+
}
|
493
|
+
return null;
|
193
494
|
}
|
495
|
+
}
|
194
496
|
|
195
|
-
|
497
|
+
public static class EmptyNode extends ReaderNode
|
498
|
+
{
|
196
499
|
|
197
|
-
public
|
198
|
-
|
199
|
-
|
500
|
+
public
|
501
|
+
EmptyNode(Ruby runtime)
|
502
|
+
{
|
503
|
+
super(runtime);
|
504
|
+
this.nodeType = ReaderNodeType.NODE.getValue();
|
200
505
|
}
|
201
506
|
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
507
|
+
@Override
|
508
|
+
public IRubyObject
|
509
|
+
getXmlVersion()
|
510
|
+
{
|
511
|
+
return this.ruby.getNil();
|
207
512
|
}
|
208
513
|
|
209
|
-
|
210
|
-
|
514
|
+
@Override
|
515
|
+
public RubyBoolean
|
516
|
+
hasValue()
|
517
|
+
{
|
518
|
+
return ruby.getFalse();
|
211
519
|
}
|
212
520
|
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
NODE(0),
|
219
|
-
ELEMENT(1),
|
220
|
-
ATTRIBUTE(2),
|
221
|
-
TEXT(3),
|
222
|
-
CDATA(4),
|
223
|
-
ENTITY_REFERENCE(5),
|
224
|
-
ENTITY(6),
|
225
|
-
PROCESSING_INSTRUCTION(7),
|
226
|
-
COMMENT(8),
|
227
|
-
DOCUMENT(9),
|
228
|
-
DOCUMENT_TYPE(10),
|
229
|
-
DOCUMENTFRAGMENT(11),
|
230
|
-
NOTATION(12),
|
231
|
-
WHITESPACE(13),
|
232
|
-
SIGNIFICANT_WHITESPACE(14),
|
233
|
-
END_ELEMENT(15),
|
234
|
-
END_ENTITY(16),
|
235
|
-
XML_DECLARATION(17);
|
236
|
-
|
237
|
-
private final int value;
|
238
|
-
ReaderNodeType(int value) {
|
239
|
-
this.value = value;
|
240
|
-
}
|
241
|
-
|
242
|
-
public int getValue() {
|
243
|
-
return value;
|
244
|
-
}
|
521
|
+
@Override
|
522
|
+
public String
|
523
|
+
getString()
|
524
|
+
{
|
525
|
+
return null;
|
245
526
|
}
|
246
|
-
|
247
|
-
|
248
|
-
|
527
|
+
}
|
528
|
+
|
529
|
+
public static class ExceptionNode extends EmptyNode
|
530
|
+
{
|
531
|
+
private final XmlSyntaxError exception;
|
532
|
+
|
533
|
+
public
|
534
|
+
ExceptionNode(Ruby runtime, Exception ex)
|
535
|
+
{
|
536
|
+
super(runtime);
|
537
|
+
exception = XmlSyntaxError.createXMLSyntaxError(runtime); // Nokogiri::XML::SyntaxError
|
538
|
+
exception.setException(ex);
|
249
539
|
}
|
250
540
|
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
super(runtime);
|
257
|
-
nodeType = ReaderNodeType.END_ELEMENT.getValue();
|
258
|
-
this.uri = "".equals(uri) ? null : uri;
|
259
|
-
this.localName = ! isBlank(localName) ? localName : qName;
|
260
|
-
this.name = qName;
|
261
|
-
parsePrefix(qName);
|
262
|
-
this.depth = depth;
|
263
|
-
if (!langStack.isEmpty()) this.lang = langStack.peek();
|
264
|
-
if (!xmlBaseStack.isEmpty()) this.xmlBase = xmlBaseStack.peek();
|
265
|
-
}
|
266
|
-
|
267
|
-
@Override
|
268
|
-
public IRubyObject getAttributeCount() {
|
269
|
-
return ruby.newFixnum(0);
|
270
|
-
}
|
271
|
-
|
272
|
-
@Override
|
273
|
-
public RubyBoolean hasValue() {
|
274
|
-
return ruby.getFalse();
|
275
|
-
}
|
276
|
-
|
277
|
-
@Override
|
278
|
-
public String getString() {
|
279
|
-
return "</" + name + '>';
|
280
|
-
}
|
541
|
+
@Override
|
542
|
+
public boolean
|
543
|
+
isError()
|
544
|
+
{
|
545
|
+
return true;
|
281
546
|
}
|
282
547
|
|
283
|
-
|
284
|
-
|
548
|
+
@Override
|
549
|
+
public IRubyObject
|
550
|
+
toSyntaxError()
|
551
|
+
{
|
552
|
+
return this.exception;
|
285
553
|
}
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
for (int i = 0; i < attrs.getLength(); i++) {
|
311
|
-
u = attrs.getURI(i);
|
312
|
-
n = attrs.getQName(i);
|
313
|
-
v = attrs.getValue(i);
|
314
|
-
if (isNamespace(n)) {
|
315
|
-
if (namespaces == null) namespaces = new HashMap<String, String>();
|
316
|
-
namespaces.put(n, v);
|
317
|
-
} else {
|
318
|
-
if (lang == null) lang = resolveLang(n, v, langStack);
|
319
|
-
if (xmlBase == null) xmlBase = resolveXmlBase(n, v, xmlBaseStack);
|
320
|
-
}
|
321
|
-
attributeList.add(u, n, v);
|
322
|
-
}
|
323
|
-
}
|
324
|
-
|
325
|
-
private String resolveLang(String n, String v, Stack<String> langStack) {
|
326
|
-
if ("xml:lang".equals(n)) {
|
327
|
-
return v;
|
328
|
-
} else if (!langStack.isEmpty()) {
|
329
|
-
return langStack.peek();
|
330
|
-
} else {
|
331
|
-
return null;
|
332
|
-
}
|
333
|
-
}
|
334
|
-
|
335
|
-
private String resolveXmlBase(String n, String v, Stack<String> xmlBaseStack) {
|
336
|
-
if (isXmlBase(n)) {
|
337
|
-
return getXmlBaseUri(n, v, xmlBaseStack);
|
338
|
-
} else if (!xmlBaseStack.isEmpty()) {
|
339
|
-
return xmlBaseStack.peek();
|
340
|
-
} else {
|
341
|
-
return null;
|
342
|
-
}
|
343
|
-
}
|
344
|
-
|
345
|
-
private String getXmlBaseUri(String n, String v, Stack<String> xmlBaseStack) {
|
346
|
-
if ("xml:base".equals(n)) {
|
347
|
-
if (v.startsWith("http://")) {
|
348
|
-
return v;
|
349
|
-
} else if (v.startsWith("/") && v.endsWith("/")) {
|
350
|
-
String sub = v.substring(1, v.length() - 2);
|
351
|
-
String base = xmlBaseStack.peek();
|
352
|
-
if (base.endsWith("/")) {
|
353
|
-
base = base.substring(0, base.length() - 1);
|
354
|
-
}
|
355
|
-
int pos = base.lastIndexOf("/");
|
356
|
-
return base.substring(0, pos).concat(sub);
|
357
|
-
} else {
|
358
|
-
String base = xmlBaseStack.peek();
|
359
|
-
if (base.endsWith("/")) return base.concat(v);
|
360
|
-
else return base.concat("/").concat(v);
|
361
|
-
}
|
362
|
-
} else if ("xlink:href".equals(n)) {
|
363
|
-
if (v.startsWith("http://")) {
|
364
|
-
return v;
|
365
|
-
} else if (!xmlBaseStack.isEmpty()) {
|
366
|
-
String base = xmlBaseStack.peek();
|
367
|
-
return base;
|
368
|
-
}
|
369
|
-
}
|
370
|
-
return null;
|
371
|
-
}
|
372
|
-
|
373
|
-
@Override
|
374
|
-
public String getString() {
|
375
|
-
StringBuffer sb = new StringBuffer(24);
|
376
|
-
sb.append('<').append(name);
|
377
|
-
if (attributeList != null) {
|
378
|
-
for (int i=0; i<attributeList.length; i++) {
|
379
|
-
String n = attributeList.names.get(i);
|
380
|
-
String v = attributeList.values.get(i);
|
381
|
-
sb.append(' ').append(n).append('=')
|
382
|
-
.append('"').append(v).append('"');
|
383
|
-
}
|
384
|
-
}
|
385
|
-
if (hasChildren) sb.append('>');
|
386
|
-
else sb.append("/>");
|
387
|
-
return sb.toString();
|
388
|
-
}
|
554
|
+
}
|
555
|
+
|
556
|
+
public static TextNode
|
557
|
+
createTextNode(Ruby ruby, String content, int depth, Stack<String> langStack, Stack<String> xmlBaseStack)
|
558
|
+
{
|
559
|
+
return new TextNode(ruby, content, depth, langStack, xmlBaseStack);
|
560
|
+
}
|
561
|
+
|
562
|
+
public static class TextNode extends ReaderNode
|
563
|
+
{
|
564
|
+
|
565
|
+
// public TextNode() {}
|
566
|
+
|
567
|
+
TextNode(Ruby runtime, String content, int depth, Stack<String> langStack, Stack<String> xmlBaseStack)
|
568
|
+
{
|
569
|
+
super(runtime);
|
570
|
+
this.value = content;
|
571
|
+
this.localName = "#text";
|
572
|
+
this.name = "#text";
|
573
|
+
this.depth = depth;
|
574
|
+
if (!isBlank(content)) { nodeType = ReaderNodeType.TEXT.getValue(); }
|
575
|
+
else { nodeType = ReaderNodeType.SIGNIFICANT_WHITESPACE.getValue(); }
|
576
|
+
if (!langStack.isEmpty()) { this.lang = langStack.peek(); }
|
577
|
+
if (!xmlBaseStack.isEmpty()) { this.xmlBase = xmlBaseStack.peek(); }
|
389
578
|
}
|
390
579
|
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
void add(String namespace, String name, String value) {
|
398
|
-
namespaces.add(namespace != null ? namespace : "");
|
399
|
-
names.add(name != null ? name : "");
|
400
|
-
values.add(value != null ? value : "");
|
401
|
-
length++;
|
402
|
-
}
|
403
|
-
|
404
|
-
String getByName(String name) {
|
405
|
-
for (int i=0; i<names.size(); i++) {
|
406
|
-
if (name.equals(names.get(i))) {
|
407
|
-
return values.get(i);
|
408
|
-
}
|
409
|
-
}
|
410
|
-
return null;
|
411
|
-
}
|
580
|
+
@Override
|
581
|
+
public RubyBoolean
|
582
|
+
hasValue()
|
583
|
+
{
|
584
|
+
return ruby.getTrue();
|
412
585
|
}
|
413
586
|
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
}
|
420
|
-
|
421
|
-
@Override
|
422
|
-
public IRubyObject getXmlVersion() {
|
423
|
-
return this.ruby.getNil();
|
424
|
-
}
|
425
|
-
|
426
|
-
@Override
|
427
|
-
public RubyBoolean hasValue() {
|
428
|
-
return ruby.getFalse();
|
429
|
-
}
|
430
|
-
|
431
|
-
@Override
|
432
|
-
public String getString() {
|
433
|
-
return null;
|
434
|
-
}
|
435
|
-
}
|
436
|
-
|
437
|
-
public static class ExceptionNode extends EmptyNode {
|
438
|
-
private final XmlSyntaxError exception;
|
439
|
-
|
440
|
-
public ExceptionNode(Ruby runtime, Exception ex) {
|
441
|
-
super(runtime);
|
442
|
-
exception = XmlSyntaxError.createXMLSyntaxError(runtime); // Nokogiri::XML::SyntaxError
|
443
|
-
exception.setException(ex);
|
444
|
-
}
|
445
|
-
|
446
|
-
@Override
|
447
|
-
public boolean isError() {
|
448
|
-
return true;
|
449
|
-
}
|
450
|
-
|
451
|
-
@Override
|
452
|
-
public IRubyObject toSyntaxError() {
|
453
|
-
return this.exception;
|
454
|
-
}
|
455
|
-
}
|
456
|
-
|
457
|
-
public static TextNode createTextNode(Ruby ruby, String content, int depth, Stack<String> langStack, Stack<String> xmlBaseStack) {
|
458
|
-
return new TextNode(ruby, content, depth, langStack, xmlBaseStack);
|
459
|
-
}
|
460
|
-
|
461
|
-
public static class TextNode extends ReaderNode {
|
462
|
-
|
463
|
-
// public TextNode() {}
|
464
|
-
|
465
|
-
TextNode(Ruby runtime, String content, int depth, Stack<String> langStack, Stack<String> xmlBaseStack) {
|
466
|
-
super(runtime);
|
467
|
-
this.value = content;
|
468
|
-
this.localName = "#text";
|
469
|
-
this.name = "#text";
|
470
|
-
this.depth = depth;
|
471
|
-
if (!isBlank(content)) nodeType = ReaderNodeType.TEXT.getValue();
|
472
|
-
else nodeType = ReaderNodeType.SIGNIFICANT_WHITESPACE.getValue();
|
473
|
-
if (!langStack.isEmpty()) this.lang = langStack.peek();
|
474
|
-
if (!xmlBaseStack.isEmpty()) this.xmlBase = xmlBaseStack.peek();
|
475
|
-
}
|
476
|
-
|
477
|
-
@Override
|
478
|
-
public RubyBoolean hasValue() {
|
479
|
-
return ruby.getTrue();
|
480
|
-
}
|
481
|
-
|
482
|
-
@Override
|
483
|
-
public String getString() {
|
484
|
-
return value;
|
485
|
-
}
|
587
|
+
@Override
|
588
|
+
public String
|
589
|
+
getString()
|
590
|
+
{
|
591
|
+
return value;
|
486
592
|
}
|
593
|
+
}
|
487
594
|
|
488
595
|
}
|