use of javax.xml.validation.Schema in project wildfly by wildfly.
the class StandardConfigsXMLValidationUnitTestCase method parseXml.
private void parseXml(String xmlName) throws ParserConfigurationException, SAXException, IOException {
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
schemaFactory.setErrorHandler(new ErrorHandlerImpl());
schemaFactory.setResourceResolver(DEFAULT_RESOURCE_RESOLVER);
Schema schema = schemaFactory.newSchema(SCHEMAS);
Validator validator = schema.newValidator();
validator.setErrorHandler(new ErrorHandlerImpl());
validator.setFeature("http://apache.org/xml/features/validation/schema", true);
validator.setResourceResolver(DEFAULT_RESOURCE_RESOLVER);
validator.validate(new StreamSource(getXmlFile(xmlName)));
}
use of javax.xml.validation.Schema in project wildfly by wildfly.
the class XSDValidationUnitTestCase method validateXsd.
private void validateXsd(final File xsdFile) throws Exception {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
DocumentBuilder parser = factory.newDocumentBuilder();
Document document = parser.parse(xsdFile);
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
schemaFactory.setErrorHandler(new ErrorHandlerImpl());
schemaFactory.setResourceResolver(new XMLResourceResolver());
Schema schema = schemaFactory.newSchema(resource("schema/XMLSchema.xsd"));
Validator validator = schema.newValidator();
validator.validate(new DOMSource(document));
}
use of javax.xml.validation.Schema in project Activiti by Activiti.
the class BpmnXMLConverter method validateModel.
public void validateModel(XMLStreamReader xmlStreamReader) throws Exception {
Schema schema = createSchema();
Validator validator = schema.newValidator();
validator.validate(new StAXSource(xmlStreamReader));
}
use of javax.xml.validation.Schema in project ACS by ACS-Community.
the class XMLValidator method run.
public void run(String[] args) {
try {
if (args.length != 2) {
System.out.println("Incorrect arguments. You need to provide the XML and XSD files.");
System.exit(3);
}
XMLValidator.error = false;
// define the type of schema - we use W3C:
String schemaLang = "http://www.w3.org/2001/XMLSchema";
// get validation driver:
SchemaFactory factory = SchemaFactory.newInstance(schemaLang);
// create schema by reading it from an XSD file:
Schema schema = factory.newSchema(new StreamSource(args[1]));
Validator validator = schema.newValidator();
ErrorHandler eh = new XMLErrorHandler(args[0]);
validator.setErrorHandler(eh);
// at last perform validation:
XMLInputFactory xFact = XMLInputFactory.newInstance();
XMLStreamReader xRead = xFact.createXMLStreamReader(new FileReader(args[0]));
if (xRead.getVersion() == null) {
System.err.println(args[0] + ": There is no XML Definition.");
XMLValidator.error = true;
} else if (xRead.getCharacterEncodingScheme() == null) {
System.err.println(args[0] + ": The encoding attribute is not defined in the XML Definition.");
XMLValidator.error = true;
} else if (xRead.getCharacterEncodingScheme().compareTo("ISO-8859-1") != 0) {
System.err.println(args[0] + ": Incorrect encoding type in the XML Definition.");
XMLValidator.error = true;
}
validator.validate(new StreamSource(args[0]));
} catch (SAXException ex) {
System.err.println("Fatal Error");
System.err.println(args[0] + ": " + ex.getMessage());
XMLValidator.error = true;
} catch (Exception ex) {
ex.printStackTrace();
XMLValidator.error = true;
}
if (XMLValidator.error) {
//System.exit(1); //Error
//Warning
System.exit(0);
} else {
System.exit(0);
}
}
use of javax.xml.validation.Schema in project oxTrust by GluuFederation.
the class Shibboleth3ConfService method validateMetadata.
/**
* @param stream
* @throws IOException
* @throws SAXException
* @throws ParserConfigurationException
* @return GluuErrorHandler
*/
public GluuErrorHandler validateMetadata(InputStream stream) throws ParserConfigurationException, SAXException, IOException {
String idpTemplatesLocation = configurationFactory.getIDPTemplatesLocation();
// String schemaDir = configurationFactory.DIR + "shibboleth3" + File.separator + "idp" + File.separator + "schema" + File.separator;
String schemaDir = idpTemplatesLocation + "shibboleth3" + File.separator + "idp" + File.separator + "schema" + File.separator;
Schema schema = SchemaBuilder.buildSchema(SchemaLanguage.XML, schemaDir);
return XMLValidator.validateMetadata(stream, schema);
}
Aggregations