use of org.iso_relax.verifier.VerifierFactory 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.VerifierFactory in project scheduling by ow2-proactive.
the class ValidationUtil method validate.
/**
* Validates the job descriptor file against the specified schema.
*
* @param jobFile
* the job descriptor file
* @param schemaIs
* the job schema
*
* @throws JobCreationException
* if the job descriptor is invalid
*/
public static void validate(File jobFile, InputStream schemaIs) throws SAXException, IOException, JobCreationException {
try {
XMLReader reader = XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser");
VerifierFactory vfactory = new com.sun.msv.verifier.jarv.TheFactoryImpl();
Schema schema = vfactory.compileSchema(schemaIs);
Verifier verifier = schema.newVerifier();
VerifierHandler handler = verifier.getVerifierHandler();
ContentHandlerDecorator contentHandlerDecorator = new ContentHandlerDecorator(handler);
reader.setContentHandler(contentHandlerDecorator);
ValidationErrorHandler errHandler = new ValidationErrorHandler(contentHandlerDecorator);
verifier.setErrorHandler(errHandler);
reader.parse(jobFile.getAbsolutePath());
} catch (SAXException se) {
Throwable cause = se.getCause();
if (cause != null && cause instanceof JobCreationException) {
// unwrap
throw (JobCreationException) cause;
} else {
throw se;
}
} catch (VerifierConfigurationException e) {
throw new IllegalStateException(e);
}
}
use of org.iso_relax.verifier.VerifierFactory 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());
}
}
Aggregations