cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From reinh...@apache.org
Subject svn commit: r703201 - in /cocoon/cocoon3/trunk/cocoon-pipeline/src: main/java/org/apache/cocoon/pipeline/component/sax/ test/java/org/apache/cocoon/pipeline/component/sax/
Date Thu, 09 Oct 2008 16:25:14 GMT
Author: reinhard
Date: Thu Oct  9 09:25:14 2008
New Revision: 703201

URL: http://svn.apache.org/viewvc?rev=703201&view=rev
Log:
COCOON3-2 Throw a specific unchecked exception (SchemaValidationException) when the XML is
invalid.

Added:
    cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/component/sax/SchemaValidationException.java
  (with props)
Modified:
    cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/component/sax/SchemaErrorHandler.java
    cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/component/sax/SchemaProcessorTransformer.java
    cocoon/cocoon3/trunk/cocoon-pipeline/src/test/java/org/apache/cocoon/pipeline/component/sax/SchemaProcessorTransformerTest.java

Modified: cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/component/sax/SchemaErrorHandler.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/component/sax/SchemaErrorHandler.java?rev=703201&r1=703200&r2=703201&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/component/sax/SchemaErrorHandler.java
(original)
+++ cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/component/sax/SchemaErrorHandler.java
Thu Oct  9 09:25:14 2008
@@ -27,65 +27,24 @@
 
     private final Log logger;
 
-    private final String uri;
+    private final String schemaUri;
 
-    private SAXParseException exception;
-
-    private SAXParseException warningEx;
-
-    public SchemaErrorHandler(Log logger, String uri) {
+    public SchemaErrorHandler(Log logger, String schemaUri) {
         this.logger = logger;
-        this.uri = uri;
+        this.schemaUri = schemaUri;
     }
 
-    public void error(SAXParseException ex) throws SAXException {
-        if (this.warningEx != null && ex.getCause() == null) {
-            ex = this.warningEx;
-        }
-        this.warningEx = null;
-
-        // Keep the exception for later use.
-        this.exception = ex;
-        // and rethrow it
-        throw ex;
+    public void error(final SAXParseException ex) throws SAXException {
+        throw new SchemaValidationException("Validation with schema " + this.schemaUri +
" failed with error", ex);
     }
 
     public void fatalError(SAXParseException ex) throws SAXException {
-        if (this.warningEx != null && ex.getCause() == null) {
-            ex = this.warningEx;
-        }
-        this.warningEx = null;
-
-        this.exception = ex;
-        throw ex;
+        throw new SchemaValidationException("Validation with schema " + this.schemaUri +
" failed with fatal error", ex);
     }
 
     public void warning(SAXParseException ex) throws SAXException {
         if (this.logger.isWarnEnabled()) {
-            this.logger.warn(ex.getMessage() + " at " + this.uri);
-        }
-
-        // Keep the warning (see below)
-        this.warningEx = ex;
-    }
-
-    /**
-     * Get the exception that was catched by this listener, if any.
-     * 
-     * @return the exception
-     */
-    public Throwable getThrowable() {
-        if (this.exception == null) {
-            return null;
+            this.logger.warn(ex.getMessage() + " at " + this.schemaUri);
         }
-
-        // No location: if it's just a wrapper, consider only the wrapped exception
-        if (this.exception.getCause() != null) {
-            return this.exception.getCause();
-        }
-
-        // That's the actual exception!
-        return this.exception;
     }
-
 }

Modified: cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/component/sax/SchemaProcessorTransformer.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/component/sax/SchemaProcessorTransformer.java?rev=703201&r1=703200&r2=703201&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/component/sax/SchemaProcessorTransformer.java
(original)
+++ cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/component/sax/SchemaProcessorTransformer.java
Thu Oct  9 09:25:14 2008
@@ -30,6 +30,9 @@
 import org.apache.commons.logging.LogFactory;
 import org.xml.sax.SAXException;
 
+/*
+ * FIXME Doesn't work in sitemaps because of missing setConfiguration() and default constructor.
+ */
 public final class SchemaProcessorTransformer extends AbstractTransformer {
 
     private final static SchemaFactory SCHEMA_FACTORY = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);

Added: cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/component/sax/SchemaValidationException.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/component/sax/SchemaValidationException.java?rev=703201&view=auto
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/component/sax/SchemaValidationException.java
(added)
+++ cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/component/sax/SchemaValidationException.java
Thu Oct  9 09:25:14 2008
@@ -0,0 +1,28 @@
+/*
+ * 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.cocoon.pipeline.component.sax;
+
+import org.apache.cocoon.pipeline.ProcessingException;
+
+public class SchemaValidationException extends ProcessingException {
+
+    private static final long serialVersionUID = 1L;
+
+    public SchemaValidationException(String message, Throwable cause) {
+        super(message, cause);
+    }
+}

Propchange: cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/component/sax/SchemaValidationException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/component/sax/SchemaValidationException.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: cocoon/cocoon3/trunk/cocoon-pipeline/src/main/java/org/apache/cocoon/pipeline/component/sax/SchemaValidationException.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: cocoon/cocoon3/trunk/cocoon-pipeline/src/test/java/org/apache/cocoon/pipeline/component/sax/SchemaProcessorTransformerTest.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-pipeline/src/test/java/org/apache/cocoon/pipeline/component/sax/SchemaProcessorTransformerTest.java?rev=703201&r1=703200&r2=703201&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-pipeline/src/test/java/org/apache/cocoon/pipeline/component/sax/SchemaProcessorTransformerTest.java
(original)
+++ cocoon/cocoon3/trunk/cocoon-pipeline/src/test/java/org/apache/cocoon/pipeline/component/sax/SchemaProcessorTransformerTest.java
Thu Oct  9 09:25:14 2008
@@ -18,20 +18,22 @@
  */
 package org.apache.cocoon.pipeline.component.sax;
 
-import java.io.ByteArrayOutputStream;
+import static junit.framework.Assert.*;
 
-import junit.framework.TestCase;
+import java.io.ByteArrayOutputStream;
 
 import org.apache.cocoon.pipeline.NonCachingPipeline;
 import org.apache.cocoon.pipeline.Pipeline;
 import org.custommonkey.xmlunit.Diff;
+import org.junit.Test;
 
-public class SchemaProcessorTransformerTest extends TestCase {
+public class SchemaProcessorTransformerTest {
 
     /**
      * A pipeline that performs an identity transformation, using the validation: generator
-> validator ->
      * serializer
      */
+    @Test
     public void testPipelineWithValidation() throws Exception {
         Pipeline pipeline = this.createValidatingPipeline("<x></x>");
 
@@ -50,16 +52,16 @@
      * A pipeline that performs an identity transformation, using the validation: generator
-&gt; validator -&gt;
      * serializer. An error is expected performing <code>execute</code> method
due to not valid xml input.
      */
-    public void testPipelineWithWrongValidation() {
+    @Test
+    public void testPipelineWithWrongValidation() throws Exception {
         Pipeline pipeline = this.createValidatingPipeline("<y><z/></y>");
 
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         pipeline.setup(baos);
         try {
             pipeline.execute();
-            fail("A validation error is expected");
-        } catch (Exception e) {
-            e.printStackTrace();
+            fail("A specific SchemaValidationException is expected.");
+        } catch (SchemaValidationException e) {
             // success
         }
     }



Mime
View raw message