You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by pi...@apache.org on 2005/09/08 03:33:39 UTC

svn commit: r279480 - in /cocoon/branches/BRANCH_2_1_X/src/blocks/validation: conf/ java/org/apache/cocoon/components/validation/impl/ samples/

Author: pier
Date: Wed Sep  7 18:32:55 2005
New Revision: 279480

URL: http://svn.apache.org/viewcvs?rev=279480&view=rev
Log:
XML-Schema through Xerces implementation finished

Added:
    cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/impl/XercesParseException.java
    cocoon/branches/BRANCH_2_1_X/src/blocks/validation/samples/schema-no.xsd
    cocoon/branches/BRANCH_2_1_X/src/blocks/validation/samples/schema-ok.xsd
Modified:
    cocoon/branches/BRANCH_2_1_X/src/blocks/validation/conf/validation.xconf
    cocoon/branches/BRANCH_2_1_X/src/blocks/validation/conf/validation.xmap
    cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/impl/XercesContentHandler.java
    cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/impl/XercesContext.java
    cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/impl/XercesEntityResolver.java
    cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/impl/XercesGrammarParser.java
    cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/impl/XercesSchema.java
    cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/impl/XercesSchemaParser.java
    cocoon/branches/BRANCH_2_1_X/src/blocks/validation/samples/schema-ok.rng
    cocoon/branches/BRANCH_2_1_X/src/blocks/validation/samples/sitemap.xmap
    cocoon/branches/BRANCH_2_1_X/src/blocks/validation/samples/source-ok.xml
    cocoon/branches/BRANCH_2_1_X/src/blocks/validation/samples/welcome.xml

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/validation/conf/validation.xconf
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/validation/conf/validation.xconf?rev=279480&r1=279479&r2=279480&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/validation/conf/validation.xconf (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/validation/conf/validation.xconf Wed Sep  7 18:32:55 2005
@@ -21,6 +21,9 @@
     <schema-parser name="jing" class="org.apache.cocoon.components.validation.impl.JingSchemaParser">
       <cache-schemas>true</cache-schemas>
     </schema-parser>
+    <schema-parser name="xerces-schema" class="org.apache.cocoon.components.validation.impl.XercesSchemaParser">
+      <cache-schemas>true</cache-schemas>
+    </schema-parser>
   </validator>
   
 </xconf>

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/validation/conf/validation.xmap
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/validation/conf/validation.xmap?rev=279480&r1=279479&r2=279480&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/validation/conf/validation.xmap (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/validation/conf/validation.xmap Wed Sep  7 18:32:55 2005
@@ -29,4 +29,10 @@
           +-->
       <grammar>http://relaxng.org/ns/structure/0.9</grammar>
     </map:transformer>
+
+    <map:transformer name="validate-xmlschema"
+                     logger="sitemap.transformer.validate"
+                     src="org.apache.cocoon.transformation.ValidatingTransformer">
+      <grammar>http://www.w3.org/2001/XMLSchema</grammar>
+    </map:transformer>
 </xmap>

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/impl/XercesContentHandler.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/impl/XercesContentHandler.java?rev=279480&r1=279479&r2=279480&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/impl/XercesContentHandler.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/impl/XercesContentHandler.java Wed Sep  7 18:32:55 2005
@@ -24,6 +24,7 @@
 import org.apache.xerces.xni.XMLAttributes;
 import org.apache.xerces.xni.XMLDocumentHandler;
 import org.apache.xerces.xni.XMLString;
+import org.apache.xerces.xni.parser.XMLParseException;
 import org.xml.sax.Attributes;
 import org.xml.sax.ContentHandler;
 import org.xml.sax.Locator;
@@ -32,6 +33,9 @@
 /**
  * <p>An implementation of the {@link ContentHandler} interface wrapping around
  * a Xerces {@link XMLDocumentHandler} instance.</p>
+ * 
+ * <p>Most of this code has been derived from the Xerces JAXP Validation interface
+ * available in the <code>org.xml.xerces.jaxp.validation</code> package.</p>
  *
  * @author <a href="mailto:pier@betaversion.org">Pier Fumagalli</a>
  */
@@ -49,29 +53,37 @@
     }
 
     public void setDocumentLocator(Locator locator) {
-        System.err.println("SETTING LOCATOR");
         this.locator.setLocator(locator);
     }
 
     public void startDocument()
     throws SAXException {
-        System.err.println("START DOCUMENT");
-        this.validationHandler.startDocument(this.locator,
-                                     this.locator.getEncoding(),
-                                     this.namespaceContext,
-                                     null);
+        try {
+            this.validationHandler.startDocument(this.locator,
+                                                 this.locator.getEncoding(),
+                                                 this.namespaceContext,
+                                                 null);
+        } catch (XMLParseException exception) {
+            throw new XercesParseException(exception);
+        }
     }
 
     public void endDocument()
     throws SAXException {
-        this.validationHandler.endDocument(null);
+        try {
+            this.validationHandler.endDocument(null);
+        } catch (XMLParseException exception) {
+            throw new XercesParseException(exception);
+        }
     }
 
     public void startPrefixMapping(String pfx, String uri)
     throws SAXException {
-        String nsPfx = pfx != null? pfx: XMLSymbols.EMPTY_STRING;
-        String nsUri = (uri != null && uri.length() > 0)? uri : null;
-        this.namespaceContext.declarePrefix(nsPfx, nsUri);
+        try {
+            this.namespaceContext.declarePrefix(pfx, uri);
+        } catch (XMLParseException exception) {
+            throw new XercesParseException(exception);
+        }
     }
 
     public void endPrefixMapping(String arg0)
@@ -82,45 +94,64 @@
     public void startElement(String namespace, String local, String qualified,
                              Attributes attributes)
     throws SAXException {
-        System.err.println("STAR ELEM " + this.locator.getLiteralSystemId());
-        QName qname = this.qname(namespace, local, qualified);
-        XMLAttributes xmlatts = new XMLAttributesImpl(attributes.getLength());
-        for (int x = 0; x < attributes.getLength(); x ++) {
-            final String aNamespace = attributes.getURI(x);
-            final String aLocalName = attributes.getLocalName(x);
-            final String aQualified = attributes.getQName(x);
-            final String aType = attributes.getType(x);
-            final String aValue = attributes.getValue(x);
-            QName aQname = this.qname(aNamespace, aLocalName, aQualified);
-            xmlatts.addAttribute(aQname, aType, aValue);
+        try {
+            QName qname = this.qname(namespace, local, qualified);
+            XMLAttributes xmlatts = new XMLAttributesImpl(attributes.getLength());
+            for (int x = 0; x < attributes.getLength(); x ++) {
+                final String aNamespace = attributes.getURI(x);
+                final String aLocalName = attributes.getLocalName(x);
+                final String aQualified = attributes.getQName(x);
+                final String aType = attributes.getType(x);
+                final String aValue = attributes.getValue(x);
+                QName aQname = this.qname(aNamespace, aLocalName, aQualified);
+                xmlatts.addAttribute(aQname, aType, aValue);
+            }
+            this.namespaceContext.pushContext();
+            this.validationHandler.startElement(qname, xmlatts, null);
+        } catch (XMLParseException exception) {
+            throw new XercesParseException(exception);
         }
-        this.namespaceContext.pushContext();
-        this.validationHandler.startElement(qname, xmlatts, null);
     }
 
     public void endElement(String namespace, String local, String qualified)
     throws SAXException {
-        QName qname = this.qname(namespace, local, qualified);
-        this.validationHandler.endElement(qname, null);
-        this.namespaceContext.popContext();
+        try {
+            QName qname = this.qname(namespace, local, qualified);
+            this.validationHandler.endElement(qname, null);
+            this.namespaceContext.popContext();
+        } catch (XMLParseException exception) {
+            throw new XercesParseException(exception);
+        }
     }
 
     public void characters(char buffer[], int offset, int length)
     throws SAXException {
-        XMLString data = new XMLString(buffer, offset, length);
-        this.validationHandler.characters(data, null);
+        try {
+            XMLString data = new XMLString(buffer, offset, length);
+            this.validationHandler.characters(data, null);
+        } catch (XMLParseException exception) {
+            throw new XercesParseException(exception);
+        }
     }
 
     public void ignorableWhitespace(char buffer[], int offset, int length)
     throws SAXException {
-        XMLString data = new XMLString(buffer, offset, length);
-        this.validationHandler.ignorableWhitespace(data, null);
+        try {
+            XMLString data = new XMLString(buffer, offset, length);
+            this.validationHandler.ignorableWhitespace(data, null);
+        } catch (XMLParseException exception) {
+            throw new XercesParseException(exception);
+        }
     }
 
     public void processingInstruction(String target, String extra)
     throws SAXException {
-        XMLString data = new XMLString(extra.toCharArray(), 0, extra.length());
-        this.validationHandler.processingInstruction(target, data, null);
+        try {
+            XMLString data = new XMLString(extra.toCharArray(), 0, extra.length());
+            this.validationHandler.processingInstruction(target, data, null);
+        } catch (XMLParseException exception) {
+            throw new XercesParseException(exception);
+        }
     }
 
     public void skippedEntity(String arg0)

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/impl/XercesContext.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/impl/XercesContext.java?rev=279480&r1=279479&r2=279480&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/impl/XercesContext.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/impl/XercesContext.java Wed Sep  7 18:32:55 2005
@@ -35,13 +35,14 @@
 import org.apache.xerces.xni.parser.XMLParseException;
 import org.xml.sax.ErrorHandler;
 import org.xml.sax.SAXException;
-import org.xml.sax.SAXParseException;
-
 
 /**
  * <p>An implementation of Xerces {@link XMLComponentManager} interface allowing
  * interoperation of components while parsing or validating.</p>
  *
+ * <p>Most of this code has been derived from the Xerces JAXP Validation interface
+ * available in the <code>org.xml.xerces.jaxp.validation</code> package.</p>
+ *
  * @author <a href="mailto:pier@betaversion.org">Pier Fumagalli</a>
  */
 public class XercesContext extends ParserConfigurationSettings {
@@ -82,8 +83,11 @@
             Constants.XERCES_FEATURE_PREFIX + Constants.USE_GRAMMAR_POOL_ONLY_FEATURE;
     private static final String F_PARSER_SETTINGS = 
             Constants.XERCES_FEATURE_PREFIX + Constants.PARSER_SETTINGS;
+    private static final String F_SCHEMA_FULL_CHECK = 
+            Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_FULL_CHECKING;
     
     private static final String FEATURES[] = {
+                F_SCHEMA_FULL_CHECK,
                 F_SCHEMA_VALIDATION,
                 F_VALIDATION,
                 F_USE_GRAMMAR_POOL_ONLY,
@@ -115,6 +119,12 @@
                                           new XMLMessageFormatter());
         XMLErrorHandler xercesHandler = new ErrorHandlerWrapper(errorHandler);
 
+        super.setFeature(F_USE_GRAMMAR_POOL_ONLY, true);
+        super.setFeature(F_PARSER_SETTINGS,       true);
+        super.setFeature(F_VALIDATION,            true);
+        super.setFeature(F_SCHEMA_VALIDATION,     true);
+        super.setFeature(F_SCHEMA_FULL_CHECK,     true);
+
         super.setProperty(P_XMLGRAMMAR_POOL,    grammar);
         super.setProperty(P_ENTITY_RESOLVER,    resolver);
         super.setProperty(P_ERROR_REPORTER,     errorReporter);
@@ -125,16 +135,15 @@
         super.setProperty(P_VALIDATION_MANAGER, new ValidationManager());
         super.setProperty(P_SYMBOL_TABLE,       new SymbolTable());
 
-        super.setFeature(F_USE_GRAMMAR_POOL_ONLY, true);
-        super.setFeature(F_PARSER_SETTINGS,       true);
-        super.setFeature(F_VALIDATION,            true);
-        super.setFeature(F_SCHEMA_VALIDATION,     true);
-
         /* Initialize all known components */
         Iterator iterator = super.fProperties.values().iterator();
         while (iterator.hasNext()) this.initialize(iterator.next());
     }
-    
+
+    /**
+     * <p>Check if an object is an instance of {@link XMLComponent} and if so
+     * contextualize it around this instance.</p>
+     */
     public Object initialize(Object object) {
         if (!(object instanceof XMLComponent)) return object;
         XMLComponent component = (XMLComponent) object;
@@ -175,52 +184,35 @@
 
         public void warning(String domain, String key, XMLParseException e)
         throws XNIException {
-            System.err.println("DETECTED " + e.getMessage() + "/" + this.errorHandler);
             if (this.errorHandler != null) try {
-                this.errorHandler.warning(this.makeException(e));
+                this.errorHandler.warning(new XercesParseException(e));
             } catch (SAXException saxException) {
                 throw new XNIException(saxException);
             } else {
-                System.err.println("THROWING " + e.getMessage());
                 throw e;
             }
         }
 
         public void error(String domain, String key, XMLParseException e)
         throws XNIException {
-            System.err.println("DETECTED " + e.getMessage() + "/" + this.errorHandler);
             if (this.errorHandler != null) try {
-                this.errorHandler.warning(this.makeException(e));
+                this.errorHandler.warning(new XercesParseException(e));
             } catch (SAXException saxException) {
                 throw new XNIException(saxException);
             } else {
-                System.err.println("THROWING " + e.getMessage());
                 throw e;
             }
         }
 
         public void fatalError(String domain, String key, XMLParseException e)
         throws XNIException {
-            System.err.println("DETECTED " + e.getMessage() + "/" + this.errorHandler);
             if (this.errorHandler != null) try {
-                this.errorHandler.warning(this.makeException(e));
+                this.errorHandler.warning(new XercesParseException(e));
             } catch (SAXException saxException) {
                 throw new XNIException(saxException);
             } else {
-                System.err.println("THROWING " + e.getMessage());
                 throw e;
             }
-        }
-        
-        private SAXParseException makeException(XMLParseException exception) {
-            final SAXParseException saxParseException;
-            saxParseException = new SAXParseException(exception.getMessage(),
-                                                      exception.getPublicId(),
-                                                      exception.getLiteralSystemId(),
-                                                      exception.getLineNumber(),
-                                                      exception.getColumnNumber(),
-                                                      exception);
-            return (SAXParseException) saxParseException.initCause(exception);
         }
     }
 }

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/impl/XercesEntityResolver.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/impl/XercesEntityResolver.java?rev=279480&r1=279479&r2=279480&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/impl/XercesEntityResolver.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/impl/XercesEntityResolver.java Wed Sep  7 18:32:55 2005
@@ -33,6 +33,9 @@
  * <p>An implementation of Xerces' {@link XMLEntityResolver} resolving URIs using
  * Excalibur's {@link SourceResolver} and {@link EntityResolver}.</p>
  *
+ * <p>Most of this code has been derived from the Xerces JAXP Validation interface
+ * available in the <code>org.xml.xerces.jaxp.validation</code> package.</p>
+ *
  * @author <a href="mailto:pier@betaversion.org">Pier Fumagalli</a>
  */
 public class XercesEntityResolver implements XMLEntityResolver {

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/impl/XercesGrammarParser.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/impl/XercesGrammarParser.java?rev=279480&r1=279479&r2=279480&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/impl/XercesGrammarParser.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/impl/XercesGrammarParser.java Wed Sep  7 18:32:55 2005
@@ -21,14 +21,19 @@
 import org.apache.cocoon.components.validation.SchemaParser;
 import org.apache.excalibur.source.SourceValidity;
 import org.apache.xerces.util.XMLGrammarPoolImpl;
+import org.apache.xerces.xni.XNIException;
 import org.apache.xerces.xni.grammars.XMLGrammarLoader;
 import org.apache.xerces.xni.grammars.XMLGrammarPool;
+import org.apache.xerces.xni.parser.XMLParseException;
 import org.xml.sax.SAXException;
 
 /**
  * <p>The implementation of the {@link SchemaParser} interface using the internals
  * of <a href="http://xml.apache.org/xerces2-j/">Xerces</a>.</p>
  *
+ * <p>Most of this code has been derived from the Xerces JAXP Validation interface
+ * available in the <code>org.xml.xerces.jaxp.validation</code> package.</p>
+ *
  * @author <a href="mailto:pier@betaversion.org">Pier Fumagalli</a>
  */
 public abstract class XercesGrammarParser extends CachingSchemaParser 
@@ -51,27 +56,33 @@
      */
     protected final Schema parseSchema(String uri)
     throws IOException, SAXException {
-        /* Create a Xerces Grammar Pool and Entity Resolver */
-        XMLGrammarPool pool = new XMLGrammarPoolImpl();
-        XercesEntityResolver res = new XercesEntityResolver(super.sourceResolver,
-                                                            super.entityResolver);
-
-        /* Create a Xerces component manager contextualizing the loader */
-        XercesContext context = new XercesContext(pool, res);
-
-        /* Create a new XML Schema Loader and set the pool into it */
-        XMLGrammarLoader loader = this.newGrammarLoader();
-        context.initialize(loader);
-
-        /* Load (parse and interpret) the grammar */
-        this.getLogger().debug("Loading grammar from " + uri);
-        loader.loadGrammar(res.resolveUri(uri));
-        this.getLogger().debug("Grammar successfully loaded from " + uri);
-
-        /* Return a new Schema instance */
-        SourceValidity validity = res.getSourceValidity();
-        Class validator = this.getValidationHandlerClass();
-        return new XercesSchema(pool, validity, validator);
+        try {
+            /* Create a Xerces Grammar Pool and Entity Resolver */
+            XMLGrammarPool pool = new XMLGrammarPoolImpl();
+            XercesEntityResolver r = new XercesEntityResolver(super.sourceResolver,
+                                                              super.entityResolver);
+
+            /* Create a Xerces component manager contextualizing the loader */
+            XercesContext context = new XercesContext(pool, r);
+
+            /* Create a new XML Schema Loader and set the pool into it */
+            XMLGrammarLoader loader = this.newGrammarLoader();
+            context.initialize(loader);
+
+            /* Load (parse and interpret) the grammar */
+            this.getLogger().debug("Loading grammar from " + uri);
+            loader.loadGrammar(r.resolveUri(uri));
+            this.getLogger().debug("Grammar successfully loaded from " + uri);
+
+            /* Return a new Schema instance */
+            SourceValidity validity = r.getSourceValidity();
+            Class validator = this.getValidationHandlerClass();
+            return new XercesSchema(pool, validity, validator);
+        } catch (XMLParseException exception) {
+            throw new XercesParseException(exception);
+        } catch (XNIException exception) {
+            throw new SAXException("Unable to parse schema", exception);
+        }
     }
 
     /**

Added: cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/impl/XercesParseException.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/impl/XercesParseException.java?rev=279480&view=auto
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/impl/XercesParseException.java (added)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/impl/XercesParseException.java Wed Sep  7 18:32:55 2005
@@ -0,0 +1,41 @@
+/*
+ * Copyright 1999-2005 The Apache Software Foundation.
+ *
+ * Licensed 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.cocoon.components.validation.impl;
+
+import org.apache.xerces.xni.parser.XMLParseException;
+import org.xml.sax.SAXParseException;
+
+/**
+ * <p>A simple wrapper around a {@link XMLParseException} exposing a
+ * {@link SAXParseException}.</p>
+ *
+ * <p>Most of this code has been derived from the Xerces JAXP Validation interface
+ * available in the <code>org.xml.xerces.jaxp.validation</code> package.</p>
+ *
+ * @author <a href="mailto:pier@betaversion.org">Pier Fumagalli</a>
+ */
+public class XercesParseException extends SAXParseException {
+
+    public XercesParseException(XMLParseException exception) {
+        super(exception.getMessage(),
+              exception.getPublicId(),
+              exception.getLiteralSystemId(),
+              exception.getLineNumber(),
+              exception.getColumnNumber(),
+              exception);
+        super.initCause(exception); 
+    }
+}

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/impl/XercesSchema.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/impl/XercesSchema.java?rev=279480&r1=279479&r2=279480&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/impl/XercesSchema.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/impl/XercesSchema.java Wed Sep  7 18:32:55 2005
@@ -25,6 +25,9 @@
 /**
  * <p>A wrapper around a schema parsed by Xerces.</p>
  *
+ * <p>Most of this code has been derived from the Xerces JAXP Validation interface
+ * available in the <code>org.xml.xerces.jaxp.validation</code> package.</p>
+ *
  * @author <a href="mailto:pier@betaversion.org">Pier Fumagalli</a>
  */
 public class XercesSchema extends AbstractSchema {

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/impl/XercesSchemaParser.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/impl/XercesSchemaParser.java?rev=279480&r1=279479&r2=279480&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/impl/XercesSchemaParser.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/validation/java/org/apache/cocoon/components/validation/impl/XercesSchemaParser.java Wed Sep  7 18:32:55 2005
@@ -17,7 +17,6 @@
 
 import org.apache.cocoon.components.validation.SchemaParser;
 import org.apache.cocoon.components.validation.Validator;
-import org.apache.xerces.impl.Constants;
 import org.apache.xerces.impl.xs.XMLSchemaLoader;
 import org.apache.xerces.impl.xs.XMLSchemaValidator;
 import org.apache.xerces.xni.grammars.XMLGrammarLoader;
@@ -26,14 +25,14 @@
  * <p>The implementation of the {@link SchemaParser} interface for the XML Schema
  * grammar using <a href="http://xml.apache.org/xerces2-j/">Xerces</a>.</p>
  *
+ * <p>Most of this code has been derived from the Xerces JAXP Validation interface
+ * available in the <code>org.xml.xerces.jaxp.validation</code> package.</p>
+ *
  * @author <a href="mailto:pier@betaversion.org">Pier Fumagalli</a>
  */
 public class XercesSchemaParser extends XercesGrammarParser implements SchemaParser {
 
-    private static final String F_SCHEMA_FULL_CHECK = 
-            Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_FULL_CHECKING;
-    private static final String[] GRAMMARS = 
-            new String[] { Validator.GRAMMAR_XML_SCHEMA };
+    private static final String[] GRAMMARS = new String[] { Validator.GRAMMAR_XML_SCHEMA };
     private static final Class VALIDATOR = XMLSchemaValidator.class;
 
     /**
@@ -58,9 +57,7 @@
      * <p>Return a {@link XMLGrammarLoader} for the XML Schema grammar.</p>
      */
     protected XMLGrammarLoader newGrammarLoader() {
-        XMLSchemaLoader loader = new XMLSchemaLoader();
-        loader.setFeature(F_SCHEMA_FULL_CHECK, true);
-        return loader;
+        return new XMLSchemaLoader();
     }
 
     /**

Added: cocoon/branches/BRANCH_2_1_X/src/blocks/validation/samples/schema-no.xsd
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/validation/samples/schema-no.xsd?rev=279480&view=auto
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/validation/samples/schema-no.xsd (added)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/validation/samples/schema-no.xsd Wed Sep  7 18:32:55 2005
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
+  elementFormDefault="qualified"
+  targetNamespace="http://test/namespace/1.0"
+  xmlns:ns1="http://test/namespace/1.0">
+  
+  <xs:element name="page">
+    <xs:this-invalidates-the-schema/>
+  </xs:element>
+</xs:schema>

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/validation/samples/schema-ok.rng
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/validation/samples/schema-ok.rng?rev=279480&r1=279479&r2=279480&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/validation/samples/schema-ok.rng (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/validation/samples/schema-ok.rng Wed Sep  7 18:32:55 2005
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<grammar xmlns="http://relaxng.org/ns/structure/1.0">
+<grammar xmlns="http://relaxng.org/ns/structure/1.0" ns="http://test/namespace/1.0">
   <define name="page">
     <element name="page">
       <empty/>

Added: cocoon/branches/BRANCH_2_1_X/src/blocks/validation/samples/schema-ok.xsd
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/validation/samples/schema-ok.xsd?rev=279480&view=auto
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/validation/samples/schema-ok.xsd (added)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/validation/samples/schema-ok.xsd Wed Sep  7 18:32:55 2005
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
+  elementFormDefault="qualified"
+  targetNamespace="http://test/namespace/1.0"
+  xmlns:ns1="http://test/namespace/1.0">
+  
+  <xs:element name="page">
+    <xs:complexType/>
+  </xs:element>
+</xs:schema>

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/validation/samples/sitemap.xmap
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/validation/samples/sitemap.xmap?rev=279480&r1=279479&r2=279480&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/validation/samples/sitemap.xmap (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/validation/samples/sitemap.xmap Wed Sep  7 18:32:55 2005
@@ -38,27 +38,64 @@
         <map:serialize/>
       </map:match>
 
-      <map:match pattern="validation-ok">
+      <!-- relax ng samples -->
+      <map:match pattern="relaxng-ok">
         <map:generate src="source-ok.xml"/>
         <map:transform type="validate-relaxng" src="schema-ok.rng"/>
         <map:transform src="validation.xslt"/>
         <map:serialize/>
       </map:match>
 
-      <map:match pattern="validation-invalid">
+      <map:match pattern="relaxng-invalid">
         <map:generate src="source-no.xml"/>
         <map:transform type="validate-relaxng" src="schema-ok.rng"/>
         <map:transform src="validation.xslt"/>
         <map:serialize/>
       </map:match>
 
-      <map:match pattern="validation-noschema">
+      <map:match pattern="relaxng-badschema">
         <map:generate src="source-ok.xml"/>
         <map:transform type="validate-relaxng" src="schema-no.rng"/>
         <map:transform src="validation.xslt"/>
         <map:serialize/>
       </map:match>
+      
+      <map:match pattern="relaxng-noschema">
+        <map:generate src="source-ok.xml"/>
+        <map:transform type="validate-relaxng" src="schema-xx.rng"/>
+        <map:transform src="validation.xslt"/>
+        <map:serialize/>
+      </map:match>
+      
+      <!-- xml schema samples -->
+      <map:match pattern="xmlschema-ok">
+        <map:generate src="source-ok.xml"/>
+        <map:transform type="validate-xmlschema" src="schema-ok.xsd"/>
+        <map:transform src="validation.xslt"/>
+        <map:serialize/>
+      </map:match>
 
+      <map:match pattern="xmlschema-invalid">
+        <map:generate src="source-no.xml"/>
+        <map:transform type="validate-xmlschema" src="schema-ok.xsd"/>
+        <map:transform src="validation.xslt"/>
+        <map:serialize/>
+      </map:match>
+
+      <map:match pattern="xmlschema-badschema">
+        <map:generate src="source-ok.xml"/>
+        <map:transform type="validate-xmlschema" src="schema-no.xsd"/>
+        <map:transform src="validation.xslt"/>
+        <map:serialize/>
+      </map:match>
+      
+      <map:match pattern="xmlschema-noschema">
+        <map:generate src="source-ok.xml"/>
+        <map:transform type="validate-xmlschema" src="schema-xx.xsd"/>
+        <map:transform src="validation.xslt"/>
+        <map:serialize/>
+      </map:match>
+      
     </map:pipeline>
   </map:pipelines>
 </map:sitemap>

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/validation/samples/source-ok.xml
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/validation/samples/source-ok.xml?rev=279480&r1=279479&r2=279480&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/validation/samples/source-ok.xml (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/validation/samples/source-ok.xml Wed Sep  7 18:32:55 2005
@@ -1,2 +1,2 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<page/>
+<page xmlns="http://test/namespace/1.0"/>

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/validation/samples/welcome.xml
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/validation/samples/welcome.xml?rev=279480&r1=279479&r2=279480&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/validation/samples/welcome.xml (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/validation/samples/welcome.xml Wed Sep  7 18:32:55 2005
@@ -24,18 +24,36 @@
     <sample name="Back" href="..">to Cocoon Blocks Samples main page</sample>
   </group>
 
-  <group name="ValidatingTransformer Samples">
-    <sample name="Successful validation" href="validation-ok">
+  <group name="ValidatingTransformer RELAX-NG Samples">
+    <sample name="Successful validation" href="relaxng-ok">
       Shows the output of a pipeline with a valid document being processed.
     </sample>
-    <sample name="Validation failure" href="validation-invalid">
+    <sample name="Validation failure" href="relaxng-invalid">
       Shows the output of a pipeline with an invalid document being processed.
     </sample>
-    <sample name="Schema parsing failure" href="validation-noschema">
-      Shows the output of a pipeline configured with a wrong schema.
+    <sample name="Non-existent schema failure" href="relaxng-noschema">
+      Shows the output of a pipeline configured with a non-existent schema.
+    </sample>
+    <sample name="Schema parsing failure" href="relaxng-badschema">
+      Shows the output of a pipeline configured with an invalid schema.
+    </sample>
+  </group>
+  
+  <group name="ValidatingTransformer XML-Schema Samples">
+    <sample name="Successful validation" href="xmlschema-ok">
+      Shows the output of a pipeline with a valid document being processed.
+    </sample>
+    <sample name="Validation failure" href="xmlschema-invalid">
+      Shows the output of a pipeline with an invalid document being processed.
+    </sample>
+    <sample name="Non-existent schema failure" href="xmlschema-noschema">
+      Shows the output of a pipeline configured with a non-existent schema.
+    </sample>
+    <sample name="Schema parsing failure" href="xmlschema-badschema">
+      Shows the output of a pipeline configured with an invalid schema.
     </sample>
   </group>
-
+  
   <group name="Avaliable Documentation">
     <sample name="Validation Block Documentation"
             href="http://cocoon.zones.apache.org/daisy/documentation/blocks/validation.html">