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:net.sourceforge.pmd.testframework.RuleTst.java
public RuleTst() { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); Schema schema;//from w w w . j av a 2 s. c om try { schema = schemaFactory.newSchema(RuleTst.class.getResource("/rule-tests_1_0_0.xsd")); dbf.setSchema(schema); dbf.setNamespaceAware(true); DocumentBuilder builder = dbf.newDocumentBuilder(); builder.setErrorHandler(new ErrorHandler() { @Override public void warning(SAXParseException exception) throws SAXException { throw exception; } @Override public void fatalError(SAXParseException exception) throws SAXException { throw exception; } @Override public void error(SAXParseException exception) throws SAXException { throw exception; } }); documentBuilder = builder; } catch (SAXException | ParserConfigurationException e) { throw new RuntimeException(e); } }
From source file:nl.armatiek.xslweb.configuration.Context.java
private void initXMLSchemas() throws Exception { SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); File schemaFile = new File(homeDir, "config/xsd/xslweb/webapp.xsd"); if (!schemaFile.isFile()) { logger.warn(String.format("XML Schema \"%s\" not found", schemaFile.getAbsolutePath())); } else {/*from ww w . j av a2 s . c om*/ webAppSchema = factory.newSchema(schemaFile); } }
From source file:nl.b3p.viewer.admin.stripes.GeoServiceActionBean.java
public Resolution validateSldXml() { Resolution jsp = new ForwardResolution(JSP_EDIT_SLD); Document sldXmlDoc = null;/*from w ww .j a v a 2 s . c o m*/ String stage = "Fout bij parsen XML document"; try { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); DocumentBuilder db = dbf.newDocumentBuilder(); sldXmlDoc = db.parse(new ByteArrayInputStream(sld.getSldBody().getBytes("UTF-8"))); stage = "Fout bij controleren SLD"; Element root = sldXmlDoc.getDocumentElement(); if (!"StyledLayerDescriptor".equals(root.getLocalName())) { throw new Exception("Root element moet StyledLayerDescriptor zijn"); } String version = root.getAttribute("version"); if (version == null || !("1.0.0".equals(version) || "1.1.0".equals(version))) { throw new Exception("Geen of ongeldige SLD versie!"); } SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); Schema s = sf .newSchema(new URL("http://schemas.opengis.net/sld/" + version + "/StyledLayerDescriptor.xsd")); s.newValidator().validate(new DOMSource(sldXmlDoc)); } catch (Exception e) { String extra = ""; if (e instanceof SAXParseException) { SAXParseException spe = (SAXParseException) e; if (spe.getLineNumber() != -1) { extra = " (regel " + spe.getLineNumber(); if (spe.getColumnNumber() != -1) { extra += ", kolom " + spe.getColumnNumber(); } extra += ")"; } } getContext().getValidationErrors() .addGlobalError(new SimpleError("{2}: {3}{4}", stage, ExceptionUtils.getMessage(e), extra)); return jsp; } getContext().getMessages().add(new SimpleMessage("SLD is valide!")); return jsp; }
From source file:nl.clockwork.mule.common.filter.AbstractXSDValidationFilter.java
public void setXsdFile(String xsdFile) { try {/*www . j ava2s .co m*/ SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); //schema = factory.newSchema(new StreamSource(this.getClass().getResourceAsStream(xsdFile))); String systemId = this.getClass().getResource(xsdFile).toString(); schema = factory.newSchema(new StreamSource(this.getClass().getResourceAsStream(xsdFile), systemId)); } catch (SAXException e) { logger.fatal("", e); throw new RuntimeException(e); } }
From source file:nl.nn.adapterframework.align.Json2Xml.java
public static String translate(JsonStructure json, URL schemaURL, boolean compactJsonArrays, String rootElement, boolean strictSyntax, boolean deepSearch, String targetNamespace, Map<String, Object> overrideValues) throws SAXException, IOException { // create the ValidatorHandler SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); Schema schema = sf.newSchema(schemaURL); ValidatorHandler validatorHandler = schema.newValidatorHandler(); // create the XSModel XMLSchemaLoader xsLoader = new XMLSchemaLoader(); XSModel xsModel = xsLoader.loadURI(schemaURL.toExternalForm()); List<XSModel> schemaInformation = new LinkedList<XSModel>(); schemaInformation.add(xsModel);// w ww.j av a 2s . c o m // create the validator, setup the chain Json2Xml j2x = new Json2Xml(validatorHandler, schemaInformation, compactJsonArrays, rootElement, strictSyntax); if (overrideValues != null) { j2x.setOverrideValues(overrideValues); } if (targetNamespace != null) { //if (DEBUG) System.out.println("setting targetNamespace ["+targetNamespace+"]"); j2x.setTargetNamespace(targetNamespace); } j2x.setDeepSearch(deepSearch); Source source = j2x.asSource(json); StringWriter writer = new StringWriter(); StreamResult result = new StreamResult(writer); String xml = null; try { TransformerFactory tf = TransformerFactory.newInstance(); Transformer transformer = tf.newTransformer(); transformer.transform(source, result); writer.flush(); xml = writer.toString(); } catch (TransformerConfigurationException e) { SAXException se = new SAXException(e); se.initCause(e); throw se; } catch (TransformerException e) { SAXException se = new SAXException(e); se.initCause(e); throw se; } return xml; }
From source file:nl.nn.adapterframework.align.XmlTo.java
public static void translate(String xml, URL schemaURL, DocumentContainer documentContainer) throws SAXException, IOException { // create the ValidatorHandler SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); Schema schema = sf.newSchema(schemaURL); ValidatorHandler validatorHandler = schema.newValidatorHandler(); // create the parser, setup the chain XMLReader parser = new SAXParser(); XmlAligner aligner = new XmlAligner(validatorHandler); XmlTo<DocumentContainer> xml2object = new XmlTo<DocumentContainer>(aligner, documentContainer); parser.setContentHandler(validatorHandler); aligner.setContentHandler(xml2object); // start translating InputSource is = new InputSource(new StringReader(xml)); parser.parse(is);// w ww .j a va 2 s . c om }
From source file:nl.nn.adapterframework.validation.JavaxXmlValidator.java
/** * Returns the {@link Schema} associated with this validator. This is an XSD schema containing knowledge about the * schema source as returned by {@link #getSchemaSources(List)} */// w w w . j a va2 s .c o m protected synchronized Schema getSchemaObject(String schemasId, List<nl.nn.adapterframework.validation.Schema> schemas) throws ConfigurationException { Schema schema = javaxSchemas.get(schemasId); if (schema == null) { SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); factory.setResourceResolver(new LSResourceResolver() { public LSInput resolveResource(String s, String s1, String s2, String s3, String s4) { return null; } }); try { Collection<Source> sources = getSchemaSources(schemas); schema = factory.newSchema(sources.toArray(new Source[sources.size()])); javaxSchemas.put(schemasId, schema); } catch (Exception e) { throw new ConfigurationException("cannot read schema's [" + schemasId + "]", e); } } return schema; }
From source file:nl.nn.adapterframework.validation.xerces_2_11.XMLSchemaFactory.java
/** * <p>Is specified schema supported by this <code>SchemaFactory</code>?</p> * * @param schemaLanguage Specifies the schema language which the returned <code>SchemaFactory</code> will understand. * <code>schemaLanguage</code> must specify a <a href="#schemaLanguage">valid</a> schema language. * * @return <code>true</code> if <code>SchemaFactory</code> supports <code>schemaLanguage</code>, else <code>false</code>. * * @throws NullPointerException If <code>schemaLanguage</code> is <code>null</code>. * @throws IllegalArgumentException If <code>schemaLanguage.length() == 0</code> * or <code>schemaLanguage</code> does not specify a <a href="#schemaLanguage">valid</a> schema language. *///from w ww. j a v a2 s . c om public boolean isSchemaLanguageSupported(String schemaLanguage) { if (schemaLanguage == null) { throw new NullPointerException(JAXPValidationMessageFormatter .formatMessage(fXMLSchemaLoader.getLocale(), "SchemaLanguageNull", null)); } if (schemaLanguage.length() == 0) { throw new IllegalArgumentException(JAXPValidationMessageFormatter .formatMessage(fXMLSchemaLoader.getLocale(), "SchemaLanguageLengthZero", null)); } // only W3C XML Schema 1.0 is supported return schemaLanguage.equals(XMLConstants.W3C_XML_SCHEMA_NS_URI); }
From source file:nl.ordina.bag.etl.xml.BatchExtractParser.java
public BatchExtractParser() { try {/*from w w w . j a v a 2s. com*/ SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); schema = schemaFactory.newSchema(new StreamSource(SchemaValidator.class.getResourceAsStream(XSD_FILE), SchemaValidator.class.getResource(XSD_FILE).toString())); objectBuilder = XMLMessageBuilder.getInstance(BAGExtractDeelbestandLVC.class); } catch (Exception e) { throw new ParserException(e); } }
From source file:org.accada.epcis.repository.capture.CaptureOperationsModule.java
/** * Initializes the EPCIS schema used for validating incoming capture * requests. Loads the WSDL and XSD files from the classpath (the schema is * bundled with epcis-commons.jar)./* ww w . j a v a 2s.c o m*/ * * @return An instantiated schema validation object. */ private Schema initEpcisSchema(String xsdFile) { InputStream is = this.getClass().getResourceAsStream(xsdFile); if (is != null) { try { SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); Source schemaSrc = new StreamSource(is); schemaSrc.setSystemId(CaptureOperationsServlet.class.getResource(xsdFile).toString()); Schema schema = schemaFactory.newSchema(schemaSrc); LOG.debug("EPCIS schema file initialized and loaded successfully"); return schema; } catch (Exception e) { LOG.warn("Unable to load or parse the EPCIS schema", e); } } else { LOG.error("Unable to load the EPCIS schema file from classpath: cannot find resource " + xsdFile); } LOG.warn("Schema validation will not be available!"); return null; }