List of usage examples for org.apache.commons.digester3 Digester setXMLSchema
public void setXMLSchema(Schema schema)
From source file:edu.wustl.bulkoperator.templateImport.AbstractImportBulkOperation.java
/** * * @param operationName/*from w w w.j a v a2s . c o m*/ * @param dropdownName * @param csvFile * @param xmlFile * @param mappingXml * @return * @throws BulkOperationException * @throws SQLException * @throws IOException * @throws DAOException */ protected Set<String> validate(String operationName, String dropdownName, String csvFile, String xmlFile, String mappingXml, String xsdLocation) throws BulkOperationException, SQLException, IOException, DAOException { Set<String> errorList = null; CsvReader csvReader = null; try { csvReader = CsvFileReader.createCsvFileReader(csvFile, true); } catch (Exception exp) { ErrorKey errorkey = ErrorKey.getErrorKey("bulk.error.incorrect.csv.file"); throw new BulkOperationException(errorkey, exp, ""); } BulkOperationMetaData bulkOperationMetaData = null; try { SchemaFactory factory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema"); File schemaLocation = new File(xsdLocation); Schema schema = factory.newSchema(schemaLocation); DigesterLoader digesterLoader = DigesterLoader.newLoader(new XmlRulesModule(mappingXml)); Digester digester = digesterLoader.newDigester(); digester.setValidating(true); digester.setXMLSchema(schema); Validator validator = schema.newValidator(); Source xmlFileForValidation = new StreamSource(new File(xmlFile)); validator.validate(xmlFileForValidation); InputStream inputStream = new FileInputStream(xmlFile); bulkOperationMetaData = digester.parse(inputStream); } catch (SAXException e) { logger.debug(e.getMessage()); ErrorKey errorkey = ErrorKey.getErrorKey("bulk.error.xml.template"); throw new BulkOperationException(errorkey, e, e.getMessage()); } Collection<BulkOperationClass> classList = bulkOperationMetaData.getBulkOperationClass(); if (classList == null) { ErrorKey errorkey = ErrorKey.getErrorKey("bulk.no.templates.loaded.message"); throw new BulkOperationException(errorkey, null, ""); } else { Iterator<BulkOperationClass> iterator = classList.iterator(); if (iterator.hasNext()) { BulkOperationClass bulkOperationClass = iterator.next(); TemplateValidator templateValidator = new TemplateValidator(); errorList = templateValidator.validateXmlAndCsv(bulkOperationClass, operationName, csvReader); } } return errorList; }