use of javax.xml.validation.Validator in project languagetool by languagetool-org.
the class XMLValidator method getValidator.
private Validator getValidator(URL xmlSchema) throws SAXException {
SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = sf.newSchema(xmlSchema);
Validator validator = schema.newValidator();
validator.setErrorHandler(new ErrorHandler());
return validator;
}
use of javax.xml.validation.Validator in project honeycomb by altamiracorp.
the class ConfigurationParser method checkValidConfig.
/**
* Performs validation on the configuration content supplied by the
* configuration supplier against the schema document provided by the
* validation supplier. Throws Runtime exception if validation fails.
*
* @param configSupplier The supplier that provides the configuration to inspect, not null
* @param schemaSupplier The supplier that provides the schema used to inspect the configuration, not null
*/
private static void checkValidConfig(final InputSupplier<? extends InputStream> configSupplier, final InputSupplier<? extends InputStream> schemaSupplier) {
try {
final SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
final Schema schema = schemaFactory.newSchema(new StreamSource(schemaSupplier.getInput()));
final Validator validator = schema.newValidator();
validator.validate(new StreamSource(configSupplier.getInput()));
} catch (Exception e) {
logger.error("Unable to validate honeycomb configuration.", e);
throw new RuntimeException("Exception while validating honeycomb configuration.", e);
}
}
use of javax.xml.validation.Validator in project voldemort by voldemort.
the class ClusterMapper method readCluster.
@SuppressWarnings("unchecked")
public Cluster readCluster(Reader input, boolean verifySchema) {
try {
SAXBuilder builder = new SAXBuilder(false);
Document doc = builder.build(input);
if (verifySchema) {
Validator validator = this.schema.newValidator();
validator.validate(new JDOMSource(doc));
}
Element root = doc.getRootElement();
if (!root.getName().equals(CLUSTER_ELMT))
throw new MappingException("Invalid root element: " + doc.getRootElement().getName());
String name = root.getChildText(CLUSTER_NAME_ELMT);
List<Zone> zones = new ArrayList<Zone>();
for (Element node : (List<Element>) root.getChildren(ZONE_ELMT)) zones.add(readZone(node));
List<Node> servers = new ArrayList<Node>();
for (Element node : (List<Element>) root.getChildren(SERVER_ELMT)) servers.add(readServer(node));
return new Cluster(name, servers, zones);
} catch (JDOMException e) {
throw new MappingException(e);
} catch (SAXException e) {
throw new MappingException(e);
} catch (IOException e) {
throw new MappingException(e);
}
}
use of javax.xml.validation.Validator in project voldemort by voldemort.
the class StoreDefinitionsMapper method readStoreList.
public List<StoreDefinition> readStoreList(Reader input, boolean verifySchema) {
try {
SAXBuilder builder = new SAXBuilder();
Document doc = builder.build(input);
if (verifySchema) {
Validator validator = schema.newValidator();
validator.validate(new JDOMSource(doc));
}
Element root = doc.getRootElement();
if (!root.getName().equals(STORES_ELMT))
throw new MappingException("Invalid root element: " + doc.getRootElement().getName());
List<StoreDefinition> stores = new ArrayList<StoreDefinition>();
for (Object store : root.getChildren(STORE_ELMT)) stores.add(readStore((Element) store));
for (Object view : root.getChildren(VIEW_ELMT)) stores.add(readView((Element) view, stores));
return stores;
} catch (JDOMException e) {
throw new MappingException(e);
} catch (SAXException e) {
throw new MappingException(e);
} catch (IOException e) {
throw new MappingException(e);
}
}
use of javax.xml.validation.Validator in project ORCID-Source by ORCID.
the class ValidateV2IdentifiersTest method validateSampleXML.
public void validateSampleXML(String name) throws SAXException, IOException {
Source source = getInputStream("/record_2.0/samples/read_samples/" + name + "-2.0.xml");
Validator validator = getValidator(name);
validator.validate(source);
}
Aggregations