cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bimargul...@apache.org
Subject svn commit: r756937 - in /cxf/trunk/common/xerces-xsd-validation: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/cxf/ src/main/java/org/apache/cxf/xsdvalidation/ src/test/ src/test/java/ src/test/...
Date Sat, 21 Mar 2009 13:53:33 GMT
Author: bimargulies
Date: Sat Mar 21 13:53:32 2009
New Revision: 756937

URL: http://svn.apache.org/viewvc?rev=756937&view=rev
Log:
Commit first piece of Xml Schema validator so that Eclipse will be less confused.

Added:
    cxf/trunk/common/xerces-xsd-validation/
    cxf/trunk/common/xerces-xsd-validation/pom.xml   (with props)
    cxf/trunk/common/xerces-xsd-validation/src/
    cxf/trunk/common/xerces-xsd-validation/src/main/
    cxf/trunk/common/xerces-xsd-validation/src/main/java/
    cxf/trunk/common/xerces-xsd-validation/src/main/java/org/
    cxf/trunk/common/xerces-xsd-validation/src/main/java/org/apache/
    cxf/trunk/common/xerces-xsd-validation/src/main/java/org/apache/cxf/
    cxf/trunk/common/xerces-xsd-validation/src/main/java/org/apache/cxf/xsdvalidation/
    cxf/trunk/common/xerces-xsd-validation/src/main/java/org/apache/cxf/xsdvalidation/DOMLSInput.java
  (with props)
    cxf/trunk/common/xerces-xsd-validation/src/main/java/org/apache/cxf/xsdvalidation/XercesSchemaValidationUtils.java
  (with props)
    cxf/trunk/common/xerces-xsd-validation/src/main/java/org/apache/cxf/xsdvalidation/XercesXsdValidationImpl.java
  (with props)
    cxf/trunk/common/xerces-xsd-validation/src/test/
    cxf/trunk/common/xerces-xsd-validation/src/test/java/
    cxf/trunk/common/xerces-xsd-validation/src/test/resources/

