Template Variable Reference

SportPage expects and provides a small set of template variables. As much as possible, SportPage does not dictate how these variables are used or what value types they may have; technology should serve the application designers, not enslave them.

The optional variables can be defined in the WEB-INF/sportpage.conf configuration file, but will assume practical defaults if they are missing. These are primarily concerned with server installation issues. The optional values and their defaults are summarized in table Table 3

Table Table 4 describes all variables provided by the SportPage page handlers. When adding new dot-variables to SportPage, using these variable names will not be trapped, but may have unexpected results. For more information on the methods and attributes of the built-in objects, consult the Sportwire API Javadocs

[Tip]Per-topic Page Handlers

The PageHandler classes in the table are the base classes; to assign a specific pagehandler to a path, subclass a parent handler naming it after the right-most general path element, for example, to assign a DOMPageHandler to /olympics/sports/*/legends (all legends pages), you would subclass it as LegendsPageHandler.

In practice, page handlers turned out not to be as useful as simply defining new Java Beans in the configuration file, and creating beans that followed the SportPage getInstance API.

Table 4. Template Variables

VariableDefinition
$req

HttpServletRequest handed to the current thread of the SportPageServlet; this object can be queried for the state of the request (see the Java Servlet (JSDK) documentation)

$res

HttpServletResponse handed to the current thread of the SportPageServlet; this object can be manipulated to cause HTTP redirects or to issue error codes.

$requestURI

String value with the raw request URI.

$mru

MRUCacheMap is the application-scoped map of objects which will persist only if referenced within the default timeout value specified in the WEB-INF/sportpage.confby mru.timeout.; items are removed after a timeout unless the item lease is renewed by another request for this data. This caches most-recently-used items and allows less popular items to fade from the cache.

$ttl

TTLCacheMap for volatile items; also application-scoped like the MRU cache, only rather than renew objects upon each request, the TTL map will expire all items after the timeout period forcing the server to create new items to replace them. The default timeout value specified in the WEB-INF/sportpage.confby ttl.timeout.

$path

PathBean contains any extra path information beyond the page handler and may be queried in parts to find the depth level or the token at some specific depth. The most common use of this variable is to pull in the rest of the path information as a static file or as a template. Keep in mind that the filename extension may be missing; to get the actual filenam, the extension must be added by using the $path.ext method.

$exception

If not false, this is set to a Java Exception object that can be queried to find out what went wrong. The variable is initialized to false to allow direct if ($exception) tests.

BasicPageHandler$date

VelocityCalendar A wrapper around the normal Java Calendar class to provide access methods more friendly to Velocity.

$page

String containing the filename of the main content area template. This page component is fixed so that SportPage can substitute other page templates, for example, to indicate a sub-page 404 or other error, or to swap in the XML-format template when the file suffix ends in XML.

$topic

String representation of the path in a Java package format (dot-delimited list of path elements); this value can be used by the application to store or fetch items based on a topic.subtopic key.

$indexpage

A flag value set to “t” if the current path describes an index page. If a page is an index page, SportPage will copy the *.index template filename in place of the normal *.page main content template.

$javabeans

BeanFactory to enable pages to load and access instances of any arbitrary Java class. When called as $javabeans.getBean(classname) and given the fully-qualified package name for any reachable java class, the new class is inspected for a SportPage-specific getInstance(context) factory method, then for a null getInstance() and finally for a null constructor.

$params

ParameterParser is adapted from Jakarta Turbine. This is a java Map object populated with GET/POST and/or PATH_INFO parameters. Access methods provide type-safe ways to get at java primitive types (getBoolean, getBigInteger...) The big advance here is with JavaBeans. This class allows you to set bean properties with one call just as you would normally do in JSP: $params.setProperties( $mybean )

$xml

DOMFileFactory for processing XML files; the actual Java class returned is specified in the dom.data.class property and defaults to creating JDOMFile objects. XML documents returned by the $xml.dom(filename) call can be queried, transformed or output as XML text. (see Sportwire JDOMFile API Docs)