diff options
author | Claude Brisson <cbrisson@apache.org> | 2017-02-20 10:58:58 +0000 |
---|---|---|
committer | Claude Brisson <cbrisson@apache.org> | 2017-02-20 10:58:58 +0000 |
commit | a970dc446c23cfec163226111b98e764df5eb128 (patch) | |
tree | d0438dd4176227d02c5056d03214722bb1069577 /velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeConstants.java | |
parent | 4dc2f90c75f9060f7e6d7add27d6eec650e0e182 (diff) | |
download | apache-velocity-engine-a970dc446c23cfec163226111b98e764df5eb128.tar.gz |
[engine] implements new strategy for reference boolean evaluation
1) return false for a null object
2) return its value for a Boolean object, or the result of the getAsBoolean() method if it exists.
3) If directive.if.emptycheck = false (true by default), stop here and return true.
4) check for emptiness:
- return whether an array is empty.
- return whether isEmpty() is false (covers String and all Collection classes).
- return whether length() is zero (covers CharSequence classes other than String).
- returns whether size() is zero.
- return whether a Number *strictly* equals zero.
5) check for emptiness after explicit conversion methods:
- return whether the result of getAsString() is empty (and false for a null result) if it exists.
- return whether the result of getAsNumber() *strictly* equals zero (and false for a null result) if it exists.
git-svn-id: https://svn.apache.org/repos/asf/velocity/engine/trunk@1783739 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeConstants.java')
-rw-r--r-- | velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeConstants.java | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeConstants.java b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeConstants.java index 2d1b5d91..b85c51f1 100644 --- a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeConstants.java +++ b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeConstants.java @@ -76,6 +76,12 @@ public interface RuntimeConstants String SKIP_INVALID_ITERATOR = "directive.foreach.skip.invalid"; /** + * An empty object (string, collection) or zero number is false. + * @since 2.0 + */ + String CHECK_EMPTY_OBJECTS = "directive.if.emptycheck"; + + /** * Starting tag for error messages triggered by passing a parameter not allowed in the #include directive. Only string literals, * and references are allowed. */ @@ -98,7 +104,7 @@ public interface RuntimeConstants * @since 1.7 */ String PROVIDE_SCOPE_CONTROL = "provide.scope.control"; - + /* * ---------------------------------------------------------------------- * R E S O U R C E M A N A G E R C O N F I G U R A T I O N |