Return-Path: Delivered-To: apmail-velocity-commits-archive@minotaur.apache.org Received: (qmail 15615 invoked from network); 1 Sep 2009 05:31:18 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 1 Sep 2009 05:31:18 -0000 Received: (qmail 73985 invoked by uid 500); 1 Sep 2009 05:31:18 -0000 Delivered-To: apmail-velocity-commits-archive@velocity.apache.org Received: (qmail 73951 invoked by uid 500); 1 Sep 2009 05:31:18 -0000 Mailing-List: contact commits-help@velocity.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@velocity.apache.org Delivered-To: mailing list commits@velocity.apache.org Received: (qmail 73940 invoked by uid 99); 1 Sep 2009 05:31:18 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 01 Sep 2009 05:31:18 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 01 Sep 2009 05:31:16 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 9133D23888DC; Tue, 1 Sep 2009 05:30:56 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r809822 - in /velocity/engine/branches/2.0_Exp/src: java/org/apache/velocity/app/event/implement/IncludeNotFound.java test/org/apache/velocity/test/BuiltInEventHandlerTestCase.java Date: Tue, 01 Sep 2009 05:30:56 -0000 To: commits@velocity.apache.org From: nbubna@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090901053056.9133D23888DC@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: nbubna Date: Tue Sep 1 05:30:56 2009 New Revision: 809822 URL: http://svn.apache.org/viewvc?rev=809822&view=rev Log: VELOCITY-734 merge feature addition and test to 2.x branch (thanks to chad davis) Modified: velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/app/event/implement/IncludeNotFound.java velocity/engine/branches/2.0_Exp/src/test/org/apache/velocity/test/BuiltInEventHandlerTestCase.java Modified: velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/app/event/implement/IncludeNotFound.java URL: http://svn.apache.org/viewvc/velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/app/event/implement/IncludeNotFound.java?rev=809822&r1=809821&r2=809822&view=diff ============================================================================== --- velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/app/event/implement/IncludeNotFound.java (original) +++ velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/app/event/implement/IncludeNotFound.java Tue Sep 1 05:30:56 2009 @@ -20,7 +20,9 @@ */ import org.apache.velocity.app.event.IncludeEventHandler; +import org.apache.velocity.context.Context; import org.apache.velocity.runtime.RuntimeServices; +import org.apache.velocity.util.ContextAware; import org.apache.velocity.util.RuntimeServicesAware; import org.apache.velocity.util.StringUtils; @@ -36,17 +38,24 @@ * eventhandler.include.notfound = error.vm * * + *

+ * The name of the missing resource is put into the Velocity context, under the + * key "missingResource", so that the "notfound" template can report the missing + * resource with a Velocity reference, like: + * $missingResource + *

* * @author Will Glass-Husain * @version $Id$ * @since 1.5 */ -public class IncludeNotFound implements IncludeEventHandler,RuntimeServicesAware { +public class IncludeNotFound implements IncludeEventHandler,RuntimeServicesAware,ContextAware { private static final String DEFAULT_NOT_FOUND = "notfound.vm"; private static final String PROPERTY_NOT_FOUND = "eventhandler.include.notfound"; private RuntimeServices rs = null; String notfound; + Context context; /** * Chseck to see if included file exists, and display "not found" page if it @@ -70,10 +79,10 @@ boolean exists = (rs.getLoaderNameForResource(includeResourcePath) != null); if (!exists) { + context.put("missingResource", includeResourcePath); if (rs.getLoaderNameForResource(notfound) != null) { return notfound; - } else { @@ -83,7 +92,6 @@ rs.getLog().error("Can't find include not found page: " + notfound); return null; } - } else return includeResourcePath; @@ -97,6 +105,13 @@ { this.rs = rs; notfound = StringUtils.nullTrim(rs.getString(PROPERTY_NOT_FOUND, DEFAULT_NOT_FOUND)); - } + } + /** + * @see org.apache.velocity.util.ContextAware#setContext(org.apache.velocity.context.Context) + */ + public void setContext(Context context) + { + this.context = context; + } } Modified: velocity/engine/branches/2.0_Exp/src/test/org/apache/velocity/test/BuiltInEventHandlerTestCase.java URL: http://svn.apache.org/viewvc/velocity/engine/branches/2.0_Exp/src/test/org/apache/velocity/test/BuiltInEventHandlerTestCase.java?rev=809822&r1=809821&r2=809822&view=diff ============================================================================== --- velocity/engine/branches/2.0_Exp/src/test/org/apache/velocity/test/BuiltInEventHandlerTestCase.java (original) +++ velocity/engine/branches/2.0_Exp/src/test/org/apache/velocity/test/BuiltInEventHandlerTestCase.java Tue Sep 1 05:30:56 2009 @@ -93,9 +93,10 @@ super(name); } - public void setUp() + public void setUp() throws Exception { assureResultsDirectoryExists(RESULTS_DIR); + super.setUp(); } public static Test suite() @@ -391,6 +392,14 @@ } + public void testIncludeNotFoundMissingResourceName() throws Exception + { + // uses base test support + engine.setProperty(RuntimeConstants.EVENTHANDLER_INCLUDE, "org.apache.velocity.app.event.implement.IncludeNotFound"); + addTemplate("notfound.vm", "$missingResource"); + assertEvalEquals("foo", "#parse('foo')"); + } + public void testIncludeRelativePath() throws Exception { VelocityEngine ve = new VelocityEngine();