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:eu.planets_project.pp.plato.evaluation.evaluators.ExperimentEvaluator.java

private String evaluateLogging(String logOutput) {
    if ((logOutput == null) || "".equals(logOutput)) {
        return "none";
    } else {/*from   w w  w  .j ava2  s.  co m*/
        String result = "text";

        SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
        try {
            Schema schema = factory.newSchema();
            Validator validator = schema.newValidator();

            validator.validate(new StreamSource(new StringReader(logOutput)));

            // ok, the log is well-formed XML
            result = "XML";
        } catch (SAXException e) {
            // no xml - this is ok
        } catch (IOException e) {
            log.error("logoutput-evaluator is not properly configured: ", e);
        }

        return result;
    }
}

From source file:com.amalto.core.storage.hibernate.SystemScatteredMappingCreator.java

@Override
public TypeMapping visit(ContainedTypeFieldMetadata containedField) {
    String containedTypeName = newNonInstantiableTypeName(containedField.getContainedType());
    SoftTypeRef typeRef = new SoftTypeRef(internalRepository, containedField.getDeclaringType().getNamespace(),
            containedTypeName, false);/*ww w  . jav a2s.co  m*/
    ReferenceFieldMetadata newFlattenField = new ReferenceFieldMetadata(currentType.peek(), false,
            containedField.isMany(), containedField.isMandatory(), context.getFieldColumn(containedField),
            typeRef, new SoftIdFieldRef(internalRepository, containedTypeName),
            Collections.<FieldMetadata>emptyList(), StringUtils.EMPTY, enforceTechnicalFK, false,
            new SimpleTypeMetadata(XMLConstants.W3C_XML_SCHEMA_NS_URI, Types.STRING),
            containedField.getWriteUsers(), containedField.getHideUsers(),
            containedField.getWorkflowAccessRights(), StringUtils.EMPTY, StringUtils.EMPTY);
    newFlattenField.setData(MetadataRepository.DATA_MAX_LENGTH, UUID_LENGTH);
    newFlattenField.setData(MappingGenerator.SQL_DELETE_CASCADE, Boolean.TRUE.toString());
    currentType.peek().addField(newFlattenField);
    currentMapping.peek().map(containedField, newFlattenField);
    entityMapping.map(containedField, newFlattenField);
    if (!processedTypes.contains(containedField.getContainedType())) {
        processedTypes.add(containedField.getContainedType());
        containedField.getContainedType().accept(this);
    }
    return null;
}

From source file:edu.duke.cabig.c3pr.webservice.studyimportexport.impl.StudyImportExportImpl.java

/**
 * Creates the export study response.// w  w  w.j  a  va2 s . c  om
 *
 * @param study the study
 * @return the sOAP message
 * @throws SOAPException the sOAP exception
 * @throws XMLUtilityException the xML utility exception
 * @throws ParserConfigurationException the parser configuration exception
 * @throws SAXException the sAX exception
 * @throws IOException Signals that an I/O exception has occurred.
 */
private SOAPMessage createExportStudyResponse(Study study)
        throws SOAPException, XMLUtilityException, ParserConfigurationException, SAXException, IOException {
    MessageFactory mf = MessageFactory.newInstance();
    SOAPMessage response = mf.createMessage();
    SOAPBody body = response.getSOAPBody();
    SOAPElement exportStudyResponse = body.addChildElement(new QName(SERVICE_NS, "ExportStudyResponse"));
    String xml = marshaller.toXML(study);

    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setNamespaceAware(true);
    factory.setSchema(SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI)
            .newSchema(XmlMarshaller.class.getResource(C3PR_DOMAIN_XSD_URL)));
    DocumentBuilder builder = factory.newDocumentBuilder();
    Document doc = builder.parse(IOUtils.toInputStream(xml));
    Element studyEl = (Element) doc.getFirstChild();
    exportStudyResponse.appendChild(body.getOwnerDocument().importNode(studyEl, true));
    response.saveChanges();
    return response;
}

From source file:csiro.pidsvc.mappingstore.Manager.java

/**************************************************************************
 *  Generic processing methods./*w w  w . j  av  a 2  s . c  o  m*/
 */

protected void validateRequest(String inputData, String xmlSchemaResourcePath)
        throws IOException, ValidationException {
    try {
        SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
        schemaFactory.setResourceResolver(new LSResourceResolver() {
            @Override
            public LSInput resolveResource(String type, String namespaceURI, String publicId, String systemId,
                    String baseURI) {
                return new XsdSchemaResolver(type, namespaceURI, publicId, systemId, baseURI);
            }
        });

        Schema schema = schemaFactory
                .newSchema(new StreamSource(getClass().getResourceAsStream(xmlSchemaResourcePath)));
        Validator validator = schema.newValidator();
        _logger.trace("Validating XML Schema.");
        validator.validate(new StreamSource(new StringReader(inputData)));
    } catch (SAXException ex) {
        _logger.debug("Unknown format.", ex);
        throw new ValidationException("Unknown format.", ex);
    }
}

From source file:de.fzi.ALERT.actor.MessageObserver.ComplexEventObserver.JMSMessageParser.java

public Schema loadSchema(String name) {
    Schema schema = null;//from   w  w w.  j  ava  2s .  com
    try {
        String language = XMLConstants.W3C_XML_SCHEMA_NS_URI;
        SchemaFactory factory = SchemaFactory.newInstance(language);
        schema = factory.newSchema(new File(name));
    } catch (Exception e) {
        System.out.println(e.toString());
    }
    return schema;
}

From source file:com.amalto.core.storage.hibernate.ScatteredMappingCreator.java

