Skip to content

Commit

Permalink
feat(jruby): allow schema resource resolver to register errors
Browse files Browse the repository at this point in the history
  • Loading branch information
flavorjones committed Dec 3, 2020
1 parent fc5948b commit 025e891
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions ext/java/nokogiri/XmlSchema.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
import org.w3c.dom.ls.LSResourceResolver;
import org.xml.sax.ErrorHandler;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;

/**
* Class for Nokogiri::XML::Schema
Expand All @@ -93,9 +94,9 @@ public Object clone() throws CloneNotSupportedException {
return super.clone();
}

private Schema getSchema(Source source, String currentDir, String scriptFileName, ErrorHandler error_handler) throws SAXException {
private Schema getSchema(Source source, String currentDir, String scriptFileName, SchemaErrorHandler error_handler) throws SAXException {
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
SchemaResourceResolver resourceResolver = new SchemaResourceResolver(currentDir, scriptFileName, null);
SchemaResourceResolver resourceResolver = new SchemaResourceResolver(currentDir, scriptFileName, null, error_handler);
schemaFactory.setResourceResolver(resourceResolver);
schemaFactory.setErrorHandler(error_handler);
return schemaFactory.newSchema(source);
Expand All @@ -111,7 +112,7 @@ static XmlSchema createSchemaInstance(ThreadContext context, RubyClass klazz, So
xmlSchema.setInstanceVariable("@errors", runtime.newEmptyArray());

try {
ErrorHandler error_handler = new SchemaErrorHandler(context.getRuntime(), (RubyArray)xmlSchema.getInstanceVariable("@errors"));
SchemaErrorHandler error_handler = new SchemaErrorHandler(context.getRuntime(), (RubyArray)xmlSchema.getInstanceVariable("@errors"));
Schema schema = xmlSchema.getSchema(source, context.getRuntime().getCurrentDirectory(), context.getRuntime().getInstanceConfig().getScriptFileName(), error_handler);
xmlSchema.setValidator(schema.newValidator());
return xmlSchema;
Expand Down Expand Up @@ -210,11 +211,13 @@ private class SchemaResourceResolver implements LSResourceResolver {
SchemaLSInput lsInput = new SchemaLSInput();
String currentDir;
String scriptFileName;
SchemaErrorHandler error_handler;
//String defaultURI;

SchemaResourceResolver(String currentDir, String scriptFileName, Object input) {
SchemaResourceResolver(String currentDir, String scriptFileName, Object input, SchemaErrorHandler error_handler) {
this.currentDir = currentDir;
this.scriptFileName = scriptFileName;
this.error_handler = error_handler;
if (input == null) return;
if (input instanceof String) {
lsInput.setStringData((String)input);
Expand Down

0 comments on commit 025e891

Please sign in to comment.