01: package com.opensymphony.module.sitemesh.tapestry;
02:
03: import com.opensymphony.module.sitemesh.HTMLPage;
04: import com.opensymphony.module.sitemesh.Page;
05: import com.opensymphony.module.sitemesh.RequestConstants;
06: import org.apache.tapestry.IRender;
07: import org.apache.tapestry.IRequestCycle;
08: import org.apache.tapestry.valid.RenderString;
09:
10: /**
11: * This utility class gives easy access to the SiteMesh page, with convenience
12: * methods for title and property. A common usage would be with OGNL expressions
13: * like this:
14: * <p/>
15: * <html jwcid="@Shell"
16: * title="ognl:@com.opensymphony.module.sitemesh.tapestry.Util@getTitle()">
17: * <p/>
18: * In future versions of Tapestry, thanks to HiveMind integration, this will
19: * become a lot cleaner, probably like this:
20: * <p/>
21: * <html jwcid="@Shell" title="sitemesh:title">
22: *
23: * @author Erik Hatcher
24: */
25: public class Util {
26:
27: public static String getTitle(IRequestCycle cycle) {
28: return getPage(cycle).getTitle();
29: }
30:
31: public static String getProperty(String name, IRequestCycle cycle) {
32: return getPage(cycle).getProperty(name);
33: }
34:
35: public static Page getPage(IRequestCycle cycle) {
36: return (Page) cycle.getRequestContext().getRequest()
37: .getAttribute(RequestConstants.PAGE);
38: }
39:
40: public static IRender getHeadRenderer(IRequestCycle cycle) {
41: return new RenderString(((HTMLPage) getPage(cycle)).getHead(),
42: true);
43: }
44: }
|