use of org.iso_relax.verifier.VerifierConfigurationException in project nokogiri by sparklemotion.
the class XmlRelaxng method getSchema.
private Schema getSchema(Source source, ThreadContext context) {
InputStream is;
VerifierFactory factory = new com.thaiopensource.relaxng.jarv.VerifierFactoryImpl();
if (source instanceof StreamSource) {
StreamSource ss = (StreamSource) source;
is = ss.getInputStream();
} else {
//if (this.source instanceof DOMSource)
DOMSource ds = (DOMSource) source;
StringWriter xmlAsWriter = new StringWriter();
StreamResult result = new StreamResult(xmlAsWriter);
try {
TransformerFactory.newInstance().newTransformer().transform(ds, result);
} catch (TransformerConfigurationException ex) {
throw context.getRuntime().newRuntimeError("Could not parse document: " + ex.getMessage());
} catch (TransformerException ex) {
throw context.getRuntime().newRuntimeError("Could not parse document: " + ex.getMessage());
}
try {
is = new ByteArrayInputStream(xmlAsWriter.toString().getBytes("UTF-8"));
} catch (UnsupportedEncodingException ex) {
throw context.getRuntime().newRuntimeError("Could not parse document: " + ex.getMessage());
}
}
try {
return factory.compileSchema(is);
} catch (VerifierConfigurationException ex) {
throw context.getRuntime().newRuntimeError("Could not parse document: " + ex.getMessage());
} catch (SAXException ex) {
throw context.getRuntime().newRuntimeError("Could not parse document: " + ex.getMessage());
} catch (IOException ex) {
throw context.getRuntime().newIOError(ex.getMessage());
}
}
use of org.iso_relax.verifier.VerifierConfigurationException in project nokogiri by sparklemotion.
the class XmlRelaxng method createSchemaInstance.
static XmlSchema createSchemaInstance(ThreadContext context, RubyClass klazz, Source source) {
Ruby runtime = context.getRuntime();
XmlRelaxng xmlRelaxng = (XmlRelaxng) NokogiriService.XML_RELAXNG_ALLOCATOR.allocate(runtime, klazz);
xmlRelaxng.setInstanceVariable("@errors", runtime.newEmptyArray());
try {
Schema schema = xmlRelaxng.getSchema(source, context);
xmlRelaxng.setVerifier(schema.newVerifier());
return xmlRelaxng;
} catch (VerifierConfigurationException ex) {
throw context.getRuntime().newRuntimeError("Could not parse document: " + ex.getMessage());
}
}
use of org.iso_relax.verifier.VerifierConfigurationException in project gocd by gocd.
the class XmlRelaxng method getSchema.
private Schema getSchema(Source source, ThreadContext context) {
InputStream is = null;
VerifierFactory factory = new com.thaiopensource.relaxng.jarv.VerifierFactoryImpl();
if (source instanceof StreamSource) {
StreamSource ss = (StreamSource) source;
is = ss.getInputStream();
} else {
//if (this.source instanceof DOMSource)
DOMSource ds = (DOMSource) source;
StringWriter xmlAsWriter = new StringWriter();
StreamResult result = new StreamResult(xmlAsWriter);
try {
TransformerFactory.newInstance().newTransformer().transform(ds, result);
} catch (TransformerConfigurationException ex) {
throw context.getRuntime().newRuntimeError("Could not parse document: " + ex.getMessage());
} catch (TransformerException ex) {
throw context.getRuntime().newRuntimeError("Could not parse document: " + ex.getMessage());
}
try {
is = new ByteArrayInputStream(xmlAsWriter.toString().getBytes("UTF-8"));
} catch (UnsupportedEncodingException ex) {
throw context.getRuntime().newRuntimeError("Could not parse document: " + ex.getMessage());
}
}
try {
return factory.compileSchema(is);
} catch (VerifierConfigurationException ex) {
throw context.getRuntime().newRuntimeError("Could not parse document: " + ex.getMessage());
} catch (SAXException ex) {
throw context.getRuntime().newRuntimeError("Could not parse document: " + ex.getMessage());
} catch (IOException ex) {
throw context.getRuntime().newIOError(ex.getMessage());
}
}
use of org.iso_relax.verifier.VerifierConfigurationException in project gocd by gocd.
the class XmlRelaxng method createSchemaInstance.
static XmlSchema createSchemaInstance(ThreadContext context, RubyClass klazz, Source source) {
Ruby runtime = context.getRuntime();
XmlRelaxng xmlRelaxng = (XmlRelaxng) NokogiriService.XML_RELAXNG_ALLOCATOR.allocate(runtime, klazz);
xmlRelaxng.setInstanceVariable("@errors", runtime.newEmptyArray());
try {
Schema schema = xmlRelaxng.getSchema(source, context);
xmlRelaxng.setVerifier(schema.newVerifier());
return xmlRelaxng;
} catch (VerifierConfigurationException ex) {
throw context.getRuntime().newRuntimeError("Could not parse document: " + ex.getMessage());
}
}
Aggregations