You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by vg...@apache.org on 2005/04/29 18:57:28 UTC

svn commit: r165318 - /cocoon/trunk/src/java/org/apache/cocoon/components/source/SourceUtil.java

Author: vgritsenko
Date: Fri Apr 29 09:57:27 2005
New Revision: 165318

URL: http://svn.apache.org/viewcvs?rev=165318&view=rev
Log:
unwrap evil SAXExceptions

Modified:
    cocoon/trunk/src/java/org/apache/cocoon/components/source/SourceUtil.java

Modified: cocoon/trunk/src/java/org/apache/cocoon/components/source/SourceUtil.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/components/source/SourceUtil.java?rev=165318&r1=165317&r2=165318&view=diff
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/components/source/SourceUtil.java (original)
+++ cocoon/trunk/src/java/org/apache/cocoon/components/source/SourceUtil.java Fri Apr 29 09:57:27 2005
@@ -1,5 +1,5 @@
 /*
- * Copyright 1999-2004 The Apache Software Foundation.
+ * 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.
@@ -62,7 +62,7 @@
  *
  * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
  * @author <a href="mailto:stephan@apache.org">Stephan Michels</a>
- * @version CVS $Id$
+ * @version $Id$
  */
 public final class SourceUtil {
 
@@ -82,6 +82,37 @@
     }
 
     /**
+     * Generates SAX events from the XMLizable and handle SAXException.
+     *
+     * @param  source    the data
+     */
+    static public void toSAX(XMLizable source,
+                             ContentHandler handler)
+    throws SAXException, IOException, ProcessingException {
+        try {
+            source.toSAX(handler);
+        } catch (SAXException e) {
+            // Unwrap ProcessingException, IOException, and extreme cases of SAXExceptions.
+            // See also handleSAXException
+            final Exception cause = e.getException();
+            if (cause != null) {
+                if (cause instanceof ProcessingException) {
+                    throw (ProcessingException) cause;
+                }
+                if (cause instanceof IOException) {
+                    throw (IOException) cause;
+                }
+                if (cause instanceof SAXException) {
+                    throw (SAXException) cause;
+                }
+            }
+
+            // Throw original SAX exception
+            throw e;
+        }
+    }
+
+    /**
      * Generates SAX events from the given source.
      *
      * <p><b>NOTE</b>: If the implementation can produce lexical events,
@@ -133,7 +164,7 @@
                              ContentHandler handler)
     throws SAXException, IOException, ProcessingException {
         if (source instanceof XMLizable) {
-            ((XMLizable) source).toSAX(handler);
+            toSAX((XMLizable) source, handler);
         } else {
             String mimeType = source.getMimeType();
             if (null == mimeType) {
@@ -205,7 +236,7 @@
                              ContentHandler handler)
     throws SAXException, IOException, ProcessingException {
         if (source instanceof XMLizable) {
-            ((XMLizable) source).toSAX(handler);
+            toSAX((XMLizable) source, handler);
         } else {
             SAXParser parser = null;
             try {