click-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From med...@apache.org
Subject svn commit: r919296 - in /click/trunk/click: documentation/docs/ examples/src/org/apache/click/examples/page/general/ extras/src/org/apache/click/extras/service/ framework/src/org/apache/click/ framework/src/org/apache/click/service/ framework/src/org/...
Date Fri, 05 Mar 2010 05:31:18 GMT
Author: medgar
Date: Fri Mar  5 05:31:18 2010
New Revision: 919296

URL: http://svn.apache.org/viewvc?rev=919296&view=rev
Log:
CLK-606

Added:
    click/trunk/click/framework/src/org/apache/click/service/TemplateException.java
Modified:
    click/trunk/click/documentation/docs/roadmap-changes.html
    click/trunk/click/examples/src/org/apache/click/examples/page/general/ExceptionPage.java
    click/trunk/click/extras/src/org/apache/click/extras/service/FreemarkerTemplateService.java
    click/trunk/click/framework/src/org/apache/click/ClickServlet.java
    click/trunk/click/framework/src/org/apache/click/service/TemplateService.java
    click/trunk/click/framework/src/org/apache/click/service/VelocityTemplateService.java
    click/trunk/click/framework/src/org/apache/click/util/ErrorReport.java

Modified: click/trunk/click/documentation/docs/roadmap-changes.html
URL: http://svn.apache.org/viewvc/click/trunk/click/documentation/docs/roadmap-changes.html?rev=919296&r1=919295&r2=919296&view=diff
==============================================================================
--- click/trunk/click/documentation/docs/roadmap-changes.html (original)
+++ click/trunk/click/documentation/docs/roadmap-changes.html Fri Mar  5 05:31:18 2010
@@ -67,9 +67,8 @@
 
 <h2>Road Map</h2>
 New Click releases will be released every quarter with the next version Click 2.2.0
-scheduled for the end of March 2010. Tentative features for the next release
-includes improved Ajax support, @Bindable support for Page getters/setters and
-an improved Menu control.
+scheduled for the end of April 2010. Tentative features for the next release
+includes improved Ajax support and @Bindable support for Page getters/setters.
 
 <p>&nbsp;</p>
 
@@ -77,7 +76,7 @@
 
 <dl>
   <dt><a name="2.2.0"></a>
-    <div class="release-header">Development Release - Version 2.2.0 M1 - ?? March 2010</div>
+    <div class="release-header">Development Release - Version 2.2.0 RC1 - 31 March
2010</div>
   </dt>
   <dd>
     <div style="margin-left:-2em;margin-bottom:1em;">
@@ -89,7 +88,13 @@
     </div>
     <ul style="padding: 0em; margin-left:0em;margin-bottom: 2em">
       <li class="change">
-          [<a target="_blank" href="https://issues.apache.org/jira/browse/CLK-???">???</a>].
+        Removed Click cores dependency on Velocity. This issue was raised by by Andrey Rybin
+        [<a target="_blank" href="https://issues.apache.org/jira/browse/CLK-CLK-606">CLK-606</a>].
+      </li>
+    </ul>
+    <ul style="padding: 0em; margin-left:0em;margin-bottom: 2em">
+      <li class="change">
+        [<a target="_blank" href="https://issues.apache.org/jira/browse/CLK-???">???</a>].
       </li>
     </ul>
   </dd>

