Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 2878B200B48 for ; Mon, 18 Jul 2016 23:20:43 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 27228160A5D; Mon, 18 Jul 2016 21:20:43 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 4B48A160A65 for ; Mon, 18 Jul 2016 23:20:42 +0200 (CEST) Received: (qmail 10118 invoked by uid 500); 18 Jul 2016 21:20:41 -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 10109 invoked by uid 99); 18 Jul 2016 21:20:41 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd4-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 18 Jul 2016 21:20:41 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd4-us-west.apache.org (ASF Mail Server at spamd4-us-west.apache.org) with ESMTP id 19F72C01A9 for ; Mon, 18 Jul 2016 21:20:41 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd4-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 0.374 X-Spam-Level: X-Spam-Status: No, score=0.374 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RP_MATCHES_RCVD=-1.426] autolearn=disabled Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd4-us-west.apache.org [10.40.0.11]) (amavisd-new, port 10024) with ESMTP id WaULqHtd2YT1 for ; Mon, 18 Jul 2016 21:20:40 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with ESMTP id CEA605F4E7 for ; Mon, 18 Jul 2016 21:20:39 +0000 (UTC) Received: from svn01-us-west.apache.org (svn.apache.org [10.41.0.6]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id 14621E04B9 for ; Mon, 18 Jul 2016 21:20:39 +0000 (UTC) Received: from svn01-us-west.apache.org (localhost [127.0.0.1]) by svn01-us-west.apache.org (ASF Mail Server at svn01-us-west.apache.org) with ESMTP id E591F3A012F for ; Mon, 18 Jul 2016 21:20:38 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1753318 - in /velocity/engine/trunk/velocity-engine-core/src: main/java/org/apache/velocity/runtime/ test/java/org/apache/velocity/test/ Date: Mon, 18 Jul 2016 21:20:38 -0000 To: commits@velocity.apache.org From: cbrisson@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20160718212038.E591F3A012F@svn01-us-west.apache.org> archived-at: Mon, 18 Jul 2016 21:20:43 -0000 Author: cbrisson Date: Mon Jul 18 21:20:38 2016 New Revision: 1753318 URL: http://svn.apache.org/viewvc?rev=1753318&view=rev Log: [engine] add optionl context.autoreference.key property, with testcase Added: velocity/engine/trunk/velocity-engine-core/src/test/java/org/apache/velocity/test/ContextAutoreferenceKeyTestCase.java Modified: velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeConstants.java velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeInstance.java Modified: velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeConstants.java URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeConstants.java?rev=1753318&r1=1753317&r2=1753318&view=diff ============================================================================== --- velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeConstants.java (original) +++ velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeConstants.java Mon Jul 18 21:20:38 2016 @@ -246,6 +246,9 @@ public interface RuntimeConstants /** Switch for ignoring nulls in math equations vs throwing exceptions. */ String STRICT_MATH = "runtime.strict.math"; + /** Key upon which a context should be accessible within itself */ + String CONTEXT_AUTOREFERENCE_KEY = "context.autoreference.key"; + /** * The parser.pool.class property specifies the name of the {@link org.apache.velocity.util.SimplePool} * implementation to use. @@ -256,7 +259,7 @@ public interface RuntimeConstants * @see #NUMBER_OF_PARSERS */ String PARSER_POOL_SIZE = "parser.pool.size"; - + /* * ---------------------------------------------------------------------- * These constants are used internally by the Velocity runtime i.e. Modified: velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeInstance.java URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeInstance.java?rev=1753318&r1=1753317&r2=1753318&view=diff ============================================================================== --- velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeInstance.java (original) +++ velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeInstance.java Mon Jul 18 21:20:38 2016 @@ -1410,6 +1410,11 @@ public class RuntimeInstance implements Object previous = ica.get(evaluateScopeName); context.put(evaluateScopeName, new Scope(this, previous)); } + /** + * optionally put the context in itself if asked so + */ + String self = getString(CONTEXT_AUTOREFERENCE_KEY); + if (self != null) context.put(self, context); nodeTree.render(ica, writer); } catch (StopCommand stop) Added: velocity/engine/trunk/velocity-engine-core/src/test/java/org/apache/velocity/test/ContextAutoreferenceKeyTestCase.java URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/test/java/org/apache/velocity/test/ContextAutoreferenceKeyTestCase.java?rev=1753318&view=auto ============================================================================== --- velocity/engine/trunk/velocity-engine-core/src/test/java/org/apache/velocity/test/ContextAutoreferenceKeyTestCase.java (added) +++ velocity/engine/trunk/velocity-engine-core/src/test/java/org/apache/velocity/test/ContextAutoreferenceKeyTestCase.java Mon Jul 18 21:20:38 2016 @@ -0,0 +1,56 @@ +package org.apache.velocity.test; + +/* + * 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. + */ + +import org.apache.velocity.VelocityContext; +import org.apache.velocity.app.VelocityEngine; + +/** + * This class tests passing expressions as method arguments + */ + +public class ContextAutoreferenceKeyTestCase extends BaseTestCase +{ + public ContextAutoreferenceKeyTestCase(final String name) + { + super(name); + } + + protected void setUpEngine(VelocityEngine engine) + { + engine.setProperty(VelocityEngine.CONTEXT_AUTOREFERENCE_KEY, "self"); + } + + protected void setUpContext(VelocityContext context) + { + context.put("foo", "bar"); + } + + public void testAutoreference() + { + assertEvalEquals("bar", "$foo"); + assertEvalEquals("bar", "$self.foo"); + assertEvalEquals("bar", "$self.self.foo"); + assertEvalEquals("true", "$self.containsKey('foo')"); + assertEvalEquals("false", "$self.containsKey('bar')"); + assertEvalEquals("bar", "$self.put('foo', 'baz')"); + assertEvalEquals("baz", "$foo"); + } +}