1 package org.apache.turbine.util.template;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 import org.apache.turbine.services.pull.ApplicationTool;
20 import org.apache.turbine.util.RelativeDynamicURI;
21 import org.apache.turbine.util.RunData;
22
23 /***
24 * A customized version of the RelativeDynamicURI to be used in Templates.
25 * Here's an example of its Velocity/WebMacro use:
26 *
27 * <p><code>
28 * $link.setPage("index.wm").addPathInfo("hello","world")
29 * </code><br />This would return: <code>/myapp/servlet/myapp/template/index.wm/hello/world
30 * </code>
31 *
32 * @author <a href="jmcnally@collab.net">John D. McNally</a>
33 * @author see the authors of TemplateLink
34 * @version $Id: RelativeTemplateLink.java 264148 2005-08-29 14:21:04Z henning $
35 * @deprecated Use {@link org.apache.turbine.services.pull.tools.RelativeTemplateLink} instead.
36 */
37 public class RelativeTemplateLink
38 extends RelativeDynamicURI
39 implements ApplicationTool
40 {
41 /*** the pathinfo key stored in the DynamicURI */
42 private static final String TEMPLATE_KEY = "template";
43
44 /*** cache of the template name for getPage() */
45 private String template = null;
46
47 /***
48 * Default constructor.
49 * <p>
50 * The init method must be called before use.
51 */
52 public RelativeTemplateLink()
53 {
54 }
55
56 /***
57 * Constructor.
58 *
59 * @param data a Turbine RunData object.
60 */
61 public RelativeTemplateLink(RunData data)
62 {
63 super(data);
64 }
65
66 /***
67 * This will initialise a TemplateLink object that was
68 * constructed with the default constructor (ApplicationTool
69 * method).
70 *
71 * @param data assumed to be a RunData object
72 */
73 public void init(Object data)
74 {
75
76
77
78 super.init((RunData) data);
79 }
80
81 /***
82 * Refresh method - does nothing
83 */
84 public void refresh()
85 {
86
87 }
88
89 /***
90 * This will turn off the execution of res.encodeURL()
91 * by making res == null. This is a hack for cases
92 * where you don't want to see the session information
93 *
94 * @return instance of RelativeTemplateLink (this)
95 */
96 public RelativeTemplateLink setEncodeURLOff()
97 {
98 this.res = null;
99 return this;
100 }
101
102 /***
103 * Sets the template variable used by the Template Service.
104 *
105 * @param template A String with the template name.
106 * @return instance of RelativeTemplateLink (this)
107 */
108 public RelativeTemplateLink setPage(String template)
109 {
110 this.template = template;
111 addPathInfo(TEMPLATE_KEY, template);
112 return this;
113 }
114
115 /***
116 * Gets the template variable used by the Template Service.
117 * It is only available after setPage() has been called.
118 *
119 * @return The template name.
120 */
121 public String getPage()
122 {
123 return template;
124 }
125
126 /***
127 * Returns the URI. After rendering the URI, it clears the
128 * pathInfo and QueryString portions of the DynamicURI.
129 *
130 * @return A String with the URI in the form
131 * http://foo.com/Turbine/template/index.wm/hello/world
132 */
133 public String toString()
134 {
135 String output = super.toString();
136
137
138
139 removePathInfo();
140 removeQueryData();
141
142 return output;
143 }
144
145 /***
146 * Returns the URI leaving the source intact. Wraps directly to the
147 * <code>DynamicURI.toString</code> method of the superclass
148 * (avoiding the local toString implementation).
149 *
150 * @return A String with the URI in the form
151 * http://foo.com/Turbine/template/index.wm/hello/world
152 */
153 public String getURI()
154 {
155 return super.toString();
156 }
157 }