Added: cxf/trunk/common/xerces-xsd-validation/pom.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/common/xerces-xsd-validation/pom.xml?rev=756937&view=auto
==============================================================================
--- cxf/trunk/common/xerces-xsd-validation/pom.xml (added)
+++ cxf/trunk/common/xerces-xsd-validation/pom.xml Sat Mar 21 13:53:32 2009
@@ -0,0 +1,67 @@
+<?xml version="1.0"?>
+<!--
+    Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements. See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership. The ASF licenses this file
+    to you under the Apache License, Version 2.0 (the
+    "License"); you may not use this file except in compliance
+    with the License. You may obtain a copy of the License at
+    
+    http://www.apache.org/licenses/LICENSE-2.0
+    
+    Unless required by applicable law or agreed to in writing,
+    software distributed under the License is distributed on an
+    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+    KIND, either express or implied. See the License for the
+    specific language governing permissions and limitations
+    under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.apache.cxf</groupId>
+  <artifactId>cxf-xerces-xsd-validation</artifactId>
+  <packaging>jar</packaging>
+  <version>2.2.1-SNAPSHOT</version>
+  <name>Apache CXF XML Schema Validation with Xerces</name>
+  <url>http://cxf.apache.org</url>
+  <parent>
+    <groupId>org.apache.cxf</groupId>
+    <artifactId>cxf-parent</artifactId>
+    <version>2.2.1-SNAPSHOT</version>
+    <relativePath>../../parent/pom.xml</relativePath>
+  </parent>
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.cxf</groupId>
+      <artifactId>cxf-api</artifactId>
+      <version>${project.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.cxf</groupId>
+      <artifactId>cxf-common-utilities</artifactId>
+      <version>${project.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.geronimo.specs</groupId>
+      <artifactId>geronimo-annotation_1.0_spec</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.ws.commons.schema</groupId>
+      <artifactId>XmlSchema</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>xerces</groupId>
+      <artifactId>xercesImpl</artifactId>
+    </dependency>
+  </dependencies>
+  <scm>
+    <connection>scm:svn:http://svn.apache.org/repos/asf/cxf/trunk/common/xerces-xsd-validation</connection>
+    <developerConnection>scm:svn:https://svn.apache.org/repos/asf/cxf/trunk/common/xerces-xsd-validation</developerConnection>
+  </scm>
+</project>

Propchange: cxf/trunk/common/xerces-xsd-validation/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/common/xerces-xsd-validation/pom.xml
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: cxf/trunk/common/xerces-xsd-validation/pom.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Added: cxf/trunk/common/xerces-xsd-validation/src/main/java/org/apache/cxf/xsdvalidation/DOMLSInput.java
URL: http://svn.apache.org/viewvc/cxf/trunk/common/xerces-xsd-validation/src/main/java/org/apache/cxf/xsdvalidation/DOMLSInput.java?rev=756937&view=auto
==============================================================================
--- cxf/trunk/common/xerces-xsd-validation/src/main/java/org/apache/cxf/xsdvalidation/DOMLSInput.java
(added)
+++ cxf/trunk/common/xerces-xsd-validation/src/main/java/org/apache/cxf/xsdvalidation/DOMLSInput.java
Sat Mar 21 13:53:32 2009
@@ -0,0 +1,131 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.xsdvalidation;
+
+import java.io.InputStream;
+import java.io.Reader;
+import java.io.StringWriter;
+import java.util.logging.Logger;
+
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.ls.LSInput;
+
+import org.apache.cxf.common.logging.LogUtils;
+
+/**
+ * 
+ */
+class DOMLSInput implements LSInput {
+    private static final Logger LOG = LogUtils.getL7dLogger(DOMLSInput.class);
+    private String systemId;
+    private String data;
+    
+    DOMLSInput(Document doc, String systemId) throws TransformerException {
+        this.systemId = systemId;
+        TransformerFactory factory = TransformerFactory.newInstance();
+        Transformer transformer = factory.newTransformer();
+        DOMSource source = new DOMSource(doc);
+        source.setSystemId(systemId);
+        StringWriter writer = new StringWriter();
+        StreamResult result = new StreamResult(writer);
+        transformer.transform(source, result);
+        data = writer.toString();
+        LOG.fine(systemId + ": " + data);
+        
+    }
+
+    /** {@inheritDoc}*/
+    public String getBaseURI() {
+        return null;
+    }
+
+    /** {@inheritDoc}*/
+    public InputStream getByteStream() {
+        return null;
+    }
+
+    /** {@inheritDoc}*/
+    public boolean getCertifiedText() {
+        return false;
+    }
+
+    /** {@inheritDoc}*/
+    public Reader getCharacterStream() {
+        return null;
+    }
+
+    /** {@inheritDoc}*/
+    public String getEncoding() {
+        return "utf-8";
+    }
+
+    /** {@inheritDoc}*/
+    public String getPublicId() {
+        return null;
+    }
+
+    /** {@inheritDoc}*/
+    public String getStringData() {
+        return data;
+    }
+
+    /** {@inheritDoc}*/
+    public String getSystemId() {
+        return systemId;
+    }
+
+    /** {@inheritDoc}*/
+    public void setBaseURI(String baseURI) {
+    }
+
+    /** {@inheritDoc}*/
+    public void setByteStream(InputStream byteStream) {
+    }
+
+    /** {@inheritDoc}*/
+    public void setCertifiedText(boolean certifiedText) {
+    }
+
+    /** {@inheritDoc}*/
+    public void setCharacterStream(Reader characterStream) {
+    }
+
+    /** {@inheritDoc}*/
+    public void setEncoding(String encoding) {
+    }
+
+    /** {@inheritDoc}*/
+    public void setPublicId(String publicId) {
+    }
+
+    /** {@inheritDoc}*/
+    public void setStringData(String stringData) {
+    }
+
+    /** {@inheritDoc}*/
+    public void setSystemId(String systemId) {
+    }
+}

Propchange: cxf/trunk/common/xerces-xsd-validation/src/main/java/org/apache/cxf/xsdvalidation/DOMLSInput.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/common/xerces-xsd-validation/src/main/java/org/apache/cxf/xsdvalidation/DOMLSInput.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: cxf/trunk/common/xerces-xsd-validation/src/main/java/org/apache/cxf/xsdvalidation/XercesSchemaValidationUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/common/xerces-xsd-validation/src/main/java/org/apache/cxf/xsdvalidation/XercesSchemaValidationUtils.java?rev=756937&view=auto
==============================================================================
--- cxf/trunk/common/xerces-xsd-validation/src/main/java/org/apache/cxf/xsdvalidation/XercesSchemaValidationUtils.java
(added)
+++ cxf/trunk/common/xerces-xsd-validation/src/main/java/org/apache/cxf/xsdvalidation/XercesSchemaValidationUtils.java
Sat Mar 21 13:53:32 2009
@@ -0,0 +1,101 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.xsdvalidation;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.XMLConstants;
+import javax.xml.transform.TransformerException;
+
+import org.w3c.dom.DOMErrorHandler;
+import org.w3c.dom.Document;
+import org.w3c.dom.ls.LSInput;
+import org.w3c.dom.ls.LSResourceResolver;
+
+import org.apache.ws.commons.schema.XmlSchema;
+import org.apache.ws.commons.schema.XmlSchemaCollection;
+import org.apache.ws.commons.schema.XmlSchemaSerializer;
+import org.apache.ws.commons.schema.XmlSchemaSerializer.XmlSchemaSerializerException;
+import org.apache.xerces.dom.DOMXSImplementationSourceImpl;
+import org.apache.xerces.xs.LSInputList;
+import org.apache.xerces.xs.XSImplementation;
+import org.apache.xerces.xs.XSLoader;
+
+/**
+ * 
+ */
+class XercesSchemaValidationUtils {
+
+    private static final class ListLSInput implements LSInputList {
+        private final List<DOMLSInput> inputs;
+
+        private ListLSInput(List<DOMLSInput> inputs) {
+            this.inputs = inputs;
+        }
+
+        public int getLength() {
+            return inputs.size();
+        }
+
+        public LSInput item(int index) {
+            return inputs.get(index);
+        }
+    }
+
+    private XSImplementation impl;
+
+    XercesSchemaValidationUtils() {
+        DOMXSImplementationSourceImpl source = new org.apache.xerces.dom.DOMXSImplementationSourceImpl();
+        impl = (XSImplementation)source.getDOMImplementation("XS-Loader");
+    }
+
+    void tryToParseSchemas(XmlSchemaCollection collection, DOMErrorHandler handler)
+        throws XmlSchemaSerializerException, TransformerException {
+
+        final List<DOMLSInput> inputs = new ArrayList<DOMLSInput>();
+        final Map<String, LSInput> resolverMap = new HashMap<String, LSInput>();
+
+        for (XmlSchema schema : collection.getXmlSchemas()) {
+            if (XMLConstants.W3C_XML_SCHEMA_NS_URI.equals(schema.getTargetNamespace())) {
+                continue;
+            }
+            Document document = new XmlSchemaSerializer().serializeSchema(schema, false)[0];
+            DOMLSInput input = new DOMLSInput(document, schema.getTargetNamespace());
+            resolverMap.put(schema.getTargetNamespace(), input);
+            inputs.add(input);
+        }
+
+        XSLoader schemaLoader = impl.createXSLoader(null);
+        schemaLoader.getConfig().setParameter("validate", Boolean.TRUE);
+        schemaLoader.getConfig().setParameter("error-handler", handler);
+        schemaLoader.getConfig().setParameter("resource-resolver", new LSResourceResolver()
{
+
+            public LSInput resolveResource(String type, String namespaceURI, String publicId,
+                                           String systemId, String baseURI) {
+                return resolverMap.get(namespaceURI);
+            }
+        });
+
+        schemaLoader.loadInputList(new ListLSInput(inputs));
+    }
+}

Propchange: cxf/trunk/common/xerces-xsd-validation/src/main/java/org/apache/cxf/xsdvalidation/XercesSchemaValidationUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/common/xerces-xsd-validation/src/main/java/org/apache/cxf/xsdvalidation/XercesSchemaValidationUtils.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: cxf/trunk/common/xerces-xsd-validation/src/main/java/org/apache/cxf/xsdvalidation/XercesXsdValidationImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/common/xerces-xsd-validation/src/main/java/org/apache/cxf/xsdvalidation/XercesXsdValidationImpl.java?rev=756937&view=auto
==============================================================================
--- cxf/trunk/common/xerces-xsd-validation/src/main/java/org/apache/cxf/xsdvalidation/XercesXsdValidationImpl.java
(added)
+++ cxf/trunk/common/xerces-xsd-validation/src/main/java/org/apache/cxf/xsdvalidation/XercesXsdValidationImpl.java
Sat Mar 21 13:53:32 2009
@@ -0,0 +1,76 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.xsdvalidation;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.Resource;
+import javax.xml.transform.TransformerException;
+
+import org.w3c.dom.DOMErrorHandler;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.common.xmlschema.XmlSchemaValidationManager;
+import org.apache.ws.commons.schema.XmlSchemaCollection;
+import org.apache.ws.commons.schema.XmlSchemaSerializer.XmlSchemaSerializerException;
+
+/**
+ * 
+ */
+public class XercesXsdValidationImpl implements XmlSchemaValidationManager {
+    private static final Logger LOG = LogUtils.getL7dLogger(XercesXsdValidationImpl.class);
+
+    private Bus bus;
+    private XercesSchemaValidationUtils utils;
+
+    @Resource
+    public void setBus(Bus b) {
+        bus = b;
+    }
+
+    @PostConstruct
+    public void register() {
+
+        try {
+            utils = new XercesSchemaValidationUtils();
+        } catch (Exception e) {
+            /* If the dependencies are missing ... */
+            return;
+        }
+
+        if (null != bus) {
+            bus.setExtension(this, XmlSchemaValidationManager.class);
+        }
+    }
+
+    /** {@inheritDoc} */
+    public void validateSchemas(XmlSchemaCollection schemas, DOMErrorHandler errorHandler)
{
+        try {
+            utils.tryToParseSchemas(schemas, errorHandler);
+        } catch (XmlSchemaSerializerException e) {
+            LOG.log(Level.WARNING, "XML Schema serialization error", e);
+        } catch (TransformerException e) {
+            LOG.log(Level.SEVERE, "TraX failure converting DOM to string", e);
+        }
+    }
+}

Propchange: cxf/trunk/common/xerces-xsd-validation/src/main/java/org/apache/cxf/xsdvalidation/XercesXsdValidationImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/common/xerces-xsd-validation/src/main/java/org/apache/cxf/xsdvalidation/XercesXsdValidationImpl.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date



Mime
View raw message