KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > workplace > tools > workplace > rfsfile > CmsRfsFileDownloadDialog


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src-modules/org/opencms/workplace/tools/workplace/rfsfile/CmsRfsFileDownloadDialog.java,v $
3  * Date : $Date: 2006/03/28 13:52:51 $
4  * Version: $Revision: 1.13 $
5  *
6  * This library is part of OpenCms -
7  * the Open Source Content Mananagement System
8  *
9  * Copyright (c) 2005 Alkacon Software GmbH (http://www.alkacon.com)
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation; either
14  * version 2.1 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * Lesser General Public License for more details.
20  *
21  * For further information about Alkacon Software GmbH, please see the
22  * company website: http://www.alkacon.com
23  *
24  * For further information about OpenCms, please see the
25  * project website: http://www.opencms.org
26  *
27  * You should have received a copy of the GNU Lesser General Public
28  * License along with this library; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */

31
32 package org.opencms.workplace.tools.workplace.rfsfile;
33
34 import org.opencms.jsp.CmsJspActionElement;
35 import org.opencms.main.CmsRuntimeException;
36 import org.opencms.main.OpenCms;
37 import org.opencms.util.CmsDateUtil;
38 import org.opencms.util.CmsFileUtil;
39 import org.opencms.util.CmsRfsFileViewer;
40 import org.opencms.workplace.CmsDialog;
41 import org.opencms.workplace.CmsWorkplaceSettings;
42
43 import java.io.File JavaDoc;
44 import java.io.IOException JavaDoc;
45 import java.text.DateFormat JavaDoc;
46 import java.util.Date JavaDoc;
47
48 import javax.servlet.http.HttpServletRequest JavaDoc;
49 import javax.servlet.http.HttpServletResponse JavaDoc;
50 import javax.servlet.jsp.PageContext JavaDoc;
51
52 /**
53  * Shows useful information about the current file chosen within the
54  * <code>{@link org.opencms.util.CmsRfsFileViewer}</code> and offers
55  * a direct download link. <p>
56  *
57  * @author Achim Westermann
58  *
59  * @version $Revision: 1.13 $
60  *
61  * @since 6.0.0
62  */

63 public class CmsRfsFileDownloadDialog extends CmsDialog {
64
65     /** The dialog type. */
66     public static final String JavaDoc DIALOG_TYPE = "rfsfiledownload";
67
68     private File JavaDoc m_downloadFile;
69
70     /**
71      * Public constructor with JSP action element.<p>
72      *
73      * @param jsp an initialized JSP action element
74      */

75     public CmsRfsFileDownloadDialog(CmsJspActionElement jsp) {
76
77         super(jsp);
78
79     }
80
81     /**
82      * Public constructor with JSP variables.<p>
83      *
84      * @param context the JSP page context
85      * @param req the JSP request
86      * @param res the JSP response
87      */

88     public CmsRfsFileDownloadDialog(PageContext JavaDoc context, HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res) {
89
90         this(new CmsJspActionElement(context, req, res));
91     }
92
93     /**
94      * Returns the HTML for the history settings input form.<p>
95      *
96      * @return the HTML code for the history settings input form
97      */

98     public String JavaDoc buildDownloadFileView() {
99
100         StringBuffer JavaDoc result = new StringBuffer JavaDoc(512);
101
102         result.append(dialogBlock(HTML_START, key(Messages.GUI_WORKPLACE_LOGVIEW_DOWNLOAD_START_MSG_0), false));
103
104         result.append("\r\n");
105         result.append("<!-- start buildDownloadFileView -->\r\n");
106         result.append("<table border=\"0\" style=\"padding:10px;\"}>\r\n");
107
108         result.append(" <tr>\r\n");
109         result.append(" <td>");
110         result.append(key(Messages.GUI_WORKPLACE_LOGVIEW_DOWNLOAD_START_FNAME_0));
111         result.append(":</td>\r\n");
112         result.append(" <td >");
113         result.append(" ").append(m_downloadFile.getName());
114         result.append("</td>\r\n");
115         result.append(" </tr>\r\n");
116
117         result.append(" <tr>\r\n");
118         result.append(" <td>");
119         result.append(key(Messages.GUI_WORKPLACE_LOGVIEW_DOWNLOAD_START_FSIZE_0));
120         result.append(":</td>\n");
121         result.append(" <td>");
122         result.append(CmsFileUtil.formatFilesize(m_downloadFile.length(), getLocale()));
123         result.append("</td>\r\n");
124         result.append(" </tr>\r\n");
125
126         result.append(" <tr>\r\n");
127         result.append(" <td>");
128         result.append(key(Messages.GUI_WORKPLACE_LOGVIEW_DOWNLOAD_START_FPATH_0));
129         result.append(":</td>\n");
130         result.append(" <td>");
131         result.append(m_downloadFile.getAbsolutePath());
132         result.append("</td>\r\n");
133         result.append(" </tr>\r\n");
134
135         result.append(" <tr>\r\n");
136         result.append(" <td>");
137         result.append(key(Messages.GUI_WORKPLACE_LOGVIEW_DOWNLOAD_START_FLMOD_0));
138         result.append(":</td>\n");
139         result.append(" <td>");
140         result.append(CmsDateUtil.getDateTime(new Date JavaDoc(m_downloadFile.lastModified()), DateFormat.MEDIUM, getLocale()));
141         result.append("</td>\r\n");
142         result.append(" </tr>\r\n");
143         result.append("</table>\r\n");
144         result.append("<!-- end buildDownloadFileView -->\r\n");
145         result.append("\r\n");
146
147         result.append(dialogBlock(HTML_END, m_downloadFile.getName(), true));
148         return result.toString();
149     }
150
151     /**
152      * Returns the script used to open the download popup.<p>
153      *
154      * Has to be called from the jsp to work propertly.<p>
155      *
156      * @return the script used to open the download popup
157      */

158     public String JavaDoc buildDownloadScript() {
159
160         StringBuffer JavaDoc result = new StringBuffer JavaDoc(212);
161         // the javasript for download button
162
result.append("<script type=\"text/javascript\">\r\n");
163         result.append("function doDownload() {\r\n");
164         result.append(" window.open(\"");
165         result.append(getJsp().link("/system/workplace/admin/workplace/logfileview/dodownload.jsp?"));
166         result.append("servletUrl=");
167         result.append(getJsp().link("/system/workplace/admin/workplace/logfileview/downloadTrigger.jsp"));
168         result.append("\", \"download\", \"width=300,height=130,left=100,top=100,menubar=no,status=no,toolbar=no\");\r\n");
169         result.append("}\r\n");
170         result.append("</script>\r\n");
171         return result.toString();
172     }
173
174     /**
175      * Returns the HTML for a button that triggers a file download with
176      * <code>{@link CmsRfsFileDownloadServlet}</code> and a button for the chancel action.<p>
177      *
178      * @see org.opencms.workplace.CmsDialog#dialogButtonsOkCancel()
179      * @return the HTML for a button that triggers a file download with
180      * <code>{@link CmsRfsFileDownloadServlet}</code> and a button for the chancel action.
181      */

182     public String JavaDoc dialogButtonsOkCancel() {
183
184         StringBuffer JavaDoc result = new StringBuffer JavaDoc();
185         result.append("<!-- button row start -->\r\n");
186         result.append("<div class=\"dialogbuttons\" unselectable=\"on\">\r\n");
187         result.append(" <p>\r\n ");
188         result.append("<input type=\"button\" value=\"").append(
189             key(org.opencms.workplace.Messages.GUI_DIALOG_BUTTON_DOWNLOAD_0)).append(
190             "\" onclick=\"doDownload();\" class=\"dialogbutton\">");
191
192         result.append("<input name=\"back\" type=\"button\" value=\"");
193         result.append(key(org.opencms.workplace.Messages.GUI_DIALOG_BUTTON_BACK_0));
194         result.append("\" onclick=\"submitAction(\'");
195         result.append(CmsDialog.DIALOG_CANCEL);
196         result.append("\', null, 'main');\" class=\"dialogbutton\">\r\n");
197         result.append("</div>\r\n");
198         result.append("<!-- button row end -->\r\n");
199
200         return result.toString();
201     }
202
203     /**
204      * Returns the file that will be downloaded upon clicking the download button
205      * generated in this form by <code>{@link #dialogButtonsOkCancel()}</code>.<p>
206      *
207      * @return the file that will be downloaded upon clicking the download button
208      * generated in this form by <code>{@link #dialogButtonsOkCancel()}</code>
209      */

210     public File JavaDoc getDownloadFile() {
211
212         return m_downloadFile;
213     }
214
215     /**
216      * @see org.opencms.workplace.CmsWorkplace#initMessages()
217      */

218     protected void initMessages() {
219     
220         addMessages(org.opencms.workplace.tools.workplace.rfsfile.Messages.get().getBundleName());
221         super.initMessages();
222     }
223
224     /**
225      * @see org.opencms.workplace.CmsWorkplace#initWorkplaceRequestValues(org.opencms.workplace.CmsWorkplaceSettings, javax.servlet.http.HttpServletRequest)
226      */

227     protected void initWorkplaceRequestValues(CmsWorkplaceSettings settings, HttpServletRequest JavaDoc request) {
228
229         // triggered by the super-constructor so cannot be
230
// placed in the constructor here or nullpointer exception occurs.
231
m_downloadFile = getDownloadFileInternal();
232
233         // fill the parameter values in the get/set methods
234
fillParamValues(request);
235         // set the dialog type
236
setParamDialogtype(DIALOG_TYPE);
237         // set the action for the JSP switch
238
if (DIALOG_CANCEL.equals(getParamAction())) {
239             setAction(ACTION_CANCEL);
240         } else if (DIALOG_OK.equals(getParamAction())) {
241             setAction(ACTION_OK);
242         } else {
243             // set the default action
244
setAction(ACTION_DEFAULT);
245             setParamTitle(key(
246                 Messages.GUI_WORKPLACE_LOGVIEW_DOWNLOAD_START_TITLE_0,
247                 new Object JavaDoc[] {getDownloadFile().getName()}));
248         }
249     }
250     
251     /**
252      * Returns the File to downoad from the <code>{@link org.opencms.workplace.WorkplaceManager}</code>'s
253      * setting {@link org.opencms.workplace.WorkplaceManager#getRfsFileViewSettings()}.<p>
254      *
255      * @return the File to downoad from the <code>{@link org.opencms.workplace.WorkplaceManager}</code>'s
256      * setting {@link org.opencms.workplace.WorkplaceManager#getRfsFileViewSettings()}
257      * @throws CmsRuntimeException if access to the chosen file to download fails
258      */

259     private File JavaDoc getDownloadFileInternal() throws CmsRuntimeException {
260
261         // no unfrozen clone needed: we just read here.
262
CmsRfsFileViewer fileView = OpenCms.getWorkplaceManager().getFileViewSettings();
263         File JavaDoc file = new File JavaDoc(fileView.getFilePath());
264         try {
265             // 2nd check: it is impossible to set an invalid path to that class.
266
return file.getCanonicalFile();
267         } catch (IOException JavaDoc ioex) {
268             throw new CmsRuntimeException(Messages.get().container(Messages.ERR_FILE_ACCESS_0), ioex);
269         }
270     }
271 }
Popular Tags