Modified: click/trunk/click/examples/src/org/apache/click/examples/page/general/ExceptionPage.java
URL: http://svn.apache.org/viewvc/click/trunk/click/examples/src/org/apache/click/examples/page/general/ExceptionPage.java?rev=919296&r1=919295&r2=919296&view=diff
==============================================================================
--- click/trunk/click/examples/src/org/apache/click/examples/page/general/ExceptionPage.java
(original)
+++ click/trunk/click/examples/src/org/apache/click/examples/page/general/ExceptionPage.java
Fri Mar  5 05:31:18 2010
@@ -25,8 +25,6 @@
 
 /**
  * Provides examples of the Click Exception handling.
- *
- * @author Malcolm Edgar
  */
 public class ExceptionPage extends BorderPage {
 
@@ -58,12 +56,12 @@
 
     public boolean onBrokenBorderClick() {
         setPath("broken-border.htm");
-        template = "broken-border.htm";
+        template = "/general/broken-border.htm";
         return true;
     }
 
     public boolean onBrokenContentClick() {
-        setPath("broken-content.htm");
+        setPath("/general/broken-content.htm");
         return true;
     }
 

Modified: click/trunk/click/extras/src/org/apache/click/extras/service/FreemarkerTemplateService.java
URL: http://svn.apache.org/viewvc/click/trunk/click/extras/src/org/apache/click/extras/service/FreemarkerTemplateService.java?rev=919296&r1=919295&r2=919296&view=diff
==============================================================================
--- click/trunk/click/extras/src/org/apache/click/extras/service/FreemarkerTemplateService.java
(original)
+++ click/trunk/click/extras/src/org/apache/click/extras/service/FreemarkerTemplateService.java
Fri Mar  5 05:31:18 2010
@@ -27,6 +27,7 @@
 import org.apache.click.Page;
 import org.apache.click.service.ConfigService;
 import org.apache.click.service.LogService;
+import org.apache.click.service.TemplateException;
 import org.apache.click.service.TemplateService;
 import org.apache.click.util.ClickUtils;
 import org.apache.commons.lang.Validate;
@@ -238,10 +239,11 @@
      * @param page the page template to render
      * @param model the model to merge with the template and render
      * @param writer the writer to send the merged template and model data to
-     * @throws Exception if an error occurs
+     * @throws IOException if an IO error occurs
+     * @throws TemplateException if template error occurs
      */
-    public void renderTemplate(Page page, Map model, Writer writer)
-            throws Exception {
+    public void renderTemplate(Page page, Map<String, Object> model, Writer writer)
+        throws IOException, TemplateException {
 
         String templatePath = page.getTemplate();
 
@@ -256,7 +258,12 @@
         Template template = configuration.getTemplate(templatePath);
 
         // Merge the data-model and the template
-        template.process(model, writer);
+        try {
+            template.process(model, writer);
+
+        } catch (freemarker.template.TemplateException fmte) {
+            throw new TemplateException(fmte);
+        }
     }
 
     /**
@@ -265,16 +272,22 @@
      * @param templatePath the path of the template to render
      * @param model the model to merge with the template and render
      * @param writer the writer to send the merged template and model data to
-     * @throws Exception if an error occurs
+     * @throws IOException if an IO error occurs
+     * @throws TemplateException if template error occurs
      */
-    public void renderTemplate(String templatePath, Map model, Writer writer)
-            throws Exception {
+    public void renderTemplate(String templatePath, Map<String, Object> model, Writer
writer)
+            throws IOException, TemplateException {
 
         // Get the template object
         Template template = configuration.getTemplate(templatePath);
 
         // Merge the data-model and the template
-        template.process(model, writer);
+        try {
+            template.process(model, writer);
+
+        } catch (freemarker.template.TemplateException fmte) {
+            throw new TemplateException(fmte);
+        }
     }
 
     /**

Modified: click/trunk/click/framework/src/org/apache/click/ClickServlet.java
URL: http://svn.apache.org/viewvc/click/trunk/click/framework/src/org/apache/click/ClickServlet.java?rev=919296&r1=919295&r2=919296&view=diff
==============================================================================
--- click/trunk/click/framework/src/org/apache/click/ClickServlet.java (original)
+++ click/trunk/click/framework/src/org/apache/click/ClickServlet.java Fri Mar  5 05:31:18
2010
@@ -47,6 +47,7 @@
 import org.apache.click.service.ConfigService;
 import org.apache.click.service.LogService;
 import org.apache.click.service.ResourceService;
+import org.apache.click.service.TemplateException;
 import org.apache.click.service.XmlConfigService;
 import org.apache.click.service.ConfigService.AutoBinding;
 import org.apache.click.util.ClickUtils;
@@ -58,7 +59,6 @@
 import org.apache.commons.fileupload.servlet.ServletFileUpload;
 import org.apache.commons.lang.ClassUtils;
 import org.apache.commons.lang.StringUtils;
-import org.apache.velocity.exception.ParseErrorException;
 
 /**
  * Provides the Click application HttpServlet.
@@ -443,7 +443,7 @@
         HttpServletResponse response, boolean isPost, Throwable exception,
         Class pageClass) {
 
-        if (exception instanceof ParseErrorException == false) {
+        if (exception instanceof TemplateException == false) {
             logger.error("handleException: ", exception);
         }
 

Added: click/trunk/click/framework/src/org/apache/click/service/TemplateException.java
URL: http://svn.apache.org/viewvc/click/trunk/click/framework/src/org/apache/click/service/TemplateException.java?rev=919296&view=auto
==============================================================================
--- click/trunk/click/framework/src/org/apache/click/service/TemplateException.java (added)
+++ click/trunk/click/framework/src/org/apache/click/service/TemplateException.java Fri Mar
 5 05:31:18 2010
@@ -0,0 +1,124 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  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.
+ */
+package org.apache.click.service;
+
+/**
+ * Provides a template exception class for use by the template service. This is
+ * used to wrap TemplateService exceptions.
+ */
+public class TemplateException extends Exception {
+
+    private static final long serialVersionUID = 1L;
+
+    /** The template column number where this exception occurred. */
+    private int columnNumber;
+
+    /** The template the line number where this exception occurred. */
+    private int lineNumber;
+
+    /** The Template name where this exception occurred. */
+    private String templateName;
+
+    // Constructors -----------------------------------------------------------
+
+    /**
+     * Create a template service exception with the given cause.
+     *
+     * @param cause the underlying cause of the template service error
+     */
+    public TemplateException(Exception cause) {
+        super(cause);
+    }
+
+    /**
+     * Create a template service exception with the given cause, template name,
+     * line number and column number.
+     *
+     * @param cause the underlying cause of the template service error
+     * @param templateName the name of the template which cause the error
+     * @param lineNumber the template error line number
+     * @param columnNumber the template error column number
+     */
+    public TemplateException(Exception cause, String templateName,
+            int lineNumber, int columnNumber) {
+
+        super(cause);
+
+        this.templateName = templateName;
+        this.lineNumber = lineNumber;
+        this.columnNumber = columnNumber;
+    }
+
+    // Public Methods ------------------------------------------------------
+
+    /**
+     * Return the template column number where this exception occurred.
+     *
+     * @return the template column number where this exception occurred
+     */
+    public int getColumnNumber() {
+        return columnNumber;
+    }
+
+    /**
+     * Return the template the line number where this exception occurred.
+     *
+     * @return the template the line number where this exception occurred
+     */
+    public int getLineNumber() {
+        return lineNumber;
+    }
+
+    /**
+     * Return the Template name where this exception occurred.
+     *
+     * @return the Template name where this exception occurred
+     */
+    public String getTemplateName() {
+        return templateName;
+    }
+
+    /**
+     * @see Object#toString()
+     *
+     * @return the string representation of this error
+     */
+    @Override
+    public String toString() {
+        StringBuilder builder = new StringBuilder();
+        builder.append(getClass().getName());
+        builder.append(": ");
+        if (getLocalizedMessage() != null) {
+            builder.append(getLocalizedMessage());
+        }
+
+        if (getTemplateName() != null) {
+            builder.append(" [templateName=");
+            builder.append(getTemplateName());
+            builder.append(",lineNumber=");
+            builder.append(getLineNumber());
+            builder.append(",columnNumber=");
+            builder.append(getColumnNumber());
+            builder.append("]");
+        }
+
+        return builder.toString();
+    }
+
+}

Modified: click/trunk/click/framework/src/org/apache/click/service/TemplateService.java
URL: http://svn.apache.org/viewvc/click/trunk/click/framework/src/org/apache/click/service/TemplateService.java?rev=919296&r1=919295&r2=919296&view=diff
==============================================================================
--- click/trunk/click/framework/src/org/apache/click/service/TemplateService.java (original)
+++ click/trunk/click/framework/src/org/apache/click/service/TemplateService.java Fri Mar
 5 05:31:18 2010
@@ -18,6 +18,7 @@
  */
 package org.apache.click.service;
 
+import java.io.IOException;
 import java.io.Writer;
 import java.util.Map;
 
@@ -71,9 +72,11 @@
      * @param page the page template to render
      * @param model the model to merge with the template and render
      * @param writer the writer to send the merged template and model data to
-     * @throws Exception if an error occurs
+     * @throws IOException if an IO error occurs
+     * @throws TemplateException if template error occurs
      */
-    public void renderTemplate(Page page, Map<String, Object> model, Writer writer)
throws Exception;
+    public void renderTemplate(Page page, Map<String, Object> model, Writer writer)
+        throws IOException, TemplateException;
 
     /**
      * Render the given template and model to the writer.
@@ -81,8 +84,10 @@
      * @param templatePath the path of the template to render
      * @param model the model to merge with the template and render
      * @param writer the writer to send the merged template and model data to
-     * @throws Exception if an error occurs
+     * @throws IOException if an IO error occurs
+     * @throws TemplateException if template error occurs
      */
-    public void renderTemplate(String templatePath, Map<String, Object> model, Writer
writer) throws Exception;
+    public void renderTemplate(String templatePath, Map<String, Object> model, Writer
writer)
+        throws IOException, TemplateException;
 
 }

Modified: click/trunk/click/framework/src/org/apache/click/service/VelocityTemplateService.java
URL: http://svn.apache.org/viewvc/click/trunk/click/framework/src/org/apache/click/service/VelocityTemplateService.java?rev=919296&r1=919295&r2=919296&view=diff
==============================================================================
--- click/trunk/click/framework/src/org/apache/click/service/VelocityTemplateService.java
(original)
+++ click/trunk/click/framework/src/org/apache/click/service/VelocityTemplateService.java
Fri Mar  5 05:31:18 2010
@@ -30,7 +30,6 @@
 
 import javax.servlet.ServletContext;
 
-import org.apache.click.Context;
 import org.apache.click.Page;
 import org.apache.click.util.ClickUtils;
 import org.apache.click.util.ErrorReport;
@@ -38,11 +37,14 @@
 import org.apache.velocity.Template;
 import org.apache.velocity.VelocityContext;
 import org.apache.velocity.app.VelocityEngine;
+import org.apache.velocity.exception.ParseErrorException;
 import org.apache.velocity.exception.ResourceNotFoundException;
+import org.apache.velocity.exception.TemplateInitException;
 import org.apache.velocity.io.VelocityWriter;
 import org.apache.velocity.runtime.RuntimeConstants;
 import org.apache.velocity.runtime.RuntimeServices;
 import org.apache.velocity.runtime.log.LogChute;
+import org.apache.velocity.runtime.parser.TemplateParseException;
 import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader;
 import org.apache.velocity.tools.view.servlet.WebappLoader;
 import org.apache.velocity.util.SimplePool;
@@ -242,7 +244,7 @@
      * @see TemplateService#onInit(ServletContext)
      *
      * @param servletContext the application servlet velocityContext
-     * @throws Exception if an error occurs initializing the Template Service
+     * @throws TemplateException if an error occurs initializing the Template Service
      */
     public void onInit(ServletContext servletContext) throws Exception {
 
@@ -309,11 +311,11 @@
      * @param page the page template to render
      * @param model the model to merge with the template and render
      * @param writer the writer to send the merged template and model data to
-     * @throws Exception if an error occurs
+     * @throws IOException if an IO error occurs
+     * @throws TemplateException if template error occurs
      */
-    public void renderTemplate(Page page, Map<String, Object> model, Writer writer)
throws Exception {
-
-        final VelocityContext context = new VelocityContext(model);
+    public void renderTemplate(Page page, Map<String, Object> model, Writer writer)
+        throws IOException, TemplateException {
 
         String templatePath = page.getTemplate();
 
@@ -324,69 +326,7 @@
             templatePath = "META-INF/resources" + NOT_FOUND_PAGE_PATH;
         }
 
-        // May throw parsing error if template could not be obtained
-        Template template = null;
-        String charset = configService.getCharset();
-        if (charset != null) {
-            template = velocityEngine.getTemplate(templatePath, charset);
-
-        } else {
-            template = velocityEngine.getTemplate(templatePath);
-        }
-
-        VelocityWriter velocityWriter = null;
-
-        try {
-            velocityWriter = (VelocityWriter) writerPool.get();
-
-            if (velocityWriter == null) {
-                velocityWriter =
-                    new VelocityWriter(writer, WRITER_BUFFER_SIZE, true);
-
-            } else {
-                velocityWriter.recycle(writer);
-            }
-
-            template.merge(context, velocityWriter);
-
-        } catch (Exception error) {
-            // Exception occurred merging template and model. It is possible
-            // that some output has already been written, so we will append the
-            // error report to the previous output.
-            ErrorReport errorReport =
-                new ErrorReport(error,
-                                page.getClass(),
-                                configService.isProductionMode(),
-                                page.getContext().getRequest(),
-                                configService.getServletContext());
-
-            if (velocityWriter == null) {
-
-                velocityWriter =
-                    new VelocityWriter(writer, WRITER_BUFFER_SIZE, true);
-            }
-
-            velocityWriter.write(errorReport.toString());
-
-            throw error;
-
-        } finally {
-            if (velocityWriter != null) {
-                // flush and put back into the pool don't close to allow
-                // us to play nicely with others.
-                velocityWriter.flush();
-
-                // Clear the VelocityWriter's reference to its
-                // internal Writer to allow the latter
-                // to be GC'd while vw is pooled.
-                velocityWriter.recycle(null);
-
-                writerPool.put(velocityWriter);
-            }
-
-            writer.flush();
-            writer.close();
-        }
+        internalRenderTemplate(templatePath, page, model, writer);
     }
 
     /**
@@ -397,76 +337,13 @@
      * @param writer the writer to send the merged template and model data to
      * @throws Exception if an error occurs
      */
-    public void renderTemplate(String templatePath, Map<String, Object> model, Writer
writer) throws Exception {
-
-        final VelocityContext velocityContext = new VelocityContext(model);
-
-        // May throw parsing error if template could not be obtained
-        Template template = null;
-        String charset = configService.getCharset();
-        if (charset != null) {
-            template = velocityEngine.getTemplate(templatePath, charset);
-
-        } else {
-            template = velocityEngine.getTemplate(templatePath);
-        }
-
-        VelocityWriter velocityWriter = null;
-
-        try {
-            velocityWriter = (VelocityWriter) writerPool.get();
-
-            if (velocityWriter == null) {
-                velocityWriter =
-                    new VelocityWriter(writer, WRITER_BUFFER_SIZE, true);
-
-            } else {
-                velocityWriter.recycle(writer);
-            }
-
-            template.merge(velocityContext, velocityWriter);
-
-        } catch (Exception error) {
-            // Exception occurred merging template and model. It is possible
-            // that some output has already been written, so we will append the
-            // error report to the previous output.
-            ErrorReport errorReport =
-                new ErrorReport(error,
-                                null,
-                                configService.isProductionMode(),
-                                Context.getThreadLocalContext().getRequest(),
-                                configService.getServletContext());
-
-            if (velocityWriter == null) {
+    public void renderTemplate(String templatePath, Map<String, Object> model, Writer
writer)
+        throws IOException, TemplateException {
 
-                velocityWriter =
-                    new VelocityWriter(writer, WRITER_BUFFER_SIZE, true);
-            }
-
-            velocityWriter.write(errorReport.toString());
-
-            throw error;
-
-        } finally {
-            if (velocityWriter != null) {
-                // flush and put back into the pool don't close to allow
-                // us to play nicely with others.
-                velocityWriter.flush();
-
-                // Clear the VelocityWriter's reference to its
-                // internal Writer to allow the latter
-                // to be GC'd while vw is pooled.
-                velocityWriter.recycle(null);
-
-                writerPool.put(velocityWriter);
-            }
-
-            writer.flush();
-            writer.close();
-        }
+        internalRenderTemplate(templatePath, null, model, writer);
     }
 
-    // ------------------------------------------------------ Protected Methods
+    // Protected Methods ------------------------------------------------------
 
     /**
      * Return the Velocity Engine initialization log level.
@@ -615,7 +492,170 @@
         return velProps;
     }
 
-    // ---------------------------------------------------------- Inner Classes
+    /**
+     * Provides the underlying Velocity template rendering.
+     *
+     * @param templatePath the template path to render
+     * @param page the page template to render
+     * @param model the model to merge with the template and render
+     * @param writer the writer to send the merged template and model data to
+     * @throws IOException if an IO error occurs
+     * @throws TemplateException if template error occurs
+     */
+    protected void internalRenderTemplate(String templatePath,
+                                          Page page,
+                                          Map<String, Object> model,
+                                          Writer writer)
+        throws IOException, TemplateException {
+
+        final VelocityContext velocityContext = new VelocityContext(model);
+
+        // May throw parsing error if template could not be obtained
+        Template template = null;
+        VelocityWriter velocityWriter = null;
+        try {
+            String charset = configService.getCharset();
+            if (charset != null) {
+                template = velocityEngine.getTemplate(templatePath, charset);
+
+            } else {
+                template = velocityEngine.getTemplate(templatePath);
+            }
+
+            velocityWriter = (VelocityWriter) writerPool.get();
+
+            if (velocityWriter == null) {
+                velocityWriter =
+                    new VelocityWriter(writer, WRITER_BUFFER_SIZE, true);
+
+            } else {
+                velocityWriter.recycle(writer);
+            }
+
+            template.merge(velocityContext, velocityWriter);
+
+        } catch (IOException ioe) {
+            throw ioe;
+
+        } catch (ParseErrorException pee) {
+            TemplateException te = new TemplateException(pee,
+                                                         pee.getTemplateName(),
+                                                         pee.getLineNumber(),
+                                                         pee.getColumnNumber());
+
+            // Exception occurred merging template and model. It is possible
+            // that some output has already been written, so we will append the
+            // error report to the previous output.
+            ErrorReport errorReport =
+                new ErrorReport(te,
+                                ((page != null) ? page.getClass() : null),
+                                configService.isProductionMode(),
+                                page.getContext().getRequest(),
+                                configService.getServletContext());
+
+
+            if (velocityWriter == null) {
+                velocityWriter =
+                    new VelocityWriter(writer, WRITER_BUFFER_SIZE, true);
+            }
+
+            velocityWriter.write(errorReport.toString());
+
+            throw te;
+
+        } catch (TemplateInitException tie) {
+            TemplateException te = new TemplateException(tie,
+                                                         tie.getTemplateName(),
+                                                         tie.getLineNumber(),
+                                                         tie.getColumnNumber());
+
+            // Exception occurred merging template and model. It is possible
+            // that some output has already been written, so we will append the
+            // error report to the previous output.
+            ErrorReport errorReport =
+                new ErrorReport(te,
+                                ((page != null) ? page.getClass() : null),
+                                configService.isProductionMode(),
+                                page.getContext().getRequest(),
+                                configService.getServletContext());
+
+
+            if (velocityWriter == null) {
+                velocityWriter =
+                    new VelocityWriter(writer, WRITER_BUFFER_SIZE, true);
+            }
+
+            velocityWriter.write(errorReport.toString());
+
+            throw te;
+
+        } catch (TemplateParseException tpe) {
+            TemplateException te = new TemplateException(tpe,
+                                                         tpe.getTemplateName(),
+                                                         tpe.getLineNumber(),
+                                                         tpe.getColumnNumber());
+
+            // Exception occurred merging template and model. It is possible
+            // that some output has already been written, so we will append the
+            // error report to the previous output.
+            ErrorReport errorReport =
+                new ErrorReport(te,
+                        ((page != null) ? page.getClass() : null),
+                        configService.isProductionMode(),
+                        page.getContext().getRequest(),
+                        configService.getServletContext());
+
+            if (velocityWriter == null) {
+                velocityWriter =
+                    new VelocityWriter(writer, WRITER_BUFFER_SIZE, true);
+            }
+
+            velocityWriter.write(errorReport.toString());
+
+            throw te;
+
+        } catch (Exception error) {
+            TemplateException te = new TemplateException(error);
+
+            // Exception occurred merging template and model. It is possible
+            // that some output has already been written, so we will append the
+            // error report to the previous output.
+            ErrorReport errorReport =
+                new ErrorReport(te,
+                        ((page != null) ? page.getClass() : null),
+                        configService.isProductionMode(),
+                        page.getContext().getRequest(),
+                        configService.getServletContext());
+
+            if (velocityWriter == null) {
+                velocityWriter =
+                    new VelocityWriter(writer, WRITER_BUFFER_SIZE, true);
+            }
+
+            velocityWriter.write(errorReport.toString());
+
+            throw te;
+
+        } finally {
+            if (velocityWriter != null) {
+                // flush and put back into the pool don't close to allow
+                // us to play nicely with others.
+                velocityWriter.flush();
+
+                // Clear the VelocityWriter's reference to its
+                // internal Writer to allow the latter
+                // to be GC'd while vw is pooled.
+                velocityWriter.recycle(null);
+
+                writerPool.put(velocityWriter);
+            }
+
+            writer.flush();
+            writer.close();
+        }
+    }
+
+    // Inner Classes ----------------------------------------------------------
 
     /**
      * Provides a Velocity <tt>LogChute</tt> adapter class around the application

Modified: click/trunk/click/framework/src/org/apache/click/util/ErrorReport.java
URL: http://svn.apache.org/viewvc/click/trunk/click/framework/src/org/apache/click/util/ErrorReport.java?rev=919296&r1=919295&r2=919296&view=diff
==============================================================================
--- click/trunk/click/framework/src/org/apache/click/util/ErrorReport.java (original)
+++ click/trunk/click/framework/src/org/apache/click/util/ErrorReport.java Fri Mar  5 05:31:18
2010
@@ -40,6 +40,8 @@
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpSession;
 
+import org.apache.click.Page;
+import org.apache.click.service.TemplateException;
 import org.apache.commons.lang.StringUtils;
 import org.apache.velocity.exception.ParseErrorException;
 
@@ -75,7 +77,7 @@
     protected final boolean isProductionMode;
 
     /** The page class which caused the error. */
-    protected final Class pageClass;
+    protected final Class<? extends Page> pageClass;
 
     /** The servlet request. */
     protected final HttpServletRequest request;
@@ -89,7 +91,7 @@
     /** The error source LineNumberReader. */
     protected LineNumberReader sourceReader;
 
-    // ------------------------------------------------------------ Constructor
+    // Constructor ------------------------------------------------------------
 
     /**
      * Create a ErrorReport instance from the given error and page.
@@ -100,7 +102,7 @@
      * @param request the page request
      * @param servletContext the servlet context
      */
-    public ErrorReport(Throwable error, Class pageClass,
+    public ErrorReport(Throwable error, Class<? extends Page> pageClass,
             boolean isProductionMode, HttpServletRequest request,
             ServletContext servletContext) {
 
@@ -112,20 +114,25 @@
 
         isParseError = error instanceof ParseErrorException;
 
-        if (error instanceof ParseErrorException) {
-            ParseErrorException pee = (ParseErrorException) error;
-            if (pee.getTemplateName().charAt(0) == '/') {
-                sourceName = pee.getTemplateName();
-            } else {
-                sourceName =  '/' + pee.getTemplateName();
-            }
-            lineNumber = pee.getLineNumber();
-            columnNumber = pee.getColumnNumber();
+        if (error instanceof TemplateException) {
+            TemplateException te = (TemplateException) error;
+            if (te.getTemplateName() != null) {
+                if (te.getTemplateName().charAt(0) == '/') {
+                    sourceName = te.getTemplateName();
+                } else {
+                    sourceName =  '/' + te.getTemplateName();
+                }
+                lineNumber = te.getLineNumber();
+                columnNumber = te.getColumnNumber();
 
-            InputStream is =
-                servletContext.getResourceAsStream(sourceName);
+                InputStream is =
+                    servletContext.getResourceAsStream(sourceName);
 
-            sourceReader = new LineNumberReader(new InputStreamReader(is));
+                sourceReader = new LineNumberReader(new InputStreamReader(is));
+
+            } else {
+                sourceName = null;
+            }
 
         } else {
             sourceName = null;
@@ -179,7 +186,7 @@
         }
     }
 
-    // --------------------------------------------------------- Public Methods
+    // Public Methods ---------------------------------------------------------
 
     /**
      * Return a error report HTML &lt;div&gt; element for the given error and
@@ -249,7 +256,7 @@
         buffer.append("<table border='1' cellspacing='1' cellpadding='4' width='100%'
style='background-color: white;'>");
         buffer.append("<tr><td colspan='2' style='color:white; background-color:
navy; font-weight: bold'>Request</td></tr>");
 
-        TreeMap requestAttributes = new TreeMap();
+        Map<String, Object> requestAttributes = new TreeMap<String, Object>();
         Enumeration attributeNames = request.getAttributeNames();
         while (attributeNames.hasMoreElements()) {
             String name = attributeNames.nextElement().toString();
@@ -271,7 +278,7 @@
         buffer.append("</a>");
         buffer.append("</td></tr>");
 
-        TreeMap requestHeaders = new TreeMap();
+        Map<String, Object> requestHeaders = new TreeMap<String, Object>();
         Enumeration headerNames = request.getHeaderNames();
         while (headerNames.hasMoreElements()) {
             String name = headerNames.nextElement().toString();
@@ -289,7 +296,7 @@
         buffer.append(request.getMethod());
         buffer.append("</td></tr>");
 
-        TreeMap requestParams = new TreeMap();
+        Map<String, Object> requestParams = new TreeMap<String, Object>();
         Enumeration paramNames = request.getParameterNames();
         while (paramNames.hasMoreElements()) {
             String name = paramNames.nextElement().toString();
@@ -320,7 +327,7 @@
         buffer.append("</a>");
         buffer.append("</td></tr>");
 
-        TreeMap sessionAttributes = new TreeMap();
+        Map<String, Object> sessionAttributes = new TreeMap<String, Object>();
         if (request.getSession(false) != null) {
             HttpSession session = request.getSession();
             attributeNames = session.getAttributeNames();
@@ -339,7 +346,7 @@
         return buffer.toString();
     }
 
-    // ------------------------------------------------------ Protected Methods
+    // Protected Methods ------------------------------------------------------
 
     /**
      * Return the cause of the error.
@@ -637,7 +644,7 @@
      * @param map the Map of name value pairs
      * @param buffer the string buffer to write out the values to
      */
-    protected void writeMap(Map map, HtmlStringBuffer buffer) {
+    protected void writeMap(Map<String, Object> map, HtmlStringBuffer buffer) {
         for (Iterator i = map.entrySet().iterator(); i.hasNext();) {
             Map.Entry entry = (Map.Entry) i.next();
             String key = entry.getKey().toString();



Mime
View raw message