Author: vgritsenko
Date: Fri Apr 29 09:55:02 2005
New Revision: 165317

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

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

Modified: 
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/source/SourceUtil.java
URL: 
http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/source/SourceUtil.java?rev=165317&r1=165316&r2=165317&view=diff
==============================================================================
--- 
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/source/SourceUtil.java
 (original)
+++ 
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/components/source/SourceUtil.java
 Fri Apr 29 09:55:02 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.
@@ -65,7 +65,7 @@
  *
  * @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a>
  * @author <a href="mailto:[EMAIL PROTECTED]">Stephan Michels</a>
- * @version CVS $Id$
+ * @version $Id$
  */
 public final class SourceUtil {
 
@@ -85,6 +85,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,
@@ -138,25 +169,7 @@
                              ContentHandler handler)
     throws SAXException, IOException, ProcessingException {
         if (source instanceof XMLizable) {
-            try {
-                ((XMLizable) 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 e;
-            }
+            toSAX((XMLizable) source, handler);
         } else {
             String mimeType = source.getMimeType();
             if (null == mimeType) {
@@ -196,7 +209,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) {
@@ -236,7 +249,7 @@
                              ContentHandler handler)
     throws SAXException, IOException, ProcessingException {
         if (source instanceof XMLizable) {
-            ((XMLizable) source).toSAX(handler);
+            toSAX((XMLizable) source, handler);
         } else {
             SAXParser parser = null;
             try {
@@ -267,7 +280,7 @@
                              ContentHandler handler)
     throws SAXException, IOException, ProcessingException {
         if (source instanceof XMLizable) {
-            ((XMLizable) source).toSAX(handler);
+            toSAX((XMLizable) source, handler);
         } else {
             SAXParser parser = null;
             try {


Reply via email to