%line | %branch | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
org.apache.turbine.util.template.RelativeTemplateLink |
|
|
1 | package org.apache.turbine.util.template; |
|
2 | ||
3 | /* |
|
4 | * Copyright 2001-2005 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 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 | 0 | 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 | 0 | { |
54 | 0 | } |
55 | ||
56 | /** |
|
57 | * Constructor. |
|
58 | * |
|
59 | * @param data a Turbine RunData object. |
|
60 | */ |
|
61 | public RelativeTemplateLink(RunData data) |
|
62 | { |
|
63 | 0 | super(data); |
64 | 0 | } |
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 | // 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 | 0 | super.init((RunData) data); |
79 | 0 | } |
80 | ||
81 | /** |
|
82 | * Refresh method - does nothing |
|
83 | */ |
|
84 | public void refresh() |
|
85 | { |
|
86 | // empty |
|
87 | 0 | } |
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 | 0 | this.res = null; |
99 | 0 | 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 | 0 | this.template = template; |
111 | 0 | addPathInfo(TEMPLATE_KEY, template); |
112 | 0 | 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 | 0 | 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 | 0 | String output = super.toString(); |
136 | ||
137 | // This was added to allow multilple $link variables in one |
|
138 | // template. |
|
139 | 0 | removePathInfo(); |
140 | 0 | removeQueryData(); |
141 | ||
142 | 0 | 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 | 0 | return super.toString(); |
156 | } |
|
157 | } |
This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |