Example usage for javax.xml XMLConstants W3C_XML_SCHEMA_NS_URI

List of usage examples for javax.xml XMLConstants W3C_XML_SCHEMA_NS_URI

Introduction

In this page you can find the example usage for javax.xml XMLConstants W3C_XML_SCHEMA_NS_URI.

Prototype

String W3C_XML_SCHEMA_NS_URI

To view the source code for javax.xml XMLConstants W3C_XML_SCHEMA_NS_URI.

Click Source Link

Document

W3C XML Schema Namespace URI.

Usage

From source file:i5.las2peer.services.mobsos.surveys.SurveyService.java

/**
 * Initialize XML parser and validator for questionnaire forms and answers
 * //w  w  w . ja  v a2  s.c  om
 * @throws SAXException
 * @throws ParserConfigurationException
 */
private void initXMLInfrastructure() throws SAXException, ParserConfigurationException {
    SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
    Schema schema = factory.newSchema(new File(questionnaireSchemaPath));
    validator = schema.newValidator();

    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    dbf.setSchema(schema);
    dbf.setNamespaceAware(true);
    dbf.setValidating(false);

    parser = dbf.newDocumentBuilder();
}

From source file:com.amalto.core.util.Util.java

/**
 * Get a node list from an xPath//from  w w  w . j a  v a 2 s  .  co m
 * 
 * @throws XtentisException
 */
public static NodeList getNodeList(Node contextNode, String xPath) throws XtentisException {
    try {
        XPathFactory xPathFactory = XPathFactory.newInstance();
        XPath xPathParser = xPathFactory.newXPath();
        xPathParser.setNamespaceContext(new NamespaceContext() {

            @Override
            public String getNamespaceURI(String s) {
                if ("xsd".equals(s)) { //$NON-NLS-1$
                    return XMLConstants.W3C_XML_SCHEMA_NS_URI;
                }
                return null;
            }

            @Override
            public String getPrefix(String s) {
                if (XMLConstants.W3C_XML_SCHEMA_NS_URI.equals(s)) {
                    return "xsd"; //$NON-NLS-1$
                }
                return null;
            }

            @Override
            public Iterator getPrefixes(String s) {
                return Collections.singletonList(s).iterator();
            }
        });
        return (NodeList) xPathParser.evaluate(xPath, contextNode, XPathConstants.NODESET);
    } catch (Exception e) {
        String err = "Unable to get the Nodes List for xpath '" + xPath + "'"
                + ((contextNode == null) ? "" : " for Node " + contextNode.getLocalName()) + ": "
                + e.getLocalizedMessage();
        throw new XtentisException(err, e);
    }
}

From source file:com.evolveum.midpoint.prism.schema.SchemaRegistry.java

private void parseJavaxSchema() throws SAXException, IOException {
    schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
    Source[] sources = new Source[schemaDescriptions.size()];
    int i = 0;/*from w  w  w.ja  v  a2  s  .  c  o m*/
    for (SchemaDescription schemaDescription : schemaDescriptions) {
        Source source = schemaDescription.getSource();
        sources[i] = source;
        i++;
    }
    schemaFactory.setResourceResolver(this);
    javaxSchema = schemaFactory.newSchema(sources);
}

From source file:com.maxl.java.aips2sqlite.Aips2Sqlite.java

