KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > link > AbsoluteLinkRenderer


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.engine.ILink;
19
20 /**
21  * Renders a link using an absolute URL, not simply a URI
22  * (as with {@link org.apache.tapestry.link.DefaultLinkRenderer}. In addition,
23  * the scheme, server and port may be changed (this may be appropriate when
24  * switching between secure and insecure portions of an application).
25  *
26  * @author Howard Lewis Ship
27  * @since 3.0
28  *
29  **/

30
31 public class AbsoluteLinkRenderer extends DefaultLinkRenderer
32 {
33     private String JavaDoc _scheme;
34     private String JavaDoc _serverName;
35     private int _port;
36
37     public int getPort()
38     {
39         return _port;
40     }
41
42     public String JavaDoc getScheme()
43     {
44         return _scheme;
45     }
46
47     public String JavaDoc getServerName()
48     {
49         return _serverName;
50     }
51
52     /**
53      * Used to override the port in the final URL, if specified. If not specified,
54      * the port provided by the {@link javax.servlet.ServletRequest#getServerPort() request}
55      * is used (typically, the value 80).
56      *
57      **/

58
59     public void setPort(int port)
60     {
61         _port = port;
62     }
63     
64     /**
65      * Used to override the scheme in the final URL, if specified. If not specified,
66      * the scheme provided by the {@link javax.servlet.ServletRequest#getScheme() request}
67      * is used (typically, <code>http</code>).
68      *
69      **/

70
71     public void setScheme(String JavaDoc scheme)
72     {
73         _scheme = scheme;
74     }
75
76     /**
77      * Used to override the server name in the final URL, if specified. If not specified,
78      * the port provided by the {@link javax.servlet.ServletRequest#getServerName() request}
79      * is used.
80      *
81      **/

82
83     public void setServerName(String JavaDoc serverName)
84     {
85         _serverName = serverName;
86     }
87
88     protected String JavaDoc constructURL(ILink link, String JavaDoc anchor, IRequestCycle cycle)
89     {
90         return link.getAbsoluteURL(_scheme, _serverName, _port, anchor, true);
91     }
92
93 }
94
Popular Tags