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:org.wso2.carbon.governance.generic.util.Util.java

public static Validator getSchemaValidator(String schemaPath) {

    if (serviceSchemaValidator == null) {
        try {/*w ww  . j  a v a  2 s  .com*/
            SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
            Schema schema = schemaFactory.newSchema(new File(schemaPath));
            serviceSchemaValidator = schema.newValidator();
        } catch (SAXException e) {
            log.error("Unable to get a schema validator from the given file path : " + schemaPath);
        }
    }
    return serviceSchemaValidator;
}

From source file:org.wso2.carbon.governance.lcm.util.CommonUtil.java

public static Validator getLifecycleSchemaValidator(String schemaPath) {

    if (lifecycleSchemaValidator == null) {
        try {//from  w w  w  .j av  a 2 s  .  c  o m
            SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
            Schema schema = schemaFactory.newSchema(new File(schemaPath));
            lifecycleSchemaValidator = schema.newValidator();
        } catch (SAXException e) {
            log.error("Unable to get a schema validator from the given file path : " + schemaPath);
        }
    }
    return lifecycleSchemaValidator;
}

From source file:org.wso2.carbon.governance.list.util.CommonUtil.java

private static boolean validateRXTContent(String rxtContent, String xsdPath) throws RegistryException {
    try {// ww w  . jav  a  2  s .  c om
        OMElement rxt = getRXTContentOMElement(rxtContent);
        AXIOMXPath xpath = new AXIOMXPath("//artifactType");
        OMElement c1 = (OMElement) xpath.selectSingleNode(rxt);
        InputStream is = new ByteArrayInputStream(c1.toString().getBytes());
        Source xmlFile = new StreamSource(is);
        SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
        Schema schema = schemaFactory.newSchema(new File(xsdPath));
        Validator validator = schema.newValidator();
        validator.validate(xmlFile);
    } catch (Exception e) {
        log.error("RXT validation fails due to: " + e.getMessage());
        return false;
    }
    return true;
}

From source file:org.wso2.carbon.identity.entitlement.internal.SchemaBuilder.java

/**
 * Builds the policy schema map. There are three schemas.
 *
 * @param configHolder holder EntitlementConfigHolder
 * @throws SAXException if fails/*  ww  w  . jav a  2  s. c o m*/
 */
public void buildPolicySchema() throws SAXException {

    if (!"true".equalsIgnoreCase((String) configHolder.getEngineProperties()
            .get(EntitlementExtensionBuilder.PDP_SCHEMA_VALIDATION))) {
        log.warn("PDP schema validation disabled.");
        return;
    }

    String[] schemaNSs = new String[] { PDPConstants.XACML_1_POLICY_XMLNS, PDPConstants.XACML_2_POLICY_XMLNS,
            PDPConstants.XACML_3_POLICY_XMLNS };

    for (String schemaNS : schemaNSs) {

        String schemaFile;

        if (PDPConstants.XACML_1_POLICY_XMLNS.equals(schemaNS)) {
            schemaFile = PDPConstants.XACML_1_POLICY_SCHEMA_FILE;
        } else if (PDPConstants.XACML_2_POLICY_XMLNS.equals(schemaNS)) {
            schemaFile = PDPConstants.XACML_2_POLICY_SCHEMA_FILE;
        } else {
            schemaFile = PDPConstants.XACML_3_POLICY_SCHEMA_FILE;
        }

        InputStream schemaFileStream = EntitlementExtensionBuilder.class.getResourceAsStream("/" + schemaFile);
        SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
        Schema schema = schemaFactory.newSchema(new StreamSource(schemaFileStream));
        configHolder.getPolicySchemaMap().put(schemaNS, schema);
    }
}

From source file:org.wso2.carbon.integration.common.tests.utils.DistributionValidationTestUtils.java

public static void validateXml(HashMap<String, Exception> xsdValidateMap, String distributionXml,
        String xsdFile) throws IOException {
    Source schemaFile = new StreamSource(new File(xsdFile));
    Source xmlFile = new StreamSource(new File(distributionXml));
    SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
    Schema schema = null;/*w  w w  . j a  va 2s . c  o  m*/
    try {
        schema = schemaFactory.newSchema(schemaFile);
    } catch (SAXException e) {
        log.error(distributionXml, e);
        xsdValidateMap.put(distributionXml, e);
    }
    if (schema != null) {
        Validator validator = schema.newValidator();
        try {
            validator.validate(xmlFile);
        } catch (SAXException e) {
            log.error(distributionXml, e);
            xsdValidateMap.put(distributionXml, e);
        }
    }
}

