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/03/09 21:13:34 UTC

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

Author: vgritsenko
Date: Wed Mar  9 12:13:32 2005
New Revision: 156677

URL: http://svn.apache.org/viewcvs?view=rev&rev=156677
Log:
minor cleanups

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?view=diff&r1=156676&r2=156677
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/components/source/SourceUtil.java (original)
+++ cocoon/trunk/src/java/org/apache/cocoon/components/source/SourceUtil.java Wed Mar  9 12:13:32 2005
@@ -70,9 +70,10 @@
 
     static {
         try {
-            uripattern = (new RECompiler()).compile("^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\\?([^#]*))?(#(.*))?$");
-        } catch (RESyntaxException rese) {
-            rese.printStackTrace();
+            uripattern = new RECompiler().compile("^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\\?([^#]*))?(#(.*))?$");
+        } catch (RESyntaxException e) {
+            // Should not happen
+            e.printStackTrace();
         }
     }
 
@@ -238,8 +239,8 @@
 
         Document document = builder.getDocument();
         if (document == null) {
-            throw new ProcessingException("Could not build DOM for '"+
-                                          source.getURI()+"'");
+            throw new ProcessingException("Could not build DOM for '" +
+                                          source.getURI() + "'");
         }
 
         return document;
@@ -263,8 +264,8 @@
 
         Document document = builder.getDocument();
         if (document == null) {
-            throw new ProcessingException("Could not build DOM for '"+
-                                          source.getURI()+"'");
+            throw new ProcessingException("Could not build DOM for '" +
+                                          source.getURI() + "'");
         }
 
         return document;
@@ -288,8 +289,8 @@
 
         Document document = builder.getDocument();
         if (document == null) {
-            throw new ProcessingException("Could not build DOM for '"+
-                                          source.getURI()+"'");
+            throw new ProcessingException("Could not build DOM for '" +
+                                          source.getURI() + "'");
         }
 
         return document;
@@ -338,14 +339,15 @@
     throws ProcessingException, IOException, SAXException {
         final Exception cause = e.getException();
         if (cause != null) {
+            // Unwrap ProcessingException, IOException, and extreme cases of SAXExceptions.
             if (cause instanceof ProcessingException) {
-                throw (ProcessingException)cause;
+                throw (ProcessingException) cause;
             }
             if (cause instanceof IOException) {
-                throw (IOException)cause;
+                throw (IOException) cause;
             }
             if (cause instanceof SAXException) {
-                throw (SAXException)cause;
+                throw (SAXException) cause;
             }
             throw new ProcessingException("Could not read resource " +
                                           source, cause);
@@ -473,7 +475,7 @@
     }
 
     /**
-     * Write a DOM Fragment to a source
+     * Write a DOM Fragment to a source.
      * If the source is a ModifiableSource the interface is used.
      * If not, the source is invoked with an additional parameter named
      * "content" containing the XML.
@@ -597,12 +599,12 @@
                                               parameters, resolver);
                 SourceUtil.toSAX(source, new DefaultHandler());
             }
-        } catch (SourceException se) {
-            throw SourceUtil.handle(se);
-        } catch (IOException ce) {
-            throw new ProcessingException(ce);
-        } catch (SAXException ce) {
-            throw new ProcessingException(ce);
+        } catch (SourceException e) {
+            throw SourceUtil.handle(e);
+        } catch (IOException e) {
+            throw new ProcessingException(e);
+        } catch (SAXException e) {
+            throw new ProcessingException(e);
         } finally {
             resolver.release(source);
         }
@@ -612,15 +614,15 @@
      * Read a DOM Fragment from a source
      *
      * @param location URI of the Source
-     * @param typeParameters Type of Source query.  Currently, only
-     * <code>method</code> parameter (value typically <code>GET</code> or
-     * <code>POST</code>) is recognized.  May be <code>null</code>.
+     * @param typeParameters Type of Source query. Currently, only
+     *        <code>method</code> parameter (value typically <code>GET</code> or
+     *        <code>POST</code>) is recognized. May be <code>null</code>.
      * @param parameters Parameters (e.g. URL params) of the source.
-     * May be <code>null</code>
+     *        May be <code>null</code>
      * @param resolver Resolver for the source.
      *
      * @return DOM <code>DocumentFragment</code> constructed from the specified
-     * Source
+     *         source.
      *
      * @throws ProcessingException
      */
@@ -631,22 +633,21 @@
     throws ProcessingException {
 
         Source source = null;
-
         try {
             source = SourceUtil.getSource(location, typeParameters,
                                           parameters, resolver);
             Document doc = SourceUtil.toDOM(source);
-            DocumentFragment fragment = doc.createDocumentFragment();
 
+            DocumentFragment fragment = doc.createDocumentFragment();
             fragment.appendChild(doc.getDocumentElement());
 
             return fragment;
-        } catch (SourceException se) {
-            throw SourceUtil.handle(se);
-        } catch (IOException ce) {
-            throw new ProcessingException(ce);
-        } catch (SAXException ce) {
-            throw new ProcessingException(ce);
+        } catch (SourceException e) {
+            throw SourceUtil.handle(e);
+        } catch (IOException e) {
+            throw new ProcessingException(e);
+        } catch (SAXException e) {
+            throw new ProcessingException(e);
         } finally {
             resolver.release(source);
         }
@@ -664,11 +665,10 @@
      */
     public static String getScheme(String uri) {
         RE re = new RE(uripattern);
-
         if (re.match(uri)) {
             return re.getParen(2);
         } else {
-            throw new IllegalArgumentException("'"+uri+
+            throw new IllegalArgumentException("'" + uri +
                                                "' is not a correct URI");
         }
     }
@@ -685,11 +685,10 @@
      */
     public static String getAuthority(String uri) {
         RE re = new RE(uripattern);
-
         if (re.match(uri)) {
             return re.getParen(4);
         } else {
-            throw new IllegalArgumentException("'"+uri+
+            throw new IllegalArgumentException("'" + uri +
                                                "' is not a correct URI");
         }
     }
@@ -706,11 +705,10 @@
      */
     public static String getPath(String uri) {
         RE re = new RE(uripattern);
-
         if (re.match(uri)) {
             return re.getParen(5);
         } else {
-            throw new IllegalArgumentException("'"+uri+
+            throw new IllegalArgumentException("'" + uri +
                                                "' is not a correct URI");
         }
     }
@@ -725,11 +723,10 @@
      */
     public static String getPathWithoutAuthority(String uri) {
         RE re = new RE(uripattern);
-
         if (re.match(uri)) {
-            return re.getParen(4)+re.getParen(5);
+            return re.getParen(4) + re.getParen(5);
         } else {
-            throw new IllegalArgumentException("'"+uri+
+            throw new IllegalArgumentException("'" + uri +
                                                "' is not a correct URI");
         }
     }
@@ -745,11 +742,10 @@
      */
     public static String getQuery(String uri) {
         RE re = new RE(uripattern);
-
         if (re.match(uri)) {
             return re.getParen(7);
         } else {
-            throw new IllegalArgumentException("'"+uri+
+            throw new IllegalArgumentException("'" + uri +
                                                "' is not a correct URI");
         }
     }
@@ -768,11 +764,10 @@
      */
     public static String getFragment(String uri) {
         RE re = new RE(uripattern);
-
         if (re.match(uri)) {
             return re.getParen(9);
         } else {
-            throw new IllegalArgumentException("'"+uri+
+            throw new IllegalArgumentException("'" + uri +
                                                "' is not a correct URI");
         }
     }