List of usage examples for javax.xml.validation SchemaFactory newSchema
public abstract Schema newSchema(Source[] schemas) throws SAXException;
From source file:io.inkstand.jcr.util.JCRContentLoaderTest.java
@Test(expected = InkstandRuntimeException.class) @Ignore/* ww w. jav a2s .c o m*/ public void testLoadContent_validating_invalidResource() throws Exception { // prepare final URL resource = getClass().getResource("test01_inkstandJcrImport_v1-0_invalid.xml"); final Session actSession = repository.login("admin", "admin"); final SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); final Schema schema = schemaFactory.newSchema(getClass().getResource("inkstandJcrImport_v1-0.xsd")); // act subject.setSchema(schema); subject.loadContent(actSession, resource); }
From source file:admincommands.Reload.java
private Schema getSchema(String xml_schema) { Schema schema = null;/*from ww w . ja v a2 s . com*/ 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:io.inkstand.jcr.util.JCRContentLoaderTest.java
@Test public void testLoadContent_validating_validResource() throws Exception { // prepare/*from w w w .j ava 2 s .c o m*/ final URL resource = getClass().getResource("test01_inkstandJcrImport_v1-0.xml"); final Session actSession = repository.login("admin", "admin"); final SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); final Schema schema = schemaFactory.newSchema(getClass().getResource("inkstandJcrImport_v1-0.xsd")); // act subject.setSchema(schema); subject.loadContent(actSession, resource); // assert final Session verifySession = repository.getRepository().login(); verifySession.refresh(true); assertNodeExistByPath(verifySession, "/root"); final Node root = verifySession.getNode("/root"); assertPrimaryNodeType(root, "nt:unstructured"); assertMixinNodeType(root, "mix:title"); assertStringPropertyEquals(root, "jcr:title", "TestTitle"); }
From source file:io.inkstand.scribble.jcr.rules.util.XMLContentLoaderTest.java
@Test(expected = AssertionError.class) public void testLoadContent_validating_invalidResource() throws Exception { // prepare/*from w w w .j a v a2 s . c o m*/ final URL resource = getClass().getResource("XMLContentLoaderTest_inkstandJcrImport_v1-0_invalid.xml"); final Session actSession = repository.getAdminSession(); final SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); final Schema schema = schemaFactory.newSchema(getClass().getResource("inkstandJcrImport_v1-0.xsd")); // act subject.setSchema(schema); subject.loadContent(actSession, resource); }
From source file:io.tourniquet.junit.jcr.rules.util.XMLContentLoaderTest.java
@Test(expected = AssertionError.class) public void testLoadContent_validating_invalidResource() throws Exception { // prepare/* w ww . j a va 2 s . c o m*/ final URL resource = getClass().getResource("XMLContentLoaderTest_tourniquetJcrImport_v1-0_invalid.xml"); final Session actSession = repository.getAdminSession(); final SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); final Schema schema = schemaFactory.newSchema(resolver.resolve("/tourniquetJcrImport_v1-0.xsd")); // act subject.setSchema(schema); subject.loadContent(actSession, resource); }
From source file:org.openwms.core.configuration.file.ApplicationPreferenceTest.java
/** * Just test to validate the given XML file against the schema declaration. If the XML file is not compliant with the schema, the test * will fail.//from ww w. j a va 2 s. c o m * * @throws Exception any error */ @Test public void testReadPreferences() throws Exception { SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); Schema schema = schemaFactory.newSchema(ResourceUtils.getFile("classpath:preferences.xsd")); // Schema schema = schemaFactory.newSchema(new // URL("http://www.openwms.org/schema/preferences.xsd")); JAXBContext ctx = JAXBContext.newInstance("org.openwms.core.configuration.file"); Unmarshaller unmarshaller = ctx.createUnmarshaller(); unmarshaller.setSchema(schema); unmarshaller.setEventHandler(new ValidationEventHandler() { @Override public boolean handleEvent(ValidationEvent event) { RuntimeException ex = new RuntimeException(event.getMessage(), event.getLinkedException()); LOGGER.error(ex.getMessage()); throw ex; } }); Preferences prefs = Preferences.class.cast(unmarshaller .unmarshal(ResourceUtils.getFile("classpath:org/openwms/core/configuration/file/preferences.xml"))); for (AbstractPreference pref : prefs.getApplications()) { LOGGER.info(pref.toString()); } for (AbstractPreference pref : prefs.getModules()) { LOGGER.info(pref.toString()); } for (AbstractPreference pref : prefs.getUsers()) { LOGGER.info(pref.toString()); } }
From source file:mx.bigdata.cfdi.CFDv3.java
public void validate(ErrorHandler handler) throws Exception { SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); Schema schema = sf.newSchema(getClass().getResource(XSD)); Validator validator = schema.newValidator(); if (handler != null) { validator.setErrorHandler(handler); }/*from ww w . j a v a 2 s . c om*/ validator.validate(new JAXBSource(CONTEXT, document)); }
From source file:io.inkstand.scribble.jcr.rules.util.XMLContentLoaderTest.java
@Test public void testLoadContent_validating_validResource() throws Exception { // prepare/*from w w w . j av a2s.co m*/ final URL resource = getClass().getResource("XMLContentLoaderTest_inkstandJcrImport_v1-0.xml"); final Session actSession = repository.getAdminSession(); final SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); final Schema schema = schemaFactory.newSchema(getClass().getResource("inkstandJcrImport_v1-0.xsd")); // act subject.setSchema(schema); Node rootNode = subject.loadContent(actSession, resource); // assert assertNotNull(rootNode); final Session verifySession = repository.getRepository().login(); verifySession.refresh(true); assertNodeExistByPath(verifySession, "/root"); final Node root = verifySession.getNode("/root"); assertNodeExistByPath(verifySession, "/root"); assertPrimaryNodeType(root, "nt:unstructured"); assertMixinNodeType(root, "mix:title"); assertStringPropertyEquals(root, "jcr:title", "TestTitle"); }
From source file:io.tourniquet.junit.jcr.rules.util.XMLContentLoaderTest.java
@Test public void testLoadContent_validating_validResource() throws Exception { // prepare/* www . ja va2 s . c o m*/ final URL resource = getClass().getResource("XMLContentLoaderTest_tourniquetJcrImport_v1-0.xml"); final Session actSession = repository.getAdminSession(); final SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); final Schema schema = schemaFactory.newSchema(resolver.resolve("/tourniquetJcrImport_v1-0.xsd")); // act subject.setSchema(schema); Node rootNode = subject.loadContent(actSession, resource); // assert assertNotNull(rootNode); final Session verifySession = repository.getRepository().login(); verifySession.refresh(true); assertNodeExistByPath(verifySession, "/root"); final Node root = verifySession.getNode("/root"); assertNodeExistByPath(verifySession, "/root"); assertPrimaryNodeType(root, "nt:unstructured"); assertMixinNodeType(root, "mix:title"); assertStringPropertyEquals(root, "jcr:title", "TestTitle"); }
From source file:mx.bigdata.sat.cfdi.TFDv1.java
public void validar(ErrorHandler handler) throws Exception { SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); Schema schema = sf.newSchema(getClass().getResource(XSD)); Validator validator = schema.newValidator(); if (handler != null) { validator.setErrorHandler(handler); }//from ww w .ja v a 2 s .c o m validator.validate(new JAXBSource(CONTEXT, tfd)); }