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
@@ -79,310 +79,375 @@ import org.xml.sax.SAXParseException;
|
|
79
79
|
* @author sergio
|
80
80
|
* @author Yoko Harada <yokolet@gmail.com>
|
81
81
|
*/
|
82
|
-
@JRubyClass(name="Nokogiri::XML::Schema")
|
83
|
-
public class XmlSchema extends RubyObject
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
82
|
+
@JRubyClass(name = "Nokogiri::XML::Schema")
|
83
|
+
public class XmlSchema extends RubyObject
|
84
|
+
{
|
85
|
+
private Validator validator;
|
86
|
+
|
87
|
+
public
|
88
|
+
XmlSchema(Ruby ruby, RubyClass klazz)
|
89
|
+
{
|
90
|
+
super(ruby, klazz);
|
91
|
+
}
|
92
|
+
|
93
|
+
/**
|
94
|
+
* Create and return a copy of this object.
|
95
|
+
*
|
96
|
+
* @return a clone of this object
|
97
|
+
*/
|
98
|
+
@Override
|
99
|
+
public Object
|
100
|
+
clone() throws CloneNotSupportedException
|
101
|
+
{
|
102
|
+
return super.clone();
|
103
|
+
}
|
104
|
+
|
105
|
+
private Schema
|
106
|
+
getSchema(Source source,
|
107
|
+
String currentDir,
|
108
|
+
String scriptFileName,
|
109
|
+
SchemaErrorHandler errorHandler,
|
110
|
+
long parseOptions) throws SAXException
|
111
|
+
{
|
112
|
+
boolean noNet = new ParserContext.Options(parseOptions).noNet;
|
113
|
+
|
114
|
+
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
|
115
|
+
SchemaResourceResolver resourceResolver =
|
116
|
+
new SchemaResourceResolver(currentDir, scriptFileName, null, errorHandler, noNet);
|
117
|
+
|
118
|
+
schemaFactory.setResourceResolver(resourceResolver);
|
119
|
+
schemaFactory.setErrorHandler(errorHandler);
|
120
|
+
|
121
|
+
return schemaFactory.newSchema(source);
|
122
|
+
}
|
123
|
+
|
124
|
+
private void
|
125
|
+
setValidator(Validator validator)
|
126
|
+
{
|
127
|
+
this.validator = validator;
|
128
|
+
}
|
129
|
+
|
130
|
+
static XmlSchema
|
131
|
+
createSchemaInstance(ThreadContext context, RubyClass klazz, Source source, IRubyObject parseOptions)
|
132
|
+
{
|
133
|
+
Ruby runtime = context.getRuntime();
|
134
|
+
XmlSchema xmlSchema = (XmlSchema) NokogiriService.XML_SCHEMA_ALLOCATOR.allocate(runtime, klazz);
|
135
|
+
|
136
|
+
if (parseOptions == null) {
|
137
|
+
parseOptions = defaultParseOptions(context.getRuntime());
|
88
138
|
}
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
139
|
+
long intParseOptions = RubyFixnum.fix2long(Helpers.invoke(context, parseOptions, "to_i"));
|
140
|
+
|
141
|
+
xmlSchema.setInstanceVariable("@errors", runtime.newEmptyArray());
|
142
|
+
xmlSchema.setInstanceVariable("@parse_options", parseOptions);
|
143
|
+
|
144
|
+
try {
|
145
|
+
SchemaErrorHandler errorHandler =
|
146
|
+
new SchemaErrorHandler(context.getRuntime(), (RubyArray)xmlSchema.getInstanceVariable("@errors"));
|
147
|
+
Schema schema =
|
148
|
+
xmlSchema.getSchema(source,
|
149
|
+
context.getRuntime().getCurrentDirectory(),
|
150
|
+
context.getRuntime().getInstanceConfig().getScriptFileName(),
|
151
|
+
errorHandler,
|
152
|
+
intParseOptions);
|
153
|
+
xmlSchema.setValidator(schema.newValidator());
|
154
|
+
return xmlSchema;
|
155
|
+
} catch (SAXException ex) {
|
156
|
+
throw context.getRuntime().newRuntimeError("Could not parse document: " + ex.getMessage());
|
98
157
|
}
|
158
|
+
}
|
159
|
+
|
160
|
+
protected static IRubyObject
|
161
|
+
defaultParseOptions(Ruby runtime)
|
162
|
+
{
|
163
|
+
return ((RubyClass)runtime.getClassFromPath("Nokogiri::XML::ParseOptions")).getConstant("DEFAULT_SCHEMA");
|
164
|
+
}
|
165
|
+
|
166
|
+
/*
|
167
|
+
* call-seq:
|
168
|
+
* from_document(doc)
|
169
|
+
*
|
170
|
+
* Create a new Schema from the Nokogiri::XML::Document +doc+
|
171
|
+
*/
|
172
|
+
@JRubyMethod(meta = true, required = 1, optional = 1)
|
173
|
+
public static IRubyObject
|
174
|
+
from_document(ThreadContext context, IRubyObject klazz, IRubyObject[] args)
|
175
|
+
{
|
176
|
+
IRubyObject document = args[0];
|
177
|
+
IRubyObject parseOptions = null;
|
178
|
+
if (args.length > 1) {
|
179
|
+
parseOptions = args[1];
|
180
|
+
}
|
181
|
+
|
182
|
+
XmlDocument doc = ((XmlDocument)((XmlNode) document).document(context));
|
99
183
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
long parseOptions) throws SAXException {
|
105
|
-
boolean noNet = new ParserContext.Options(parseOptions).noNet;
|
184
|
+
RubyArray errors = (RubyArray) doc.getInstanceVariable("@errors");
|
185
|
+
if (!errors.isEmpty()) {
|
186
|
+
throw((XmlSyntaxError) errors.first()).toThrowable();
|
187
|
+
}
|
106
188
|
|
107
|
-
|
108
|
-
SchemaResourceResolver resourceResolver =
|
109
|
-
new SchemaResourceResolver(currentDir, scriptFileName, null, errorHandler, noNet);
|
189
|
+
DOMSource source = new DOMSource(doc.getDocument());
|
110
190
|
|
111
|
-
|
112
|
-
schemaFactory.setErrorHandler(errorHandler);
|
191
|
+
IRubyObject uri = doc.url(context);
|
113
192
|
|
114
|
-
|
193
|
+
if (!uri.isNil()) {
|
194
|
+
source.setSystemId(uri.convertToString().asJavaString());
|
115
195
|
}
|
116
196
|
|
117
|
-
|
118
|
-
|
197
|
+
return getSchema(context, (RubyClass)klazz, source, parseOptions);
|
198
|
+
}
|
199
|
+
|
200
|
+
@JRubyMethod(meta = true, required = 1, optional = 1)
|
201
|
+
public static IRubyObject
|
202
|
+
read_memory(ThreadContext context, IRubyObject klazz, IRubyObject[] args)
|
203
|
+
{
|
204
|
+
IRubyObject content = args[0];
|
205
|
+
IRubyObject parseOptions = null;
|
206
|
+
if (args.length > 1) {
|
207
|
+
parseOptions = args[1];
|
208
|
+
}
|
209
|
+
String data = content.convertToString().asJavaString();
|
210
|
+
return getSchema(context, (RubyClass) klazz, new StreamSource(new StringReader(data)), parseOptions);
|
211
|
+
}
|
212
|
+
|
213
|
+
private static IRubyObject
|
214
|
+
getSchema(ThreadContext context, RubyClass klazz, Source source, IRubyObject parseOptions)
|
215
|
+
{
|
216
|
+
String moduleName = klazz.getName();
|
217
|
+
if ("Nokogiri::XML::Schema".equals(moduleName)) {
|
218
|
+
return XmlSchema.createSchemaInstance(context, klazz, source, parseOptions);
|
219
|
+
} else if ("Nokogiri::XML::RelaxNG".equals(moduleName)) {
|
220
|
+
return XmlRelaxng.createSchemaInstance(context, klazz, source, parseOptions);
|
221
|
+
}
|
222
|
+
return context.getRuntime().getNil();
|
223
|
+
}
|
224
|
+
|
225
|
+
@JRubyMethod(visibility = Visibility.PRIVATE)
|
226
|
+
public IRubyObject
|
227
|
+
validate_document(ThreadContext context, IRubyObject document)
|
228
|
+
{
|
229
|
+
return validate_document_or_file(context, (XmlDocument)document);
|
230
|
+
}
|
231
|
+
|
232
|
+
@JRubyMethod(visibility = Visibility.PRIVATE)
|
233
|
+
public IRubyObject
|
234
|
+
validate_file(ThreadContext context, IRubyObject file)
|
235
|
+
{
|
236
|
+
Ruby runtime = context.runtime;
|
237
|
+
|
238
|
+
XmlDomParserContext ctx = new XmlDomParserContext(runtime, RubyFixnum.newFixnum(runtime, 1L));
|
239
|
+
ctx.setInputSourceFile(context, file);
|
240
|
+
XmlDocument xmlDocument = ctx.parse(context, getNokogiriClass(runtime, "Nokogiri::XML::Document"), context.nil);
|
241
|
+
return validate_document_or_file(context, xmlDocument);
|
242
|
+
}
|
243
|
+
|
244
|
+
IRubyObject
|
245
|
+
validate_document_or_file(ThreadContext context, XmlDocument xmlDocument)
|
246
|
+
{
|
247
|
+
RubyArray errors = (RubyArray) this.getInstanceVariable("@errors");
|
248
|
+
ErrorHandler errorHandler = new SchemaErrorHandler(context.runtime, errors);
|
249
|
+
setErrorHandler(errorHandler);
|
250
|
+
|
251
|
+
try {
|
252
|
+
validate(xmlDocument.getDocument());
|
253
|
+
} catch (SAXException ex) {
|
254
|
+
XmlSyntaxError xmlSyntaxError = XmlSyntaxError.createXMLSyntaxError(context.runtime);
|
255
|
+
xmlSyntaxError.setException(ex);
|
256
|
+
errors.append(xmlSyntaxError);
|
257
|
+
} catch (IOException ex) {
|
258
|
+
throw context.runtime.newIOError(ex.getMessage());
|
119
259
|
}
|
120
260
|
|
121
|
-
|
122
|
-
|
123
|
-
|
261
|
+
return errors;
|
262
|
+
}
|
263
|
+
|
264
|
+
protected void
|
265
|
+
setErrorHandler(ErrorHandler errorHandler)
|
266
|
+
{
|
267
|
+
validator.setErrorHandler(errorHandler);
|
268
|
+
}
|
269
|
+
|
270
|
+
protected void
|
271
|
+
validate(Document document) throws SAXException, IOException
|
272
|
+
{
|
273
|
+
DOMSource docSource = new DOMSource(document);
|
274
|
+
validator.validate(docSource);
|
275
|
+
}
|
276
|
+
|
277
|
+
private class SchemaResourceResolver implements LSResourceResolver
|
278
|
+
{
|
279
|
+
SchemaLSInput lsInput = new SchemaLSInput();
|
280
|
+
String currentDir;
|
281
|
+
String scriptFileName;
|
282
|
+
SchemaErrorHandler errorHandler;
|
283
|
+
boolean noNet;
|
284
|
+
//String defaultURI;
|
285
|
+
|
286
|
+
SchemaResourceResolver(String currentDir, String scriptFileName, Object input, SchemaErrorHandler errorHandler,
|
287
|
+
boolean noNet)
|
288
|
+
{
|
289
|
+
this.currentDir = currentDir;
|
290
|
+
this.scriptFileName = scriptFileName;
|
291
|
+
this.errorHandler = errorHandler;
|
292
|
+
this.noNet = noNet;
|
293
|
+
if (input == null) { return; }
|
294
|
+
if (input instanceof String) {
|
295
|
+
lsInput.setStringData((String)input);
|
296
|
+
} else if (input instanceof Reader) {
|
297
|
+
lsInput.setCharacterStream((Reader)input);
|
298
|
+
} else if (input instanceof InputStream) {
|
299
|
+
lsInput.setByteStream((InputStream)input);
|
300
|
+
}
|
301
|
+
}
|
124
302
|
|
125
|
-
|
126
|
-
|
303
|
+
@Override
|
304
|
+
public LSInput
|
305
|
+
resolveResource(String type,
|
306
|
+
String namespaceURI,
|
307
|
+
String publicId,
|
308
|
+
String systemId,
|
309
|
+
String baseURI)
|
310
|
+
{
|
311
|
+
if (noNet && (systemId.startsWith("http://") || systemId.startsWith("ftp://"))) {
|
312
|
+
if (systemId.startsWith(XMLConstants.W3C_XML_SCHEMA_NS_URI)) {
|
313
|
+
return null; // use default resolver
|
127
314
|
}
|
128
|
-
long intParseOptions = RubyFixnum.fix2long(Helpers.invoke(context, parseOptions, "to_i"));
|
129
|
-
|
130
|
-
xmlSchema.setInstanceVariable("@errors", runtime.newEmptyArray());
|
131
|
-
xmlSchema.setInstanceVariable("@parse_options", parseOptions);
|
132
|
-
|
133
315
|
try {
|
134
|
-
|
135
|
-
new SchemaErrorHandler(context.getRuntime(), (RubyArray)xmlSchema.getInstanceVariable("@errors"));
|
136
|
-
Schema schema =
|
137
|
-
xmlSchema.getSchema(source,
|
138
|
-
context.getRuntime().getCurrentDirectory(),
|
139
|
-
context.getRuntime().getInstanceConfig().getScriptFileName(),
|
140
|
-
errorHandler,
|
141
|
-
intParseOptions);
|
142
|
-
xmlSchema.setValidator(schema.newValidator());
|
143
|
-
return xmlSchema;
|
316
|
+
this.errorHandler.warning(new SAXParseException(String.format("Attempt to load network entity '%s'", systemId), null));
|
144
317
|
} catch (SAXException ex) {
|
145
|
-
throw context.getRuntime().newRuntimeError("Could not parse document: " + ex.getMessage());
|
146
318
|
}
|
319
|
+
} else {
|
320
|
+
String adjusted = adjustSystemIdIfNecessary(currentDir, scriptFileName, baseURI, systemId);
|
321
|
+
lsInput.setPublicId(publicId);
|
322
|
+
lsInput.setSystemId(adjusted != null ? adjusted : systemId);
|
323
|
+
lsInput.setBaseURI(baseURI);
|
324
|
+
}
|
325
|
+
return lsInput;
|
147
326
|
}
|
327
|
+
}
|
328
|
+
|
329
|
+
private class SchemaLSInput implements LSInput
|
330
|
+
{
|
331
|
+
protected String fPublicId;
|
332
|
+
protected String fSystemId;
|
333
|
+
protected String fBaseSystemId;
|
334
|
+
protected InputStream fByteStream;
|
335
|
+
protected Reader fCharStream;
|
336
|
+
protected String fData;
|
337
|
+
protected String fEncoding;
|
338
|
+
protected boolean fCertifiedText = false;
|
148
339
|
|
149
|
-
|
150
|
-
|
340
|
+
@Override
|
341
|
+
public String
|
342
|
+
getBaseURI()
|
343
|
+
{
|
344
|
+
return fBaseSystemId;
|
151
345
|
}
|
152
346
|
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
*/
|
159
|
-
@JRubyMethod(meta=true, required=1, optional=1)
|
160
|
-
public static IRubyObject from_document(ThreadContext context, IRubyObject klazz, IRubyObject[] args) {
|
161
|
-
IRubyObject document = args[0];
|
162
|
-
IRubyObject parseOptions = null;
|
163
|
-
if (args.length > 1) {
|
164
|
-
parseOptions = args[1];
|
165
|
-
}
|
166
|
-
|
167
|
-
XmlDocument doc = ((XmlDocument) ((XmlNode) document).document(context));
|
168
|
-
|
169
|
-
RubyArray errors = (RubyArray) doc.getInstanceVariable("@errors");
|
170
|
-
if (!errors.isEmpty()) {
|
171
|
-
throw ((XmlSyntaxError) errors.first()).toThrowable();
|
172
|
-
}
|
173
|
-
|
174
|
-
DOMSource source = new DOMSource(doc.getDocument());
|
175
|
-
|
176
|
-
IRubyObject uri = doc.url(context);
|
177
|
-
|
178
|
-
if (!uri.isNil()) {
|
179
|
-
source.setSystemId(uri.convertToString().asJavaString());
|
180
|
-
}
|
181
|
-
|
182
|
-
return getSchema(context, (RubyClass)klazz, source, parseOptions);
|
347
|
+
@Override
|
348
|
+
public InputStream
|
349
|
+
getByteStream()
|
350
|
+
{
|
351
|
+
return fByteStream;
|
183
352
|
}
|
184
353
|
|
185
|
-
@
|
186
|
-
public
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
parseOptions = args[1];
|
191
|
-
}
|
192
|
-
String data = content.convertToString().asJavaString();
|
193
|
-
return getSchema(context, (RubyClass) klazz, new StreamSource(new StringReader(data)), parseOptions);
|
354
|
+
@Override
|
355
|
+
public boolean
|
356
|
+
getCertifiedText()
|
357
|
+
{
|
358
|
+
return fCertifiedText;
|
194
359
|
}
|
195
360
|
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
return XmlRelaxng.createSchemaInstance(context, klazz, source, parseOptions);
|
202
|
-
}
|
203
|
-
return context.getRuntime().getNil();
|
361
|
+
@Override
|
362
|
+
public Reader
|
363
|
+
getCharacterStream()
|
364
|
+
{
|
365
|
+
return fCharStream;
|
204
366
|
}
|
205
367
|
|
206
|
-
@
|
207
|
-
public
|
208
|
-
|
368
|
+
@Override
|
369
|
+
public String
|
370
|
+
getEncoding()
|
371
|
+
{
|
372
|
+
return fEncoding;
|
209
373
|
}
|
210
374
|
|
211
|
-
@
|
212
|
-
public
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
ctx.setInputSourceFile(context, file);
|
217
|
-
XmlDocument xmlDocument = ctx.parse(context, getNokogiriClass(runtime, "Nokogiri::XML::Document"), context.nil);
|
218
|
-
return validate_document_or_file(context, xmlDocument);
|
375
|
+
@Override
|
376
|
+
public String
|
377
|
+
getPublicId()
|
378
|
+
{
|
379
|
+
return fPublicId;
|
219
380
|
}
|
220
381
|
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
try {
|
227
|
-
validate(xmlDocument.getDocument());
|
228
|
-
}
|
229
|
-
catch (SAXException ex) {
|
230
|
-
XmlSyntaxError xmlSyntaxError = XmlSyntaxError.createXMLSyntaxError(context.runtime);
|
231
|
-
xmlSyntaxError.setException(ex);
|
232
|
-
errors.append(xmlSyntaxError);
|
233
|
-
}
|
234
|
-
catch (IOException ex) {
|
235
|
-
throw context.runtime.newIOError(ex.getMessage());
|
236
|
-
}
|
237
|
-
|
238
|
-
return errors;
|
382
|
+
@Override
|
383
|
+
public String
|
384
|
+
getStringData()
|
385
|
+
{
|
386
|
+
return fData;
|
239
387
|
}
|
240
388
|
|
241
|
-
|
242
|
-
|
389
|
+
@Override
|
390
|
+
public String
|
391
|
+
getSystemId()
|
392
|
+
{
|
393
|
+
return fSystemId;
|
243
394
|
}
|
244
395
|
|
245
|
-
|
246
|
-
|
247
|
-
|
396
|
+
@Override
|
397
|
+
public void
|
398
|
+
setBaseURI(String baseURI)
|
399
|
+
{
|
400
|
+
fBaseSystemId = baseURI;
|
248
401
|
}
|
249
402
|
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
boolean noNet;
|
256
|
-
//String defaultURI;
|
257
|
-
|
258
|
-
SchemaResourceResolver(String currentDir, String scriptFileName, Object input, SchemaErrorHandler errorHandler, boolean noNet) {
|
259
|
-
this.currentDir = currentDir;
|
260
|
-
this.scriptFileName = scriptFileName;
|
261
|
-
this.errorHandler = errorHandler;
|
262
|
-
this.noNet = noNet;
|
263
|
-
if (input == null) return;
|
264
|
-
if (input instanceof String) {
|
265
|
-
lsInput.setStringData((String)input);
|
266
|
-
} else if (input instanceof Reader) {
|
267
|
-
lsInput.setCharacterStream((Reader)input);
|
268
|
-
} else if (input instanceof InputStream) {
|
269
|
-
lsInput.setByteStream((InputStream)input);
|
270
|
-
}
|
271
|
-
}
|
272
|
-
|
273
|
-
@Override
|
274
|
-
public LSInput resolveResource(String type,
|
275
|
-
String namespaceURI,
|
276
|
-
String publicId,
|
277
|
-
String systemId,
|
278
|
-
String baseURI) {
|
279
|
-
if (noNet && (systemId.startsWith("http://") || systemId.startsWith("ftp://"))) {
|
280
|
-
if (systemId.startsWith(XMLConstants.W3C_XML_SCHEMA_NS_URI)) {
|
281
|
-
return null; // use default resolver
|
282
|
-
}
|
283
|
-
try {
|
284
|
-
this.errorHandler.warning(new SAXParseException(String.format("Attempt to load network entity '%s'", systemId), null));
|
285
|
-
} catch (SAXException ex) {
|
286
|
-
}
|
287
|
-
} else {
|
288
|
-
String adjusted = adjustSystemIdIfNecessary(currentDir, scriptFileName, baseURI, systemId);
|
289
|
-
lsInput.setPublicId(publicId);
|
290
|
-
lsInput.setSystemId(adjusted != null? adjusted : systemId);
|
291
|
-
lsInput.setBaseURI(baseURI);
|
292
|
-
}
|
293
|
-
return lsInput;
|
294
|
-
}
|
403
|
+
@Override
|
404
|
+
public void
|
405
|
+
setByteStream(InputStream byteStream)
|
406
|
+
{
|
407
|
+
fByteStream = byteStream;
|
295
408
|
}
|
296
409
|
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
protected String fData;
|
304
|
-
protected String fEncoding;
|
305
|
-
protected boolean fCertifiedText = false;
|
306
|
-
|
307
|
-
@Override
|
308
|
-
public String getBaseURI() {
|
309
|
-
return fBaseSystemId;
|
310
|
-
}
|
311
|
-
|
312
|
-
@Override
|
313
|
-
public InputStream getByteStream() {
|
314
|
-
return fByteStream;
|
315
|
-
}
|
316
|
-
|
317
|
-
@Override
|
318
|
-
public boolean getCertifiedText() {
|
319
|
-
return fCertifiedText;
|
320
|
-
}
|
321
|
-
|
322
|
-
@Override
|
323
|
-
public Reader getCharacterStream() {
|
324
|
-
return fCharStream;
|
325
|
-
}
|
326
|
-
|
327
|
-
@Override
|
328
|
-
public String getEncoding() {
|
329
|
-
return fEncoding;
|
330
|
-
}
|
331
|
-
|
332
|
-
@Override
|
333
|
-
public String getPublicId() {
|
334
|
-
return fPublicId;
|
335
|
-
}
|
336
|
-
|
337
|
-
@Override
|
338
|
-
public String getStringData() {
|
339
|
-
return fData;
|
340
|
-
}
|
341
|
-
|
342
|
-
@Override
|
343
|
-
public String getSystemId() {
|
344
|
-
return fSystemId;
|
345
|
-
}
|
346
|
-
|
347
|
-
@Override
|
348
|
-
public void setBaseURI(String baseURI) {
|
349
|
-
fBaseSystemId = baseURI;
|
350
|
-
}
|
351
|
-
|
352
|
-
@Override
|
353
|
-
public void setByteStream(InputStream byteStream) {
|
354
|
-
fByteStream = byteStream;
|
355
|
-
}
|
356
|
-
|
357
|
-
@Override
|
358
|
-
public void setCertifiedText(boolean certified) {
|
359
|
-
fCertifiedText = certified;
|
360
|
-
}
|
361
|
-
|
362
|
-
@Override
|
363
|
-
public void setCharacterStream(Reader charStream) {
|
364
|
-
fCharStream = charStream;
|
365
|
-
}
|
410
|
+
@Override
|
411
|
+
public void
|
412
|
+
setCertifiedText(boolean certified)
|
413
|
+
{
|
414
|
+
fCertifiedText = certified;
|
415
|
+
}
|
366
416
|
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
417
|
+
@Override
|
418
|
+
public void
|
419
|
+
setCharacterStream(Reader charStream)
|
420
|
+
{
|
421
|
+
fCharStream = charStream;
|
422
|
+
}
|
371
423
|
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
424
|
+
@Override
|
425
|
+
public void
|
426
|
+
setEncoding(String encoding)
|
427
|
+
{
|
428
|
+
fEncoding = encoding;
|
429
|
+
}
|
376
430
|
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
431
|
+
@Override
|
432
|
+
public void
|
433
|
+
setPublicId(String pubId)
|
434
|
+
{
|
435
|
+
fPublicId = pubId;
|
436
|
+
}
|
381
437
|
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
438
|
+
@Override
|
439
|
+
public void
|
440
|
+
setStringData(String stringData)
|
441
|
+
{
|
442
|
+
fData = stringData;
|
443
|
+
}
|
386
444
|
|
445
|
+
@Override
|
446
|
+
public void
|
447
|
+
setSystemId(String sysId)
|
448
|
+
{
|
449
|
+
fSystemId = sysId;
|
387
450
|
}
|
451
|
+
|
452
|
+
}
|
388
453
|
}
|