Return-Path:
The supplied vars should be null only in derived classes that override the get/set/has methods.
* For a default vars context with a code supplied vars, use the default no-parameter contructor.
* At the base is an evaluator similar to the Unified EL evaluator used in JSP/JSF based on JEXL.
- * At the top is a template engine that uses JEXL (instead of OGNL/VTL) as the scripting
+ * At the top is a template engine inspired by Velocity that uses JEXL (instead of OGNL/VTL) as the scripting
* language.
*
@@ -33,9 +33,9 @@ import java.util.Set;
* and facilitate the implementation of expression evaluation.
*
- * The template engine is intended to output text, html, XML.
+ * The template engine is intended to output any form of text; html, XML, CSV...
*
+ * This allows to completely hide a package, class, interface, constructor, method of field from + * JEXL; a NoJexl annotated element will not be usable through any kind of JEXL expression or script. + *
+ *See {@link org.apache.commons.jexl3.Sandbox} for another way to restrict JEXL access. + */ +@Documented +@Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.TYPE, ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.FIELD, ElementType.PACKAGE}) +public @interface NoJexl { + +} Propchange: commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/annotations/NoJexl.java ------------------------------------------------------------------------------ svn:eol-style = native Copied: commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/annotations/package.html (from r1209060, commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/package.html) URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/annotations/package.html?p2=commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/annotations/package.html&p1=commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/package.html&r1=1209060&r2=1211428&rev=1211428&view=diff ============================================================================== --- commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/package.html (original) +++ commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/annotations/package.html Wed Dec 7 13:22:36 2011 @@ -16,21 +16,12 @@ limitations under the License. -->
-- This internal package is not intended for public usage and there is no - guarantee that its public classes or methods will remain as is in subsequent - versions. -
-- This set of classes implement the various forms of setters and getters - used by Jexl. These are specialized forms for 'pure' properties, discovering - methods of the {s,g}etProperty form, for Maps, Lists and Ducks - - attempting to discover a 'get' or 'set' method, making an object walk and - quack. +
The only annotation in this package allows to restrict what JEXL + can introspect and expose through scripting.
Modified: commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/Engine.java URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/Engine.java?rev=1211428&r1=1211427&r2=1211428&view=diff ============================================================================== --- commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/Engine.java (original) +++ commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/Engine.java Wed Dec 7 13:22:36 2011 @@ -16,24 +16,7 @@ */ package org.apache.commons.jexl3.internal; -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.StringReader; -import java.io.Reader; -import java.net.URL; -import java.net.URLConnection; -import java.lang.ref.SoftReference; -import java.util.ArrayList; -import java.util.Map; -import java.util.Set; -import java.util.Collections; -import java.util.LinkedHashMap; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Map.Entry; + import org.apache.commons.jexl3.JexlArithmetic; import org.apache.commons.jexl3.JexlBuilder; import org.apache.commons.jexl3.JexlContext; @@ -43,21 +26,41 @@ import org.apache.commons.jexl3.JexlExpr import org.apache.commons.jexl3.JexlInfo; import org.apache.commons.jexl3.JexlInfoHandle; import org.apache.commons.jexl3.JexlScript; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import org.apache.commons.jexl3.parser.ParseException; -import org.apache.commons.jexl3.parser.Parser; -import org.apache.commons.jexl3.parser.JexlNode; -import org.apache.commons.jexl3.parser.TokenMgrError; -import org.apache.commons.jexl3.parser.ASTJexlScript; +import org.apache.commons.jexl3.internal.introspection.Uberspect; +import org.apache.commons.jexl3.introspection.JexlMethod; +import org.apache.commons.jexl3.introspection.JexlUberspect; import org.apache.commons.jexl3.parser.ASTArrayAccess; import org.apache.commons.jexl3.parser.ASTIdentifier; +import org.apache.commons.jexl3.parser.ASTJexlScript; import org.apache.commons.jexl3.parser.ASTReference; +import org.apache.commons.jexl3.parser.JexlNode; +import org.apache.commons.jexl3.parser.ParseException; +import org.apache.commons.jexl3.parser.Parser; +import org.apache.commons.jexl3.parser.TokenMgrError; -import org.apache.commons.jexl3.introspection.JexlUberspect; -import org.apache.commons.jexl3.introspection.JexlMethod; -import org.apache.commons.jexl3.internal.introspection.Uberspect; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.Reader; +import java.io.StringReader; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; + +import java.lang.ref.SoftReference; +import java.net.URL; +import java.net.URLConnection; /** * A JexlEngine implementation. @@ -168,6 +171,10 @@ public class Engine extends JexlEngine { */ public Engine(JexlBuilder conf) { this.uberspect = conf.uberspect() == null ? getUberspect(conf.logger()) : conf.uberspect(); + ClassLoader loader = conf.loader(); + if (loader != null) { + uberspect.setClassLoader(loader); + } this.logger = conf.logger() == null ? LogFactory.getLog(JexlEngine.class) : conf.logger(); this.functions = conf.namespaces() == null ? Collections.
Modified: commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/introspection/ClassMap.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/introspection/ClassMap.java?rev=1211428&r1=1211427&r2=1211428&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/introspection/ClassMap.java (original)
+++ commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/introspection/ClassMap.java Wed Dec 7 13:22:36 2011
@@ -84,7 +84,9 @@ final class ClassMap {
if (fields.length > 0) {
Map Since methods can be overriden, this also checks that no superclass or interface
+ * explictly disallows this methods.> evars = check.getVariables();
@@ -107,8 +103,8 @@ public class UnifiedJEXLTest extends Jex
}
public void testAssign() throws Exception {
- JxltEngine.UnifiedExpression assign = EL.createExpression("${froboz.value = 10}");
- JxltEngine.UnifiedExpression check = EL.createExpression("${froboz.value}");
+ JxltEngine.UnifiedExpression assign = JXLT.createExpression("${froboz.value = 10}");
+ JxltEngine.UnifiedExpression check = JXLT.createExpression("${froboz.value}");
Object o = assign.evaluate(context);
assertEquals("Result is not 10", new Integer(10), o);
o = check.evaluate(context);
@@ -117,14 +113,14 @@ public class UnifiedJEXLTest extends Jex
public void testComposite() throws Exception {
String source = "Dear ${p} ${name};";
- JxltEngine.UnifiedExpression expr = EL.createExpression(source);
- vars.put("p", "Mr");
- vars.put("name", "Doe");
+ JxltEngine.UnifiedExpression expr = JXLT.createExpression(source);
+ context.set("p", "Mr");
+ context.set("name", "Doe");
assertTrue("expression should be immediate", expr.isImmediate());
Object o = expr.evaluate(context);
assertEquals("Dear Mr Doe;", o);
- vars.put("p", "Ms");
- vars.put("name", "Jones");
+ context.set("p", "Ms");
+ context.set("name", "Jones");
o = expr.evaluate(context);
assertEquals("Dear Ms Jones;", o);
assertEquals(source, getSource(expr.toString()));
@@ -132,21 +128,22 @@ public class UnifiedJEXLTest extends Jex
public void testPrepareEvaluate() throws Exception {
final String source = "Dear #{p} ${name};";
- JxltEngine.UnifiedExpression expr = EL.createExpression("Dear #{p} ${name};");
+ JxltEngine.UnifiedExpression expr = JXLT.createExpression("Dear #{p} ${name};");
assertTrue("expression should be deferred", expr.isDeferred());
Set
> evars = expr.getVariables();
assertEquals(1, evars.size());
assertTrue(evars.contains(Arrays.asList("name")));
- vars.put("name", "Doe");
+ context.set("name", "Doe");
JxltEngine.UnifiedExpression phase1 = expr.prepare(context);
String as = phase1.asString();
assertEquals("Dear ${p} Doe;", as);
Set
> evars1 = phase1.getVariables();
assertEquals(1, evars1.size());
assertTrue(evars1.contains(Arrays.asList("p")));
- vars.put("p", "Mr");
- vars.put("name", "Should not be used in 2nd phase");
+ context.clearVariables();
+ context.set("p", "Mr");
+ context.set("name", "Should not be used in 2nd phase");
Object o = phase1.evaluate(context);
assertEquals("Dear Mr Doe;", o);
@@ -157,14 +154,14 @@ public class UnifiedJEXLTest extends Jex
public void testNested() throws Exception {
final String source = "#{${hi}+'.world'}";
- JxltEngine.UnifiedExpression expr = EL.createExpression(source);
+ JxltEngine.UnifiedExpression expr = JXLT.createExpression(source);
Set
> evars = expr.getVariables();
assertEquals(1, evars.size());
assertTrue(evars.contains(Arrays.asList("hi")));
- vars.put("hi", "greeting");
- vars.put("greeting.world", "Hello World!");
+ context.set("hi", "greeting");
+ context.set("greeting.world", "Hello World!");
assertTrue("expression should be deferred", expr.isDeferred());
Object o = expr.evaluate(context);
assertEquals("Hello World!", o);
@@ -175,7 +172,7 @@ public class UnifiedJEXLTest extends Jex
public void testImmediate() throws Exception {
JexlContext none = null;
final String source = "${'Hello ' + 'World!'}";
- JxltEngine.UnifiedExpression expr = EL.createExpression(source);
+ JxltEngine.UnifiedExpression expr = JXLT.createExpression(source);
JxltEngine.UnifiedExpression prepared = expr.prepare(none);
assertEquals("prepare should return same expression", "Hello World!", prepared.asString());
Object o = expr.evaluate(none);
@@ -188,7 +185,7 @@ public class UnifiedJEXLTest extends Jex
public void testConstant() throws Exception {
JexlContext none = null;
final String source = "Hello World!";
- JxltEngine.UnifiedExpression expr = EL.createExpression(source);
+ JxltEngine.UnifiedExpression expr = JXLT.createExpression(source);
assertTrue("prepare should return same expression", expr.prepare(none) == expr);
Object o = expr.evaluate(none);
assertTrue("expression should be immediate", expr.isImmediate());
@@ -200,7 +197,7 @@ public class UnifiedJEXLTest extends Jex
public void testDeferred() throws Exception {
JexlContext none = null;
final String source = "#{'world'}";
- JxltEngine.UnifiedExpression expr = EL.createExpression(source);
+ JxltEngine.UnifiedExpression expr = JXLT.createExpression(source);
assertTrue("expression should be deferred", expr.isDeferred());
String as = expr.prepare(none).asString();
assertEquals("prepare should return immediate version", "${'world'}", as);
@@ -215,23 +212,23 @@ public class UnifiedJEXLTest extends Jex
JxltEngine.UnifiedExpression expr;
Object o;
// $ and # are escapable in TemplateEngine
- expr = EL.createExpression("\\#{'world'}");
+ expr = JXLT.createExpression("\\#{'world'}");
o = expr.evaluate(none);
assertEquals("#{'world'}", o);
- expr = EL.createExpression("\\${'world'}");
+ expr = JXLT.createExpression("\\${'world'}");
o = expr.evaluate(none);
assertEquals("${'world'}", o);
}
public void testEscapeString() throws Exception {
- JxltEngine.UnifiedExpression expr = EL.createExpression("\\\"${'world\\'s finest'}\\\"");
+ JxltEngine.UnifiedExpression expr = JXLT.createExpression("\\\"${'world\\'s finest'}\\\"");
JexlContext none = null;
Object o = expr.evaluate(none);
assertEquals("\"world's finest\"", o);
}
public void testNonEscapeString() throws Exception {
- JxltEngine.UnifiedExpression expr = EL.createExpression("c:\\some\\windows\\path");
+ JxltEngine.UnifiedExpression expr = JXLT.createExpression("c:\\some\\windows\\path");
JexlContext none = null;
Object o = expr.evaluate(none);
assertEquals("c:\\some\\windows\\path", o);
@@ -239,7 +236,7 @@ public class UnifiedJEXLTest extends Jex
public void testMalformed() throws Exception {
try {
- JxltEngine.UnifiedExpression expr = EL.createExpression("${'world'");
+ JxltEngine.UnifiedExpression expr = JXLT.createExpression("${'world'");
JexlContext none = null;
expr.evaluate(none);
fail("should be malformed");
@@ -252,7 +249,7 @@ public class UnifiedJEXLTest extends Jex
public void testMalformedNested() throws Exception {
try {
- JxltEngine.UnifiedExpression expr = EL.createExpression("#{${hi} world}");
+ JxltEngine.UnifiedExpression expr = JXLT.createExpression("#{${hi} world}");
JexlContext none = null;
expr.evaluate(none);
fail("should be malformed");
@@ -265,7 +262,7 @@ public class UnifiedJEXLTest extends Jex
public void testBadContextNested() throws Exception {
try {
- JxltEngine.UnifiedExpression expr = EL.createExpression("#{${hi}+'.world'}");
+ JxltEngine.UnifiedExpression expr = JXLT.createExpression("#{${hi}+'.world'}");
JexlContext none = null;
expr.evaluate(none);
fail("should be malformed");
@@ -277,15 +274,15 @@ public class UnifiedJEXLTest extends Jex
}
public void testCharAtBug() throws Exception {
- vars.put("foo", "abcdef");
- JxltEngine.UnifiedExpression expr = EL.createExpression("${foo.substring(2,4)/*comment*/}");
+ context.set("foo", "abcdef");
+ JxltEngine.UnifiedExpression expr = JXLT.createExpression("${foo.substring(2,4)/*comment*/}");
Object o = expr.evaluate(context);
assertEquals("cd", o);
- vars.put("bar", "foo");
+ context.set("bar", "foo");
try {
context.setSilent(true);
- expr = EL.createExpression("#{${bar}+'.charAt(-2)'}");
+ expr = JXLT.createExpression("#{${bar}+'.charAt(-2)'}");
expr = expr.prepare(context);
o = expr.evaluate(context);
assertEquals(null, o);
@@ -300,16 +297,16 @@ public class UnifiedJEXLTest extends Jex
StringWriter strw;
String output;
- JxltEngine.Template t = EL.createTemplate(source);
+ JxltEngine.Template t = JXLT.createTemplate(source);
- vars.put("x", 42);
+ context.set("x", 42);
strw = new StringWriter();
t.evaluate(context, strw);
output = strw.toString();
assertEquals("x is 42\n", output);
strw = new StringWriter();
- vars.put("x", "");
+ context.set("x", "");
t.evaluate(context, strw);
output = strw.toString();
assertEquals("no x\n", output);
@@ -323,7 +320,7 @@ public class UnifiedJEXLTest extends Jex
StringWriter strw;
String output;
- JxltEngine.Template t = EL.createTemplate("$$", new StringReader(source), "x");
+ JxltEngine.Template t = JXLT.createTemplate("$$", new StringReader(source), "x");
String dstr = t.asString();
assertNotNull(dstr);
@@ -344,7 +341,7 @@ public class UnifiedJEXLTest extends Jex
+ "${l10n}=#{x}\n"
+ "$$ }\n";
int[] args = { 42 };
- JxltEngine.Template tl10n = EL.createTemplate(source, "list");
+ JxltEngine.Template tl10n = JXLT.createTemplate(source, "list");
String dstr = tl10n.asString();
assertNotNull(dstr);
context.set("l10n", "valeur");
@@ -377,7 +374,7 @@ public class UnifiedJEXLTest extends Jex
+ "The value ${x} is under fourty-two\n"
+ "$$ }\n"
+ "$$ }\n";
- JxltEngine.Template t = EL.createTemplate("$$", new StringReader(test42), "list");
+ JxltEngine.Template t = JXLT.createTemplate("$$", new StringReader(test42), "list");
StringWriter strw = new StringWriter();
int[] list = {1, 3, 5, 42, 169};
t.evaluate(context, strw, list);
@@ -414,7 +411,7 @@ public class UnifiedJEXLTest extends Jex
public void testWriter() throws Exception {
Froboz froboz = new Froboz(42);
Writer writer = new FrobozWriter(new StringWriter());
- JxltEngine.Template t = EL.createTemplate("$$", new StringReader("$$$jexl.print(froboz)"), "froboz");
+ JxltEngine.Template t = JXLT.createTemplate("$$", new StringReader("$$$jexl.print(froboz)"), "froboz");
t.evaluate(context, writer, froboz);
assertEquals("froboz{42}", writer.toString());
}