KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > turbine > util > template > RelativeTemplateLink


1 package org.apache.turbine.util.template;
2
3 /*
4  * Copyright 2001-2004 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License")
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
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,v 1.8.2.2 2004/05/20 03:27:23 seade Exp $
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 JavaDoc TEMPLATE_KEY = "template";
43
44     /** cache of the template name for getPage() */
45     private String JavaDoc 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 JavaDoc data)
74     {
75         // we just blithely cast to RunData as if another object
76
// or null is passed in we'll throw an appropriate runtime
77
// exception.
78
super.init((RunData) data);
79     }
80
81     /**
82      * Refresh method - does nothing
83      */

84     public void refresh()
85     {
86         // empty
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 JavaDoc 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 JavaDoc 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 JavaDoc toString()
134     {
135         String JavaDoc output = super.toString();
136
137         // This was added to allow multilple $link variables in one
138
// template.
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 JavaDoc getURI()
154     {
155         return super.toString();
156     }
157 }
158
Popular Tags