List of usage examples for javax.xml.validation SchemaFactory newSchema
public abstract Schema newSchema(Source[] schemas) throws SAXException;
From source file:com.aionemu.gameserver.dataholders.ReloadableData.java
protected Schema getSchema(String xml_schema) { Schema schema = null;//from ww w.ja v a 2s . c om SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); try { schema = sf.newSchema(new File(xml_schema)); } catch (SAXException saxe) { throw new Error("Error while getting schema", saxe); } return schema; }
From source file:com.springsource.hq.plugin.tcserver.serverconfig.ProfileMarshaller.java
public ProfileMarshaller() throws JAXBException, SAXException, IOException { jaxbContext = JAXBContext.newInstance(Profile.class, TomcatDataSource.class, DbcpDataSource.class, AjpConnector.class, HttpConnector.class); Resource schemaResource = new ClassPathResource("tomcatserverconfig-profile-2.0.xsd", Profile.class); SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); profileSchema = schemaFactory.newSchema(schemaResource.getURL()); }
From source file:org.geowebcache.config.XMLConfiguration.java
static void validate(Node rootNode) throws SAXException, IOException { // Perform validation // TODO dont know why this one suddenly failed to look up, revert to // XMLConstants.W3C_XML_SCHEMA_NS_URI SchemaFactory factory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema"); InputStream is = XMLConfiguration.class.getResourceAsStream("geowebcache.xsd"); Schema schema = factory.newSchema(new StreamSource(is)); Validator validator = schema.newValidator(); // debugPrint(rootNode); DOMSource domSrc = new DOMSource(rootNode); validator.validate(domSrc);//w w w . j a va 2 s . c om }
From source file:au.id.hazelwood.xmltvguidebuilder.config.ConfigFactory.java
public ConfigFactory() throws Exception { StopWatch stopWatch = new StopWatch(); stopWatch.start();//from w w w . j av a 2 s. c o m SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); schema = schemaFactory.newSchema(new StreamSource(toInputStream("/config.xsd"))); stopWatch.stop(); LOGGER.debug("ConfigFactory created in {}", formatDurationWords(stopWatch.getTime())); }
From source file:com.ebay.jetstream.event.processor.esper.raw.EsperTestConfigurationValidator.java
public boolean validate(String instance, String schema) { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); try {/*from w ww .j a va 2s . c om*/ warnings = 0; errors = 0; fatalErrors = 0; try { //Set the validation feature factory.setFeature("http://xml.org/sax/features/validation", true); //Set the schema validation feature factory.setFeature("http://apache.org/xml/features/validation/schema", true); //Set schema full grammar checking factory.setFeature("http://apache.org/xml/features/validation/schema-full-checking", true); // If there is an external schema set it if (schema != null) { SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); Schema s = sf.newSchema(new StreamSource(schema)); factory.setSchema(s); } DocumentBuilder parser = factory.newDocumentBuilder(); parser.setErrorHandler(this); // Parse and validate parser.parse(instance); // Return true if we made it this far with no errors return ((errors == 0) && (fatalErrors == 0)); } catch (SAXException e) { log.error("Could not activate validation features - " + e.getMessage()); } } catch (Exception e) { log.error(e.getMessage()); } return false; }
From source file:gov.nih.nci.ncicb.cadsr.bulkloader.schema.validator.SchemaValidatorImpl.java
/** * //from w ww . j a va2s. c om * @return <code>javax.xml.validation.Schema</code> * @throws SchemaValidationException */ private Schema getSchema() throws SAXException { URL xsdURL = getSchemaURL(); SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); Schema schema = schemaFactory.newSchema(xsdURL); return schema; }
From source file:net.geoprism.gis.sld.SLDValidator.java
public void validate(String sld) { try {/*w ww . j a v a2 s . co m*/ SchemaFactory f = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); Source xsdS = new StreamSource(xsd); Schema schema = f.newSchema(xsdS); Validator v = schema.newValidator(); InputStream stream; stream = new ByteArrayInputStream(sld.getBytes("UTF-8")); Source s = new StreamSource(stream); v.validate(s); } catch (Throwable e) { log.error(sld, e); throw new ProgrammingErrorException("Invalid SLD", e); } }
From source file:com.maxl.java.aips2xml.Aips2Xml.java
static List<MedicalInformations.MedicalInformation> readAipsFile() { List<MedicalInformations.MedicalInformation> med_list = null; try {//from ww w .j a va 2 s.c om JAXBContext context = JAXBContext.newInstance(MedicalInformations.class); // Validation SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); Schema schema = sf.newSchema(new File(FILE_MEDICAL_INFOS_XSD)); Validator validator = schema.newValidator(); validator.setErrorHandler(new MyErrorHandler()); // Marshaller /* Marshaller ma = context.createMarshaller(); ma.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); MedicalInformations medi_infos = new MedicalInformations(); ma.marshal(medi_infos, System.out); */ // Unmarshaller long startTime = System.currentTimeMillis(); if (SHOW_LOGS) System.out.print("- Unmarshalling Swissmedic xml ... "); FileInputStream fis = new FileInputStream(new File(FILE_MEDICAL_INFOS_XML)); Unmarshaller um = context.createUnmarshaller(); MedicalInformations med_infos = (MedicalInformations) um.unmarshal(fis); med_list = med_infos.getMedicalInformation(); long stopTime = System.currentTimeMillis(); if (SHOW_LOGS) System.out.println(med_list.size() + " medis in " + (stopTime - startTime) / 1000.0f + " sec"); } catch (IOException e) { e.printStackTrace(); } catch (JAXBException e) { e.printStackTrace(); } catch (SAXException e) { e.printStackTrace(); } return med_list; }
From source file:com.bluecloud.ioc.parse.KernelXMLParser.java
public KernelXMLParser() throws KernelXMLParserException { InputStream is = KernelXMLParser.class.getClassLoader().getResourceAsStream(SHCAME); if (null == is) { throw new KernelXMLParserException(SHCAME + "?"); }//from ww w . j a v a 2 s . c o m SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); try { Schema schema = factory.newSchema(new StreamSource(is)); validator = schema.newValidator(); is.close(); } catch (Exception e) { throw new KernelXMLParserException(e); } }
From source file:com.geewhiz.pacify.managers.EntityManager.java
public EntityManager(File startPath) { this.startPath = startPath; try {/*from www . j a v a2s . co m*/ jaxbContext = JAXBContext.newInstance(ObjectFactory.class); SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); schema = factory.newSchema( new StreamSource(EntityManager.class.getClassLoader().getResourceAsStream("pacify.xsd"))); } catch (Exception e) { throw new RuntimeException("Couldn't instanciate jaxb.", e); } }