]> git.argeo.org Git - lgpl/argeo-commons.git/blob - base/runtime/org.argeo.eclipse.ui.rap/src/main/java/org/argeo/eclipse/ui/specific/AbstractOpenFileHandler.java
First try to solve RAP specific file download service issue revealed by the upgrade...
[lgpl/argeo-commons.git] / base / runtime / org.argeo.eclipse.ui.rap / src / main / java / org / argeo / eclipse / ui / specific / AbstractOpenFileHandler.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 handler to open a file stored in the server file system, among
28 * other tmp files created for exports.
29 *
30 */
31 public abstract class AbstractOpenFileHandler extends AbstractHandler {
32 private final static Log log = LogFactory
33 .getLog(AbstractOpenFileHandler.class);
34
35 // Must be declared by implementing classes
36 // public final static String ID = "org.argeo.eclipse.ui.specific.openFile";
37
38 public final static String PARAM_FILE_NAME = FileDownloadServiceHandler.PARAM_FILE_NAME;
39 public final static String PARAM_FILE_PATH = FileDownloadServiceHandler.PARAM_FILE_PATH;
40
41 public Object execute(ExecutionEvent event) throws ExecutionException {
42
43 // Try to register each time we execute the command.
44 // try {
45 // ServiceHandler handler = new FileDownloadServiceHandler();
46 // RWT.getServiceManager().registerServiceHandler(
47 // FileDownloadServiceHandler.DOWNLOAD_SERVICE_NAME, handler);
48 // } catch (IllegalArgumentException iae) {
49 // log.warn("Handler is already registered, clean this registering process");
50 // }
51
52 // The real usefull handler
53 String fileName = event.getParameter(PARAM_FILE_NAME);
54 String filePath = event.getParameter(PARAM_FILE_PATH);
55
56 StringBuilder url = new StringBuilder();
57 url.append("&").append(PARAM_FILE_NAME).append("=");
58 url.append(fileName);
59 url.append("&").append(PARAM_FILE_PATH).append("=");
60 url.append(filePath);
61
62 String downloadUrl = RWT.getServiceManager().getServiceHandlerUrl(
63 getDownloadServiceHandlerId())
64 + url.toString();
65 if (log.isTraceEnabled())
66 log.debug("URL : " + downloadUrl);
67
68 UrlLauncher launcher = RWT.getClient().getService(UrlLauncher.class);
69 launcher.openURL(downloadUrl);
70
71 // These lines are useless in the current use case but might be
72 // necessary with new browsers. Stored here for memo
73 // response.setContentType("application/force-download");
74 // response.setHeader("Content-Disposition", contentDisposition);
75 // response.setHeader("Content-Transfer-Encoding", "binary");
76 // response.setHeader("Pragma", "no-cache");
77 // response.setHeader("Cache-Control", "no-cache, must-revalidate");
78 return null;
79 }
80
81 protected abstract String getDownloadServiceHandlerId();
82 }