click-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From med...@apache.org
Subject svn commit: r920802 - in /click/trunk/click/framework/src/org/apache/click: service/TemplateService.java service/VelocityTemplateService.java util/ErrorReport.java
Date Tue, 09 Mar 2010 11:17:54 GMT
Author: medgar
Date: Tue Mar  9 11:17:53 2010
New Revision: 920802

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

Modified:
    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/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=920802&r1=920801&r2=920802&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 Tue Mar
 9 11:17:53 2010
@@ -76,7 +76,7 @@ public interface TemplateService {
      * @throws TemplateException if template error occurs
      */
     public void renderTemplate(Page page, Map<String, Object> model, Writer writer)
-        throws TemplateException, Exception;
+        throws IOException, TemplateException;
 
     /**
      * Render the given template and model to the writer.
@@ -88,6 +88,6 @@ public interface TemplateService {
      * @throws TemplateException if template error occurs
      */
     public void renderTemplate(String templatePath, Map<String, Object> model, Writer
writer)
-        throws TemplateException, Exception;
+        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=920802&r1=920801&r2=920802&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
Tue Mar  9 11:17:53 2010
@@ -31,7 +31,7 @@ import java.util.TreeMap;
 import javax.servlet.ServletContext;
 
 import org.apache.click.Page;
-import org.apache.click.Context;
+
 import org.apache.click.util.ClickUtils;
 import org.apache.click.util.ErrorReport;
 import org.apache.commons.lang.Validate;
@@ -245,7 +245,7 @@ public class VelocityTemplateService imp
      * @see TemplateService#onInit(ServletContext)
      *
      * @param servletContext the application servlet velocityContext
-     * @throws TemplateException if an error occurs initializing the Template Service
+     * @throws Exception if an error occurs initializing the Template Service
      */
     public void onInit(ServletContext servletContext) throws Exception {
 
@@ -316,7 +316,7 @@ public class VelocityTemplateService imp
      * @throws TemplateException if template error occurs
      */
     public void renderTemplate(Page page, Map<String, Object> model, Writer writer)
-        throws TemplateException, Exception {
+        throws IOException, TemplateException {
 
         String templatePath = page.getTemplate();
 
@@ -336,10 +336,11 @@ public class VelocityTemplateService imp
      * @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 an error occurs
      */
     public void renderTemplate(String templatePath, Map<String, Object> model, Writer
writer)
-        throws TemplateException, Exception {
+        throws IOException, TemplateException {
 
         internalRenderTemplate(templatePath, null, model, writer);
     }
@@ -507,7 +508,7 @@ public class VelocityTemplateService imp
                                           Page page,
                                           Map<String, Object> model,
                                           Writer writer)
-        throws TemplateException, Exception {
+        throws IOException, TemplateException {
 
         final VelocityContext velocityContext = new VelocityContext(model);
 
@@ -535,6 +536,9 @@ public class VelocityTemplateService imp
 
             template.merge(velocityContext, velocityWriter);
 
+        } catch (IOException ioe) {
+            throw ioe;
+
         } catch (ParseErrorException pee) {
             TemplateException te = new TemplateException(pee,
                                                          pee.getTemplateName(),
@@ -613,23 +617,16 @@ public class VelocityTemplateService imp
             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.
-
-            Context context = null;
-            if (page == null) {
-                context = Context.getThreadLocalContext();
-            } else {
-                context = page.getContext();
-            }
-
             ErrorReport errorReport =
-                new ErrorReport(error,
+                new ErrorReport(te,
                         ((page != null) ? page.getClass() : null),
                         configService.isProductionMode(),
-                        context.getRequest(),
+                        page.getContext().getRequest(),
                         configService.getServletContext());
 
             if (velocityWriter == null) {
@@ -639,7 +636,7 @@ public class VelocityTemplateService imp
 
             velocityWriter.write(errorReport.toString());
 
-            throw error;
+            throw te;
 
         } finally {
             if (velocityWriter != null) {

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=920802&r1=920801&r2=920802&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 Tue Mar  9 11:17:53
2010
@@ -43,7 +43,6 @@ 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;
 
 /**
  * Provides an HTML &lt;div&gt; error report for the display of page error
@@ -112,29 +111,27 @@ public class ErrorReport {
         this.request = request;
         this.servletContext = servletContext;
 
-        isParseError = error instanceof ParseErrorException;
+        if (error instanceof TemplateException
+            && ((TemplateException) error).getTemplateName() != null) {
 
-        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);
-
-                sourceReader = new LineNumberReader(new InputStreamReader(is));
 
+            if (te.getTemplateName().charAt(0) == '/') {
+                sourceName = te.getTemplateName();
             } else {
-                sourceName = null;
+                sourceName =  '/' + te.getTemplateName();
             }
+            lineNumber = te.getLineNumber();
+            columnNumber = te.getColumnNumber();
+
+            InputStream is =
+                servletContext.getResourceAsStream(sourceName);
+
+            sourceReader = new LineNumberReader(new InputStreamReader(is));
+            isParseError = true;
 
         } else {
+            isParseError = false;
             sourceName = null;
             columnNumber = -1;
 



Mime
View raw message