use of nokogiri.internals.SchemaErrorHandler in project gocd by gocd.
the class XmlSchema method validate_document_or_file.
IRubyObject validate_document_or_file(ThreadContext context, XmlDocument xmlDocument) {
RubyArray errors = (RubyArray) this.getInstanceVariable("@errors");
ErrorHandler errorHandler = new SchemaErrorHandler(context.getRuntime(), errors);
setErrorHandler(errorHandler);
try {
validate(xmlDocument.getDocument());
} catch (SAXException ex) {
XmlSyntaxError xmlSyntaxError = (XmlSyntaxError) NokogiriService.XML_SYNTAXERROR_ALLOCATOR.allocate(context.getRuntime(), getNokogiriClass(context.getRuntime(), "Nokogiri::XML::SyntaxError"));
xmlSyntaxError.setException(ex);
errors.append(xmlSyntaxError);
} catch (IOException ex) {
throw context.getRuntime().newIOError(ex.getMessage());
}
return errors;
}
use of nokogiri.internals.SchemaErrorHandler in project nokogiri by sparklemotion.
the class XmlSchema method validate_document_or_file.
IRubyObject validate_document_or_file(ThreadContext context, XmlDocument xmlDocument) {
RubyArray<?> errors = (RubyArray) this.getInstanceVariable("@errors");
ErrorHandler errorHandler = new SchemaErrorHandler(context.runtime, errors);
setErrorHandler(errorHandler);
try {
validate(xmlDocument.getDocument());
} catch (SAXException ex) {
XmlSyntaxError xmlSyntaxError = XmlSyntaxError.createXMLSyntaxError(context.runtime);
xmlSyntaxError.setException(ex);
errors.append(xmlSyntaxError);
} catch (IOException ex) {
throw context.runtime.newIOError(ex.getMessage());
}
return errors;
}
use of nokogiri.internals.SchemaErrorHandler in project nokogiri by sparklemotion.
the class XmlSchema method createSchemaInstance.
static XmlSchema createSchemaInstance(ThreadContext context, RubyClass klazz, Source source, IRubyObject parseOptions) {
Ruby runtime = context.getRuntime();
XmlSchema xmlSchema = (XmlSchema) NokogiriService.XML_SCHEMA_ALLOCATOR.allocate(runtime, klazz);
if (parseOptions == null) {
parseOptions = defaultParseOptions(context.getRuntime());
}
long intParseOptions = RubyFixnum.fix2long(Helpers.invoke(context, parseOptions, "to_i"));
xmlSchema.setInstanceVariable("@errors", runtime.newEmptyArray());
xmlSchema.setInstanceVariable("@parse_options", parseOptions);
try {
SchemaErrorHandler errorHandler = new SchemaErrorHandler(context.getRuntime(), (RubyArray) xmlSchema.getInstanceVariable("@errors"));
Schema schema = xmlSchema.getSchema(source, context.getRuntime().getCurrentDirectory(), context.getRuntime().getInstanceConfig().getScriptFileName(), errorHandler, intParseOptions);
xmlSchema.setValidator(schema.newValidator());
return xmlSchema;
} catch (SAXException ex) {
throw context.getRuntime().newRuntimeError("Could not parse document: " + ex.getMessage());
}
}
Aggregations