Classes in this File | Line Coverage | Branch Coverage | Complexity | |||||||
AbsoluteLinkRenderer |
|
| 1.0;1 |
1 | // Copyright 2004, 2005 The Apache Software Foundation |
|
2 | // |
|
3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
|
4 | // you may not use this file except in compliance with the License. |
|
5 | // You may obtain a copy of the License at |
|
6 | // |
|
7 | // http://www.apache.org/licenses/LICENSE-2.0 |
|
8 | // |
|
9 | // Unless required by applicable law or agreed to in writing, software |
|
10 | // distributed under the License is distributed on an "AS IS" BASIS, |
|
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
12 | // See the License for the specific language governing permissions and |
|
13 | // limitations under the License. |
|
14 | ||
15 | package org.apache.tapestry.link; |
|
16 | ||
17 | import org.apache.tapestry.IRequestCycle; |
|
18 | import org.apache.tapestry.components.ILinkComponent; |
|
19 | import org.apache.tapestry.engine.ILink; |
|
20 | ||
21 | /** |
|
22 | * Renders a link using an absolute URL, not simply a URI (as with |
|
23 | * {@link org.apache.tapestry.link.DefaultLinkRenderer}. In addition, the scheme, server and port |
|
24 | * may be changed (this may be appropriate when switching between secure and insecure portions of an |
|
25 | * application). |
|
26 | * |
|
27 | * @author Howard Lewis Ship |
|
28 | * @since 3.0 |
|
29 | */ |
|
30 | ||
31 | 0 | public class AbsoluteLinkRenderer extends DefaultLinkRenderer |
32 | { |
|
33 | private String _scheme; |
|
34 | ||
35 | private String _serverName; |
|
36 | ||
37 | private int _port; |
|
38 | ||
39 | public int getPort() |
|
40 | { |
|
41 | 0 | return _port; |
42 | } |
|
43 | ||
44 | public String getScheme() |
|
45 | { |
|
46 | 0 | return _scheme; |
47 | } |
|
48 | ||
49 | public String getServerName() |
|
50 | { |
|
51 | 0 | return _serverName; |
52 | } |
|
53 | ||
54 | /** |
|
55 | * Used to override the port in the final URL, if specified. If not specified, the port provided |
|
56 | * by the {@link javax.servlet.ServletRequest#getServerPort() request} is used (typically, the |
|
57 | * value 80). |
|
58 | */ |
|
59 | ||
60 | public void setPort(int port) |
|
61 | { |
|
62 | 0 | _port = port; |
63 | 0 | } |
64 | ||
65 | /** |
|
66 | * Used to override the scheme in the final URL, if specified. If not specified, the scheme |
|
67 | * provided by the {@link javax.servlet.ServletRequest#getScheme() request} is used (typically, |
|
68 | * <code>http</code>). |
|
69 | */ |
|
70 | ||
71 | public void setScheme(String scheme) |
|
72 | { |
|
73 | 0 | _scheme = scheme; |
74 | 0 | } |
75 | ||
76 | /** |
|
77 | * Used to override the server name in the final URL, if specified. If not specified, the port |
|
78 | * provided by the {@link javax.servlet.ServletRequest#getServerName() request} is used. |
|
79 | */ |
|
80 | ||
81 | public void setServerName(String serverName) |
|
82 | { |
|
83 | 0 | _serverName = serverName; |
84 | 0 | } |
85 | ||
86 | protected String constructURL(ILinkComponent component, IRequestCycle cycle) |
|
87 | { |
|
88 | 0 | ILink link = component.getLink(cycle); |
89 | ||
90 | 0 | return link.getAbsoluteURL(_scheme, _serverName, _port, component.getAnchor(), true); |
91 | } |
|
92 | ||
93 | } |