KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > networkplaces > NetworkPlaceItem


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.networkplaces;
21
22 import java.util.List JavaDoc;
23
24 import javax.servlet.http.HttpServletRequest JavaDoc;
25
26 import com.sslexplorer.boot.Util;
27 import com.sslexplorer.core.CoreUtil;
28 import com.sslexplorer.navigation.RequiresSessionPasswordAbstractFavoriteItem;
29 import com.sslexplorer.vfs.utils.URI;
30 import com.sslexplorer.vfs.webdav.DAVUtilities;
31
32 /**
33  * <p>
34  * Implementation of {@link com.sslexplorer.navigation.AbstractFavoriteItem} to
35  * display the network places in a sortable table.
36  * @author James D Robinson <a HREF="mailto:james@3sp.com">&lt;james@3sp.com&gt;</a>
37  */

38 public class NetworkPlaceItem extends RequiresSessionPasswordAbstractFavoriteItem {
39
40     /**
41      * Default window width for popup
42      */

43     public final static int WINDOW_WIDTH = 790;
44
45     /**
46      * Default window width for popup
47      */

48     public final static int WINDOW_HEIGHT = 480;
49
50     // Private instance variables
51

52     private String JavaDoc mountPath;
53
54     /**
55      * Constructor
56      * @param networkPlace The network place represented by the NetworkPlaceItem.
57      * @param mountPath The DAVMount path.
58      * @param policies The policies for the resource.
59      * @param requiresSessionPassword if session password is required.
60      */

61     public NetworkPlaceItem(NetworkPlace networkPlace, String JavaDoc mountPath, List JavaDoc policies, boolean requiresSessionPassword) {
62         super(networkPlace, policies, requiresSessionPassword);
63         this.mountPath = mountPath;
64     }
65
66     /*
67      * (non-Javadoc)
68      * @see com.sslexplorer.navigation.FavoriteItem#getOnClick()
69      */

70     public String JavaDoc getOnClick(int policy, HttpServletRequest JavaDoc request) {
71         return "";
72     }
73
74     /*
75      * (non-Javadoc)
76      * @see com.sslexplorer.navigation.FavoriteItem#getLink(java.lang.String)
77      */

78     public String JavaDoc getLink(int policy, String JavaDoc referer, HttpServletRequest JavaDoc request) {
79         return "launchNetworkPlace.do?policy=" +
80                         policy + "&resourceId=" + getResource().getResourceId() +
81                         "&returnTo=" + Util.urlEncode(Util.isNullOrTrimmedBlank(referer) ? CoreUtil.getRealRequestURI(request) : referer);
82     }
83
84     /*
85      * (non-Javadoc)
86      * @see com.sslexplorer.navigation.FavoriteItem#getTarget()
87      */

88     public String JavaDoc getTarget() {
89         return "_blank";
90     }
91
92     /**
93      * Get the pathname to use for the web folder.
94      * @param policy policy
95      * @param request request
96      * @return web folder path
97      */

98     public String JavaDoc getWebFolderPath(int policy, HttpServletRequest JavaDoc request) {
99         if (this.getRequiresSessionPassword()) {
100             /* TODO this wont work properly as it is. Wait until Lee's
101              * new redirecting code is merged
102              */

103             return "/promptForSessionPassword.do?forwardTo=" +
104                 DAVUtilities.encodePath(getFullWebFolderPath(policy, request));
105         }
106         return getFullWebFolderPath(policy, request);
107     }
108
109     /**
110      * @return The DAVMount path
111      */

112     public String JavaDoc getMountPath() {
113         return mountPath;
114     }
115
116     /**
117      * @param mountPath The DAVMount path.
118      */

119     public void setMountPath(String JavaDoc mountPath) {
120         this.mountPath = mountPath;
121     }
122
123     /*
124      * (non-Javadoc)
125      * @see com.sslexplorer.navigation.FavoriteItem#getName()
126      */

127     public String JavaDoc getFavoriteName() {
128         return getResource().getResourceName();
129     }
130
131     /*
132      * (non-Javadoc)
133      * @see com.sslexplorer.navigation.AbstractFavoriteItem#getFavoriteSubType()
134      */

135     public String JavaDoc getFavoriteSubType() {
136         try {
137             return new URI(((NetworkPlace) getResource()).getPath()).getScheme().toUpperCase();
138         } catch (Exception JavaDoc e) {
139             return "";
140         }
141     }
142
143     /*
144      * (non-Javadoc)
145      * @see com.sslexplorer.navigation.AbstractFavoriteItem#getSmallIconPath(javax.servlet.http.HttpServletRequest)
146      */

147     public String JavaDoc getSmallIconPath(HttpServletRequest JavaDoc request) {
148         return CoreUtil.getThemePath(request.getSession()) + "/images/actions/runNetworkPlace.gif";
149     }
150
151     /*
152      * (non-Javadoc)
153      * @see com.sslexplorer.navigation.AbstractFavoriteItem#getLargeIconPath(javax.servlet.http.HttpServletRequest)
154      */

155     public String JavaDoc getLargeIconPath(HttpServletRequest JavaDoc request) {
156         return CoreUtil.getThemePath(request.getSession()) + "/images/actions/runNetworkPlaceLarge.gif";
157     }
158     
159     private String JavaDoc getFullWebFolderPath(int policy, HttpServletRequest JavaDoc request) {
160         // Web folder paths MUST be fully qualified
161
StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
162         buf.append(request.getScheme());
163         buf.append("://");
164         int port = request.getServerPort();
165         buf.append(request.getServerName());
166         if( ( port == 443 && !request.getScheme().equals("https") ) ||
167             ( port == 80 && !request.getScheme().equals("http") ) ||
168             ( port != 80 && port != 443 ) ) {
169             buf.append(":");
170             buf.append(port);
171         }
172         buf.append("/fs/");
173         buf.append(mountPath);
174         return buf.toString();
175         
176     }
177 }
Popular Tags