<?xml version="1.0" encoding="UTF-8" standalone="yes"?><extensionVersion xmlns="http://www.xwiki.org/extension"><id>org.xwiki.commons:xwiki-commons-velocity</id><name>XWiki Commons - Velocity</name><type>jar</type><rating><totalVotes>0</totalVotes><averageVote>0.0</averageVote></rating><summary>XWiki Commons - Velocity</summary><description>{{info}}&#13;
You can also check the [[XWiki Platform Developer's Guide&gt;&gt;xwiki:Documentation.DevGuide.Scripting||anchor="HVelocitySpecificInformation"]] for information about Velocity scripting in the XWiki Platform&#13;
{{/info}}&#13;
&#13;
This module offers APIs to evaluate content with Velocity.&#13;
&#13;
The following concepts are exposed:&#13;
&#13;
* ##VelocityManager##: This is the main entry point for anyone who need to manipulate Velocity scripts&#13;
&#13;
* ##VelocityTemplate##: {{version since="15.8"}}This is a helper to manipulate/cache/reuse a "compiled" version of a Velocity script{{/version}}&#13;
* ##VelocityEngine##: This is the object on which you call ##evaluate()##. In XWiki Standard, each skin has an associated ##ScriptEngine##. This allows each Skin to provide its own set of global Velocity macros.&#13;
* ##VelocityConfiguration##: Default Velocity configuration. Sets default configuration parameters and default tools (see below)&#13;
&#13;
* ##VelocityContextFactory##: Allows to create Velocity Context. Context are used when evaluating in order to expose some variable to the script content&#13;
* ##VelocityFactory##: Allows to create several ##VelocityEngine## based on a key you defined. {{version since="15.9"}}Deprecated, used only ##VelocityManager##.{{/version}}&#13;
&#13;
* ##VelocityContextInitializer##: A role to implement when you need to inject Velocity specific binding in the ##VelocityContext##. In most cases, it's recommended to implement ##org.xwiki.script.ScriptContextInitializer## so that the binding you inject is exposed to all scripting languages and not just Velocity.&#13;
&#13;
= Velocity Tools =&#13;
&#13;
For security reasons, we're not exposing some APIs to Velocity scripting (such as Reflection or Threading APIs). In addition, Velocity is a template language and doesn't have the full support a complete development language has (for example, you cannot instantiate new classes). Thus, we need to offer some Tools (i.e. API) that are meant to be used from Velocity to make it easy to create powerful scripts in Velocity code.&#13;
&#13;
The following Velocity tools are made available:&#13;
&#13;
* {{scm project="xwiki-commons" path="xwiki-commons-core/xwiki-commons-legacy/xwiki-commons-legacy-velocity/src/main/java/org/xwiki/velocity/tools/CollectionsTool.java"}}Collections Tool{{/scm}}: **##$collectionstool##** (since 4.0M1 and {{warning}}deprecated since 12.1RC1. Use ##$collectiontool## instead.{{/warning}})&#13;
* [[Comparison Date Tool&gt;&gt;https://github.com/xwiki/xwiki-commons/blob/master/xwiki-commons-core/xwiki-commons-velocity/src/main/java/org/xwiki/velocity/tools/ComparisonDateTool.java]] (extends the standard Velocity [[Comparison Date Tool&gt;&gt;http://velocity.apache.org/tools/3.0/apidocs/org/apache/velocity/tools/generic/ComparisonDateTool.html]], which in turn extends the [[Date Tool&gt;&gt;http://velocity.apache.org/tools/3.0/apidocs/org/apache/velocity/tools/generic/DateTool.html]]): **##$datetool##**&#13;
* [[Escape Tool&gt;&gt;https://github.com/xwiki/xwiki-commons/blob/master/xwiki-commons-core/xwiki-commons-velocity/src/main/java/org/xwiki/velocity/tools/EscapeTool.java]] (extends the standard Velocity [[escape tool&gt;&gt;http://velocity.apache.org/tools/3.0/apidocs/org/apache/velocity/tools/generic/EscapeTool.html]]): **##$escapetool##** (since 2.7RC1)&#13;
* [[JSON Tool&gt;&gt;https://github.com/xwiki/xwiki-commons/blob/master/xwiki-commons-core/xwiki-commons-velocity/src/main/java/org/xwiki/velocity/tools/JSONTool.java]]: **##$jsontool##** (since 4.0M2)&#13;
* [[Math Tool&gt;&gt;http://velocity.apache.org/tools/3.0/apidocs/org/apache/velocity/tools/generic/MathTool.html]]: **##$mathtool##**&#13;
* [[Number Tool&gt;&gt;http://velocity.apache.org/tools/3.0/apidocs/org/apache/velocity/tools/generic/NumberTool.html]]: **##$numbertool##**&#13;
* [[Regex Tool&gt;&gt;https://github.com/xwiki/xwiki-commons/blob/master/xwiki-commons-core/xwiki-commons-velocity/src/main/java/org/xwiki/velocity/tools/RegexTool.java]]: **##$regextool##** (since 2.0RC2)&#13;
* [[Sort Tool&gt;&gt;http://velocity.apache.org/tools/3.0/apidocs/org/apache/velocity/tools/generic/SortTool.html]]: **##$sorttool##** ({{warning}}deprecated since 12.0. Use ##$collectiontool## instead.{{/warning}})&#13;
* [[String Tool&gt;&gt;http://commons.apache.org/proper/commons-lang/apidocs/org/apache/commons/lang3/StringUtils.html]]: **##$stringtool##** (since 3.4M1). Also provides the {{scm project="xwiki-commons" path="xwiki-commons-core/xwiki-commons-text/src/main/java/org/xwiki/text/StringUtils.java"}}following APIs{{/scm}} (since 6.3M1). {{version since="15.7RC1"}}And it provides {{scm project="xwiki-commons" path="xwiki-commons-core/xwiki-commons-velocity/src/main/java/org/xwiki/velocity/tools/StringTool.java"}}the following APIs too.{{/scm}}{{/version}}&#13;
* {{scm project="xwiki-commons" path="xwiki-commons-core/xwiki-commons-velocity/src/main/java/org/xwiki/velocity/tools/URLTool.java"}}URL Tool{{/scm}}: **##$urltool##** allows to parse URL's; currently only a ##parseQuery## method is supported to parse the query string of a given URL (since 6.3M1)&#13;
* [[Exception Tool&gt;&gt;http://commons.apache.org/proper/commons-lang/javadocs/api-3.1/org/apache/commons/lang3/exception/ExceptionUtils.html]]: **##$exceptiontool##** provides useful helpers to manipulate exceptions (get root cause, transform into a String, etc) (since 6.3M1)&#13;
* {{scm project="xwiki-commons" path="xwiki-commons-core/xwiki-commons-velocity/src/main/java/org/xwiki/velocity/tools/nio/NIOTool.java"}}NIO Tool{{/scm}}: **##$niotool##** allows to use some non-dangerous NIO2 API from Velocity (since 7.4M2). Useful along with the [[VFS API&gt;&gt;Extension.VFS API]].&#13;
* [[Log Tool&gt;&gt;http://velocity.apache.org/tools/3.0/apidocs/org/apache/velocity/tools/generic/LogTool.html]]: **##$logtool##** allows logging from Velocity scripts (since 12.0)&#13;
* [[Object Tool&gt;&gt;http://commons.apache.org/proper/commons-lang/apidocs/org/apache/commons/lang3/ObjectUtils.html]]: **##$objecttool##** offer object-related convenience APIs (such as checking for null and more) (since 12.1). Also provides the {{scm project="xwiki-commons" path="xwiki-commons-core/xwiki-commons-velocity/src/main/java/org/xwiki/velocity/tools/ObjectTool.java"}}following APIs{{/scm}}.&#13;
* {{scm project="xwiki-commons" path="xwiki-commons-core/xwiki-commons-velocity/src/main/java/org/xwiki/velocity/tools/CollectionTool.java"}}Collection Tool{{/scm}} (extends [[Velocity's CollectionTool&gt;&gt;https://velocity.apache.org/tools/3.0/apidocs/org/apache/velocity/tools/generic/CollectionTool.html]]): **##$collectiontool##** (since 12.1)&#13;
&#13;
See more available variables at [[XWiki Scripting Reference Documentation&gt;&gt;xwiki:ScriptingDocumentation.WebHome]]&#13;
&#13;
= Velocity Macros =&#13;
&#13;
See [[available Velocity macros&gt;&gt;extensions:Extension.Web Resources for XWiki.WebHome]].&#13;
&#13;
= Velocity Uberspectors =&#13;
&#13;
The introspection behaviour in Velocity can be customized by implementing an uberspector. Velocity supports by default only one uberspector. To overcome this limitation we have implemented an uberspector that forwards all calls to a chain of uberspectors.&#13;
&#13;
== Method Arguments Uberspector ==&#13;
&#13;
A chainable uberspector that tries to convert method arguments to formal parameter types when the passed arguments don't match the method signature. In other words, it looks for a method matching the passed arguments and if none is found then it tries the convert the arguments to match the available method signatures (the available methods with the same name and the same number of parameters but with different parameter types). E.g.:&#13;
&#13;
{{code}}&#13;
$obj.someMethod('VALUE')&#13;
// will forward to&#13;
obj.someMethod(SomeEnum.VALUE)&#13;
// if obj has a method with signature someMethod(SomeEnum) and not someMethod(String)&#13;
{{/code}}&#13;
&#13;
But this is not limited to enums. The conversion is done using the [[Properties Module]] which means you can create and register custom converters for data types specific to your application domain.&#13;
&#13;
{{version since="13.7"}}&#13;
The strategies to select the right method when none exactly matches the passed parameters has been greatly improved:&#13;
* in case of different method name case, give priority to same case&#13;
* calculate a weight based on the compatibility between passed parameters and each method parameters:&#13;
** exact same type worth 10 per argument&#13;
** compatible type (the passed argument can be cast to the method argument type) worth 1 per argument&#13;
*** this includes unboxing (for example ##Boolean## to ##boolean##)&#13;
** two numbers of different types (which is a very common use case) worth 0.5&#13;
* as last resort compare the ##toString()## of each method to make sure the list is always stable across environments to reduce the "it worked on my machine" effect&#13;
{{/version}}&#13;
&#13;
= Velocity Directives =&#13;
&#13;
{{info}}Since 6.3M1{{/info}} XWiki provides a Velocity Directive to catch Exceptions from Velocity.&#13;
&#13;
For example:&#13;
&#13;
{{code language="velocity"}}&#13;
#try()&#13;
   ... velocity code here...&#13;
#end&#13;
...&#13;
  #if ("$!exception" != '')&#13;
    #displayException('some summary to display', $exception)&#13;
  #else&#13;
    ...&#13;
  #end&#13;
...&#13;
{{/code}}&#13;
&#13;
{{version since='8.3M2,7.4.5,8.1.2'}}&#13;
It's possible to name the Velocity variable in which the exception will be saved. For example:&#13;
&#13;
{{code language="velocity"}}&#13;
{{velocity}}&#13;
#try("myexception")&#13;
$services.query.xwql("zzzzz").execute()&#13;
#end&#13;
&#13;
#if ("$!myexception" != '')&#13;
  ... do something...&#13;
#end&#13;
{{/velocity}}&#13;
{{/code}}&#13;
{{/version}}</description><licenses><name>GNU Lesser General Public License 2.1</name></licenses><website>http://extensions.xwiki.org/xwiki/bin/view/Extension/Velocity%20Module</website><authors><name>XWiki Development Team</name><url>https://xwiki.org/xwiki/bin/view/XWiki/XWikiTeam</url></authors><scm><connection><system>git</system><path>git://github.com/xwiki/xwiki-commons.git/xwiki-commons-pom/xwiki-commons-core/xwiki-commons-velocity</path></connection><developerConnection><system>git</system><path>git@github.com:xwiki/xwiki-commons.git/xwiki-commons-pom/xwiki-commons-core/xwiki-commons-velocity</path></developerConnection><url>https://github.com/xwiki/xwiki-commons/tree/master/xwiki-commons-pom/xwiki-commons-core/xwiki-commons-velocity/</url></scm><issueManagement><system>jira</system><url>https://jira.xwiki.org/browse/XCOMMONS</url></issueManagement><recommended>false</recommended><properties><key>maven.groupid</key><stringValue>org.xwiki.commons</stringValue></properties><properties><key>maven.artifactid</key><stringValue>xwiki-commons-velocity</stringValue></properties><properties><key>maven.Model</key><stringValue>org.xwiki.commons:xwiki-commons-velocity:jar:18.6.0</stringValue></properties><properties><key>xwiki.extension.recommendedVersions.commons</key><stringValue>org.xwiki.commons:.*/[18.6.0]</stringValue></properties><properties><key>xwiki.extension.recommendedVersions</key><stringValue>${xwiki.extension.recommendedVersion.commons}</stringValue></properties><version>4.2-milestone-3</version><repositories><id>maven-xwiki</id><uri>https://nexus.xwiki.org/nexus/content/groups/public</uri><type>maven</type></repositories></extensionVersion>