From source file:org.wso2.carbon.lcm.core.util.LifecycleUtils.java

/**
 * Method used to get schema validator object for lifecycle configurations.
 * @param schemaPath Schema path in the server extracted directory.
 * @return schema validator object//  ww w.  ja v  a2s  . c  o m
 */
public static synchronized Validator getLifecycleSchemaValidator(String schemaPath) {
    if (lifecycleSchemaValidator != null) {
        return lifecycleSchemaValidator;
    }
    try {
        SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
        Schema schema = schemaFactory.newSchema(new File(schemaPath));
        lifecycleSchemaValidator = schema.newValidator();
    } catch (SAXException e) {
        log.error("Unable to get a schema validator from the given file path : " + schemaPath);
    }
    return lifecycleSchemaValidator;
}

From source file:org.xsystem.bpmn2.formats.xml.XMLParser3.java

Schema buildSxema() throws SAXException, IOException {
    final ClassLoader classLoader = this.getClass().getClassLoader();
    //Thread.currentThread().getContextClassLoader();

    try (InputStream is = classLoader.getResourceAsStream("BPMN20/BPMN20.xsd")) {

        SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);//"http://www.w3.org/2001/XMLSchema");
        StreamSource ss = new StreamSource(is);
        factory.setResourceResolver(// w  w w . j a  v  a 2s . c  o m
                (String type, String namespaceURI, String publicId, String systemId, String baseURI) -> {
                    InputStream resourceAsStream = classLoader.getResourceAsStream("BPMN20/" + systemId);
                    LSInput ret = new LSInputImpl(publicId, systemId, resourceAsStream);
                    return ret;
                });
        Schema shema = factory.newSchema(ss);
        return shema;
    }
}

From source file:oscar.oscarLab.ca.all.parsers.HRMXMLHandler.java

public void init(String hl7Body) throws HL7Exception {

    // this.version = p.getVersion(hl7Body);
    logger.info("A NEW HRM XML PARSER OBJECT INSTANTIATED TO PARSE HL7 FILE " + hl7Body);

    try {//from  www. j a  va 2s  .  c o m
        ByteArrayInputStream byeArrayInputStream = new ByteArrayInputStream(hl7Body.getBytes());

        // Create a SchemaFactory capable of understanding WXS schemas.
        SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);

        // Load a WXS schema, represented by a Schema instance.
        Source schemaFile = new StreamSource(new File(SFTPConnector.OMD_directory + "report_manager_cds.xsd"));
        Schema schema = factory.newSchema(schemaFile); //new File(SFTPConnector.OMD_directory + "report_manager_cds.xsd"));

        JAXBContext jc = JAXBContext.newInstance("oscar.hospitalReportManager.xsd");
        Unmarshaller u = jc.createUnmarshaller();
        root = (OmdCds) u.unmarshal(byeArrayInputStream);
        pr = root.getPatientRecord();

    } catch (Exception e) {
        logger.error("error", e);
    }

    headers = new ArrayList<String>();

}

From source file:pl.nask.hsn2.workflow.parser.HWLParser.java

private void createSchema() throws IOException, SAXException {
    final DOMResult result = new DOMResult();

    SchemaOutputResolver outputResolver = new HwlSchemaOutputResolver(result);

    ctx.generateSchema(outputResolver);/*from   w w w . ja v a  2s  . com*/
    this.schemaNode = result.getNode();
    this.schemaSystemId = result.getSystemId();

    Source source = new DOMSource(schemaNode, schemaSystemId);

    this.schema = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI).newSchema(source);
}

From source file:pl.psnc.synat.wrdz.zmkd.plan.MigrationPlansBean.java

/**
 * // w ww.ja va 2s .  c om
 * Bean initialization instructions.
 * 
 * @throws JAXBException
 *             if creating an instance of JAXBContext fails
 * @throws SAXException
 *             if creating a schema object fails
 */
@PostConstruct
protected void init() throws JAXBException, SAXException {

    deleteErrorMessage = "notSet";

    jaxbContext = JAXBContext.newInstance(pl.psnc.darceo.migration.MigrationPlan.class);

    InputStream schemaInput = null;
    try {
        schemaInput = getClass().getResourceAsStream(XML_SCHEMA_FILE);
        schema = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI)
                .newSchema(new StreamSource(schemaInput));
    } finally {
        IOUtils.closeQuietly(schemaInput);
    }
}