List of usage examples for javax.xml XMLConstants W3C_XML_SCHEMA_NS_URI
String W3C_XML_SCHEMA_NS_URI
To view the source code for javax.xml XMLConstants W3C_XML_SCHEMA_NS_URI.
Click Source Link
From source file:de.intevation.test.irixservice.UploadReportTest.java
public ReportType getReportFromFile(String file) { try {//w w w . java 2 s . com JAXBContext jaxbContext = JAXBContext.newInstance(ReportType.class.getPackage().getName()); SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); Schema schema = schemaFactory.newSchema(testObj.irixSchemaFile); Unmarshaller u = jaxbContext.createUnmarshaller(); u.setSchema(schema); JAXBElement obj = (JAXBElement) u.unmarshal(new File(file)); return (ReportType) obj.getValue(); } catch (JAXBException | SAXException e) { log.debug("Failed to parse report test data: " + file); log.debug(e); return null; } }
From source file:mx.bigdata.sat.cfdi.TFDv11c33.java
public void validar(ErrorHandler handler) throws Exception { SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); Source[] schemas = new Source[XSD.length]; for (int i = 0; i < XSD.length; i++) { schemas[i] = new StreamSource(getClass().getResourceAsStream(XSD[i])); }/*from www .j a v a2 s .co m*/ Schema schema = sf.newSchema(schemas); Validator validator = schema.newValidator(); if (handler != null) { validator.setErrorHandler(handler); } validator.validate(new JAXBSource(CONTEXT, tfd)); }
From source file:it.polimi.modaclouds.qos_models.util.XMLHelper.java
public static <T> ValidationResult validate(URL xmlUrl, Class<T> targetClass) { SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); Unmarshaller unmarshaller;/* w w w .j av a 2s . c om*/ ValidationResult result; try { Schema schema = schemaFactory.newSchema(); unmarshaller = JAXBContext.newInstance(targetClass).createUnmarshaller(); unmarshaller.setSchema(schema); } catch (SAXException | JAXBException e) { result = new ValidationResult(false); result.addMessage("Error occured in creating the schema"); result.addMessage(e.getLocalizedMessage()); return result; } try { unmarshaller.unmarshal(xmlUrl); } catch (JAXBException e) { result = new ValidationResult(false); if (e.getMessage() != null) result.addMessage(e.getLocalizedMessage()); if (e.getLinkedException() != null && e.getLinkedException().getLocalizedMessage() != null) result.addMessage(e.getLinkedException().getLocalizedMessage()); return result; } return new ValidationResult(true); }
From source file:com.agimatec.validation.jsr303.xml.ValidationParser.java
static Schema getSchema(String xsd) { ClassLoader loader = PrivilegedActions.getClassLoader(ValidationParser.class); SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); URL schemaUrl = loader.getResource(xsd); try {//from w w w .ja va2 s . c o m return sf.newSchema(schemaUrl); } catch (SAXException e) { log.warn("Unable to parse schema: " + xsd, e); return null; } }
From source file:de.tudarmstadt.ukp.experiments.dip.wp1.data.QueryResultContainer.java
/** * Validates input XML file using 'queryResult.xsd' schema. * * @param xml xml//from w ww .j a v a 2 s . c o m * @throws IOException if file is not valid */ public static void validateXML(String xml) throws IOException { String xsdName = "queryResult.xsd"; URL resource = QueryResultContainer.class.getClass().getResource(xsdName); if (resource == null) { throw new IllegalStateException("Cannot locate resource " + xsdName + " on classpath"); } URL xsdFile; try { xsdFile = resource.toURI().toURL(); } catch (MalformedURLException | URISyntaxException e) { throw new IOException(e); } SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); try { Schema schema = factory.newSchema(xsdFile); Validator validator = schema.newValidator(); validator.validate(new StreamSource(new StringReader(xml))); } catch (SAXException e) { throw new IOException(e); } }
From source file:at.gv.egiz.slbinding.SLUnmarshaller.java
private static Schema createSchema(Collection<String> schemaUrls) throws SAXException, IOException { Logger log = LoggerFactory.getLogger(SLUnmarshaller.class); Source[] sources = new Source[schemaUrls.size()]; Iterator<String> urls = schemaUrls.iterator(); StringBuilder sb = null;/*w w w. j av a2 s . c o m*/ if (log.isDebugEnabled()) { sb = new StringBuilder(); sb.append("Created schema using URLs: "); } for (int i = 0; i < sources.length && urls.hasNext(); i++) { String url = urls.next(); if (url != null && url.startsWith("classpath:")) { URL schemaUrl = new URL(null, url, new ClasspathURLStreamHandler()); sources[i] = new StreamSource(schemaUrl.openStream()); } else { sources[i] = new StreamSource(url); } if (sb != null) { sb.append(url); if (urls.hasNext()) { sb.append(", "); } } } SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); Schema schema = schemaFactory.newSchema(sources); if (sb != null) { log.debug(sb.toString()); } return schema; }
From source file:edu.northwestern.bioinformatics.studycalendar.grid.PSCStudyServiceTest.java
public void testCopy() throws Exception { // InputStream config = Thread.currentThread().getContextClassLoader(). // getResourceAsStream("edu/northwestern/bioinformatics/studycalendar/grid/client/client-config.wsdd"); //example of this study xml // <?xml version="1.0" encoding="UTF-8"?> // <study xmlns="http://bioinformatics.northwestern.edu/ns/psc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" // assigned-identifier="cc" id="96507ff5-06e7-4f45-bfc5-179b888e69f6" // xsi:schemaLocation="http://bioinformatics.northwestern.edu/ns/psc // http://bioinformatics.northwestern.edu/ns/psc/psc.xsd"> // <planned-calendar id="9a2ec400-ef49-4d7d-9917-5766193c8181"/> // </study> // String studyDocumentXml= studyXmlSerializer.createDocumentString(gridStudy); // logger.debug("study doc xml"+studyDocumentXml); String studyXML = studyXMLWriter.createStudyXML(study); validate(studyXML, true);//from w w w . ja v a 2s. c o m edu.northwestern.bioinformatics.studycalendar.grid.Study gridStudy = populateGridStudy(studyXML); assertNotNull(gridStudy); //now serialize back this grid study to study xml StringWriter studyXml = new StringWriter(); Utils.serializeObject(gridStudy, new javax.xml.namespace.QName("http://bioinformatics.northwestern.edu/ns/psc", "study", XMLConstants.W3C_XML_SCHEMA_NS_URI), studyXml); //logger.info("study xml:" + studyXml.toString()); ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream( studyXml.getBuffer().toString().getBytes()); StudyXMLReader studyXMLReader = new StudyXMLReader(); studyXMLReader.readAndSave(byteArrayInputStream); }
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 a va 2 s.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:eu.europa.ejusticeportal.dss.controller.config.Config.java
/** * /*from w ww. j a v a 2 s. c o m*/ * The default constructor for SigningContextRepositoryXmlImpl. */ private Config() { InputStream is = null; try { is = Config.class.getClassLoader().getResourceAsStream("signingcontext-v1.xsd"); StreamSource source = new StreamSource(is, CardProfileNamespace.NS); schema = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI).newSchema(source); } catch (SAXException e) { LOGGER.error("Unable to load XML validation schema - validation of configuration xml will not be done.", e); } finally { IOUtils.closeQuietly(is); } }
From source file:io.tourniquet.junit.jcr.rules.util.XMLContentLoaderTest.java
@Test public void testLoadContent_validating_validResource() throws Exception { // prepare/*w w w .j av a2 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"); }