You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@click.apache.org by me...@apache.org on 2009/07/09 14:09:15 UTC

svn commit: r792519 - /incubator/click/trunk/click/framework/src/org/apache/click/service/VelocityTemplateService.java

Author: medgar
Date: Thu Jul  9 12:09:15 2009
New Revision: 792519

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

Modified:
    incubator/click/trunk/click/framework/src/org/apache/click/service/VelocityTemplateService.java

Modified: incubator/click/trunk/click/framework/src/org/apache/click/service/VelocityTemplateService.java
URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/framework/src/org/apache/click/service/VelocityTemplateService.java?rev=792519&r1=792518&r2=792519&view=diff
==============================================================================
--- incubator/click/trunk/click/framework/src/org/apache/click/service/VelocityTemplateService.java (original)
+++ incubator/click/trunk/click/framework/src/org/apache/click/service/VelocityTemplateService.java Thu Jul  9 12:09:15 2009
@@ -34,11 +34,11 @@
 import org.apache.click.Page;
 import org.apache.click.util.ClickUtils;
 import org.apache.click.util.ErrorReport;
-
 import org.apache.commons.lang.Validate;
 import org.apache.velocity.Template;
 import org.apache.velocity.VelocityContext;
 import org.apache.velocity.app.VelocityEngine;
+import org.apache.velocity.exception.ResourceNotFoundException;
 import org.apache.velocity.io.VelocityWriter;
 import org.apache.velocity.runtime.RuntimeConstants;
 import org.apache.velocity.runtime.RuntimeServices;
@@ -199,11 +199,17 @@
      */
     protected static final String DEFAULT_TEMPLATE_PROPS = "/WEB-INF/velocity.properties";
 
+    /** The click error page template path. */
+    protected static final String ERROR_PAGE_PATH = "/click/error.htm";
+
     /**
      * The user supplied macro file name: &nbsp; "<tt>macro.vm</tt>".
      */
     protected static final String MACRO_VM_FILE_NAME = "macro.vm";
 
+    /** The click not found page template path. */
+    protected static final String NOT_FOUND_PAGE_PATH = "/click/not-found.htm";
+
     /**
      * The global Velocity macro file path: &nbsp;
      * "<tt>/click/VM_global_library.vm</tt>".
@@ -218,6 +224,12 @@
     /** The application configuration service. */
     protected ConfigService configService;
 
+    /** The /click/error.htm page template has been deployed. */
+    protected boolean deployedErrorTemplate;
+
+    /** The /click/not-found.htm page template has been deployed. */
+    protected boolean deployedNotFoundTemplate;
+
     /** The VelocityEngine instance. */
     protected VelocityEngine velocityEngine = new VelocityEngine();
 
@@ -265,6 +277,20 @@
                 logChuteAdapter.logLevel = LogChute.WARN_ID;
             }
         }
+
+        // Attempt to load click error page and not found templates from the
+        // web click directory
+        try {
+            velocityEngine.getTemplate(ERROR_PAGE_PATH);
+            deployedErrorTemplate = true;
+        } catch (ResourceNotFoundException rnfe) {
+        }
+
+        try {
+            velocityEngine.getTemplate(NOT_FOUND_PAGE_PATH);
+            deployedNotFoundTemplate = true;
+        } catch (ResourceNotFoundException rnfe) {
+        }
     }
 
     /**
@@ -289,14 +315,23 @@
 
         final VelocityContext context = new VelocityContext(model);
 
+        String templatePath = page.getTemplate();
+
+        if (!deployedErrorTemplate && templatePath.equals(ERROR_PAGE_PATH)) {
+            templatePath = "META-INF/web" + ERROR_PAGE_PATH;
+        }
+        if (!deployedErrorTemplate && templatePath.equals(NOT_FOUND_PAGE_PATH)) {
+            templatePath = "META-INF/web" + 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(page.getTemplate(), charset);
+            template = velocityEngine.getTemplate(templatePath, charset);
 
         } else {
-            template = velocityEngine.getTemplate(page.getTemplate());
+            template = velocityEngine.getTemplate(templatePath);
         }
 
         VelocityWriter velocityWriter = null;