1 package org.apache.turbine.util.uri;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.turbine.util.RunData;
23 import org.apache.turbine.util.ServerData;
24
25 /***
26 * This class can convert a simple link into a turbine relative
27 * URL. It should be used to convert references for images, style
28 * sheets and similar references.
29 *
30 * The resulting links have no query data or path info. If you need
31 * this, use TurbineURI or TemplateURI.
32 *
33 * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
34 * @version $Id: DataURI.java 644601 2008-04-04 03:58:58Z seade $
35 *
36 */
37
38 public class DataURI
39 extends BaseURI
40 implements URIConstants
41 {
42 /***
43 * Empty C'tor. Uses Turbine.getDefaultServerData().
44 *
45 */
46 public DataURI()
47 {
48 super();
49 }
50
51 /***
52 * Constructor with a RunData object
53 *
54 * @param runData A RunData object
55 */
56 public DataURI(RunData runData)
57 {
58 super(runData);
59 }
60
61 /***
62 * Constructor, set explicit redirection
63 *
64 * @param runData A RunData object
65 * @param redirect True if redirection allowed.
66 */
67 public DataURI(RunData runData, boolean redirect)
68 {
69 super(runData, redirect);
70 }
71
72 /***
73 * Constructor with a ServerData object
74 *
75 * @param serverData A ServerData object
76 */
77 public DataURI(ServerData serverData)
78 {
79 super(serverData);
80 }
81
82 /***
83 * Constructor, set explicit redirection
84 *
85 * @param serverData A ServerData object
86 * @param redirect True if redirection allowed.
87 */
88 public DataURI(ServerData serverData, boolean redirect)
89 {
90 super(serverData, redirect);
91 }
92
93
94 /***
95 * Content Tool wants to be able to turn the encoding
96 * of the servlet container off. After calling this method,
97 * the encoding will not happen any longer.
98 */
99 public void clearResponse()
100 {
101 setResponse(null);
102 }
103
104 /***
105 * Builds the URL with all of the data URL-encoded as well as
106 * encoded using HttpServletResponse.encodeUrl(). The resulting
107 * URL is absolute; it starts with http/https...
108 *
109 * <p>
110 * <code><pre>
111 * TurbineURI tui = new TurbineURI (data, "UserScreen");
112 * tui.addPathInfo("user","jon");
113 * tui.getAbsoluteLink();
114 * </pre></code>
115 *
116 * The above call to getAbsoluteLink() would return the String:
117 *
118 * <p>
119 * http://www.server.com/servlets/Turbine/screen/UserScreen/user/jon
120 *
121 * @return A String with the built URL.
122 */
123 public String getAbsoluteLink()
124 {
125 StringBuffer output = new StringBuffer();
126
127 getSchemeAndPort(output);
128 getContextAndScript(output);
129
130 if (hasReference())
131 {
132 output.append('#');
133 output.append(getReference());
134 }
135
136
137
138
139 return encodeResponse(output.toString());
140 }
141
142 /***
143 * Builds the URL with all of the data URL-encoded as well as
144 * encoded using HttpServletResponse.encodeUrl(). The resulting
145 * URL is relative to the webserver root.
146 *
147 * <p>
148 * <code><pre>
149 * TurbineURI tui = new TurbineURI (data, "UserScreen");
150 * tui.addPathInfo("user","jon");
151 * tui.getRelativeLink();
152 * </pre></code>
153 *
154 * The above call to getRelativeLink() would return the String:
155 *
156 * <p>
157 * /servlets/Turbine/screen/UserScreen/user/jon
158 *
159 * @return A String with the built URL.
160 */
161 public String getRelativeLink()
162 {
163 StringBuffer output = new StringBuffer();
164
165 getContextAndScript(output);
166
167 if (hasReference())
168 {
169 output.append('#');
170 output.append(getReference());
171 }
172
173
174
175
176 return encodeResponse(output.toString());
177 }
178
179 /***
180 * toString() simply calls getAbsoluteLink. You should not use this in your
181 * code unless you have to. Use getAbsoluteLink.
182 *
183 * @return This URI as a String
184 *
185 */
186 public String toString()
187 {
188 return getAbsoluteLink();
189 }
190 }