use of javax.xml.validation.SchemaFactory in project camel by apache.
the class XAdESSignaturePropertiesTest method validateAgainstSchema.
private void validateAgainstSchema(Document doc) throws Exception {
SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Source schema1 = new StreamSource(new File("target/test-classes/org/apache/camel/component/xmlsecurity/xades/XAdES.xsd"));
Source schema2 = new StreamSource(new File("target/test-classes/org/apache/camel/component/xmlsecurity/xades/xmldsig-core-schema.xsd"));
Schema schema = factory.newSchema(new Source[] { schema2, schema1 });
Validator validator = schema.newValidator();
validator.validate(new DOMSource(doc));
}
use of javax.xml.validation.SchemaFactory in project camel by apache.
the class XmlSignatureProcessor method getSchema.
protected Schema getSchema(Message message) throws SAXException, XmlSignatureException, IOException {
String schemaResourceUri = getSchemaResourceUri(message);
if (schemaResourceUri == null || schemaResourceUri.isEmpty()) {
return null;
}
InputStream is = ResourceHelper.resolveResourceAsInputStream(getConfiguration().getCamelContext().getClassResolver(), schemaResourceUri);
if (is == null) {
throw new XmlSignatureException("XML Signature component is wrongly configured: No XML schema found for specified schema resource URI " + schemaResourceUri);
}
byte[] bytes = null;
try {
bytes = IOConverter.toBytes(is);
} finally {
// and make sure to close the input stream after the schema has been loaded
IOHelper.close(is);
}
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
schemaFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
schemaFactory.setResourceResolver(new DefaultLSResourceResolver(getConfiguration().getCamelContext(), getConfiguration().getSchemaResourceUri()));
LOG.debug("Instantiating schema for validation");
return schemaFactory.newSchema(new BytesSource(bytes));
}
use of javax.xml.validation.SchemaFactory in project hazelcast by hazelcast.
the class ClientDiscoverySpiTest method testSchema.
@Test
public void testSchema() throws Exception {
String xmlFileName = "hazelcast-client-discovery-spi-test.xml";
SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
URL schemaResource = ClientDiscoverySpiTest.class.getClassLoader().getResource("hazelcast-client-config-3.9.xsd");
Schema schema = factory.newSchema(schemaResource);
InputStream xmlResource = ClientDiscoverySpiTest.class.getClassLoader().getResourceAsStream(xmlFileName);
Source source = new StreamSource(xmlResource);
Validator validator = schema.newValidator();
validator.validate(source);
}
use of javax.xml.validation.SchemaFactory in project gocd by gocd.
the class MagicalGoConfigXmlWriterTest method shouldBeAValidXSD.
@Test
public void shouldBeAValidXSD() throws Exception {
SchemaFactory factory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
factory.newSchema(new StreamSource(getClass().getResourceAsStream("/cruise-config.xsd")));
}
use of javax.xml.validation.SchemaFactory in project graphhopper by graphhopper.
the class InstructionListTest method verifyGPX.
public void verifyGPX(String gpx) {
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = null;
try {
Source schemaFile = new StreamSource(getClass().getResourceAsStream("gpx-schema.xsd"));
schema = schemaFactory.newSchema(schemaFile);
// using more schemas: http://stackoverflow.com/q/1094893/194609
} catch (SAXException e1) {
throw new IllegalStateException("There was a problem with the schema supplied for validation. Message:" + e1.getMessage());
}
Validator validator = schema.newValidator();
try {
validator.validate(new StreamSource(new StringReader(gpx)));
} catch (Exception e) {
throw new RuntimeException(e);
}
}
Aggregations