KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > webforwards > WebForwardItem


1 /*
2  * SSL-Explorer
3  *
4  * Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */

19             
20 package com.sslexplorer.webforwards;
21
22 import java.util.List JavaDoc;
23
24 import javax.servlet.http.HttpServletRequest JavaDoc;
25
26 import com.sslexplorer.boot.HostService;
27 import com.sslexplorer.boot.Util;
28 import com.sslexplorer.core.CoreUtil;
29 import com.sslexplorer.navigation.RequiresSessionPasswordAbstractFavoriteItem;
30
31 /**
32  * Wrapper to make a suitable struts bean for
33  * {@link com.sslexplorer.webforwards.WebForward} instances.
34  *
35  * @author Brett Smith <a HREF="mailto: brett@3sp.com">&lt;brett@3sp.com&gt;</a>
36  * @author James D Robinson <a HREF="mailto:james@3sp.com">&lt;james@3sp.com&gt;</a>
37  */

38 public class WebForwardItem extends RequiresSessionPasswordAbstractFavoriteItem {
39
40     // Private instance variables
41

42     private String JavaDoc selected;
43     private HostService sslexplorerHost;
44
45     /**
46      * 6 Construct a new web forward item wrapping a {@link WebForward}.
47      *
48      * @param webForward the web forward object
49      * @param sslexplorerHost the hostname of this SSL-Explorer server as the
50      * client sees it.
51      * @param policies list of policies
52      * @param requiresPassword requires password
53      */

54     public WebForwardItem(WebForward webForward, HostService sslexplorerHost, List JavaDoc policies, boolean requiresPassword) {
55         /*
56          * TODO this needs to use ResourceItem and the actual resource object as /*
57          * per NetworkPlaceItem
58          */

59         super(webForward, policies, requiresPassword);
60         this.sslexplorerHost = sslexplorerHost;
61     }
62
63     /**
64      * Get the host
65      *
66      * @return host
67      */

68     public HostService getHost() {
69         return sslexplorerHost;
70     }
71
72     /**
73      * Get the URL required to 'launch' this web forward.
74      *
75      * @return link
76      */

77     public String JavaDoc getLink(int policy, String JavaDoc referer, HttpServletRequest JavaDoc request) {
78         return "/launchWebForward.do?resourceId=" + getWebForward().getResourceId() + "&policy=" + policy +
79         "&returnTo=" + Util.urlEncode(Util.isNullOrTrimmedBlank(referer) ? CoreUtil.getRealRequestURI(request) : referer);
80     }
81
82     /**
83      * Get a descriptive name for the type of web forward this item represents.
84      *
85      * @return type name
86      */

87     public String JavaDoc getTypeName() {
88         return ((WebForwardTypeItem) WebForwardTypes.WEB_FORWARD_TYPES.get(this.getWebForward().getType())).getName();
89     }
90
91     /**
92      * Set whether this item is selected
93      *
94      * @param selected
95      */

96     public void setSelected(String JavaDoc selected) {
97         this.selected = selected;
98     }
99
100     /**
101      * Get if this item is selected
102      *
103      * @return selected
104      */

105     public String JavaDoc getSelected() {
106         return selected;
107     }
108
109     /**
110      * Get the web forward
111      *
112      * @return
113      */

114     public WebForward getWebForward() {
115         return (WebForward) this.getResource();
116     }
117
118     /*
119      * (non-Javadoc)
120      *
121      * @see com.sslexplorer.navigation.FavoriteItem#getOnClick()
122      */

123     public String JavaDoc getOnClick(int policy, HttpServletRequest JavaDoc request) {
124         return "";
125     }
126
127     /*
128      * (non-Javadoc)
129      *
130      * @see com.sslexplorer.navigation.FavoriteItem#getTarget()
131      */

132     public String JavaDoc getTarget() {
133         return "_blank";
134     }
135
136     /**
137      * Get the category for this web forward
138      *
139      * @return category
140      */

141     public String JavaDoc getCategory() {
142         return ((WebForward) this.getResource()).getCategory();
143     }
144
145     /*
146      * (non-Javadoc)
147      *
148      * @see com.sslexplorer.table.TableItem#getColumnValue(int)
149      */

150     public Object JavaDoc getColumnValue(int col) {
151         if (col < 2) {
152             return super.getColumnValue(col);
153         }
154         switch (col) {
155             case 2:
156                 return getTypeName();
157             default:
158                 return getCategory();
159         }
160     }
161
162     /*
163      * (non-Javadoc)
164      *
165      * @see com.sslexplorer.navigation.AbstractFavoriteItem#getFavoriteName()
166      */

167     public String JavaDoc getFavoriteName() {
168         return getResource().getResourceName();
169     }
170
171     /*
172      * (non-Javadoc)
173      *
174      * @see com.sslexplorer.navigation.AbstractFavoriteItem#getFavoriteSubType()
175      */

176     public String JavaDoc getFavoriteSubType() {
177         return getTypeName();
178     }
179
180     /*
181      * (non-Javadoc)
182      *
183      * @see com.sslexplorer.navigation.AbstractFavoriteItem#getSmallIconPath(javax.servlet.http.HttpServletRequest)
184      */

185     public String JavaDoc getSmallIconPath(HttpServletRequest JavaDoc request) {
186         return CoreUtil.getThemePath(request.getSession()) + "/images/actions/runWebForward.gif";
187     }
188
189     /*
190      * (non-Javadoc)
191      *
192      * @see com.sslexplorer.navigation.AbstractFavoriteItem#getLargeIconPath(javax.servlet.http.HttpServletRequest)
193      */

194     public String JavaDoc getLargeIconPath(HttpServletRequest JavaDoc request) {
195         return CoreUtil.getThemePath(request.getSession()) + "/images/actions/runWebForwardLarge.gif";
196     }
197 }
Popular Tags