Velocity upgrade to 2.2
Last modified by Vincent Massol on 2021/04/06
After 9 years Velocity finally got a update. You can see a detailed changelog on https://velocity.apache.org/engine/2.2/changes.html but here are the important new things from XWiki script authors:
- Allow expressions inside []: $foo[$bar + 1]
- New strategy for reference boolean evaluation:
- return false for a null object
- return its value for a Boolean object, or the result of the getAsBoolean() method if it exists.
- if directive.if.emptycheck is false (true by default), stop here and return true.
- 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.
- 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.
- Support $array.empty, as for $list.empty
- Fix parsing of $obj._method()
- Have #foreach honnor the Closeable interface on the iterator
- Fix regression: #set<tab>left-paren no longer valid grammar
- Fix parser for '$map{key}' text rendering
- #foreach should work over any Iterable class
- Method arguments can now be expressions
- Fixed quotes escaping so that doubling single quotes only works when enclosing quotes are single quotes (and same behaviour for double quotes)
- Add ability to specify default values for macro parameters, e.g.; #macro(foo bar=1)
- Add ability to place line comments next to macro parameter definitions
- Block directives no longer require parenthesis so #@foo #end is now allowed. Also, brackets now work with Block Macros so #{@foo}bar#end works
- Default block for empty loops: #foreach($i in []) loop block #else empty #end
- Rendering of arrays should display their content, as for lists
- New generic $collectiontool which replaces and enhances the former SortTool
- New generic $logtool