Modified: velocity/site/production/engine/devel/vtl-reference.html URL: http://svn.apache.org/viewvc/velocity/site/production/engine/devel/vtl-reference.html?rev=1834410&r1=1834409&r2=1834410&view=diff ============================================================================== --- velocity/site/production/engine/devel/vtl-reference.html (original) +++ velocity/site/production/engine/devel/vtl-reference.html Tue Jun 26 10:03:18 2018 @@ -400,17 +400,17 @@ h2:hover > .headerlink, h3:hover > .head <li>Range operator: <code>#foreach ( $item in [1..3] )</code></li> </ul> <p>Velocity provides an easy way to get the loop counter so that you can do something like the following:</p> -<div class="codehilite"><pre><span class="nt"><table></span> -#foreach( $customer in $customerList ) - <span class="nt"><tr><td></span>$foreach.count<span class="nt"></td><td></span>$customer.Name<span class="nt"></td></tr></span> -#end -<span class="nt"></table></span> +<div class="codehilite"><pre><span class="p"><</span><span class="nt">table</span><span class="p">></span> +<span class="cp">#</span><span class="nf">foreach</span><span class="p">(</span> <span class="p">$</span><span class="nv">customer</span> <span class="o">in</span> <span class="p">$</span><span class="nv">customerList</span> <span class="p">)</span> + <span class="p"><</span><span class="nt">tr</span><span class="p">><</span><span class="nt">td</span><span class="p">>$</span><span class="nv">foreach</span><span class="p">.</span><span class="nv">count</span><span class="p"></</span><span class="nt">td</span><span class="p">><</span><span class="nt">td</span><span class="p">>$</span><span class="nv">customer</span><span class="p">.</span><span class="nv">Name</span><span class="p"></</span><span class="nt">td</span><span class="p">></</span><span class="nt">tr</span><span class="p">></span> +<span class="cp">#</span><span class="nf">end</span> +<span class="p"></</span><span class="nt">table</span><span class="p">></span> </pre></div> -<p>Additionally, the maximum allowed number of loop iterations can be controlled engine-wide (an ability introduced in Velocity 1.5). By default, there is no limit:</p> -<div class="codehilite"><pre># The maximum allowed number of loops. -directive.foreach.maxloops = -1 +<p>Additionally, the maximum allowed number of loop iterations can be controlled engine-wide with <code>velocity.properties</code>. By default, there is no limit:</p> +<div class="codehilite"><pre><span class="c"># The maximum allowed number of loops.</span> +<span class="na">directive.foreach.maxloops</span> <span class="o">=</span> <span class="s">-1</span> </pre></div> @@ -484,12 +484,12 @@ directive.foreach.maxloops = -1 <li><em>[ VM VTL code... ]</em> - Any valid VTL code, anything you can put into a template, can be put into a VM.</li> </ul> <p>Once defined, the VM is used like any other VTL directive in a template.</p> -<div class="codehilite"><pre>#vmname( $arg1 $arg2 ) +<div class="codehilite"><pre><span class="cp">#</span><span class="nf">vmname</span><span class="p">(</span> <span class="p">$</span><span class="nv">arg1</span> <span class="p">$</span><span class="nv">arg2</span> <span class="p">)</span><span class="x"></span> </pre></div> <p><strong>Except</strong>, that when you wish to call a VM with a body, then you must prefix the name of the VM with @. The content of that body may be referenced in the macro definition via $!bodyContent as many or few times as you like.</p> -<div class="codehilite"><pre>#@vmname( $arg1 $arg2 ) here is the body#end +<div class="codehilite"><pre><span class="err">#</span><span class="x">@vmname( </span><span class="p">$</span><span class="nv">arg1</span><span class="x"> </span><span class="p">$</span><span class="nv">arg2</span><span class="x"> ) here is the body</span><span class="cp">#</span><span class="nf">end</span><span class="x"></span> </pre></div> @@ -502,31 +502,31 @@ directive.foreach.maxloops = -1 <p>Comments are not rendered at runtime.</p> <h3 id="single-line-comments">Single Line Comments<a class="headerlink" href="#single-line-comments" title="Permanent link">¶</a></h3> <p>Example:</p> -<div class="codehilite"><pre>## This is a comment.** +<div class="codehilite"><pre><span class="cp">##</span><span class="c"> This is a comment.**</span><span class="x"></span> </pre></div> <h3 id="multi-line-comments">Multi Line Comments<a class="headerlink" href="#multi-line-comments" title="Permanent link">¶</a></h3> <p>Example:</p> -<div class="codehilite"><pre>#** - This is a multiline comment. - This is the second line. -*# +<div class="codehilite"><pre><span class="cp">#</span><span class="c">**</span> +<span class="c"> This is a multiline comment.</span> +<span class="c"> This is the second line.</span> +<span class="c">*</span><span class="cp">#</span><span class="x"></span> </pre></div> <h2 id="unparsed-content">Unparsed Content<a class="headerlink" href="#unparsed-content" title="Permanent link">¶</a></h2> <p>Unparsed content is rendered at runtime, but is not parsed or interpreted.</p> <p>Example:</p> -<div class="codehilite"><pre>#[[ +<div class="codehilite"><pre><span class="err">#</span><span class="x">[[</span> -This has invalid syntax that would normally need -"poor man's escaping" like: +<span class="x">This has invalid syntax that would normally need </span> +<span class="x">"poor man's escaping" like:</span> - - #define() - - ${blah +<span class="x"> - </span><span class="cp">#</span><span class="nf">define</span><span class="p">()</span><span class="x"></span> +<span class="x"> - </span><span class="p">${</span><span class="nv">blah</span><span class="x"></span> -]]# +<span class="x">]]</span><span class="err">#</span><span class="x"></span> </pre></div></div></div> <hr/> <div id="copyright">
Modified: velocity/site/production/engine/devel/webapps.html URL: http://svn.apache.org/viewvc/velocity/site/production/engine/devel/webapps.html?rev=1834410&r1=1834409&r2=1834410&view=diff ============================================================================== --- velocity/site/production/engine/devel/webapps.html (original) +++ velocity/site/production/engine/devel/webapps.html Tue Jun 26 10:03:18 2018 @@ -249,33 +249,33 @@ providing a consistent way to mark up te <p>Really, any of the other ResourceLoader implementations out there are preferred, but all the other ResourceLoaders shipped with Velocity Engine will require you to store your templates somewhere besides the standard file system (e.g. in the classpath, in a database, or on a remote server). If that works for you, then great! However, we recognize that these are not convenient for most people's development cycle.</p> <p>The simplest replacement for FileResourceLoader in a web application is actually a part of the VelocityTools project. It is the <a href="/tools/devel/apidocs/org/apache/velocity/tools/view/WebappResourceLoader.html">WebappResourceLoader</a> This ResourceLoader implementation is specifically designed to work just like the FileResourceLoader, but it is aware of the servlet context and allows you to configure resource paths relative to the servlet root, rather than the local file system.</p> <p>If you are using the VelocityViewServlet, then it is automatically configured and ready to use the WebappResourceLoader. So if you want to change the configured path(s), you need only add a line like the following to your velocity.properties:</p> -<div class="codehilite"><pre>webapp.resource.loader.path=/WEB-INF/mytemplates/ +<div class="codehilite"><pre><span class="na">webapp.resource.loader.path</span><span class="o">=</span><span class="s">/WEB-INF/mytemplates/</span> </pre></div> <p>If you need to set the WebappResourceLoader up on your own, then you can make your properties something like this:</p> -<div class="codehilite"><pre>resource.loader=webapp -webapp.resource.loader.class=org.apache.velocity.tools.view.WebappResourceLoader -webapp.resource.loader.path=/WEB-INF/mytemplates/ +<div class="codehilite"><pre><span class="na">resource.loader</span><span class="o">=</span><span class="s">webapp</span> +<span class="na">webapp.resource.loader.class</span><span class="o">=</span><span class="s">org.apache.velocity.tools.view.WebappResourceLoader</span> +<span class="na">webapp.resource.loader.path</span><span class="o">=</span><span class="s">/WEB-INF/mytemplates/</span> </pre></div> <p>You will <strong>also need to put the ServletContext into your VelocityEngine's application attributes</strong> before initializing that Engine. This is how the WebappResourceLoader knows how to find templates.</p> -<div class="codehilite"><pre>myVelocityEngine.setApplicationAttribute("javax.servlet.ServletContext", servletContext); +<div class="codehilite"><pre><span class="n">myVelocityEngine</span><span class="o">.</span><span class="na">setApplicationAttribute</span><span class="o">(</span><span class="s">"javax.servlet.ServletContext"</span><span class="o">,</span> <span class="n">servletContext</span><span class="o">);</span> </pre></div> <h3 id="changing-object-state-dont">Changing Object State - Don't!<a class="headerlink" href="#changing-object-state-dont" title="Permanent link">¶</a></h3> <p>Velocity provides the ability to call any method of an object acting as a reference. This can be useful when displaying information into the page but is dangerous when object or application state is modified.</p> <p>For example, the following code safely calls the size() method of a list and displays the result.</p> -<div class="codehilite"><pre>There are $users.size() currently logged in. +<div class="codehilite"><pre><span class="x">There are </span><span class="p">$</span><span class="nv">users</span><span class="p">.</span><span class="nv">size</span><span class="p">()</span><span class="x"> currently logged in.</span> </pre></div> <p>An example of an unsafe operation concerns a financial web page with an object in the context that calculates data year by year. The method calculateNextYear() calculates data for the next year and advances an internal counter:</p> -<div class="codehilite"><pre>2005 data: $table.data -$table.calculateNextYear() -2006 data: $table.data +<div class="codehilite"><pre><span class="x">2005 data: </span><span class="p">$</span><span class="nv">table</span><span class="p">.</span><span class="nv">data</span><span class="x"></span> +<span class="p">$</span><span class="nv">table</span><span class="p">.</span><span class="nv">calculateNextYear</span><span class="p">()</span><span class="x"></span> +<span class="x">2006 data: </span><span class="p">$</span><span class="nv">table</span><span class="p">.</span><span class="nv">data</span><span class="x"></span> </pre></div> @@ -286,15 +286,15 @@ $table.calculateNextYear() <h3 id="escaping-htmlxml-entities">Escaping HTML/XML Entities<a class="headerlink" href="#escaping-htmlxml-entities" title="Permanent link">¶</a></h3> <p>Any user-entered text that contains special HTML or XML entities (such as <, >, or &) needs to be escaped before included in the web page. This is required, both to ensure the text is visible, and also to prevent dangerous <a href="http://en.wikipedia.org/wiki/Cross_site_scripting">cross-site scripting</a>. Unlike, for example, JSTL (the Java Standard Tag Language found in Java Server Pages), Velocity does not escape references by default.</p> <p>However, Velocity provides the ability to specify a <code>ReferenceInsertionEventHandler</code> which will alter the value of a reference before it is inserted into the page. Specifically, you can configure the <code>EscapeHtmlReference</code> handler into your <code>velocity.properties</code> file to escape all references (optionally) matching a regular expression. The following example will escape HTML entities in any reference that starts with "msg" (e.g. <code>$msgText</code>).</p> -<div class="codehilite"><pre>eventhandler.referenceinsertion.class = org.apache.velocity.app.event.implement.EscapeHtmlReference -eventhandler.escape.html.match = /msg.*/ +<div class="codehilite"><pre><span class="na">eventhandler.referenceinsertion.class</span> <span class="o">=</span> <span class="s">org.apache.velocity.app.event.implement.EscapeHtmlReference</span> +<span class="na">eventhandler.escape.html.match</span> <span class="o">=</span> <span class="s">/msg.*/</span> </pre></div> <p>Note that other kinds of escaping are sometimes required. For example, in style sheets the @ character needs to be escaped, and in Javascript strings the single apostrophe ' needs to be escaped.</p> <h3 id="securing-the-application">Securing the Application<a class="headerlink" href="#securing-the-application" title="Permanent link">¶</a></h3> <p>Since a web application is running on a central server, that typically has multiple users and confidential resources, care must be taken to make certain that the web application is secure. Most standard web security principles apply to a web application built with Velocity. A few specific issues (such as system configuration, more on cross-site scripting, and method introspection) are written up in this article on <a href="http://wiki.apache.org/velocity/BuildingSecureWebApplications">Building Secure Applications with Velocity</a>. In particular, you may want to prevent template designers from including "dangerous" reflection-related methods by specifying the <code>SecureUberspector</code> to get/set properties and execute method calls.</p> -<div class="codehilite"><pre>runtime.introspector.uberspect = org.apache.velocity.util.introspection.SecureUberspector +<div class="codehilite"><pre><span class="na">runtime.introspector.uberspect</span> <span class="o">=</span> <span class="s">org.apache.velocity.util.introspection.SecureUberspector</span> </pre></div> @@ -317,7 +317,8 @@ eventhandler.escape.html.match = /msg.*/ </li> </ol> <p>3.Take a look at the "examples" directory. You will see a file "index.vm". Here's an excerpt:</p> -<div class="codehilite"><pre> <span class="nt"><html></span> +<div class="codehilite"><pre> :::html+velocity + <span class="nt"><html></span> <span class="nt"><body></span> I'm a velocity template. @@ -342,7 +343,8 @@ eventhandler.escape.html.match = /msg.*/ <p>You can copy any additional velocity files into this same directory. In <code>examples/WEB-INF</code> you will see a file "tools.xml". This specifies a list of "Tools" that are automatically included in the context.</p> -<div class="codehilite"><pre> <span class="nt"><tools></span> +<div class="codehilite"><pre> :::xml + <span class="nt"><tools></span> <span class="nt"><data</span> <span class="na">type=</span><span class="s">"boolean"</span> <span class="na">key=</span><span class="s">"xhtml"</span> <span class="na">value=</span><span class="s">"true"</span><span class="nt">/></span> <span class="nt"><data</span> <span class="na">type=</span><span class="s">"boolean"</span> <span class="na">key=</span><span class="s">"isSimple"</span> <span class="na">value=</span><span class="s">"true"</span><span class="nt">/></span> <span class="nt"><data</span> <span class="na">type=</span><span class="s">"number"</span> <span class="na">key=</span><span class="s">"version"</span> <span class="na">value=</span><span class="s">"2.0"</span><span class="nt">/></span> @@ -359,7 +361,8 @@ eventhandler.escape.html.match = /msg.*/ <p>And finally the web.xml file specifies the name of the servlet and location of toolbox.properties.</p> -<div class="codehilite"><pre> <span class="nt"><web-app></span> +<div class="codehilite"><pre> :::xml + <span class="nt"><web-app></span> <span class="nt"><servlet></span> <span class="nt"><servlet-name></span>velocity<span class="nt"></servlet-name></span> <span class="nt"><servlet-class></span>org.apache.velocity.tools.view.VelocityViewServlet<span class="nt"></servlet-class></span> Modified: velocity/site/production/tools/2.0/config-java.html URL: http://svn.apache.org/viewvc/velocity/site/production/tools/2.0/config-java.html?rev=1834410&r1=1834409&r2=1834410&view=diff ============================================================================== --- velocity/site/production/tools/2.0/config-java.html (original) +++ velocity/site/production/tools/2.0/config-java.html Tue Jun 26 10:03:18 2018 @@ -216,23 +216,23 @@ h2:hover > .headerlink, h3:hover > .head h2:hover > .headerlink, h3:hover > .headerlink, h1:hover > .headerlink, h6:hover > .headerlink, h4:hover > .headerlink, h5:hover > .headerlink, dt:hover > .elementid-permalink { visibility: visible }</style> <h2 id="configuration-using-java">Configuration using Java<a class="headerlink" href="#configuration-using-java" title="Permanent link">¶</a></h2> <p>As of VelocityTools 2, its no longer merely possible to configure things purely via Java, it is now much easier to do and can be done in several different ways. Here again, is an example that is equivalent to those demonstrated in the <a href="config-properties.html">properties</a> and <a href="config-xml.html">XML</a> configurations:</p> -<div class="codehilite"><pre>EasyFactoryConfiguration config = new EasyFactoryConfiguration(); -config.toolbox("request").property("xhtml", true) -.tool("toytool", ToyTool.class).restrictTo("index.vm") -.tool("custom", CustomTool.class).property("randomProperty", "whatever"); -config.toolbox("session").property("create-session", true) -.tool("map", HashMap.class); -config.toolbox("application") -.tool(DateTool.class); -config.number("version", 1.1); -config.data("date", "Mon Sep 17 10:08:03 PDT 2007") -.target(Date.class) -.converter(DateLocaleConverter.class); -config.bool("isSimple", true); -config.string("foo", "this is foo."); -config.string("bar", "this is bar."); -config.data("dataKeys", "list", "version,date,isSimple,foo,bar,dataKeys,switches"); -config.data("switches", "list.boolean", "true,false,false,true"); +<div class="codehilite"><pre><span class="n">EasyFactoryConfiguration</span> <span class="n">config</span> <span class="o">=</span> <span class="k">new</span> <span class="n">EasyFactoryConfiguration</span><span class="o">();</span> +<span class="n">config</span><span class="o">.</span><span class="na">toolbox</span><span class="o">(</span><span class="s">"request"</span><span class="o">).</span><span class="na">property</span><span class="o">(</span><span class="s">"xhtml"</span><span class="o">,</span> <span class="kc">true</span><span class="o">)</span> +<span class="o">.</span><span class="na">tool</span><span class="o">(</span><span class="s">"toytool"</span><span class="o">,</span> <span class="n">ToyTool</span><span class="o">.</span><span class="na">class</span><span class="o">).</span><span class="na">restrictTo</span><span class="o">(</span><span class="s">"index.vm"</span><span class="o">)</span> +<span class="o">.</span><span class="na">tool</span><span class="o">(</span><span class="s">"custom"</span><span class="o">,</span> <span class="n">CustomTool</span><span class="o">.</span><span class="na">class</span><span class="o">).</span><span class="na">property</span><span class="o">(</span><span class="s">"randomProperty"</span><span class="o">,</span> <span class="s">"whatever"</span><span class="o">);</span> +<span class="n">config</span><span class="o">.</span><span class="na">toolbox</span><span class="o">(</span><span class="s">"session"</span><span class="o">).</span><span class="na">property</span><span class="o">(</span><span class="s">"create-session"</span><span class="o">,</span> <span class="kc">true</span><span class="o">)</span> +<span class="o">.</span><span class="na">tool</span><span class="o">(</span><span class="s">"map"</span><span class="o">,</span> <span class="n">HashMap</span><span class="o">.</span><span class="na">class</span><span class="o">);</span> +<span class="n">config</span><span class="o">.</span><span class="na">toolbox</span><span class="o">(</span><span class="s">"application"</span><span class="o">)</span> +<span class="o">.</span><span class="na">tool</span><span class="o">(</span><span class="n">DateTool</span><span class="o">.</span><span class="na">class</span><span class="o">);</span> +<span class="n">config</span><span class="o">.</span><span class="na">number</span><span class="o">(</span><span class="s">"version"</span><span class="o">,</span> <span class="mf">1.1</span><span class="o">);</span> +<span class="n">config</span><span class="o">.</span><span class="na">data</span><span class="o">(</span><span class="s">"date"</span><span class="o">,</span> <span class="s">"Mon Sep 17 10:08:03 PDT 2007"</span><span class="o">)</span> +<span class="o">.</span><span class="na">target</span><span class="o">(</span><span class="n">Date</span><span class="o">.</span><span class="na">class</span><span class="o">)</span> +<span class="o">.</span><span class="na">converter</span><span class="o">(</span><span class="n">DateLocaleConverter</span><span class="o">.</span><span class="na">class</span><span class="o">);</span> +<span class="n">config</span><span class="o">.</span><span class="na">bool</span><span class="o">(</span><span class="s">"isSimple"</span><span class="o">,</span> <span class="kc">true</span><span class="o">);</span> +<span class="n">config</span><span class="o">.</span><span class="na">string</span><span class="o">(</span><span class="s">"foo"</span><span class="o">,</span> <span class="s">"this is foo."</span><span class="o">);</span> +<span class="n">config</span><span class="o">.</span><span class="na">string</span><span class="o">(</span><span class="s">"bar"</span><span class="o">,</span> <span class="s">"this is bar."</span><span class="o">);</span> +<span class="n">config</span><span class="o">.</span><span class="na">data</span><span class="o">(</span><span class="s">"dataKeys"</span><span class="o">,</span> <span class="s">"list"</span><span class="o">,</span> <span class="s">"version,date,isSimple,foo,bar,dataKeys,switches"</span><span class="o">);</span> +<span class="n">config</span><span class="o">.</span><span class="na">data</span><span class="o">(</span><span class="s">"switches"</span><span class="o">,</span> <span class="s">"list.boolean"</span><span class="o">,</span> <span class="s">"true,false,false,true"</span><span class="o">);</span> </pre></div> Modified: velocity/site/production/tools/2.0/config-properties.html URL: http://svn.apache.org/viewvc/velocity/site/production/tools/2.0/config-properties.html?rev=1834410&r1=1834409&r2=1834410&view=diff ============================================================================== --- velocity/site/production/tools/2.0/config-properties.html (original) +++ velocity/site/production/tools/2.0/config-properties.html Tue Jun 26 10:03:18 2018 @@ -216,33 +216,33 @@ h2:hover > .headerlink, h3:hover > .head h2:hover > .headerlink, h3:hover > .headerlink, h1:hover > .headerlink, h6:hover > .headerlink, h4:hover > .headerlink, h5:hover > .headerlink, dt:hover > .elementid-permalink { visibility: visible }</style> <h2 id="configuration-using-properties">Configuration using Properties<a class="headerlink" href="#configuration-using-properties" title="Permanent link">¶</a></h2> <p>VelocityTools 2 can be configured using a properties file. Here's the same configuration as the <a href="config-xml.html">XML</a> and <a href="config-java.html">Java</a> examples in the properties format:</p> -<div class="codehilite"><pre>tools.toolbox = request,session,application +<div class="codehilite"><pre><span class="na">tools.toolbox</span> <span class="o">=</span> <span class="s">request,session,application</span> -tools.request.property.xhtml = true -tools.request.toytool = ToyTool -tools.request.toytool.restrictTo = index.vm -tools.request.custom = org.mine.CustomTool -tools.request.custom.randomProperty = whatever +<span class="na">tools.request.property.xhtml</span> <span class="o">=</span> <span class="s">true</span> +<span class="na">tools.request.toytool</span> <span class="o">=</span> <span class="s">ToyTool</span> +<span class="na">tools.request.toytool.restrictTo</span> <span class="o">=</span> <span class="s">index.vm</span> +<span class="na">tools.request.custom</span> <span class="o">=</span> <span class="s">org.mine.CustomTool</span> +<span class="na">tools.request.custom.randomProperty</span> <span class="o">=</span> <span class="s">whatever</span> -tools.session.property.create-session = true -tools.session.property.create-session.type = boolean -tools.session.map = java.util.HashMap +<span class="na">tools.session.property.create-session</span> <span class="o">=</span> <span class="s">true</span> +<span class="na">tools.session.property.create-session.type</span> <span class="o">=</span> <span class="s">boolean</span> +<span class="na">tools.session.map</span> <span class="o">=</span> <span class="s">java.util.HashMap</span> -tools.application.date = org.apache.velocity.tools.generic.DateTool +<span class="na">tools.application.date</span> <span class="o">=</span> <span class="s">org.apache.velocity.tools.generic.DateTool</span> -tools.data.version = 1.1 -tools.data.version.type = number -tools.data.date = Mon Sep 17 10:08:03 PDT 2007 -tools.data.date.class = java.util.Date -tools.data.date.converter = org.apache.commons.beanutils.locale.converters.DateLocaleConverter -tools.data.isSimple = true -tools.data.type = boolean -tools.data.foo = this is foo. -tools.data.bar = this is bar. -tools.data.dataKeys = version,date,isSimple.foo,bar,dataKeys,switches -tools.data.dataKeys.type = list -tools.data.switches = true,false,false,true -tools.data.switches.type = list.boolean +<span class="na">tools.data.version</span> <span class="o">=</span> <span class="s">1.1</span> +<span class="na">tools.data.version.type</span> <span class="o">=</span> <span class="s">number</span> +<span class="na">tools.data.date</span> <span class="o">=</span> <span class="s">Mon Sep 17 10:08:03 PDT 2007</span> +<span class="na">tools.data.date.class</span> <span class="o">=</span> <span class="s">java.util.Date</span> +<span class="na">tools.data.date.converter</span> <span class="o">=</span> <span class="s">org.apache.commons.beanutils.locale.converters.DateLocaleConverter</span> +<span class="na">tools.data.isSimple</span> <span class="o">=</span> <span class="s">true</span> +<span class="na">tools.data.type</span> <span class="o">=</span> <span class="s">boolean</span> +<span class="na">tools.data.foo</span> <span class="o">=</span> <span class="s">this is foo.</span> +<span class="na">tools.data.bar</span> <span class="o">=</span> <span class="s">this is bar.</span> +<span class="na">tools.data.dataKeys</span> <span class="o">=</span> <span class="s">version,date,isSimple.foo,bar,dataKeys,switches</span> +<span class="na">tools.data.dataKeys.type</span> <span class="o">=</span> <span class="s">list</span> +<span class="na">tools.data.switches</span> <span class="o">=</span> <span class="s">true,false,false,true</span> +<span class="na">tools.data.switches.type</span> <span class="o">=</span> <span class="s">list.boolean</span> </pre></div></div></div> <hr/> <div id="copyright"> Modified: velocity/site/production/tools/2.0/creating-tools.html URL: http://svn.apache.org/viewvc/velocity/site/production/tools/2.0/creating-tools.html?rev=1834410&r1=1834409&r2=1834410&view=diff ============================================================================== --- velocity/site/production/tools/2.0/creating-tools.html (original) +++ velocity/site/production/tools/2.0/creating-tools.html Tue Jun 26 10:03:18 2018 @@ -251,14 +251,14 @@ h2:hover > .headerlink, h3:hover > .head <h3 id="tool-keysnames">Tool Keys/Names<a class="headerlink" href="#tool-keysnames" title="Permanent link">¶</a></h3> <p>As of VelocityTools 2, the toolbox support can now automatically determine the key name for a tool from its classname. So, a tool named org.com.FooTool would be assigned the key $foo in your templates, tool named org.com.FooBarTool would be $fooBar, and a tool named org.com.FooBar would be also be $fooBar.</p> <p>If you would prefer to give your org.com.FooBar tool the key $foob, you can use the <code>org.apache.velocity.tools.config.DefaultKey</code> annotation like this:</p> -<div class="codehilite"><pre><span class="n">package</span> <span class="n">org</span><span class="o">.</span><span class="n">com</span><span class="p">;</span> +<div class="codehilite"><pre><span class="kn">package</span> <span class="nn">org.com</span><span class="o">;</span> -<span class="kn">import</span> <span class="nn">org.apache.velocity.tools.config.DefaultKey</span><span class="p">;</span> +<span class="kn">import</span> <span class="nn">org.apache.velocity.tools.config.DefaultKey</span><span class="o">;</span> -<span class="nd">@DefaultKey</span><span class="p">(</span><span class="s2">"foob"</span><span class="p">)</span> -<span class="n">public</span> <span class="k">class</span> <span class="nc">FooBar</span> <span class="p">{</span> +<span class="nd">@DefaultKey</span><span class="o">(</span><span class="s">"foob"</span><span class="o">)</span> +<span class="kd">public</span> <span class="kd">class</span> <span class="nc">FooBar</span> <span class="o">{</span> <span class="o">...</span> -<span class="p">}</span> +<span class="o">}</span> </pre></div> @@ -296,11 +296,11 @@ h2:hover > .headerlink, h3:hover > .head <p>There are three Annotations provided for tool authors: <a href="apidocs/org/apache/velocity/tools/config/DefaultKey.html">DefaultKey</a>, <a href="apidocs/org/apache/velocity/tools/config/InvalidScope.html">InvalidScope</a> and <a href="apidocs/org/apache/velocity/tools/config/ValidScope.html">ValidScope</a>.</p> <p>As described above, the @DefaultKey annotation is used to specify a default key for your tool. The @InvalidScope and @ValidScope annotations allow you to restrict the <a href="apidocs/org/apache/velocity/tools/Scope.html">Scope</a>(s) in which the tool can be used in either negative or positive terms. When described positively using the @ValidScope annotation, the tool may <strong>only</strong> be used in a toolbox with the specified scope. If placed in any other toolbox, an <code>org.apache.velocity.tools.config.InvalidScopeException</code> will be thrown. Using @InvalidScope, on the other hand, allows you reject specific scope(s), whilst implicitly allowing any others.</p> <p>Here's a scope annotation example:</p> -<div class="codehilite"><pre>@InvalidScope({Scope.APPLICATION,Scope.SESSION}) -public class PagerTool -{ - ... -} +<div class="codehilite"><pre><span class="nd">@InvalidScope</span><span class="o">({</span><span class="n">Scope</span><span class="o">.</span><span class="na">APPLICATION</span><span class="o">,</span><span class="n">Scope</span><span class="o">.</span><span class="na">SESSION</span><span class="o">})</span> +<span class="kd">public</span> <span class="kd">class</span> <span class="nc">PagerTool</span> +<span class="o">{</span> + <span class="o">...</span> +<span class="o">}</span> </pre></div> @@ -324,7 +324,7 @@ public class PagerTool </ul> <h3 id="be-robust">Be Robust<a class="headerlink" href="#be-robust" title="Permanent link">¶</a></h3> <p>Always return null on errors! No Exceptions! Ok, maybe there are some exceptions if you are sure that's what you want your tool to do. Just be aware that this will likely surprise the user because uncaught exceptions halt template processing at the point the exception is thrown. If the output of the template is not buffered, this will result in an awkward, partial rendering. So, if you are going to let an exception through, make sure it is worth halting everything for. Often it is sufficient to return null, thus allowing the failed reference to appear in the output like this:</p> -<div class="codehilite"><pre>$mytool.somemethod('bad input') +<div class="codehilite"><pre><span class="p">$</span><span class="nv">mytool</span><span class="p">.</span><span class="nv">somemethod</span><span class="p">(</span><span class="s1">'bad input'</span><span class="p">)</span><span class="x"></span> </pre></div> Modified: velocity/site/production/tools/2.0/standalone.html URL: http://svn.apache.org/viewvc/velocity/site/production/tools/2.0/standalone.html?rev=1834410&r1=1834409&r2=1834410&view=diff ============================================================================== --- velocity/site/production/tools/2.0/standalone.html (original) +++ velocity/site/production/tools/2.0/standalone.html Tue Jun 26 10:03:18 2018 @@ -218,10 +218,10 @@ h2:hover > .headerlink, h3:hover > .head <p>There's nothing particularly special about the tools in VelocityTools 2. No special interfaces, most don't ''need'' any configuration or API access, and those that do are now relatively easy to handle (compared to VelocityTools 1.x). So, if you need a tool, just create an instance, do any configuration you want or need and go. Nothing else to it.</p> <h2 id="toolmanager">ToolManager<a class="headerlink" href="#toolmanager" title="Permanent link">¶</a></h2> <p>However, if you want to externalize your configuration or have your tools created and configured for you on demand and you are not working in a servlet environment, then we have created a simple ToolManager that you can use. It's relatively simple. Just create a ToolManager (can be created with or without default tools available), configure it (if you want to), ask it to create a context for you, and use the context as you would any other. Of course, there's more to it, but this should get you started:</p> -<div class="codehilite"><pre>ToolManager manager = new ToolManager(); -manager.configure("/path/to/my/configuration.xml"); -Context context = manager.createContext(); -myVelocityEngine.evaluate(context, myOutputWriter, "This is a $text.test", "Test template"); +<div class="codehilite"><pre><span class="n">ToolManager</span> <span class="n">manager</span> <span class="o">=</span> <span class="k">new</span> <span class="n">ToolManager</span><span class="o">();</span> +<span class="n">manager</span><span class="o">.</span><span class="na">configure</span><span class="o">(</span><span class="s">"/path/to/my/configuration.xml"</span><span class="o">);</span> +<span class="n">Context</span> <span class="n">context</span> <span class="o">=</span> <span class="n">manager</span><span class="o">.</span><span class="na">createContext</span><span class="o">();</span> +<span class="n">myVelocityEngine</span><span class="o">.</span><span class="na">evaluate</span><span class="o">(</span><span class="n">context</span><span class="o">,</span> <span class="n">myOutputWriter</span><span class="o">,</span> <span class="s">"This is a $text.test"</span><span class="o">,</span> <span class="s">"Test template"</span><span class="o">);</span> </pre></div> Modified: velocity/site/production/tools/2.0/view-layoutservlet.html URL: http://svn.apache.org/viewvc/velocity/site/production/tools/2.0/view-layoutservlet.html?rev=1834410&r1=1834409&r2=1834410&view=diff ============================================================================== --- velocity/site/production/tools/2.0/view-layoutservlet.html (original) +++ velocity/site/production/tools/2.0/view-layoutservlet.html Tue Jun 26 10:03:18 2018 @@ -221,36 +221,36 @@ h2:hover > .headerlink, h3:hover > .head <p><a href="apidocs/org/apache/velocity/tools/view/servlet/VelocityLayoutServlet.html">org.apache.velocity.tools.view.servlet.VelocityLayoutServlet</a></p> <h2 id="configuration-settings">Configuration Settings<a class="headerlink" href="#configuration-settings" title="Permanent link">¶</a></h2> <p>Three settings can be added to velocity.properties to control the VLS, or the following default values will be used:</p> -<div class="codehilite"><pre># Filepath for error template, -# relative to web application root directory -tools.view.servlet.error.template = Error.vm - -# Directory for layout templates, -# relative to web application root directory -tools.view.servlet.layout.directory = layout/ - -# Filepath of the default layout template -# relative to the layout directory -# NOT relative to the root directory of the webapp! -tools.view.servlet.layout.default.template = Default.vm<span class="nt"></sourcecode></pre></span> +<div class="codehilite"><pre><span class="c"># Filepath for error template,</span> +<span class="c"># relative to web application root directory</span> +<span class="na">tools.view.servlet.error.template</span> <span class="o">=</span> <span class="s">Error.vm</span> + +<span class="c"># Directory for layout templates,</span> +<span class="c"># relative to web application root directory</span> +<span class="na">tools.view.servlet.layout.directory</span> <span class="o">=</span> <span class="s">layout/</span> + +<span class="c"># Filepath of the default layout template</span> +<span class="c"># relative to the layout directory</span> +<span class="c"># NOT relative to the root directory of the webapp!</span> +<span class="na">tools.view.servlet.layout.default.template</span> <span class="o">=</span> <span class="s">Default.vm</sourcecode></pre></span> </pre></div> <h2 id="layouts">Layouts<a class="headerlink" href="#layouts" title="Permanent link">¶</a></h2> <p>Now, in your layout templates, the only thing you really need is the screen content reference. So an acceptable layout template could be:</p> -<div class="codehilite"><pre>$screen_content +<div class="codehilite"><pre><span class="p">$</span><span class="nv">screen_content</span><span class="x"></span> </pre></div> <p>...but that would make this whole thing an idiotic waste of time. At the least, you'll probably want to do something along these lines:</p> -<div class="codehilite"><pre><span class="nt"><html></span> -<span class="nt"><head></span> - <span class="nt"><title></span>$!page_title<span class="nt"></title></span> -<span class="nt"></head></span> -<span class="nt"><body></span> - $screen_content -<span class="nt"></body></span> -<span class="nt"></html></span> +<div class="codehilite"><pre><span class="p"><</span><span class="nt">html</span><span class="p">></span> +<span class="p"><</span><span class="nt">head</span><span class="p">></span> + <span class="p"><</span><span class="nt">title</span><span class="p">>$!</span><span class="nv">page_title</span><span class="p"></</span><span class="nt">title</span><span class="p">></span> +<span class="p"></</span><span class="nt">head</span><span class="p">></span> +<span class="p"><</span><span class="nt">body</span><span class="p">></span> + <span class="p">$</span><span class="nv">screen_content</span> +<span class="p"></</span><span class="nt">body</span><span class="p">></span> +<span class="p"></</span><span class="nt">html</span><span class="p">></span> </pre></div> @@ -258,65 +258,64 @@ tools.view.servlet.layout.default.templa <h2 id="alternative-layouts">Alternative Layouts<a class="headerlink" href="#alternative-layouts" title="Permanent link">¶</a></h2> <p>VLS provides two ways to specify an alternate template for a requested page:</p> <ol> -<li> -<p><strong>Specify the layout in the request parameters</strong></p> +<li><strong>Specify the layout in the request parameters</strong></li> +</ol> <p>Just add the query string "layout=MyOtherLayout.vm" to any request params and the VLS will find it and render your screen within that layout instead of the default layout. It don't matter how you get the layout param into the query data, only that it's there. If you're using the struts tools, the most common will likely be:</p> -<div class="codehilite"><pre><a href="$link.setRelative('MyScreen.vm').addQueryData('layout','MyOtherLayout.vm')"> +<div class="codehilite"><pre><span class="p"><</span><span class="nt">a</span> <span class="na">href</span><span class="o">=</span><span class="s">"</span><span class="p">$</span><span class="nv">link</span><span class="p">.</span><span class="nv">setRelative</span><span class="p">(</span><span class="s1">'MyScreen.vm'</span><span class="p">).</span><span class="nv">addQueryData</span><span class="p">(</span><span class="s1">'layout'</span><span class="p">,</span><span class="s1">'MyOtherLayout.vm'</span><span class="p">)</span><span class="s">"</span><span class="p">></span> </pre></div> -<p>but form post data will work just as well. -2. <strong>Specify the layout in the requested screen.</strong></p> -</li> +<p>but form post data will work just as well.</p> +<ol> +<li><strong>Specify the layout in the requested screen.</strong></li> </ol> <p>In the requested screen, put a line like this:</p> -<div class="codehilite"><pre> #set( $layout = "MyOtherLayout.vm" ) - -This will direct the VLS to use "MyOtherLayout.vm" instead of "Default.vm". *Setting the layout in this fashion will override any layout set by the request parameters.* +<div class="codehilite"><pre><span class="cp">#</span><span class="nf">set</span><span class="p">(</span> <span class="p">$</span><span class="nv">layout</span> <span class="o">=</span> <span class="s2">"MyOtherLayout.vm"</span> <span class="p">)</span><span class="x"></span> </pre></div> +<p>This will direct the VLS to use "MyOtherLayout.vm" instead of "Default.vm". <em>Setting the layout in this fashion will override any layout set by the request parameters.</em></p> <h2 id="navigations-tiles-and-how">'Navigations', 'Tiles', and How<a class="headerlink" href="#navigations-tiles-and-how" title="Permanent link">¶</a></h2> <p>Those of you who are (or were) Turbine or Struts users will probably want to do more than just set the layout and screen content. You want to include arbitrary "tiles" or "navigations", right? Well, thanks to Velocity's built-in <code>#parse</code> directive, this is easy.</p> <p>First, create your "tile" as a separate template file like:</p> -<div class="codehilite"><pre><span class="nt"><div</span> <span class="na">id=</span><span class="s">"footer"</span><span class="nt">></span>I made this!<span class="nt"></div></span> +<div class="codehilite"><pre><span class="p"><</span><span class="nt">div</span> <span class="na">id</span><span class="o">=</span><span class="s">"footer"</span><span class="p">></span>I made this!<span class="p"></</span><span class="nt">div</span><span class="p">></span> </pre></div> <p>For creativity's sake, we'll pretend this code is in a file named "Footer.vm" that is located in the root of my webapp like my other non-layout templates.</p> -<div class="codehilite"><pre><span class="nt"><html></span> -<span class="nt"><head></span> - <span class="nt"><title></span>$!page_title<span class="nt"></title></span> -<span class="nt"></head></span> -<span class="nt"><body></span> +<div class="codehilite"><pre><span class="p"><</span><span class="nt">html</span><span class="p">></span> +<span class="p"><</span><span class="nt">head</span><span class="p">></span> + <span class="p"><</span><span class="nt">title</span><span class="p">>$!</span><span class="nv">page_title</span><span class="p"></</span><span class="nt">title</span><span class="p">></span> +<span class="p"></</span><span class="nt">head</span><span class="p">></span> +<span class="p"><</span><span class="nt">body</span><span class="p">></span> -$screen_content +<span class="p">$</span><span class="nv">screen_content</span> -#parse('Footer.vm') +<span class="cp">#</span><span class="nf">parse</span><span class="p">(</span><span class="s1">'Footer.vm'</span><span class="p">)</span> -<span class="nt"></body></span> -<span class="nt"></html></span> +<span class="p"></</span><span class="nt">body</span><span class="p">></span> +<span class="p"></</span><span class="nt">html</span><span class="p">></span> </pre></div> <p>Easy, eh?</p> <p>Now, what if you have a lot of different "footer" files and you want your screen to decide which one will be used? No problem! Do something like this:</p> -<div class="codehilite"><pre><span class="nt"><html></span> -<span class="nt"><head></span> - <span class="nt"><title></span>$!page_title<span class="nt"></title></span> -<span class="nt"></head></span> -<span class="nt"><body></span> +<div class="codehilite"><pre><span class="p"><</span><span class="nt">html</span><span class="p">></span> +<span class="p"><</span><span class="nt">head</span><span class="p">></span> + <span class="p"><</span><span class="nt">title</span><span class="p">>$!</span><span class="nv">page_title</span><span class="p"></</span><span class="nt">title</span><span class="p">></span> +<span class="p"></</span><span class="nt">head</span><span class="p">></span> +<span class="p"><</span><span class="nt">body</span><span class="p">></span> -$screen_content +<span class="p">$</span><span class="nv">screen_content</span> -#parse( $screen_footer ) +<span class="cp">#</span><span class="nf">parse</span><span class="p">(</span> <span class="p">$</span><span class="nv">screen_footer</span> <span class="p">)</span> -<span class="nt"></body></span> -<span class="nt"></html></span> +<span class="p"></</span><span class="nt">body</span><span class="p">></span> +<span class="p"></</span><span class="nt">html</span><span class="p">></span> </pre></div> -<p>and in your screen, just do `#set( $screen_footer = 'FooFooter.vm' ).\</p> +<p>and in your screen, just do <code>#set( $screen_footer = 'FooFooter.vm' )</code>.</p> <p>Remember, your #parsed footer template will have access to the same velocity context as your layout, which gets the screen's context once the screen is done with it. This lets you set variables for the layout and footer to use from your screens.</p> <h2 id="error-screen">Error Screen<a class="headerlink" href="#error-screen" title="Permanent link">¶</a></h2> <p>Ok, the idea here is pretty simple. If an uncaught exception or error is thrown at some point during the processing of your screen and layout, the error() method of the VLS is called. This overrides the default error() method of the VelocityViewServlet to render a template instead of hardcoded html.</p> @@ -340,13 +339,13 @@ $screen_content </tbody> </table> <p>In the event that a MethodInvocationException is behind the calling of error(), the root cause is extracted from it and dealt with as described above. But, since template reference behavior is partly at fault here, the VLS will also add the MethodInvocationException itself to the context as $invocation_exception. This allows you to discover the reference and method call that triggered the root cause. To get those, do something like this in your error template:</p> -<div class="codehilite"><pre>#if( $invocation_exception ) - oh joy! it's a MethodInvocationException! +<div class="codehilite"><pre><span class="cp">#</span><span class="nf">if</span><span class="p">(</span> <span class="p">$</span><span class="nv">invocation_exception</span> <span class="p">)</span><span class="x"></span> +<span class="x"> oh joy! it's a MethodInvocationException!</span> - Message: $invocation_exception.message - Reference name: $invocation_exception.referenceName - Method name: $invocation_exception.methodName -#end +<span class="x"> Message: </span><span class="p">$</span><span class="nv">invocation_exception</span><span class="p">.</span><span class="nv">message</span><span class="x"></span> +<span class="x"> Reference name: </span><span class="p">$</span><span class="nv">invocation_exception</span><span class="p">.</span><span class="nv">referenceName</span><span class="x"></span> +<span class="x"> Method name: </span><span class="p">$</span><span class="nv">invocation_exception</span><span class="p">.</span><span class="nv">methodName</span><span class="x"></span> +<span class="cp">#</span><span class="nf">end</span><span class="x"></span> </pre></div></div></div> <hr/> <div id="copyright"> Modified: velocity/site/production/tools/2.0/view-servlet.html URL: http://svn.apache.org/viewvc/velocity/site/production/tools/2.0/view-servlet.html?rev=1834410&r1=1834409&r2=1834410&view=diff ============================================================================== --- velocity/site/production/tools/2.0/view-servlet.html (original) +++ velocity/site/production/tools/2.0/view-servlet.html Tue Jun 26 10:03:18 2018 @@ -263,11 +263,11 @@ h2:hover > .headerlink, h3:hover > .head <p>The default configuration specifies the location of a 'global' Velocimacro template. This file can contain macros which will be made available to all templates.</p> <p>The location of the configuration file may be specified in web.xml, but it is recommended the file be placed inside the hidden WEB-INF directory of the web application and named 'velocity.properties' which is where the VelocityViewServlet will look for it in the absence of any location specified in the web.xml. An example configuration file is included with the distribution.</p> <p>Please see the <a href="/engine/devel/user-guide.html">Velocity User's Guide</a> for more information on Velocity configuration.</p> -<div class="codehilite"><pre>velocimacro.library = /WEB-INF/VM_global_library.vm -velocimacro.permissions.allow.inline = true -velocimacro.permissions.allow.inline.to.replace.global = false -velocimacro.permissions.allow.inline.local.scope = false -velocimacro.context.localscope = false +<div class="codehilite"><pre><span class="na">velocimacro.library</span> <span class="o">=</span> <span class="s">/WEB-INF/VM_global_library.vm</span> +<span class="na">velocimacro.permissions.allow.inline</span> <span class="o">=</span> <span class="s">true</span> +<span class="na">velocimacro.permissions.allow.inline.to.replace.global</span> <span class="o">=</span> <span class="s">false</span> +<span class="na">velocimacro.permissions.allow.inline.local.scope</span> <span class="o">=</span> <span class="s">false</span> +<span class="na">velocimacro.context.localscope</span> <span class="o">=</span> <span class="s">false</span> </pre></div> @@ -276,11 +276,11 @@ velocimacro.context.localscope = false <p>Think about asking our friend Jon to grab us a 'wrench' from a real toolbox. Jon just needs to know which wrench we want (metric, pipe, crescent etc,). He doesn't need to know what the wrench does nor what we are planning to do with it.</p> <p>The Velocity Toolbox works the same way, we must only specify which tool we want, and then the Velocity engine takes care of the rest by making any public method available to the template. For example, from the definitions below, the template could call <code>$wrench.size</code>.</p> <p><strong>PipeWrench.java</strong></p> -<div class="codehilite"><pre>public class PipeWrench { - public String getSize() { - return "Large Pipe Wrench!"; - } -} +<div class="codehilite"><pre><span class="kd">public</span> <span class="kd">class</span> <span class="nc">PipeWrench</span> <span class="o">{</span> + <span class="kd">public</span> <span class="n">String</span> <span class="nf">getSize</span><span class="o">()</span> <span class="o">{</span> + <span class="k">return</span> <span class="s">"Large Pipe Wrench!"</span><span class="o">;</span> + <span class="o">}</span> +<span class="o">}</span> </pre></div> @@ -304,8 +304,8 @@ velocimacro.context.localscope = false </ul> <h4 id="tool-path-restrictions">Tool Path Restrictions<a class="headerlink" href="#tool-path-restrictions" title="Permanent link">¶</a></h4> <p>You can specify a restriction on the request URIs for which the tool will be available in the context using the "restrictTo" attribute of your tool configuration. It can be an exact request path (matching one page) or end with the <code>*</code> wildcard, meaning that incoming request paths need only start with the provided value for the tool to be available. For instance:</p> -<div class="codehilite"><pre><tool restrictTo="/catalog/*" - class="com.mycompany.tools.CatalogTool"/> +<div class="codehilite"><pre><span class="nt"><tool</span> <span class="na">restrictTo=</span><span class="s">"/catalog/*"</span> + <span class="na">class=</span><span class="s">"com.mycompany.tools.CatalogTool"</span><span class="nt">/></span> </pre></div> Modified: velocity/site/production/tools/2.0/view-tag.html URL: http://svn.apache.org/viewvc/velocity/site/production/tools/2.0/view-tag.html?rev=1834410&r1=1834409&r2=1834410&view=diff ============================================================================== --- velocity/site/production/tools/2.0/view-tag.html (original) +++ velocity/site/production/tools/2.0/view-tag.html Tue Jun 26 10:03:18 2018 @@ -218,19 +218,19 @@ h2:hover > .headerlink, h3:hover > .head <p class="note">This page is still unfinished. For details on configuring the VelocityViewTag, you can follow most of the instructions for the <a href="view-servlet.html">VelocityViewServlet</a> and of course on the <a href="configuration.html">configuration pages</a>. <a href="index.html#Contribution">Help finishing this is welcome!</a> </p> <p>This is a JSP tag that allows you to use Velocity and VelocityTools from within a JSP page or tag. There are many ways to use this tag. This simplest is to have it process an external template using the current page context. Assuming you have a template called "foo.vm" that can be found by your resource loader(s) that looks like this:</p> -<div class="codehilite"><pre>Hello $!bodyContent World! +<div class="codehilite"><pre><span class="x">Hello </span><span class="p">$!</span><span class="nv">bodyContent</span><span class="x"> World!</span> </pre></div> <p>This tag can process that template by doing:</p> -<div class="codehilite"><pre><span class="cp"><%</span><span class="vi">@taglib</span> <span class="n">prefix</span><span class="o">=</span><span class="s2">"velocity"</span> <span class="n">uri</span><span class="o">=</span><span class="s2">"http://velocity.apache.org/velocity-view"</span> <span class="cp">%></span><span class="x"></span> +<div class="codehilite"><pre><span class="k"><%@</span><span class="n">taglib</span> <span class="n">prefix</span><span class="o">=</span><span class="s">"velocity"</span> <span class="n">uri</span><span class="o">=</span><span class="s">"http://velocity.apache.org/velocity-view"</span> <span class="k">%></span> -<span class="x"><velocity:view template="foo.vm"/></span> +<span class="nt"><velocity:view</span> <span class="na">template=</span><span class="s">"foo.vm"</span><span class="nt">/></span> </pre></div> <p>VTL in the body of the tag:</p> -<div class="codehilite"><pre><span class="cp"><%</span><span class="vi">@taglib</span> <span class="n">prefix</span><span class="o">=</span><span class="s2">"velocity"</span> <span class="n">uri</span><span class="o">=</span><span class="s2">"http://velocity.apache.org/velocity-view"</span> <span class="cp">%></span> +<div class="codehilite"><pre><span class="k"><%@</span><span class="n">taglib</span> <span class="n">prefix</span><span class="o">=</span><span class="s">"velocity"</span> <span class="n">uri</span><span class="o">=</span><span class="s">"http://velocity.apache.org/velocity-view"</span> <span class="k">%></span> <span class="nt"><velocity:view></span> #if( $date.E eq 'Friday' ) @@ -243,7 +243,7 @@ h2:hover > .headerlink, h3:hover > .head <p>or combine both by first processing the body of the tag, then inserting the results of that into the context for the separate template as $bodyContent:</p> -<div class="codehilite"><pre><span class="cp"><%</span><span class="vi">@taglib</span> <span class="n">prefix</span><span class="o">=</span><span class="s2">"velocity"</span> <span class="n">uri</span><span class="o">=</span><span class="s2">"http://velocity.apache.org/velocity-view"</span> <span class="cp">%></span> +<div class="codehilite"><pre><span class="k"><%@</span><span class="n">taglib</span> <span class="n">prefix</span><span class="o">=</span><span class="s">"velocity"</span> <span class="n">uri</span><span class="o">=</span><span class="s">"http://velocity.apache.org/velocity-view"</span> <span class="k">%></span> <span class="nt"><velocity:view</span> <span class="na">template=</span><span class="s">"foo.vm"</span><span class="nt">></span> #if( $date.E eq 'Friday' ) @@ -256,7 +256,7 @@ h2:hover > .headerlink, h3:hover > .head <p>You can also store the results of any of the options above into a variable of any name and scope (default scope is "page"):</p> -<div class="codehilite"><pre><span class="cp"><%</span><span class="vi">@taglib</span> <span class="n">prefix</span><span class="o">=</span><span class="s2">"velocity"</span> <span class="n">uri</span><span class="o">=</span><span class="s2">"http://velocity.apache.org/velocity-view"</span> <span class="cp">%></span> +<div class="codehilite"><pre><span class="k"><%@</span><span class="n">taglib</span> <span class="n">prefix</span><span class="o">=</span><span class="s">"velocity"</span> <span class="n">uri</span><span class="o">=</span><span class="s">"http://velocity.apache.org/velocity-view"</span> <span class="k">%></span> <span class="nt"><velocity:view</span> <span class="na">var=</span><span class="s">"foo"</span> <span class="na">scope=</span><span class="s">"request"</span> <span class="na">template=</span><span class="s">"foo.vm"</span><span class="nt">></span> #if( $date.E eq 'Friday' ) @@ -268,7 +268,7 @@ h2:hover > .headerlink, h3:hover > .head </pre></div> -<p>For more details, see the <a href="apidocs/org/apache/velocity/tools/view/jsp/VelocityViewTag.html">Javadoc</a> or the <a href="http://svn.apache.org/repos/asf/velocity/tools/trunk/src/main/java/META-INF/velocity-view.tld">TLD</a>.</p></div></div> +<p>For more details, see the <a href="apidocs/org/apache/velocity/tools/view/jsp/VelocityViewTag.html">Javadoc</a> or the <a href="http://svn.apache.org/repos/asf/velocity/tools/trunk/src/main/resources/META-INF/velocity-view.tld">TLD</a>.</p></div></div> <hr/> <div id="copyright"> Copyright © 2016 The Apache Software Foundation, Licensed under the <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache License, Version 2.0</a>.<br/>Apache and the Apache feather logo are trademarks of The Apache Software Foundation. Modified: velocity/site/production/tools/devel/config-java.html URL: http://svn.apache.org/viewvc/velocity/site/production/tools/devel/config-java.html?rev=1834410&r1=1834409&r2=1834410&view=diff ============================================================================== --- velocity/site/production/tools/devel/config-java.html (original) +++ velocity/site/production/tools/devel/config-java.html Tue Jun 26 10:03:18 2018 @@ -209,23 +209,23 @@ h2:hover > .headerlink, h3:hover > .head h2:hover > .headerlink, h3:hover > .headerlink, h1:hover > .headerlink, h6:hover > .headerlink, h4:hover > .headerlink, h5:hover > .headerlink, dt:hover > .elementid-permalink { visibility: visible }</style> <h2 id="configuration-using-java">Configuration using Java<a class="headerlink" href="#configuration-using-java" title="Permanent link">¶</a></h2> <p>As of VelocityTools 2, its no longer merely possible to configure things purely via Java, it is now much easier to do and can be done in several different ways. Here again, is an example that is equivalent to those demonstrated in the <a href="config-properties.html">properties</a> and <a href="config-xml.html">XML</a> configurations:</p> -<div class="codehilite"><pre>EasyFactoryConfiguration config = new EasyFactoryConfiguration(); -config.toolbox("request").property("xhtml", true) -.tool("toytool", ToyTool.class).restrictTo("index.vm") -.tool("custom", CustomTool.class).property("randomProperty", "whatever"); -config.toolbox("session").property("create-session", true) -.tool("map", HashMap.class); -config.toolbox("application") -.tool(DateTool.class); -config.number("version", 1.1); -config.data("date", "Mon Sep 17 10:08:03 PDT 2007") -.target(Date.class) -.converter(DateLocaleConverter.class); -config.bool("isSimple", true); -config.string("foo", "this is foo."); -config.string("bar", "this is bar."); -config.data("dataKeys", "list", "version,date,isSimple,foo,bar,dataKeys,switches"); -config.data("switches", "list.boolean", "true,false,false,true"); +<div class="codehilite"><pre><span class="n">EasyFactoryConfiguration</span> <span class="n">config</span> <span class="o">=</span> <span class="k">new</span> <span class="n">EasyFactoryConfiguration</span><span class="o">();</span> +<span class="n">config</span><span class="o">.</span><span class="na">toolbox</span><span class="o">(</span><span class="s">"request"</span><span class="o">).</span><span class="na">property</span><span class="o">(</span><span class="s">"xhtml"</span><span class="o">,</span> <span class="kc">true</span><span class="o">)</span> +<span class="o">.</span><span class="na">tool</span><span class="o">(</span><span class="s">"toytool"</span><span class="o">,</span> <span class="n">ToyTool</span><span class="o">.</span><span class="na">class</span><span class="o">).</span><span class="na">restrictTo</span><span class="o">(</span><span class="s">"index.vm"</span><span class="o">)</span> +<span class="o">.</span><span class="na">tool</span><span class="o">(</span><span class="s">"custom"</span><span class="o">,</span> <span class="n">CustomTool</span><span class="o">.</span><span class="na">class</span><span class="o">).</span><span class="na">property</span><span class="o">(</span><span class="s">"randomProperty"</span><span class="o">,</span> <span class="s">"whatever"</span><span class="o">);</span> +<span class="n">config</span><span class="o">.</span><span class="na">toolbox</span><span class="o">(</span><span class="s">"session"</span><span class="o">).</span><span class="na">property</span><span class="o">(</span><span class="s">"create-session"</span><span class="o">,</span> <span class="kc">true</span><span class="o">)</span> +<span class="o">.</span><span class="na">tool</span><span class="o">(</span><span class="s">"map"</span><span class="o">,</span> <span class="n">HashMap</span><span class="o">.</span><span class="na">class</span><span class="o">);</span> +<span class="n">config</span><span class="o">.</span><span class="na">toolbox</span><span class="o">(</span><span class="s">"application"</span><span class="o">)</span> +<span class="o">.</span><span class="na">tool</span><span class="o">(</span><span class="n">DateTool</span><span class="o">.</span><span class="na">class</span><span class="o">);</span> +<span class="n">config</span><span class="o">.</span><span class="na">number</span><span class="o">(</span><span class="s">"version"</span><span class="o">,</span> <span class="mf">1.1</span><span class="o">);</span> +<span class="n">config</span><span class="o">.</span><span class="na">data</span><span class="o">(</span><span class="s">"date"</span><span class="o">,</span> <span class="s">"Mon Sep 17 10:08:03 PDT 2007"</span><span class="o">)</span> +<span class="o">.</span><span class="na">target</span><span class="o">(</span><span class="n">Date</span><span class="o">.</span><span class="na">class</span><span class="o">)</span> +<span class="o">.</span><span class="na">converter</span><span class="o">(</span><span class="n">DateLocaleConverter</span><span class="o">.</span><span class="na">class</span><span class="o">);</span> +<span class="n">config</span><span class="o">.</span><span class="na">bool</span><span class="o">(</span><span class="s">"isSimple"</span><span class="o">,</span> <span class="kc">true</span><span class="o">);</span> +<span class="n">config</span><span class="o">.</span><span class="na">string</span><span class="o">(</span><span class="s">"foo"</span><span class="o">,</span> <span class="s">"this is foo."</span><span class="o">);</span> +<span class="n">config</span><span class="o">.</span><span class="na">string</span><span class="o">(</span><span class="s">"bar"</span><span class="o">,</span> <span class="s">"this is bar."</span><span class="o">);</span> +<span class="n">config</span><span class="o">.</span><span class="na">data</span><span class="o">(</span><span class="s">"dataKeys"</span><span class="o">,</span> <span class="s">"list"</span><span class="o">,</span> <span class="s">"version,date,isSimple,foo,bar,dataKeys,switches"</span><span class="o">);</span> +<span class="n">config</span><span class="o">.</span><span class="na">data</span><span class="o">(</span><span class="s">"switches"</span><span class="o">,</span> <span class="s">"list.boolean"</span><span class="o">,</span> <span class="s">"true,false,false,true"</span><span class="o">);</span> </pre></div> Modified: velocity/site/production/tools/devel/config-properties.html URL: http://svn.apache.org/viewvc/velocity/site/production/tools/devel/config-properties.html?rev=1834410&r1=1834409&r2=1834410&view=diff ============================================================================== --- velocity/site/production/tools/devel/config-properties.html (original) +++ velocity/site/production/tools/devel/config-properties.html Tue Jun 26 10:03:18 2018 @@ -209,33 +209,33 @@ h2:hover > .headerlink, h3:hover > .head h2:hover > .headerlink, h3:hover > .headerlink, h1:hover > .headerlink, h6:hover > .headerlink, h4:hover > .headerlink, h5:hover > .headerlink, dt:hover > .elementid-permalink { visibility: visible }</style> <h2 id="configuration-using-properties">Configuration using Properties<a class="headerlink" href="#configuration-using-properties" title="Permanent link">¶</a></h2> <p>VelocityTools 2 can be configured using a properties file. Here's the same configuration as the <a href="config-xml.html">XML</a> and <a href="config-java.html">Java</a> examples in the properties format:</p> -<div class="codehilite"><pre>tools.toolbox = request,session,application +<div class="codehilite"><pre><span class="na">tools.toolbox</span> <span class="o">=</span> <span class="s">request,session,application</span> -tools.request.property.xhtml = true -tools.request.toytool = ToyTool -tools.request.toytool.restrictTo = index.vm -tools.request.custom = org.mine.CustomTool -tools.request.custom.randomProperty = whatever +<span class="na">tools.request.property.xhtml</span> <span class="o">=</span> <span class="s">true</span> +<span class="na">tools.request.toytool</span> <span class="o">=</span> <span class="s">ToyTool</span> +<span class="na">tools.request.toytool.restrictTo</span> <span class="o">=</span> <span class="s">index.vm</span> +<span class="na">tools.request.custom</span> <span class="o">=</span> <span class="s">org.mine.CustomTool</span> +<span class="na">tools.request.custom.randomProperty</span> <span class="o">=</span> <span class="s">whatever</span> -tools.session.property.create-session = true -tools.session.property.create-session.type = boolean -tools.session.map = java.util.HashMap +<span class="na">tools.session.property.create-session</span> <span class="o">=</span> <span class="s">true</span> +<span class="na">tools.session.property.create-session.type</span> <span class="o">=</span> <span class="s">boolean</span> +<span class="na">tools.session.map</span> <span class="o">=</span> <span class="s">java.util.HashMap</span> -tools.application.date = org.apache.velocity.tools.generic.DateTool +<span class="na">tools.application.date</span> <span class="o">=</span> <span class="s">org.apache.velocity.tools.generic.DateTool</span> -tools.data.version = 1.1 -tools.data.version.type = number -tools.data.date = Mon Sep 17 10:08:03 PDT 2007 -tools.data.date.class = java.util.Date -tools.data.date.converter = org.apache.commons.beanutils.locale.converters.DateLocaleConverter -tools.data.isSimple = true -tools.data.type = boolean -tools.data.foo = this is foo. -tools.data.bar = this is bar. -tools.data.dataKeys = version,date,isSimple.foo,bar,dataKeys,switches -tools.data.dataKeys.type = list -tools.data.switches = true,false,false,true -tools.data.switches.type = list.boolean +<span class="na">tools.data.version</span> <span class="o">=</span> <span class="s">1.1</span> +<span class="na">tools.data.version.type</span> <span class="o">=</span> <span class="s">number</span> +<span class="na">tools.data.date</span> <span class="o">=</span> <span class="s">Mon Sep 17 10:08:03 PDT 2007</span> +<span class="na">tools.data.date.class</span> <span class="o">=</span> <span class="s">java.util.Date</span> +<span class="na">tools.data.date.converter</span> <span class="o">=</span> <span class="s">org.apache.commons.beanutils.locale.converters.DateLocaleConverter</span> +<span class="na">tools.data.isSimple</span> <span class="o">=</span> <span class="s">true</span> +<span class="na">tools.data.type</span> <span class="o">=</span> <span class="s">boolean</span> +<span class="na">tools.data.foo</span> <span class="o">=</span> <span class="s">this is foo.</span> +<span class="na">tools.data.bar</span> <span class="o">=</span> <span class="s">this is bar.</span> +<span class="na">tools.data.dataKeys</span> <span class="o">=</span> <span class="s">version,date,isSimple.foo,bar,dataKeys,switches</span> +<span class="na">tools.data.dataKeys.type</span> <span class="o">=</span> <span class="s">list</span> +<span class="na">tools.data.switches</span> <span class="o">=</span> <span class="s">true,false,false,true</span> +<span class="na">tools.data.switches.type</span> <span class="o">=</span> <span class="s">list.boolean</span> </pre></div></div></div> <hr/> <div id="copyright"> Modified: velocity/site/production/tools/devel/creating-tools.html URL: http://svn.apache.org/viewvc/velocity/site/production/tools/devel/creating-tools.html?rev=1834410&r1=1834409&r2=1834410&view=diff ============================================================================== --- velocity/site/production/tools/devel/creating-tools.html (original) +++ velocity/site/production/tools/devel/creating-tools.html Tue Jun 26 10:03:18 2018 @@ -244,14 +244,14 @@ h2:hover > .headerlink, h3:hover > .head <h3 id="tool-keysnames">Tool Keys/Names<a class="headerlink" href="#tool-keysnames" title="Permanent link">¶</a></h3> <p>As of VelocityTools 2, the toolbox support can now automatically determine the key name for a tool from its classname. So, a tool named org.com.FooTool would be assigned the key $foo in your templates, tool named org.com.FooBarTool would be $fooBar, and a tool named org.com.FooBar would be also be $fooBar.</p> <p>If you would prefer to give your org.com.FooBar tool the key $foob, you can use the <code>org.apache.velocity.tools.config.DefaultKey</code> annotation like this:</p> -<div class="codehilite"><pre><span class="n">package</span> <span class="n">org</span><span class="o">.</span><span class="n">com</span><span class="p">;</span> +<div class="codehilite"><pre><span class="kn">package</span> <span class="nn">org.com</span><span class="o">;</span> -<span class="kn">import</span> <span class="nn">org.apache.velocity.tools.config.DefaultKey</span><span class="p">;</span> +<span class="kn">import</span> <span class="nn">org.apache.velocity.tools.config.DefaultKey</span><span class="o">;</span> -<span class="nd">@DefaultKey</span><span class="p">(</span><span class="s2">"foob"</span><span class="p">)</span> -<span class="n">public</span> <span class="k">class</span> <span class="nc">FooBar</span> <span class="p">{</span> +<span class="nd">@DefaultKey</span><span class="o">(</span><span class="s">"foob"</span><span class="o">)</span> +<span class="kd">public</span> <span class="kd">class</span> <span class="nc">FooBar</span> <span class="o">{</span> <span class="o">...</span> -<span class="p">}</span> +<span class="o">}</span> </pre></div> @@ -289,11 +289,11 @@ h2:hover > .headerlink, h3:hover > .head <p>There are three Annotations provided for tool authors: <a href="apidocs/org/apache/velocity/tools/config/DefaultKey.html">DefaultKey</a>, <a href="apidocs/org/apache/velocity/tools/config/InvalidScope.html">InvalidScope</a> and <a href="apidocs/org/apache/velocity/tools/config/ValidScope.html">ValidScope</a>.</p> <p>As described above, the @DefaultKey annotation is used to specify a default key for your tool. The @InvalidScope and @ValidScope annotations allow you to restrict the <a href="apidocs/org/apache/velocity/tools/Scope.html">Scope</a>(s) in which the tool can be used in either negative or positive terms. When described positively using the @ValidScope annotation, the tool may <strong>only</strong> be used in a toolbox with the specified scope. If placed in any other toolbox, an <code>org.apache.velocity.tools.config.InvalidScopeException</code> will be thrown. Using @InvalidScope, on the other hand, allows you reject specific scope(s), whilst implicitly allowing any others.</p> <p>Here's a scope annotation example:</p> -<div class="codehilite"><pre>@InvalidScope({Scope.APPLICATION,Scope.SESSION}) -public class PagerTool -{ - ... -} +<div class="codehilite"><pre><span class="nd">@InvalidScope</span><span class="o">({</span><span class="n">Scope</span><span class="o">.</span><span class="na">APPLICATION</span><span class="o">,</span><span class="n">Scope</span><span class="o">.</span><span class="na">SESSION</span><span class="o">})</span> +<span class="kd">public</span> <span class="kd">class</span> <span class="nc">PagerTool</span> +<span class="o">{</span> + <span class="o">...</span> +<span class="o">}</span> </pre></div> @@ -317,7 +317,7 @@ public class PagerTool </ul> <h3 id="be-robust">Be Robust<a class="headerlink" href="#be-robust" title="Permanent link">¶</a></h3> <p>Always return null on errors! No Exceptions! Ok, maybe there are some exceptions if you are sure that's what you want your tool to do. Just be aware that this will likely surprise the user because uncaught exceptions halt template processing at the point the exception is thrown. If the output of the template is not buffered, this will result in an awkward, partial rendering. So, if you are going to let an exception through, make sure it is worth halting everything for. Often it is sufficient to return null, thus allowing the failed reference to appear in the output like this:</p> -<div class="codehilite"><pre>$mytool.somemethod('bad input') +<div class="codehilite"><pre><span class="p">$</span><span class="nv">mytool</span><span class="p">.</span><span class="nv">somemethod</span><span class="p">(</span><span class="s1">'bad input'</span><span class="p">)</span><span class="x"></span> </pre></div> Modified: velocity/site/production/tools/devel/generic.html URL: http://svn.apache.org/viewvc/velocity/site/production/tools/devel/generic.html?rev=1834410&r1=1834409&r2=1834410&view=diff ============================================================================== --- velocity/site/production/tools/devel/generic.html (original) +++ velocity/site/production/tools/devel/generic.html Tue Jun 26 10:03:18 2018 @@ -213,54 +213,55 @@ h2:hover > .headerlink, h3:hover > .head <ul> <li> <p>Initialization with only standard generic tools, using the default configuration file:</p> -<div class="codehilite"><pre><span class="cm">/* Create tools initialization properties */</span><span class="w"></span> -Map<span class="o"><</span>String<span class="o">,</span><span class="w"> </span>Object<span class="o">></span><span class="w"> </span>properties<span class="w"> </span><span class="o">=</span><span class="w"> </span>new<span class="w"> </span>HashMap<span class="o"><</span>String<span class="o">,</span><span class="w"> </span>Object<span class="o">>()</span><span class="err">;</span><span class="w"></span> -<span class="cm">/* RenderTool needs to know the VelocityEngine. Setting the engine will also set the logger. */</span><span class="w"></span> -properties<span class="o">.</span>put<span class="o">(</span><span class="s">"engine"</span><span class="o">,</span><span class="w"> </span>engine<span class="o">)</span><span class="err">;</span><span class="w"></span> +<div class="codehilite"><pre><span class="cm">/* Create tools initialization properties */</span> +<span class="n">Map</span><span class="o"><</span><span class="n">String</span><span class="o">,</span> <span class="n">Object</span><span class="o">></span> <span class="n">properties</span> <span class="o">=</span> <span class="k">new</span> <span class="n">HashMap</span><span class="o"><</span><span class="n">String</span><span class="o">,</span> <span class="n">Object</span><span class="o">>();</span> +<span class="cm">/* RenderTool needs to know the VelocityEngine. Setting the engine will also set the logger. */</span> +<span class="n">properties</span><span class="o">.</span><span class="na">put</span><span class="o">(</span><span class="s">"engine"</span><span class="o">,</span> <span class="n">engine</span><span class="o">);</span> <span class="cm">/* If the render tool is not to be used, you can instead just set the logger if needed as follow:</span> <span class="cm"> *</span> <span class="cm"> * properties.put("log", logger);</span> <span class="cm"> *</span> <span class="cm"> * Otherwise, the engine logger will be used.</span> <span class="cm"> * </span> -<span class="cm"> */</span><span class="w"></span> +<span class="cm"> */</span> -<span class="cm">/* Create the manager. autoConfigure and includeDefaults are both booleans which default to true. */</span><span class="w"></span> -ToolManager<span class="w"> </span>manager<span class="w"> </span><span class="o">=</span><span class="w"> </span>new<span class="w"> </span>ToolManager<span class="o">(</span>autoConfigure<span class="o">,</span><span class="w"> </span>includeDefaults<span class="o">)</span><span class="err">;</span><span class="w"></span> +<span class="cm">/* Create the manager. autoConfigure and includeDefaults are both booleans which default to true. */</span> +<span class="n">ToolManager</span> <span class="n">manager</span> <span class="o">=</span> <span class="k">new</span> <span class="n">ToolManager</span><span class="o">(</span><span class="n">autoConfigure</span><span class="o">,</span> <span class="n">includeDefaults</span><span class="o">);</span> </pre></div> </li> <li> <p>Initialization using a provided configuration file (to customize tools or tune standard tools configuration):</p> -<div class="codehilite"><pre><span class="cm">/* Create tools initialization properties */</span><span class="w"></span> -Map<span class="o"><</span>String<span class="o">,</span><span class="w"> </span>Object<span class="o">></span><span class="w"> </span>properties<span class="w"> </span><span class="o">=</span><span class="w"> </span>new<span class="w"> </span>HashMap<span class="o"><</span>String<span class="o">,</span><span class="w"> </span>Object<span class="o">>()</span><span class="err">;</span><span class="w"></span> -<span class="cm">/* RenderTool needs to know the VelocityEngine. Setting the engine will also set the logger. */</span><span class="w"></span> -properties<span class="o">.</span>put<span class="o">(</span><span class="s">"engine"</span><span class="o">,</span><span class="w"> </span>engine<span class="o">)</span><span class="err">;</span><span class="w"></span> +<div class="codehilite"><pre><span class="cm">/* Create tools initialization properties */</span> +<span class="n">Map</span><span class="o"><</span><span class="n">String</span><span class="o">,</span> <span class="n">Object</span><span class="o">></span> <span class="n">properties</span> <span class="o">=</span> <span class="k">new</span> <span class="n">HashMap</span><span class="o"><</span><span class="n">String</span><span class="o">,</span> <span class="n">Object</span><span class="o">>();</span> +<span class="cm">/* RenderTool needs to know the VelocityEngine. Setting the engine will also set the logger. */</span> +<span class="n">properties</span><span class="o">.</span><span class="na">put</span><span class="o">(</span><span class="s">"engine"</span><span class="o">,</span> <span class="n">engine</span><span class="o">);</span> <span class="cm">/* If the render tool is not to be used, you can instead just set the logger if needed as follow:</span> <span class="cm"> *</span> <span class="cm"> * properties.put("log", logger);</span> <span class="cm"> *</span> <span class="cm"> * Otherwise, the engine logger will be used.</span> <span class="cm"> * </span> -<span class="cm"> */</span><span class="w"></span> +<span class="cm"> */</span> -<span class="cm">/* Create the manager. includeDefaults is a boolean which defaults to true. */</span><span class="w"></span> -ToolManager<span class="w"> </span>manager<span class="w"> </span><span class="o">=</span><span class="w"> </span>new<span class="w"> </span>ToolManager<span class="o">(</span>false<span class="o">,</span><span class="w"> </span>includeDefaults<span class="o">)</span><span class="err">;</span><span class="w"></span> +<span class="cm">/* Create the manager. includeDefaults is a boolean which defaults to true. */</span> +<span class="n">ToolManager</span> <span class="n">manager</span> <span class="o">=</span> <span class="k">new</span> <span class="n">ToolManager</span><span class="o">(</span><span class="kc">false</span><span class="o">,</span> <span class="n">includeDefaults</span><span class="o">);</span> <span class="cm">/* Configure the manager</span> <span class="cm"> * toolsConfiguration is a filesystem- or class- path towards your tools configuration,</span> <span class="cm"> * which can be a .xml, a .properties, or a .class of a configuration factory which</span> <span class="cm"> * has a getConfiguration() method returning a FactoryConfiguration object.");</span> -<span class="cm"> */</span><span class="w"></span> -manager<span class="o">.</span>configure<span class="o">(</span>toolsConfiguration<span class="o">)</span><span class="err">;</span><span class="w"></span> +<span class="cm"> */</span> +<span class="n">manager</span><span class="o">.</span><span class="na">configure</span><span class="o">(</span><span class="n">toolsConfiguration</span><span class="o">);</span> </pre></div> </li> </ul> <p>You can then create Velocity contexts with:</p> -<div class="codehilite"><pre> Context context = manager.createContext(); +<div class="codehilite"><pre> :::java + Context context = manager.createContext(); </pre></div> Modified: velocity/site/production/tools/devel/standalone.html URL: http://svn.apache.org/viewvc/velocity/site/production/tools/devel/standalone.html?rev=1834410&r1=1834409&r2=1834410&view=diff ============================================================================== --- velocity/site/production/tools/devel/standalone.html (original) +++ velocity/site/production/tools/devel/standalone.html Tue Jun 26 10:03:18 2018 @@ -211,10 +211,10 @@ h2:hover > .headerlink, h3:hover > .head <p>There's nothing particularly special about the tools in VelocityTools 2. No special interfaces, most don't ''need'' any configuration or API access, and those that do are now relatively easy to handle (compared to VelocityTools 1.x). So, if you need a tool, just create an instance, do any configuration you want or need and go. Nothing else to it.</p> <h2 id="toolmanager">ToolManager<a class="headerlink" href="#toolmanager" title="Permanent link">¶</a></h2> <p>However, if you want to externalize your configuration or have your tools created and configured for you on demand and you are not working in a servlet environment, then we have created a simple ToolManager that you can use. It's relatively simple. Just create a ToolManager (can be created with or without default tools available), configure it (if you want to), ask it to create a context for you, and use the context as you would any other. Of course, there's more to it, but this should get you started:</p> -<div class="codehilite"><pre>ToolManager manager = new ToolManager(); -manager.configure("/path/to/my/configuration.xml"); -Context context = manager.createContext(); -myVelocityEngine.evaluate(context, myOutputWriter, "This is a $text.test", "Test template"); +<div class="codehilite"><pre><span class="n">ToolManager</span> <span class="n">manager</span> <span class="o">=</span> <span class="k">new</span> <span class="n">ToolManager</span><span class="o">();</span> +<span class="n">manager</span><span class="o">.</span><span class="na">configure</span><span class="o">(</span><span class="s">"/path/to/my/configuration.xml"</span><span class="o">);</span> +<span class="n">Context</span> <span class="n">context</span> <span class="o">=</span> <span class="n">manager</span><span class="o">.</span><span class="na">createContext</span><span class="o">();</span> +<span class="n">myVelocityEngine</span><span class="o">.</span><span class="na">evaluate</span><span class="o">(</span><span class="n">context</span><span class="o">,</span> <span class="n">myOutputWriter</span><span class="o">,</span> <span class="s">"This is a $text.test"</span><span class="o">,</span> <span class="s">"Test template"</span><span class="o">);</span> </pre></div>