01: /*
02: * Created on Apr 26, 2006
03: */
04: package uk.org.ponder.rsf.templateresolver;
05:
06: import uk.org.ponder.rsf.viewstate.ContextURLProvider;
07: import uk.org.ponder.rsf.viewstate.ViewParameters;
08: import uk.org.ponder.stringutil.StringList;
09: import uk.org.ponder.webapputil.ConsumerInfo;
10:
11: /**
12: * A simple TemplateResolverStrategy that looks in any ConsumerRequestInfo valid
13: * for the current request for a prefix to be applied to the view id to form a
14: * template name, or else falls back to just the view id.
15: *
16: * @author Antranig Basman (antranig@caret.cam.ac.uk)
17: *
18: */
19:
20: public class CRITemplateResolverStrategy implements
21: TemplateResolverStrategy, BaseAwareTemplateResolverStrategy,
22: RootAwareTRS {
23: private String basedir = "";
24:
25: private ConsumerInfo ciproxy;
26:
27: private ContextURLProvider cup;
28:
29: private int rootpriority = 1;
30:
31: /** The default is to seek ServletContext resources in the current webapp **/
32: private String trbase = "/";
33: public static final String CONSUMERTYPE_SEPARATOR = "-";
34:
35: public void setContextURLProvider(ContextURLProvider cup) {
36: this .cup = cup;
37: }
38:
39: /**
40: * Set the base directory in which template files will be sought. This must
41: * contain both trailing slash and leading slash.
42: */
43: public void setBaseDirectory(String basedir) {
44: this .basedir = basedir;
45: }
46:
47: public void setConsumerInfo(ConsumerInfo ci) {
48: this .ciproxy = ci;
49: }
50:
51: public void setRootResolverPriority(int rootpriority) {
52: this .rootpriority = rootpriority;
53: }
54:
55: public StringList resolveTemplatePath(ViewParameters viewparams) {
56: StringList togo = new StringList();
57: ConsumerInfo ci = ciproxy.get();
58: if (ci.consumertype != null) {
59: String consumerprefix = ci.consumertype
60: + CONSUMERTYPE_SEPARATOR;
61: togo.add(basedir + consumerprefix + viewparams.viewID);
62: }
63:
64: togo.add(basedir + viewparams.viewID);
65: return togo;
66: }
67:
68: public String getExternalURLBase() {
69: return cup == null ? "" : cup.getContextBaseURL();
70: }
71:
72: public String getTemplateResourceBase() {
73: return trbase;
74: }
75:
76: public void setTemplateResourceBase(String trbase) {
77: this .trbase = trbase;
78: }
79:
80: public int getRootResolverPriority() {
81: return rootpriority;
82: }
83:
84: public boolean isStatic() {
85: return false;
86: }
87:
88: }
|