cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From reinh...@apache.org
Subject svn commit: r882875 - in /cocoon/cocoon3/trunk/cocoon-sitemap/src/main/java/org/apache/cocoon/sitemap: SitemapBuilder.java xml/
Date Sat, 21 Nov 2009 10:30:15 GMT
Author: reinhard
Date: Sat Nov 21 10:30:15 2009
New Revision: 882875

URL: http://svn.apache.org/viewvc?rev=882875&view=rev
Log:
The SitemapBuilder throws a custom unchecked exception when the build of the sitemap fails
(usually this means it is not recoverable)

Removed:
    cocoon/cocoon3/trunk/cocoon-sitemap/src/main/java/org/apache/cocoon/sitemap/xml/
Modified:
    cocoon/cocoon3/trunk/cocoon-sitemap/src/main/java/org/apache/cocoon/sitemap/SitemapBuilder.java

Modified: cocoon/cocoon3/trunk/cocoon-sitemap/src/main/java/org/apache/cocoon/sitemap/SitemapBuilder.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-sitemap/src/main/java/org/apache/cocoon/sitemap/SitemapBuilder.java?rev=882875&r1=882874&r2=882875&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-sitemap/src/main/java/org/apache/cocoon/sitemap/SitemapBuilder.java
(original)
+++ cocoon/cocoon3/trunk/cocoon-sitemap/src/main/java/org/apache/cocoon/sitemap/SitemapBuilder.java
Sat Nov 21 10:30:15 2009
@@ -37,17 +37,25 @@
 
     private SitemapNodeFactory sitemapNodeFactory;
 
-    public SitemapNode build(URL sitemap) throws Exception {
+    public SitemapNode build(URL sitemap) {
+        if (sitemap == null) {
+            throw new NullPointerException("A valid sitemap URL has to be passed.");
+        }
+
         SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
         saxParserFactory.setNamespaceAware(true);
         // saxParserFactory.setSchema(SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema").newSchema());
 
-        SAXParser saxParser = saxParserFactory.newSAXParser();
-
-        InputStream inputStream = sitemap.openStream();
         SitemapHandler sitemapHandler = new SitemapHandler();
-        saxParser.parse(inputStream, sitemapHandler);
-        inputStream.close();
+        try {
+            SAXParser saxParser = saxParserFactory.newSAXParser();
+
+            InputStream inputStream = sitemap.openStream();
+            saxParser.parse(inputStream, sitemapHandler);
+            inputStream.close();
+        } catch (Exception e) {
+            throw new SitemapBuilderException("Can't build sitemap.", e);
+        }
 
         return sitemapHandler.getSitemap();
     }
@@ -60,7 +68,16 @@
         return SitemapBuilder.this.sitemapNodeFactory.createNode(localName, parameters);
     }
 
-    class SitemapHandler extends DefaultHandler {
+    private static class SitemapBuilderException extends RuntimeException {
+
+        private static final long serialVersionUID = 1L;
+
+        public SitemapBuilderException(String msg, Throwable t) {
+            super(msg, t);
+        }
+    }
+
+    private class SitemapHandler extends DefaultHandler {
 
         private SitemapNode currentNode;
         private SitemapNode sitemap;



Mime
View raw message