You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by he...@apache.org on 2020/06/12 14:41:36 UTC
[commons-jexl] 02/02: JEXL-333: documentation,
javadoc & checkstyle nitpicks Task #JEXL-333 - Allow declaration of
namespace within script
This is an automated email from the ASF dual-hosted git repository.
henrib pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-jexl.git
commit 356e806eb5a3c845ecf7a9339fa750c5838ba7e2
Author: henrib <he...@apache.org>
AuthorDate: Fri Jun 12 16:41:15 2020 +0200
JEXL-333: documentation, javadoc & checkstyle nitpicks
Task #JEXL-333 - Allow declaration of namespace within script
---
.../org/apache/commons/jexl3/JexlArithmetic.java | 3 ++-
.../org/apache/commons/jexl3/internal/Engine.java | 27 +++++++++++-----------
src/site/xdoc/reference/syntax.xml | 12 ++++++++++
3 files changed, 27 insertions(+), 15 deletions(-)
diff --git a/src/main/java/org/apache/commons/jexl3/JexlArithmetic.java b/src/main/java/org/apache/commons/jexl3/JexlArithmetic.java
index 5b1c4a2..f23b427 100644
--- a/src/main/java/org/apache/commons/jexl3/JexlArithmetic.java
+++ b/src/main/java/org/apache/commons/jexl3/JexlArithmetic.java
@@ -211,7 +211,8 @@ public class JexlArithmetic {
if (ctor != null) {
try {
return ctor.newInstance(astrict, bigdContext, bigdScale);
- } catch (IllegalAccessException | IllegalArgumentException | InstantiationException | InvocationTargetException xany) {
+ } catch (IllegalAccessException | IllegalArgumentException
+ | InstantiationException | InvocationTargetException xany) {
// it was worth the try
}
}
diff --git a/src/main/java/org/apache/commons/jexl3/internal/Engine.java b/src/main/java/org/apache/commons/jexl3/internal/Engine.java
index d458139..ec8484f 100644
--- a/src/main/java/org/apache/commons/jexl3/internal/Engine.java
+++ b/src/main/java/org/apache/commons/jexl3/internal/Engine.java
@@ -389,22 +389,21 @@ public class Engine extends JexlEngine {
for(Map.Entry<String, Object> pragma : pragmas.entrySet()) {
String key = pragma.getKey();
Object value = pragma.getValue();
- if (PRAGMA_OPTIONS.equals(key)) {
- // jexl.options
- if (value instanceof String) {
- String[] vs = ((String) value).split(" ");
+ if (value instanceof String) {
+ if (PRAGMA_OPTIONS.equals(key)) {
+ // jexl.options
+ String[] vs = value.toString().split(" ");
opts.setFlags(vs);
- }
- }
- else if (key.startsWith(PRAGMA_JEXLNS) && value instanceof String) {
- // jexl.namespace.***
- String nsname = key.substring(PRAGMA_JEXLNS.length());
- if (nsname != null && !nsname.isEmpty()) {
- String nsclass = value.toString();
- if (ns == null) {
- ns = new HashMap<>(functions);
+ } else if (key.startsWith(PRAGMA_JEXLNS)) {
+ // jexl.namespace.***
+ String nsname = key.substring(PRAGMA_JEXLNS.length());
+ if (nsname != null && !nsname.isEmpty()) {
+ String nsclass = value.toString();
+ if (ns == null) {
+ ns = new HashMap<>(functions);
+ }
+ ns.put(nsname, nsclass);
}
- ns.put(nsname, nsclass);
}
}
if (processor != null) {
diff --git a/src/site/xdoc/reference/syntax.xml b/src/site/xdoc/reference/syntax.xml
index 720c5a5..bdae6d7 100644
--- a/src/site/xdoc/reference/syntax.xml
+++ b/src/site/xdoc/reference/syntax.xml
@@ -135,6 +135,18 @@
<p>Although pragmas are statements, they are <em>not</em> evaluated at runtime; they are constants
associated to the script after parsing. It is expected that user code accesses the pragma map from
scripts to alter some functions behavior.</p>
+ <p>The are two built-in pragmas:</p>
+ <p>
+ <b>jexl.options</b> overrides the evaluation options using the option-flags syntax.
+ <code>#pragma jexl.options "+strict -safe +lexical +lexicalShade"</code> will let the script run with
+ the options strict being true, safe false, lexical true and lexical-shade true.</p>
+
+ <p>
+ <b>jexl.namespace.<i>ns_prefix</i></b> declares a namespace valid for the script
+ execution lifetime, the value being the fully-qualified namespace class-name.
+ <code>#pragma jexl.namespace.str java.lang.String</code> declare 'str' as the namespace using
+ the String class.
+ </p>
</td>
</tr>
<tr>