Return-Path:
Delivered-To: apmail-commons-commits-archive@minotaur.apache.org
Received: (qmail 32159 invoked from network); 1 Aug 2009 21:37:29 -0000
Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3)
by minotaur.apache.org with SMTP; 1 Aug 2009 21:37:29 -0000
Received: (qmail 26056 invoked by uid 500); 1 Aug 2009 21:37:32 -0000
Delivered-To: apmail-commons-commits-archive@commons.apache.org
Received: (qmail 25967 invoked by uid 500); 1 Aug 2009 21:37:32 -0000
Mailing-List: contact commits-help@commons.apache.org; run by ezmlm
Precedence: bulk
List-Help:
List-Unsubscribe:
List-Post:
List-Id:
Reply-To: dev@commons.apache.org
Delivered-To: mailing list commits@commons.apache.org
Received: (qmail 25958 invoked by uid 99); 1 Aug 2009 21:37:32 -0000
Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136)
by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 01 Aug 2009 21:37:32 +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; Sat, 01 Aug 2009 21:37:30 +0000
Received: by eris.apache.org (Postfix, from userid 65534)
id BD680238889B; Sat, 1 Aug 2009 21:37:09 +0000 (UTC)
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Subject: svn commit: r799932 - in /commons/proper/jexl/branches/2.0/src:
java/org/apache/commons/jexl/scripting/JexlScriptEngine.java
java/org/apache/commons/jexl/scripting/JexlScriptObject.java
test/org/apache/commons/jexl/scripting/JexlScriptEngineTest.java
Date: Sat, 01 Aug 2009 21:37:09 -0000
To: commits@commons.apache.org
From: sebb@apache.org
X-Mailer: svnmailer-1.0.8
Message-Id: <20090801213709.BD680238889B@eris.apache.org>
X-Virus-Checked: Checked by ClamAV on apache.org
Author: sebb
Date: Sat Aug 1 21:37:09 2009
New Revision: 799932
URL: http://svn.apache.org/viewvc?rev=799932&view=rev
Log:
Initial implementation of "JEXL" engine-scoped object
Added:
commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/scripting/JexlScriptObject.java (with props)
Modified:
commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/scripting/JexlScriptEngine.java
commons/proper/jexl/branches/2.0/src/test/org/apache/commons/jexl/scripting/JexlScriptEngineTest.java
Modified: commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/scripting/JexlScriptEngine.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/scripting/JexlScriptEngine.java?rev=799932&r1=799931&r2=799932&view=diff
==============================================================================
--- commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/scripting/JexlScriptEngine.java (original)
+++ commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/scripting/JexlScriptEngine.java Sat Aug 1 21:37:09 2009
@@ -49,12 +49,18 @@
* If no variable is found, and the JEXL script is writing to a variable,
* it will be stored in the ENGINE scope.
*
+ *
+ * The implementation also creates the "JEXL" script object as an instance of the
+ * class {@link JexlScriptObject} for access to utility methods and variables.
+ *
* See
* Java Scripting API
* Javadoc.
*/
public class JexlScriptEngine extends AbstractScriptEngine {
+ public static final String JEXL_OBJECT_KEY = "JEXL";
+
public static final String CONTEXT_KEY = "context";
private final ScriptEngineFactory factory;
@@ -68,6 +74,8 @@
public JexlScriptEngine(final ScriptEngineFactory _factory) {
factory = _factory;
engine = new JexlEngine();
+ // Add utility object
+ this.put(JEXL_OBJECT_KEY, new JexlScriptObject());
}
/** {@inheritDoc} */
@@ -110,6 +118,7 @@
}
// This is mandated by JSR-223 (end of section SCR.4.3.4.1.2 - Script Execution)
context.setAttribute(CONTEXT_KEY, context, ScriptContext.ENGINE_SCOPE);
+
try {
Script script = engine.createScript(scriptText);
JexlContext ctxt = new JexlContext(){
Added: commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/scripting/JexlScriptObject.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/scripting/JexlScriptObject.java?rev=799932&view=auto
==============================================================================
--- commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/scripting/JexlScriptObject.java (added)
+++ commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/scripting/JexlScriptObject.java Sat Aug 1 21:37:09 2009
@@ -0,0 +1,48 @@
+/*
+ * 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.commons.jexl.scripting;
+
+import java.io.PrintStream;
+
+/**
+ * Implements variables and methods for use by JEXL scripts.
+ *
+ * The following items are defined:
+ *
+ * - out - System.out
+ * - err - System.err
+ *
+ *
+ *
+ */
+public class JexlScriptObject {
+
+ public JexlScriptObject(){
+
+ }
+
+ public static PrintStream getOut() {
+ return System.out;
+ }
+
+ public static PrintStream getErr() {
+ return System.err;
+ }
+
+}
Propchange: commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/scripting/JexlScriptObject.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: commons/proper/jexl/branches/2.0/src/java/org/apache/commons/jexl/scripting/JexlScriptObject.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Modified: commons/proper/jexl/branches/2.0/src/test/org/apache/commons/jexl/scripting/JexlScriptEngineTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/branches/2.0/src/test/org/apache/commons/jexl/scripting/JexlScriptEngineTest.java?rev=799932&r1=799931&r2=799932&view=diff
==============================================================================
--- commons/proper/jexl/branches/2.0/src/test/org/apache/commons/jexl/scripting/JexlScriptEngineTest.java (original)
+++ commons/proper/jexl/branches/2.0/src/test/org/apache/commons/jexl/scripting/JexlScriptEngineTest.java Sat Aug 1 21:37:09 2009
@@ -50,6 +50,10 @@
assertEquals(initialValue,engine.get("old"));
assertEquals(newValue,engine.get("value"));
assertEquals(engine.getContext(),engine.get(JexlScriptEngine.CONTEXT_KEY));
+ // Check behaviour of JEXL object
+ assertNotNull(engine.get("JEXL"));
+ assertEquals(System.out,engine.eval("JEXL.out"));
+ assertEquals(System.err,engine.eval("JEXL.err"));
}
public void testNulls() throws Exception {