static List<MedicalInformations.MedicalInformation> readAipsFile() {
    List<MedicalInformations.MedicalInformation> med_list = null;
    try {//from ww w  .  jav  a2 s .  c o  m
        JAXBContext context = JAXBContext.newInstance(MedicalInformations.class);

        // Validation
        SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
        Schema schema = sf.newSchema(new File(Constants.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 (CmlOptions.SHOW_LOGS)
            System.out.print("- Unmarshalling Swissmedic xml... ");

        FileInputStream fis = new FileInputStream(new File(Constants.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 (CmlOptions.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.legstar.cob2xsd.XsdEmitter.java

/**
 * Create an XML schema restriction.//from  w ww. jav  a2s.co m
 * 
 * @param xsdTypeName the XML schema built-in type name to use as a
 *            restriction
 * @return an XML schema restriction
 */
protected XmlSchemaSimpleTypeRestriction createRestriction(final String xsdTypeName) {
    XmlSchemaSimpleTypeRestriction restriction = new XmlSchemaSimpleTypeRestriction();
    restriction.setBaseTypeName(new QName(XMLConstants.W3C_XML_SCHEMA_NS_URI, xsdTypeName));
    return restriction;
}

From source file:net.nicholaswilliams.java.teamcity.plugin.buildNumber.PluginConfigurationServiceDefault.java

protected void initializeXmlDigesterLoader() {
    if (PluginConfigurationServiceDefault.logger.isDebugEnabled())
        PluginConfigurationServiceDefault.logger.debug("Initializing the XML digester.");

    Schema schema;//from  w ww .  j  av a2 s .c  o m
    FileInputStream stream = null;
    try {
        stream = FileUtils.openInputStream(this.xsdFile);
        schema = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI)
                .newSchema(new StreamSource(stream));
    } catch (SAXException e) {
        throw new FatalBeanException("Could not parse plugin configuration XSD", e);
    } catch (IOException e) {
        throw new FatalBeanException("Could not parse plugin configuration XSD", e);
    } finally {
        try {
            if (stream != null)
                stream.close();
        } catch (IOException e) {
            PluginConfigurationServiceDefault.logger.warn("Failed to close XSD file stream.", e);
        }
    }

    this.digesterLoader.setNamespaceAware(true);
    this.digesterLoader.setSchema(schema);
    this.digesterLoader.setErrorHandler(new ConfigurationErrorHandler());
    this.digesterLoader.setUseContextClassLoader(false);
    this.digesterLoader.setClassLoader(Digester.class.getClassLoader());

    ConvertUtils.register(new JodaXML8601DateTimeConverter(), DateTime.class);
}

From source file:com.evolveum.midpoint.prism.schema.SchemaRegistryImpl.java

private void parseJavaxSchema() throws SAXException, IOException {
    schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
    Source[] sources = new Source[schemaDescriptions.size()];
    int i = 0;// ww  w .  j  a  v a 2  s .  c om
    for (SchemaDescription schemaDescription : schemaDescriptions) {
        Source source = schemaDescription.getSource();
        sources[i] = source;
        i++;
    }
    schemaFactory.setResourceResolver(entityResolver);
    javaxSchema = schemaFactory.newSchema(sources);
}

From source file:info.novatec.ita.check.config.StereotypeCheckReader.java

/**
 * Read and validate the given file to a configuration for stereotype check.
 * //from   w  w  w  . j  av a  2  s.  c o m
 * @param file
 *            The file to read.
 * @param additionalCheckCfg
 *            a previously read configuration which may override parts of
 *            the configuration read by the file.
 * @param readingAdditionalCfg
 *            Are we reading the additionalCfg.
 * @return the configuration.
 * @throws XMLStreamException
 * @throws IllegalArgumentException
 * @throws SAXException
 * @throws IOException
 */
private static StereotypeCheckConfiguration read(File file, String checkstyleStereotypeXsd,
        StereotypeCheckConfiguration additionalCheckCfg, boolean readingAdditionalCfg)
        throws XMLStreamException, IllegalArgumentException, SAXException, IOException {

    // Validate with StreamSource because Stax Validation is not provided
    // with every implementation of JAXP
    SchemaFactory schemafactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
    Schema schema = schemafactory
            .newSchema(StereotypeCheckReader.class.getClassLoader().getResource(checkstyleStereotypeXsd));

    Validator validator = schema.newValidator();
    validator.validate(new StreamSource(file));

    // Parse with Stax
    XMLStreamReader reader = XMLInputFactory.newInstance()
            .createXMLStreamReader(new BufferedInputStream(new FileInputStream(file)));
    StereotypeCheckConfigurationReader delegate = new StereotypeCheckConfigurationReader(reader,
            additionalCheckCfg, readingAdditionalCfg);

    while (delegate.hasNext()) {
        delegate.next();
    }

    return delegate.getConfig();
}

From source file:edu.unc.lib.dl.ingest.sip.METSPackageSIPProcessor.java

private void xsdValidate(File metsFile2) throws IngestException {
    // TODO can reuse schema object, it is thread safe
    javax.xml.validation.SchemaFactory schemaFactory = javax.xml.validation.SchemaFactory
            .newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
    StreamSource xml = new StreamSource(getClass().getResourceAsStream(schemaPackage + "xml.xsd"));
    StreamSource xlink = new StreamSource(getClass().getResourceAsStream(schemaPackage + "xlink.xsd"));
    StreamSource mets = new StreamSource(getClass().getResourceAsStream(schemaPackage + "mets.xsd"));
    StreamSource premis = new StreamSource(getClass().getResourceAsStream(schemaPackage + "premis-v2-0.xsd"));
    StreamSource mods = new StreamSource(getClass().getResourceAsStream(schemaPackage + "mods-3-4.xsd"));
    StreamSource acl = new StreamSource(getClass().getResourceAsStream(schemaPackage + "acl.xsd"));
    Schema schema;//from w  w w.  j  a  v  a 2s  .  com
    try {
        Source[] sources = { xml, xlink, mets, premis, mods, acl };
        schema = schemaFactory.newSchema(sources);
    } catch (SAXException e) {
        throw new Error("Cannot locate METS schema in classpath.", e);
    }

    Validator metsValidator = schema.newValidator();
    METSParseException handler = new METSParseException("There was a problem parsing METS XML.");
    metsValidator.setErrorHandler(handler);
    // TODO get a Result document for reporting error
    try {
        metsValidator.validate(new StreamSource(metsFile2));
    } catch (SAXException e) {
        if (log.isDebugEnabled()) {
            log.debug(e.getMessage());
        }
        throw handler;
    } catch (IOException e) {
        throw new IngestException("The supplied METS file is not readable.", e);
    }
}

From source file:com.legstar.cob2xsd.Cob2Xsd.java

/**
 * Create an empty XML Schema./*w w w  .  j a  va 2  s .  c o  m*/
 * <p/>
 * If no targetNamespace, make sure there is no default namespace otherwise
 * our complex types would be considered part of that default namespace
 * (usually XML Schema namespace).
 * 
 * @param encoding the character set used to encode this XML Schema
 * @return a new empty XML schema using the model
 */
protected XmlSchema createXmlSchema(final String encoding) {
    XmlSchema xsd = new XmlSchema(getModel().getTargetNamespace(), new XmlSchemaCollection());
    if (getModel().getTargetNamespace() != null) {
        xsd.setElementFormDefault(new XmlSchemaForm(XmlSchemaForm.QUALIFIED));
    }
    xsd.setAttributeFormDefault(null);
    xsd.setInputEncoding(encoding);
    if (getModel().getTargetNamespace() == null) {
        NamespaceMap prefixmap = new NamespaceMap();
        NamespacePrefixList npl = xsd.getNamespaceContext();
        if (npl == null) {
            prefixmap.add("xsd", XMLConstants.W3C_XML_SCHEMA_NS_URI);
        } else {
            for (int i = 0; i < npl.getDeclaredPrefixes().length; i++) {
                String prefix = npl.getDeclaredPrefixes()[i];
                String namespace = npl.getNamespaceURI(prefix);
                if (namespace.equals(XMLConstants.W3C_XML_SCHEMA_NS_URI)) {
                    if (prefix.equals("")) {
                        prefix = "xsd";
                    }
                }
                prefixmap.add(prefix, namespace);
            }
        }
        xsd.setNamespaceContext(prefixmap);
    }
    return xsd;
}