KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > contrib > link > PopupLinkRenderer


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.contrib.link;
16
17 import org.apache.tapestry.IRequestCycle;
18 import org.apache.tapestry.engine.ILink;
19 import org.apache.tapestry.link.DefaultLinkRenderer;
20
21 /**
22  * This renderer emits javascript to launch the link in a window.
23  *
24  * @author David Solis
25  * @since 3.0.1
26  **/

27 public class PopupLinkRenderer extends DefaultLinkRenderer
28 {
29
30     private String JavaDoc _windowName;
31
32     private String JavaDoc _features;
33
34     public PopupLinkRenderer()
35     {
36     }
37
38     /**
39      * Initializes the name and features for javascript window.open function.
40      *
41      * @param windowName the window name
42      * @param features the window features
43      */

44     public PopupLinkRenderer(String JavaDoc windowName, String JavaDoc features)
45     {
46         _windowName = windowName;
47         _features = features;
48     }
49
50     /**
51      * @see DefaultLinkRenderer#constructURL(org.apache.tapestry.engine.ILink, String, org.apache.tapestry.IRequestCycle)
52      */

53     protected String JavaDoc constructURL(ILink link, String JavaDoc anchor, IRequestCycle cycle)
54     {
55         String JavaDoc url = link.getURL(anchor, true);
56         return "javascript: w = window.open(" + normalizeString(url) + ", " + normalizeString(getWindowName()) + ", " + normalizeString(getFeatures()) + "); w.focus();";
57     }
58
59     private String JavaDoc normalizeString(String JavaDoc str)
60     {
61         return str == null ? "''" : "'" + str + "'";
62     }
63
64     public String JavaDoc getWindowName()
65     {
66         return _windowName;
67     }
68
69     public void setWindowName(String JavaDoc windowName)
70     {
71         _windowName = windowName;
72     }
73
74     public String JavaDoc getFeatures()
75     {
76         return _features;
77     }
78
79     public void setFeatures(String JavaDoc features)
80     {
81         _features = features;
82     }
83 }
84
Popular Tags