Red Hat Web Application Framework 6.1 用户手册

下载
页码 230
Chapter 12. Presentation (Bebop) Tutorial
159
*/
private class BannerAd extends SimpleComponent {
public void generateXML(PageState ps, Element parent) {
Element elt = new Element("socksite:bannerAd",
SOCKSITE_XML_NS);
elt.setText(BannerAdManager.getInstance().getBanner());
parent.addContent(elt);
}
}
}
You must also amend the XSLT stylesheet:
&
!-- match the layout element and put the
header, footer, etc., in their appropriate places. --
'
&
xsl:template match="socksite:layout"
xmlns:socksite="http://www.sockpuppet.com/xmlns"
'
&
xsl:apply-templates select="socksite:top"/
'
&
xsl:apply-templates select="socksite:bannerAd"/
'
&
table
'
&
tr
'
&
td width="25%"
'
&
xsl:apply-templates
select="socksite:side"/
'
&
/td
'
&
td
'
&
xsl:apply-templates select="socksite:main"/
'
&
/td
'
&
/tr
'
&
/table
'
&
xsl:apply-templates select="bebop:bottom"/
'
&
/xsl:template
'
Note
The above stylesheet will work whether or not the input DOM actually contains a banner ad; the
(
xsl:apply-templates select="socksite:bannerAd"/
)
code will simply be ignored if no such
element exists in the DOM.
12.5. Special-Case Stylesheets
You may occasionally want to override the default stylesheet rules for one particular page. Because of
the way XSLT works, you can choose to override only some
template match=...
rules, allowing
others to be handled by the default stylesheet.
You should handle this in the dispatcher for your application, or by overriding the
getStylesheet-
Transformer()
or
servePage
methods in a
PresentationManager
class specific to your appli-
cation. For example:
public class SockPuppetPresentationManager extends
BasePresentationManager {
public void servePage(Page p,