@Override
public TypeMapping visit(ContainedTypeFieldMetadata containedField) {
    String containedTypeName = newNonInstantiableTypeName(containedField.getContainedType());
    SoftTypeRef typeRef = new SoftTypeRef(internalRepository, containedField.getDeclaringType().getNamespace(),
            containedTypeName, false);/* w  w  w . ja va2  s  .  c om*/
    ReferenceFieldMetadata newFlattenField = new ReferenceFieldMetadata(currentType.peek(), false,
            containedField.isMany(), isDatabaseMandatory(containedField, containedField.getDeclaringType()),
            context.getFieldColumn(containedField), typeRef,
            new SoftIdFieldRef(internalRepository, containedTypeName), Collections.<FieldMetadata>emptyList(),
            StringUtils.EMPTY, enforceTechnicalFK, false,
            new SimpleTypeMetadata(XMLConstants.W3C_XML_SCHEMA_NS_URI, Types.STRING),
            containedField.getWriteUsers(), containedField.getHideUsers(),
            containedField.getWorkflowAccessRights(), StringUtils.EMPTY, StringUtils.EMPTY);
    newFlattenField.setData(MetadataRepository.DATA_MAX_LENGTH, Types.UUID_LENGTH);
    newFlattenField.setData(MappingGenerator.SQL_DELETE_CASCADE, Boolean.TRUE.toString());
    currentType.peek().addField(newFlattenField);
    currentMapping.peek().map(containedField, newFlattenField);
    entityMapping.map(containedField, newFlattenField);
    if (!processedTypes.contains(containedField.getContainedType())) {
        processedTypes.add(containedField.getContainedType());
        containedField.getContainedType().accept(this);
        // recreate contained -> container association on mapped types
        TypeMapping containedTypeMapping = mappings.getMappingFromUser(containedField.getContainedType());
        ComplexTypeMetadata mappedContainedComplexType = containedTypeMapping.getDatabase();
        mappedContainedComplexType.setContainer(newFlattenField);
    }
    return null;
}

From source file:com.marklogic.client.impl.CombinedQueryBuilderImpl.java

private XMLStreamWriter makeXMLSerializer(OutputStream out) {
    XMLOutputFactory factory = XMLOutputFactory.newInstance();
    factory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, true);

    try {/* w w  w. j av  a2s  .  c  o  m*/
        XMLStreamWriter serializer = factory.createXMLStreamWriter(out, "UTF-8");

        serializer.setDefaultNamespace("http://marklogic.com/appservices/search");
        serializer.setPrefix("xs", XMLConstants.W3C_XML_SCHEMA_NS_URI);

        return serializer;
    } catch (Exception e) {
        throw new MarkLogicIOException(e);
    }
}

From source file:io.fabric8.camel.tooling.util.CamelNamespaces.java

private static void loadSchemas(SchemaFinder loader) throws SAXException, IOException {
    SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);

    XsdDetails[] xsds = new XsdDetails[] {
            new XsdDetails("camel-spring.xsd", "http://camel.apache.org/schema/spring/camel-spring.xsd",
                    CamelEndpointFactoryBean.class),
            new XsdDetails("camel-blueprint.xsd",
                    "http://camel.apache.org/schema/blueprint/camel-blueprint.xsd",
                    org.apache.camel.blueprint.CamelEndpointFactoryBean.class) };

    List<Source> sources = new ArrayList<Source>(xsds.length);

    for (XsdDetails xsdd : xsds) {
        URL url = loader.findSchema(xsdd);
        if (url != null) {
            sources.add(new StreamSource(url.openStream(), xsdd.getUri()));
        } else {//from  www .j a  v a  2  s . c  o  m
            System.out.println("Warning could not find local resource " + xsdd.getPath() + " on classpath");
            sources.add(new StreamSource(xsdd.getUri()));
        }
    }

    _schema = factory.newSchema(sources.toArray(new Source[sources.size()]));
}

From source file:org.psikeds.knowledgebase.xml.impl.XSDValidator.java

/**
 * Validate XML against specified XSD schmema.<br>
 * <b>Note:</b> The XML source/stream will not be closed. This must be
 * invoked by the caller afterwards!<br>
 * /*from w  w w.j  a  v  a 2 s.  co m*/
 * @param xsd
 *          Source for XSD-schema that will be used to validate the XML
 * @param xml
 *          Source for XML
 * @throws SAXException
 *           if XML is not valid against XSD
 * @throws IOException
 */
public static void validate(final Source xsd, final Source xml) throws SAXException, IOException {
    final SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
    final Schema schema = factory.newSchema(xsd);
    final Validator validator = schema.newValidator();
    validator.validate(xml);
}

From source file:cz.cas.lib.proarc.common.workflow.profile.WorkflowProfiles.java

private Unmarshaller getUnmarshaller() throws JAXBException {
    JAXBContext jctx = JAXBContext.newInstance(WorkflowDefinition.class);
    Unmarshaller unmarshaller = jctx.createUnmarshaller();
    SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
    URL schemaUrl = WorkflowDefinition.class.getResource("workflow.xsd");
    Schema schema = null;// ww w.  j  a  va 2  s  . com
    try {
        schema = sf.newSchema(new StreamSource(schemaUrl.toExternalForm()));
    } catch (SAXException ex) {
        throw new JAXBException("Missing schema workflow.xsd!", ex);
    }
    unmarshaller.setSchema(schema);
    ValidationEventCollector errors = new ValidationEventCollector() {

        @Override
        public boolean handleEvent(ValidationEvent event) {
            super.handleEvent(event);
            return true;
        }

    };
    unmarshaller.setEventHandler(errors);
    return unmarshaller;
}