You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@velocity.apache.org by nb...@apache.org on 2008/08/14 23:23:50 UTC

svn commit: r686045 - in /velocity/engine/trunk/xdocs/docs: developer-guide.xml user-guide.xml

Author: nbubna
Date: Thu Aug 14 14:23:50 2008
New Revision: 686045

URL: http://svn.apache.org/viewvc?rev=686045&view=rev
Log:
VELOCITY-602 document new method tricks in 1.6

Modified:
    velocity/engine/trunk/xdocs/docs/developer-guide.xml
    velocity/engine/trunk/xdocs/docs/user-guide.xml

Modified: velocity/engine/trunk/xdocs/docs/developer-guide.xml
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/xdocs/docs/developer-guide.xml?rev=686045&r1=686044&r2=686045&view=diff
==============================================================================
--- velocity/engine/trunk/xdocs/docs/developer-guide.xml (original)
+++ velocity/engine/trunk/xdocs/docs/developer-guide.xml Thu Aug 14 14:23:50 2008
@@ -568,7 +568,11 @@
 <li> <code>Object [] </code>  Regular object array, not much needs to be said
 here. Velocity will internally wrap your array in a class that provides an
 Iterator interface,  but that shouldn't concern you as the programmer, or the
-template author.
+template author.  Of more interest, is the fact that Velocity will now
+allow template authors to treat arrays as fixed-length lists (as of Velocity 1.6). 
+This means they may call methods like <code>size()</code>,
+<code>isEmpty()</code> and <code>get(int)</code> on both arrays and standard
+java.util.List instances without concerning themselves about the difference.
 </li>
 
 <li> <code>java.util.Collection</code>  Velocity will use the

Modified: velocity/engine/trunk/xdocs/docs/user-guide.xml
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/xdocs/docs/user-guide.xml?rev=686045&r1=686044&r2=686045&view=diff
==============================================================================
--- velocity/engine/trunk/xdocs/docs/user-guide.xml (original)
+++ velocity/engine/trunk/xdocs/docs/user-guide.xml Thu Aug 14 14:23:50 2008
@@ -538,7 +538,41 @@
 ## Velocity assumes I mean $sisyphus.getRock()
 
 $book.setTitle( "Homage to Catalonia" )
-## Can't pass a parameter list
+## Can't pass a parameter
+]]></source>
+
+  <p>
+    As of Velocity 1.6, all array references are now "magically" treated as if
+    they are fixed-length lists.  This means that you can call java.util.List methods
+    on array references.  So, if you have a reference to an array (let's say
+    this one is a String[] with three values), you can do:
+  </p>
+
+<source><![CDATA[
+$myarray.isEmpty()
+
+$myarray.size()
+
+$myarray.get(2)
+
+$myarray.set(1, 'test')
+]]></source>
+
+  <p>
+    Also new in Velocity 1.6 is support for vararg methods. A method like
+    <code>public void setPlanets(String... planets)</code> or even just
+    <code>public void setPlanets(String[] planets)</code> (if you are
+    using a pre-Java 5 JDK), can now accept
+    any number of arguments when called in a template.
+  </p>
+
+<source><![CDATA[
+$sun.setPlanets('Earth', 'Mars', 'Neptune')
+
+$sun.setPlanets('Mercury')
+
+$sun.setPlanets()
+## Will just pass in an empty, zero-length array
 ]]></source>
 
  <p>