org.apache.velocity.tools.view.tools |
Provides the ViewTool and Configurable interfaces, as well as a number
of useful implementing classes. These are tools specifically meant for use
in a web application.
Package Specification
Related Documentation
|
Java Source File Name | Type | Comment |
AbstractPagerTool.java | Class | Abstract view tool for doing request-based pagination of
items in an a list.
Usage:
To use this class, you must extend it and implement
the setup(HttpServletRequest) method.
The setup(HttpServletRequest) method ought to extract
from the current request the current list index and,
optionally, the number of items to display per page.
Upon extracting these parameters, they should be set using
the provided setIndex(int) and setItemsPerPage(int) methods.
A simple implementation would be:
public void setup(HttpServletRequest req)
{
ParameterParser pp = new ParameterParser(req);
setIndex(pp.getInt("index", 0));
setItemsPerPage(pp.getInt("show", DEFAULT_ITEMS_PER_PAGE));
}
You can also set the list of items to be paged at this point
using the setItems(List) method, or you can always set the
item list at another point (even from within the template).
Here's an example of how your subclass would be used in a template:
#if( $pager.hasItems() )
Showing $!pager.pageDescription<br>
#set( $i = $pager.index )
#foreach( $item in $pager.page )
${i}. |
AbstractSearchTool.java | Class | Abstract view tool for doing "searching" and robust
pagination of search results. |
BrowserSnifferTool.java | Class | browser-sniffing tool (session or request scope requested, session scope advised).
Usage:
BrowserSniffer defines properties that are used to test the client browser, operating system, device...
Apart from properties related to versioning, all properties are booleans.
The following properties are available:
- Versioning:version majorVersion minorVersion geckoVersion
- Browser:mosaic netscape nav2 nav3 nav4 nav4up nav45 nav45up nav6 nav6up navgold firefox safari
ie ie3 ie4 ie4up ie5 ie5up ie55 ie55up ie6 opera opera3 opera4 opera5 opera6 opera7 lynx links
aol aol3 aol4 aol5 aol6 neoplanet neoplanet2 amaya icab avantgo emacs mozilla gecko webtv staroffice
lotusnotes konqueror
- Operating systems:win16 win3x win31 win95 win98 winnt windows win32 win2k winxp winme dotnet
mac macosx mac68k macppc os2 unix sun sun4 sun5 suni86 irix irix5 irix6 hpux hpux9 hpux10 aix aix1 aix2 aix3 aix4
linux sco unixware mpras reliant dec sinix freebsd bsd vms x11 amiga
- Devices:palm audrey iopener wap blackberry
- Features:javascript css css1 css2 dom0 dom1 dom2
- Special:robot (true if the page is requested by a robot, i.e.
|
Configurable.java | Interface | Interface for tools that can be passed configuration parameters. |
ContextTool.java | Class | |
CookieTool.java | Class | |
ImportTool.java | Class | General-purpose text-importing view tool for templates.
Usage:
Just call $import.read("http://www.foo.com/bleh.jsp?sneh=bar") to insert the contents of the named
resource into the template.
Toolbox configuration:
<tool>
<key>import</key>
<scope>request</scope>
<class>org.apache.velocity.tools.view.tools.ImportTool</class>
</tool>
author: Marino A. |
LinkTool.java | Class | |
ParameterParser.java | Class | Utility class for easy parsing of
ServletRequest parameters.
Template example(s):
$params.foo -> bar
$params.getNumber('baz') -> 12.6
$params.getInt('baz') -> 12
$params.getNumbers('baz') -> [12.6]
Toolbox configuration:
<tool>
<key>params</key>
<scope>request</scope>
<class>org.apache.velocity.tools.view.tools.ParameterParser</class>
</tool>
When used as a view tool, this should only be used in the request scope. |
ViewRenderTool.java | Class | This tool expose methods to evaluate the given
strings as VTL (Velocity Template Language)
and automatically using the current context.
Example of eval():
Input
-----
#set( $list = [1,2,3] )
#set( $object = '$list' )
#set( $method = 'size()' )
$render.eval("${object}.$method")
Output
------
3
Example of recurse():
Input
-----
#macro( say_hi )hello world!#end
#set( $foo = '#say_hi()' )
#set( $bar = '$foo' )
$render.recurse('$bar')
Output
------
hello world!
Toolbox configuration:
<tool>
<key>render</key>
<scope>request</scope>
<class>org.apache.velocity.tools.view.tools.ViewRenderTool</class>
<parameter name="parse.depth" value="10"/>
</tool>
Ok, so these examples are really lame. |
ViewResourceTool.java | Class | Tool for accessing ResourceBundles and formatting messages therein.
Template example(s):
$text.foo -> bar
$text.hello.world -> Hello World!
#set( $otherText = $text.bundle('otherBundle') )
$otherText.foo -> woogie
$otherText.bar -> The args are {0} and {1}.
$otherText.bar.insert(4) -> The args are 4 and {1}.
$otherText.bar.insert(4,true) -> The args are 4 and true.
Toolbox configuration example:
<tool>
<key>text</key>
<class>org.apache.velocity.tools.view.tools.ViewResourceTool</class>
<parameter name="bundles" value="resources,com.foo.moreResources"/>
</tool>
This comes in very handy when internationalizing templates.
Note that the default resource bundle baseName is "resources", and
the default locale is the result of HttpServletRequest.getLocale().
The default bundle baseName can be overridden as shown above.
Also, be aware that very few performance considerations have been made
in this initial version. |
ViewTool.java | Interface | Generic view tool interface to assist in tool management.
This interface provides the
ViewTool.init(Object initData) method
as a hook for ToolboxManager implementations to pass data in to
tools to initialize them. |