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:org.apache.oozie.cli.OozieCLI.java
/** * Validate on client-side. This is only for backward compatibility. Need to removed after <tt>4.2.0</tt> higher version. * @param commandLine//from w ww . jav a 2 s .c o m * @throws OozieCLIException */ @Deprecated @VisibleForTesting void validateCommandV41(CommandLine commandLine) throws OozieCLIException { String[] args = commandLine.getArgs(); if (args.length != 1) { throw new OozieCLIException("One file must be specified"); } File file = new File(args[0]); if (file.exists()) { try { List<StreamSource> sources = new ArrayList<StreamSource>(); sources.add(new StreamSource(Thread.currentThread().getContextClassLoader() .getResourceAsStream("oozie-workflow-0.1.xsd"))); sources.add(new StreamSource(Thread.currentThread().getContextClassLoader() .getResourceAsStream("shell-action-0.1.xsd"))); sources.add(new StreamSource(Thread.currentThread().getContextClassLoader() .getResourceAsStream("shell-action-0.2.xsd"))); sources.add(new StreamSource(Thread.currentThread().getContextClassLoader() .getResourceAsStream("shell-action-0.3.xsd"))); sources.add(new StreamSource(Thread.currentThread().getContextClassLoader() .getResourceAsStream("email-action-0.1.xsd"))); sources.add(new StreamSource(Thread.currentThread().getContextClassLoader() .getResourceAsStream("email-action-0.2.xsd"))); sources.add(new StreamSource(Thread.currentThread().getContextClassLoader() .getResourceAsStream("distcp-action-0.1.xsd"))); sources.add(new StreamSource(Thread.currentThread().getContextClassLoader() .getResourceAsStream("distcp-action-0.2.xsd"))); sources.add(new StreamSource(Thread.currentThread().getContextClassLoader() .getResourceAsStream("oozie-workflow-0.2.xsd"))); sources.add(new StreamSource(Thread.currentThread().getContextClassLoader() .getResourceAsStream("oozie-workflow-0.2.5.xsd"))); sources.add(new StreamSource(Thread.currentThread().getContextClassLoader() .getResourceAsStream("oozie-workflow-0.3.xsd"))); sources.add(new StreamSource(Thread.currentThread().getContextClassLoader() .getResourceAsStream("oozie-workflow-0.4.xsd"))); sources.add(new StreamSource(Thread.currentThread().getContextClassLoader() .getResourceAsStream("oozie-workflow-0.4.5.xsd"))); sources.add(new StreamSource(Thread.currentThread().getContextClassLoader() .getResourceAsStream("oozie-workflow-0.5.xsd"))); sources.add(new StreamSource(Thread.currentThread().getContextClassLoader() .getResourceAsStream("oozie-coordinator-0.1.xsd"))); sources.add(new StreamSource(Thread.currentThread().getContextClassLoader() .getResourceAsStream("oozie-coordinator-0.2.xsd"))); sources.add(new StreamSource(Thread.currentThread().getContextClassLoader() .getResourceAsStream("oozie-coordinator-0.3.xsd"))); sources.add(new StreamSource(Thread.currentThread().getContextClassLoader() .getResourceAsStream("oozie-coordinator-0.4.xsd"))); sources.add(new StreamSource(Thread.currentThread().getContextClassLoader() .getResourceAsStream("oozie-bundle-0.1.xsd"))); sources.add(new StreamSource(Thread.currentThread().getContextClassLoader() .getResourceAsStream("oozie-bundle-0.2.xsd"))); sources.add(new StreamSource( Thread.currentThread().getContextClassLoader().getResourceAsStream("oozie-sla-0.1.xsd"))); sources.add(new StreamSource( Thread.currentThread().getContextClassLoader().getResourceAsStream("oozie-sla-0.2.xsd"))); sources.add(new StreamSource( Thread.currentThread().getContextClassLoader().getResourceAsStream("hive-action-0.2.xsd"))); sources.add(new StreamSource( Thread.currentThread().getContextClassLoader().getResourceAsStream("hive-action-0.3.xsd"))); sources.add(new StreamSource( Thread.currentThread().getContextClassLoader().getResourceAsStream("hive-action-0.4.xsd"))); sources.add(new StreamSource( Thread.currentThread().getContextClassLoader().getResourceAsStream("hive-action-0.5.xsd"))); sources.add(new StreamSource( Thread.currentThread().getContextClassLoader().getResourceAsStream("hive-action-0.6.xsd"))); sources.add(new StreamSource(Thread.currentThread().getContextClassLoader() .getResourceAsStream("sqoop-action-0.2.xsd"))); sources.add(new StreamSource(Thread.currentThread().getContextClassLoader() .getResourceAsStream("sqoop-action-0.3.xsd"))); sources.add(new StreamSource(Thread.currentThread().getContextClassLoader() .getResourceAsStream("sqoop-action-0.4.xsd"))); sources.add(new StreamSource( Thread.currentThread().getContextClassLoader().getResourceAsStream("ssh-action-0.1.xsd"))); sources.add(new StreamSource( Thread.currentThread().getContextClassLoader().getResourceAsStream("ssh-action-0.2.xsd"))); sources.add(new StreamSource(Thread.currentThread().getContextClassLoader() .getResourceAsStream("hive2-action-0.1.xsd"))); sources.add(new StreamSource(Thread.currentThread().getContextClassLoader() .getResourceAsStream("hive2-action-0.2.xsd"))); sources.add(new StreamSource(Thread.currentThread().getContextClassLoader() .getResourceAsStream("spark-action-0.1.xsd"))); sources.add(new StreamSource(Thread.currentThread().getContextClassLoader() .getResourceAsStream("spark-action-0.2.xsd"))); SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); Schema schema = factory.newSchema(sources.toArray(new StreamSource[sources.size()])); Validator validator = schema.newValidator(); validator.validate(new StreamSource(new FileReader(file))); System.out.println("Valid workflow-app"); } catch (Exception ex) { throw new OozieCLIException("Invalid app definition, " + ex.toString(), ex); } } else { throw new OozieCLIException("File does not exists"); } }
From source file:org.apache.stratos.adc.mgt.utils.PolicyHolder.java
public void validate(final OMElement omElement, final File schemaFile) throws SAXException, IOException { Element sourceElement;/* w w w . ja va2s. co m*/ // if the OMElement is created using DOM implementation use it if (omElement instanceof ElementImpl) { sourceElement = (Element) omElement; } else { // else convert from llom to dom sourceElement = getDOMElement(omElement); } // Create a SchemaFactory capable of understanding WXS schemas. // Load a WXS schema, represented by a Schema instance. SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); Source source = new StreamSource(schemaFile); // Create a Validator object, which can be used to validate // an instance document. Schema schema = factory.newSchema(source); Validator validator = schema.newValidator(); // Validate the DOM tree. validator.validate(new DOMSource(sourceElement)); }
From source file:org.apache.stratos.cloud.controller.axiom.AxiomXpathParser.java
public void validate(final OMElement omElement, final File schemaFile) throws Exception { Element sourceElement;/* ww w. j a va 2 s .c om*/ // if the OMElement is created using DOM implementation use it if (omElement instanceof ElementImpl) { sourceElement = (Element) omElement; } else { // else convert from llom to dom sourceElement = getDOMElement(omElement); } // Create a SchemaFactory capable of understanding WXS schemas. // Load a WXS schema, represented by a Schema instance. SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); Source source = new StreamSource(schemaFile); // Create a Validator object, which can be used to validate // an instance document. Schema schema = factory.newSchema(source); Validator validator = schema.newValidator(); // Validate the DOM tree. validator.validate(new DOMSource(sourceElement)); }
From source file:org.apache.stratos.cloud.controller.axiom.AxiomXpathParserUtil.java
public static void validate(final OMElement omElement, final File schemaFile) throws SAXException, IOException { Element sourceElement;//from w ww .j a v a 2s . c o m // if the OMElement is created using DOM implementation use it if (omElement instanceof ElementImpl) { sourceElement = (Element) omElement; } else { // else convert from llom to dom sourceElement = getDOMElement(omElement); } // Create a SchemaFactory capable of understanding WXS schemas. // Load a WXS schema, represented by a Schema instance. SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); Source source = new StreamSource(schemaFile); // Create a Validator object, which can be used to validate // an instance document. Schema schema = factory.newSchema(source); Validator validator = schema.newValidator(); // Validate the DOM tree. validator.validate(new DOMSource(sourceElement)); }
From source file:org.apache.stratos.manager.utils.PolicyHolder.java
public void validate(final OMElement omElement, final File schemaFile) throws SAXException, IOException { Element sourceElement;//from w w w .ja va 2 s .co m // if the OMElement is created using DOM implementation use it if (omElement instanceof ElementImpl) { sourceElement = (Element) omElement; } else { // else convert from llom to dom sourceElement = getDOMElement(omElement); } // Create a SchemaFactory capable of understanding WXS schemas. // Load a WXS schema, represented by a Schema subscription. SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); Source source = new StreamSource(schemaFile); // Create a Validator object, which can be used to validate // an subscription document. Schema schema = factory.newSchema(source); Validator validator = schema.newValidator(); // Validate the DOM tree. validator.validate(new DOMSource(sourceElement)); }
From source file:org.apache.synapse.format.syslog.SyslogMessageBuilderTest.java
private SyslogMessage test(String message) throws Exception { MessageContext msgContext = new MessageContext(); ByteArrayInputStream in = new ByteArrayInputStream(message.getBytes("us-ascii")); OMElement element = new SyslogMessageBuilder().processDocument(in, null, msgContext); SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); Schema schema = factory.newSchema( new StreamSource(SyslogMessageBuilderTest.class.getResource("schema.xsd").toExternalForm())); Validator validator = schema.newValidator(); validator.setErrorHandler(new ErrorHandler() { public void error(SAXParseException exception) throws SAXException { throw exception; }/* w w w . j a va2s. c om*/ public void fatalError(SAXParseException exception) throws SAXException { throw exception; } public void warning(SAXParseException exception) throws SAXException { throw exception; } }); validator.validate(new OMSource(element)); String pidString = element.getAttributeValue(new QName(SyslogConstants.PID)); return new SyslogMessage(element.getAttributeValue(new QName(SyslogConstants.FACILITY)), element.getAttributeValue(new QName(SyslogConstants.SEVERITY)), element.getAttributeValue(new QName(SyslogConstants.TAG)), pidString == null ? -1 : Integer.parseInt(pidString), element.getText()); }
From source file:org.apache.tinkerpop.gremlin.structure.io.IoTest.java
private static void validateXmlAgainstGraphMLXsd(final File file) throws Exception { final Source xmlFile = new StreamSource(file); final SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); final Schema schema = schemaFactory.newSchema(IoTest.class.getResource( TestHelper.convertPackageToResourcePath(GraphMLResourceAccess.class) + "graphml-1.1.xsd")); final Validator validator = schema.newValidator(); validator.validate(xmlFile);//from w w w .j a v a2 s . co m }
From source file:org.apache.tinkerpop.gremlin.structure.IoTest.java
private void validateXmlAgainstGraphMLXsd(final File file) throws Exception { final Source xmlFile = new StreamSource(file); final SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); final Schema schema = schemaFactory .newSchema(IoTest.class.getResource(GRAPHML_RESOURCE_PATH_PREFIX + "graphml-1.1.xsd")); final Validator validator = schema.newValidator(); validator.validate(xmlFile);//www . j a va2s . co m }
From source file:org.apache.xml.security.stax.ext.XMLSecurityUtils.java
public static Schema loadXMLSecuritySchemas() throws SAXException { SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); schemaFactory.setResourceResolver(new LSResourceResolver() { @Override// www . j av a 2 s .c om public LSInput resolveResource(String type, String namespaceURI, String publicId, String systemId, String baseURI) { if ("http://www.w3.org/2001/XMLSchema.dtd".equals(systemId)) { ConcreteLSInput concreteLSInput = new ConcreteLSInput(); concreteLSInput.setByteStream(ClassLoaderUtils .getResourceAsStream("bindings/schemas/XMLSchema.dtd", XMLSecurityConstants.class)); return concreteLSInput; } else if ("XMLSchema.dtd".equals(systemId)) { ConcreteLSInput concreteLSInput = new ConcreteLSInput(); concreteLSInput.setByteStream(ClassLoaderUtils .getResourceAsStream("bindings/schemas/XMLSchema.dtd", XMLSecurityConstants.class)); return concreteLSInput; } else if ("datatypes.dtd".equals(systemId)) { ConcreteLSInput concreteLSInput = new ConcreteLSInput(); concreteLSInput.setByteStream(ClassLoaderUtils .getResourceAsStream("bindings/schemas/datatypes.dtd", XMLSecurityConstants.class)); return concreteLSInput; } else if ("http://www.w3.org/TR/2002/REC-xmldsig-core-20020212/xmldsig-core-schema.xsd" .equals(systemId)) { ConcreteLSInput concreteLSInput = new ConcreteLSInput(); concreteLSInput.setByteStream(ClassLoaderUtils.getResourceAsStream( "bindings/schemas/xmldsig-core-schema.xsd", XMLSecurityConstants.class)); return concreteLSInput; } else if ("http://www.w3.org/2001/xml.xsd".equals(systemId)) { ConcreteLSInput concreteLSInput = new ConcreteLSInput(); concreteLSInput.setByteStream(ClassLoaderUtils.getResourceAsStream("bindings/schemas/xml.xsd", XMLSecurityConstants.class)); return concreteLSInput; } return null; } }); Schema schema = schemaFactory.newSchema(new Source[] { new StreamSource(ClassLoaderUtils.getResourceAsStream("bindings/schemas/exc-c14n.xsd", XMLSecurityConstants.class)), new StreamSource(ClassLoaderUtils.getResourceAsStream("bindings/schemas/xmldsig-core-schema.xsd", XMLSecurityConstants.class)), new StreamSource(ClassLoaderUtils.getResourceAsStream("bindings/schemas/xenc-schema.xsd", XMLSecurityConstants.class)), new StreamSource(ClassLoaderUtils.getResourceAsStream("bindings/schemas/xenc-schema-11.xsd", XMLSecurityConstants.class)), new StreamSource(ClassLoaderUtils.getResourceAsStream("bindings/schemas/xmldsig11-schema.xsd", XMLSecurityConstants.class)), }); return schema; }
From source file:org.artifactory.jaxb.JaxbHelper.java
@SuppressWarnings({ "unchecked" }) public T read(InputStream stream, Class clazz, URL schemaUrl) { T o = null;/*from ww w . j a va 2 s .c o m*/ try { JAXBContext context = JAXBContext.newInstance(clazz); Unmarshaller unmarshaller = context.createUnmarshaller(); if (schemaUrl != null) { SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); Schema schema = sf.newSchema(schemaUrl); unmarshaller.setSchema(schema); } o = (T) unmarshaller.unmarshal(stream); } catch (Throwable t) { // The following code resolves the errors from JAXB result. // Just throwing new RuntimeException doesn't shows the root cause of the failure and it is almost impossible // to conclude it without this log. if (t instanceof IllegalAnnotationsException) { List<IllegalAnnotationException> errors = ((IllegalAnnotationsException) t).getErrors(); if (errors != null) { for (IllegalAnnotationException error : errors) { log.error("Failed to read object from stream, error:", error); } } } throw new RuntimeException("Failed to read object from stream.", t); } finally { IOUtils.closeQuietly(stream); } return o; }