roller-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agillil...@apache.org
Subject svn commit: r428913 - in /incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering: Renderer.java RendererManager.java RenderingException.java velocity/VelocityRenderer.java
Date Fri, 04 Aug 2006 22:36:37 GMT
Author: agilliland
Date: Fri Aug  4 15:36:36 2006
New Revision: 428913

URL: http://svn.apache.org/viewvc?rev=428913&view=rev
Log:
quick tweak to support better exception handling.  rendering system classes throw RenderingExceptions,
not just generic Exceptions.


Added:
    incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/RenderingException.java
Modified:
    incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/Renderer.java
    incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/RendererManager.java
    incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/velocity/VelocityRenderer.java

Modified: incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/Renderer.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/Renderer.java?rev=428913&r1=428912&r2=428913&view=diff
==============================================================================
--- incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/Renderer.java
(original)
+++ incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/Renderer.java
Fri Aug  4 15:36:36 2006
@@ -34,6 +34,6 @@
      *
      * Throws an exception if there is a problem during rendering.
      */
-    public void render(Map model, Writer writer) throws Exception;
+    public void render(Map model, Writer writer) throws RenderingException;
     
 }

Modified: incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/RendererManager.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/RendererManager.java?rev=428913&r1=428912&r2=428913&view=diff
==============================================================================
--- incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/RendererManager.java
(original)
+++ incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/RendererManager.java
Fri Aug  4 15:36:36 2006
@@ -107,7 +107,8 @@
      * instance and tries to find a Renderer for the content.  If no Renderer
      * can be found then we throw an exception.
      */
-    public static Renderer getRenderer(Template template) throws Exception {
+    public static Renderer getRenderer(Template template) 
+            throws RenderingException {
         
         Renderer renderer = null;
         
@@ -122,7 +123,8 @@
             }
         }
         
-        throw new Exception("No renderer found!");
+        throw new RenderingException("No renderer found for template "+
+                template.getId()+"!");
     }
     
 }

Added: incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/RenderingException.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/RenderingException.java?rev=428913&view=auto
==============================================================================
--- incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/RenderingException.java
(added)
+++ incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/RenderingException.java
Fri Aug  4 15:36:36 2006
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+
+package org.apache.roller.ui.rendering;
+
+import org.apache.roller.RollerException;
+
+
+/**
+ * A generic Roller rendering exception.
+ */
+public class RenderingException extends RollerException {
+    
+    public RenderingException(String s) {
+        super(s);
+    }
+    
+    public RenderingException(String s, Throwable t) {
+        super(s, t);
+    }
+    
+    public RenderingException(Throwable t) {
+        super(t);
+    }
+    
+}

Modified: incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/velocity/VelocityRenderer.java
URL: http://svn.apache.org/viewvc/incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/velocity/VelocityRenderer.java?rev=428913&r1=428912&r2=428913&view=diff
==============================================================================
--- incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/velocity/VelocityRenderer.java
(original)
+++ incubator/roller/branches/roller_3.0/src/org/apache/roller/ui/rendering/velocity/VelocityRenderer.java
Fri Aug  4 15:36:36 2006
@@ -25,10 +25,13 @@
 import org.apache.commons.logging.LogFactory;
 import org.apache.roller.pojos.Template;
 import org.apache.roller.ui.rendering.Renderer;
+import org.apache.roller.ui.rendering.RenderingException;
 import org.apache.roller.ui.rendering.model.UtilitiesModel;
 import org.apache.velocity.VelocityContext;
 import org.apache.velocity.context.Context;
+import org.apache.velocity.exception.MethodInvocationException;
 import org.apache.velocity.exception.ParseErrorException;
+import org.apache.velocity.exception.ResourceNotFoundException;
 
 
 /**
@@ -76,56 +79,62 @@
     }
     
     
-    public void render(Map model, Writer out) throws Exception {
+    public void render(Map model, Writer out) throws RenderingException {
         
-        if(parseException != null) {
-            
-            Context ctx = new VelocityContext(model);
-            ctx.put("exception", parseException);
-            ctx.put("exceptionSource", renderTemplate.getId());
-            ctx.put("utils", new UtilitiesModel());
-            
-            // render output to Writer
-            velocityTemplate.merge(ctx, out);
-            
-            // and we're done
-            return;
-        }
-        
-        long startTime = System.currentTimeMillis();
-        
-        // convert model to Velocity Context
-        Context ctx = new VelocityContext(model);
-        
-        if(velocityDecorator != null) {
-            
-            /**
-             * We only allow decorating once, so the process isn't
-             * fully recursive.  This is just to keep it simple.
-             */
+        try {
+            if(parseException != null) {
+                
+                Context ctx = new VelocityContext(model);
+                ctx.put("exception", parseException);
+                ctx.put("exceptionSource", renderTemplate.getId());
+                ctx.put("utils", new UtilitiesModel());
+                
+                // render output to Writer
+                velocityTemplate.merge(ctx, out);
+                
+                // and we're done
+                return;
+            }
             
-            // render base template to a temporary StringWriter
-            StringWriter sw = new StringWriter();
-            velocityTemplate.merge(ctx, sw);
+            long startTime = System.currentTimeMillis();
             
-            // put rendered template into context
-            ctx.put("decorator_body", sw.toString());
+            // convert model to Velocity Context
+            Context ctx = new VelocityContext(model);
             
-            log.debug("Applying decorator "+velocityDecorator.getName());
+            if(velocityDecorator != null) {
+                
+                /**
+                 * We only allow decorating once, so the process isn't
+                 * fully recursive.  This is just to keep it simple.
+                 */
+                
+                // render base template to a temporary StringWriter
+                StringWriter sw = new StringWriter();
+                velocityTemplate.merge(ctx, sw);
+                
+                // put rendered template into context
+                ctx.put("decorator_body", sw.toString());
+                
+                log.debug("Applying decorator "+velocityDecorator.getName());
+                
+                // now render decorator to our output writer
+                velocityDecorator.merge(ctx, out);
+                
+            } else {
+                
+                // no decorator, so just merge template to our output writer
+                velocityTemplate.merge(ctx, out);
+            }
             
-            // now render decorator to our output writer
-            velocityDecorator.merge(ctx, out);
+            long endTime = System.currentTimeMillis();
+            long renderTime = (endTime - startTime)/1000;
             
-        } else {
+            log.debug("Rendered ["+renderTemplate.getId()+"] in "+renderTime+" secs");
             
-            // no decorator, so just merge template to our output writer
-            velocityTemplate.merge(ctx, out);
+        } catch (Exception ex) {
+            // wrap and rethrow so caller can deal with it
+            throw new RenderingException("Error during rendering", ex);
         }
-        
-        long endTime = System.currentTimeMillis();
-        long renderTime = (endTime - startTime)/1000;
-        
-        log.debug("Rendered ["+renderTemplate.getId()+"] in "+renderTime+" secs");
     }
 
 }



Mime
View raw message