KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > navigation > forms > FileDownloadForm


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.navigation.forms;
21
22 import java.awt.Rectangle JavaDoc;
23
24 import javax.servlet.http.HttpServletRequest JavaDoc;
25
26 import org.apache.commons.logging.Log;
27 import org.apache.commons.logging.LogFactory;
28
29 import com.sslexplorer.boot.Util;
30 import com.sslexplorer.core.CoreUtil;
31 import com.sslexplorer.core.DownloadContent;
32 import com.sslexplorer.core.WindowOpenJavascriptLink;
33 import com.sslexplorer.core.forms.CoreForm;
34 import com.sslexplorer.security.LogonControllerFactory;
35 import com.sslexplorer.security.SessionInfo;
36
37 /**
38  * Form for performing file downloads.
39  *
40  * @author James D Robinson <a HREF="mailto:james@3sp.com">&lt;james@3sp.com&gt;</a>
41  *
42  */

43 public class FileDownloadForm extends CoreForm {
44
45     static Log log = LogFactory.getLog(FileDownloadForm.class);
46
47     /**
48      * Default window width for popup
49      */

50     public final static int WINDOW_WIDTH = 790;
51
52     /**
53      * Default window width for popup
54      */

55     public final static int WINDOW_HEIGHT = 480;
56
57     private DownloadContent download;
58
59     /**
60      * @param download
61      */

62     public void init(DownloadContent download) {
63         this.download = download;
64     }
65
66     /**
67      * @return Returns the download.
68      */

69     public DownloadContent getDownload() {
70         return download;
71     }
72     
73     /**
74      * Get the link show the temporary download directory for the current session/
75      *
76      * @param request request
77      * @return String
78      */

79     public String JavaDoc getTempDownloadLink(HttpServletRequest JavaDoc request){
80         SessionInfo session = LogonControllerFactory.getInstance().getSessionInfo(request);
81         WindowOpenJavascriptLink windowOpenJavascriptLink = new WindowOpenJavascriptLink("fileSystem.do?actionTarget=list&path=" + Util.urlEncode("temp/" + session.getUser().getPrincipalName() + "."
82             + session.getHttpSession().getId())+ "&resourceId=0",
83                         "vfs_" + "0" + "_" + System.currentTimeMillis(),
84                         new Rectangle JavaDoc(20, 20, WINDOW_WIDTH, WINDOW_HEIGHT), true, false, false, true, false);
85         return "javascript: " + windowOpenJavascriptLink.toJavascript();
86     }
87     
88     /* (non-Javadoc)
89      * @see com.sslexplorer.core.forms.CoreForm#getReferer()
90      */

91     public String JavaDoc getReferer() {
92         String JavaDoc tmpReferer = super.getReferer();
93         // if there is no referer then just go back to home.
94
if (tmpReferer == null){
95             return "window.location = '/showHome.do'";
96         }
97         return tmpReferer;
98     }
99
100     /**
101      * @return String
102      */

103     public String JavaDoc getLink() {
104         return "/fileDownload.do?id=" + download.getId();
105     }
106 }
Popular Tags