@Test(expected = ConfigurationException.class) public void validateXMLTestInvalidURL() throws MalformedURLException { XMLValidator validator = new XMLValidator(); URL xsd = validator.getClass().getResource("/configTest.xsd"); URL xml = new URL("http: validator.validateXML(xml, xsd); }
@Override public void validateXML(File xmlFile, URL xsdUrl) { Validate.notNull(xmlFile, "No URL to xml file provided!"); if (xsdUrl != null) { SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); try { Schema schema = factory.newSchema(xsdUrl); Validator validator = schema.newValidator(); StreamSource source = new StreamSource(xmlFile); validator.validate(source); } catch (SAXException e) { LOGGER.error("Invalid XML", e); throw new ConfigurationException("The config File " + xmlFile + " could not be validated against" + xsdUrl, e); } catch (IOException e) { LOGGER.error("File access failing", e); throw new ConfigurationException("The config File could not be validated", e); } } }
XMLValidator extends IXMLValidator { @Override public void validateXML(File xmlFile, URL xsdUrl) { Validate.notNull(xmlFile, "No URL to xml file provided!"); if (xsdUrl != null) { SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); try { Schema schema = factory.newSchema(xsdUrl); Validator validator = schema.newValidator(); StreamSource source = new StreamSource(xmlFile); validator.validate(source); } catch (SAXException e) { LOGGER.error("Invalid XML", e); throw new ConfigurationException("The config File " + xmlFile + " could not be validated against" + xsdUrl, e); } catch (IOException e) { LOGGER.error("File access failing", e); throw new ConfigurationException("The config File could not be validated", e); } } } }
XMLValidator extends IXMLValidator { @Override public void validateXML(File xmlFile, URL xsdUrl) { Validate.notNull(xmlFile, "No URL to xml file provided!"); if (xsdUrl != null) { SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); try { Schema schema = factory.newSchema(xsdUrl); Validator validator = schema.newValidator(); StreamSource source = new StreamSource(xmlFile); validator.validate(source); } catch (SAXException e) { LOGGER.error("Invalid XML", e); throw new ConfigurationException("The config File " + xmlFile + " could not be validated against" + xsdUrl, e); } catch (IOException e) { LOGGER.error("File access failing", e); throw new ConfigurationException("The config File could not be validated", e); } } }  }
XMLValidator extends IXMLValidator { @Override public void validateXML(File xmlFile, URL xsdUrl) { Validate.notNull(xmlFile, "No URL to xml file provided!"); if (xsdUrl != null) { SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); try { Schema schema = factory.newSchema(xsdUrl); Validator validator = schema.newValidator(); StreamSource source = new StreamSource(xmlFile); validator.validate(source); } catch (SAXException e) { LOGGER.error("Invalid XML", e); throw new ConfigurationException("The config File " + xmlFile + " could not be validated against" + xsdUrl, e); } catch (IOException e) { LOGGER.error("File access failing", e); throw new ConfigurationException("The config File could not be validated", e); } } }  @Override void validateXML(File xmlFile, URL xsdUrl); }
XMLValidator extends IXMLValidator { @Override public void validateXML(File xmlFile, URL xsdUrl) { Validate.notNull(xmlFile, "No URL to xml file provided!"); if (xsdUrl != null) { SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); try { Schema schema = factory.newSchema(xsdUrl); Validator validator = schema.newValidator(); StreamSource source = new StreamSource(xmlFile); validator.validate(source); } catch (SAXException e) { LOGGER.error("Invalid XML", e); throw new ConfigurationException("The config File " + xmlFile + " could not be validated against" + xsdUrl, e); } catch (IOException e) { LOGGER.error("File access failing", e); throw new ConfigurationException("The config File could not be validated", e); } } }  @Override void validateXML(File xmlFile, URL xsdUrl);  }