Red Hat Web Application Framework 6.1 用户手册

下载
页码 230
Chapter 5. WAF Component: Presentation
21
BasePresentationManager
or swap it out with its own to use a different algorithm for choosing a
stylesheet for the current request.
XSLT integration into WAF is accomplished by associating stylesheet documents with both WAF
packages and site nodes. A default stylesheet is associated with each WAF package, and the package
defaults can be overridden within a particular URL prefix’s scope. A site node represents a node in
the webapp’s URL tree; each site node, combined with its ancestors, generates a URL prefix. For the
purposes of this discussion, subsite is defined to mean any site node that contains child site nodes —
that is, a directory that contains subdirectories.
Because XSLT templates are also XML documents, they can be manipulated and composed dynami-
cally. A
PresentationManager
could compute a new XSLT stylesheet on the fly, taking fragments
from files on disk or in the database.
For more information about using XSLT with WAF, see Section 12.1 Calling XSLT from a WAF
Application.
5.2.2. WAF Templating Package
The WAF Templating package (com.arsdigita.templating) serves as a repository for all classes relating
to the XSL templating.
5.2.2.1. Template Resolution
This section discusses the process of resolving the primary, top level stylesheet for transforming an
application’s XML DOM into an HTML page.
5.2.2.1.1. Background
The original WAF method for resolving top level stylesheets required the application
programmer
to
register
a
default
com.arsdigita.kernel.StyleSheet
object
against
its
com.arsdigita.kernel.PackageType
object.
Project
integrators
could
override this default application stylesheet by registering a custom stylesheet against a
com.arsdigita.kernel.SiteNode
object.
These mappings were maintained in the database and the rules for querying them to discover the
top level XSL template for an application were written into the standard presentation manager class
(
com.arsdigita.sitenode.BasePresentationManager
). This resulted in an XSL templating
architecture that was spread across multiple Java packages and left little scope for extending or altering
the template resolution algorithms, without massive code replacement / duplication.
5.2.2.1.2. Stylesheet Resolver
A quick analysis of XSLT usage across projects and applications shows that there are a large number
of variables that can come into play when deciding which stylesheet to apply to an application’s DOM.
Rather than attempt to standardize on a particular algorithm for resolving stylesheets, the WAF tem-
plating package introduces the
com.arsdigita.templating.StylesheetResolver
interface as
a means to plug in an arbitrary template resolution algorithm. This interface contains a single method:
public URL resolve(HttpServletRequest sreq);
This method may use any available state information to locate a stylesheet, which transforms XML
that has been generated during this supplied request object. The returned object must represent an
absolute URL under any protocol supported by the
java.net.URL
class (typically, either file:// or
http://). The
com.arsdigita.templating.LegacyStylesheetResolver
class provides a
resolver compatible with the resolution method used in WAF releases older than 6.0. The