Viewtools are java classes that encapsulate functionality and are exposed to velocity. All velocity contexts have access to use dotCMS viewtools. Viewtools are mapped to a key in velocity in the toolbox.xml file, which is loaded at startup. Viewtools can also be mapped dynamically, using OSGI.
Viewtools are important for web developers to understand as they provide access to the dotCMS content repository along with a huge amount of methods and utilities that help with things such as String formatting, date and date calculation, XML/Json manipulation, math and other functions often needed when building the display layer.
Viewtools are important for Java developers to understand as they allow java developers to build custom APIs and Java classes that integrate and encapsulate business systems and functionality for use by the web development team.
By way of a hypothetical example, think about integrating dotCMS with an external ecommerce system. The Java developers on the team could build a viewtool called StoreApiTool that was accessible to web developers for use in building templates, widgets, containers, etc.
We would expect the StoreApiToolhave methods like:
or even cleaner:
Velocity would parse this, map $store to the StoreApiTool class and call the getProduct(String upn) method on the StoreTool. This method could then perform a webservice or any other integration call to build and return a Product object for use in the velocity template.
To continue or example, theStoreApiTool could offer other convenience methods for the web developers such as:
Keep in mind, Viewtool methods return full fledged Java Objects and or Lists that can be used in building the presentation layer in dotCMS.
- CAS Tool
- CookieTool Class
- Dotcontent Tool
- ErrorsTool Class
- Elasticsearch Viewtool
- EscapeTool Class
- IteratorTool Class
- Markdown Tool
- PageAPI Tool
- ParserTool Class
- SiteSearch Viewtool
- TextFormatter Class
- User Agent Viewtool
- WikiTool Class