}
}
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()