/[Apache-SVN]/cocoon/trunk/src/java/org/apache/cocoon/components/source/SourceUtil.java
ViewVC logotype

Diff of /cocoon/trunk/src/java/org/apache/cocoon/components/source/SourceUtil.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

--- cocoon/trunk/src/java/org/apache/cocoon/components/source/SourceUtil.java	2005/04/29 16:55:02	165317
+++ cocoon/trunk/src/java/org/apache/cocoon/components/source/SourceUtil.java	2005/04/29 16:57:27	165318
@@ -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 @@ import org.xml.sax.helpers.DefaultHandle
  *
  * @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 @@ public final class SourceUtil {
     }
 
     /**
+     * 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 @@ public final class SourceUtil {
                              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 @@ public final class SourceUtil {
                              ContentHandler handler)
     throws SAXException, IOException, ProcessingException {
         if (source instanceof XMLizable) {
-            ((XMLizable) source).toSAX(handler);
+            toSAX((XMLizable) source, handler);
         } else {
             SAXParser parser = null;
             try {

 

infrastructure at apache.org
ViewVC Help
Powered by ViewVC 1.1.26