2 * Copyright (C) 2007-2012 Argeo GmbH
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org
.argeo
.eclipse
.ui
.specific
;
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
;
27 * Rap specific handler to open a file stored in the server file system, among
28 * other tmp files created for exports.
31 public class SimpleOpenFile
extends AbstractHandler
{
32 private final static Log log
= LogFactory
33 .getLog(SimpleOpenFile
.class);
35 private String serviceId
;
37 public final static String PARAM_FILE_NAME
= FileDownloadService
.PARAM_FILE_NAME
;
38 public final static String PARAM_FILE_PATH
= FileDownloadService
.PARAM_FILE_PATH
;
40 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
41 String fileName
= event
.getParameter(PARAM_FILE_NAME
);
42 String filePath
= event
.getParameter(PARAM_FILE_PATH
);
45 if (serviceId
== null || "".equals(serviceId
.trim())
46 || fileName
== null || "".equals(fileName
.trim())
47 || filePath
== null || "".equals(filePath
.trim()))
50 StringBuilder url
= new StringBuilder();
51 url
.append("&").append(PARAM_FILE_NAME
).append("=");
53 url
.append("&").append(PARAM_FILE_PATH
).append("=");
56 String downloadUrl
= RWT
.getServiceManager().getServiceHandlerUrl(
59 if (log
.isTraceEnabled())
60 log
.debug("URL : " + downloadUrl
);
62 UrlLauncher launcher
= RWT
.getClient().getService(UrlLauncher
.class);
63 launcher
.openURL(downloadUrl
);
65 // These lines are useless in the current use case but might be
66 // necessary with new browsers. Stored here for memo
67 // response.setContentType("application/force-download");
68 // response.setHeader("Content-Disposition", contentDisposition);
69 // response.setHeader("Content-Transfer-Encoding", "binary");
70 // response.setHeader("Pragma", "no-cache");
71 // response.setHeader("Cache-Control", "no-cache, must-revalidate");
75 /* DEPENDENCY INJECTION */
76 public void setDownloadServiceHandlerId(String downloadServiceHandlerId
) {
77 this.serviceId
= downloadServiceHandlerId
;