]> git.argeo.org Git - lgpl/argeo-commons.git/blob - base/runtime/org.argeo.eclipse.ui.rap/src/main/java/org/argeo/eclipse/ui/specific/OpenFsFile.java
Go on working on the rap specific file download issue. New better name for command...
[lgpl/argeo-commons.git] / base / runtime / org.argeo.eclipse.ui.rap / src / main / java / org / argeo / eclipse / ui / specific / OpenFsFile.java
1 /*
2 * Copyright (C) 2007-2012 Argeo GmbH
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package org.argeo.eclipse.ui.specific;
17
18 import org.apache.commons.logging.Log;
19 import org.apache.commons.logging.LogFactory;
20 import org.eclipse.core.commands.AbstractHandler;
21 import org.eclipse.core.commands.ExecutionEvent;
22 import org.eclipse.core.commands.ExecutionException;
23 import org.eclipse.rap.rwt.RWT;
24 import org.eclipse.rap.rwt.client.service.UrlLauncher;
25
26 /**
27 * Rap specific command handler to open a file stored in the server file system.
28 * The file absolute path and name must be passed as parameters.
29 *
30 * It relies on an existing {@link DownloadFsFileService} to forward the
31 * corresponding file to the user browser.
32 *
33 */
34 public class OpenFsFile extends AbstractHandler {
35 private final static Log log = LogFactory.getLog(OpenFsFile.class);
36
37 /* DEPENDENCY INJECTION */
38 private String serviceId;
39
40 public final static String PARAM_FILE_NAME = DownloadFsFileService.PARAM_FILE_NAME;
41 public final static String PARAM_FILE_PATH = DownloadFsFileService.PARAM_FILE_PATH;
42
43 public Object execute(ExecutionEvent event) throws ExecutionException {
44 String fileName = event.getParameter(PARAM_FILE_NAME);
45 String filePath = event.getParameter(PARAM_FILE_PATH);
46
47 // sanity check
48 if (serviceId == null || "".equals(serviceId.trim())
49 || fileName == null || "".equals(fileName.trim())
50 || filePath == null || "".equals(filePath.trim()))
51 return null;
52
53 StringBuilder url = new StringBuilder();
54 url.append("&").append(PARAM_FILE_NAME).append("=");
55 url.append(fileName);
56 url.append("&").append(PARAM_FILE_PATH).append("=");
57 url.append(filePath);
58
59 String downloadUrl = RWT.getServiceManager().getServiceHandlerUrl(
60 serviceId)
61 + url.toString();
62 if (log.isTraceEnabled())
63 log.debug("URL : " + downloadUrl);
64
65 UrlLauncher launcher = RWT.getClient().getService(UrlLauncher.class);
66 launcher.openURL(downloadUrl);
67
68 // These lines are useless in the current use case but might be
69 // necessary with new browsers. Stored here for memo
70 // response.setContentType("application/force-download");
71 // response.setHeader("Content-Disposition", contentDisposition);
72 // response.setHeader("Content-Transfer-Encoding", "binary");
73 // response.setHeader("Pragma", "no-cache");
74 // response.setHeader("Cache-Control", "no-cache, must-revalidate");
75 return null;
76 }
77
78 /* DEPENDENCY INJECTION */
79 public void setDownloadServiceHandlerId(String downloadServiceHandlerId) {
80 this.serviceId = downloadServiceHandlerId;
81 }
82 }