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
.argeo
.ArgeoException
;
21 import org
.eclipse
.rap
.rwt
.RWT
;
22 import org
.eclipse
.rap
.rwt
.client
.service
.UrlLauncher
;
23 import org
.eclipse
.rap
.rwt
.service
.ServiceHandler
;
26 * RAP SPECIFIC handler to enable the opening of a download dialog box triggered
27 * by whatever action in the UI
29 * Manages the registration of the effective DownloadServiceHandler at
32 * Manages the process of forwarding the request to the handler at runtime to
33 * open the dialog box encodedURL
35 public class FileHandler
{
36 public final static String DOWNLOAD_SERVICE_NAME
= "argeo.rap.download.service";
37 private final static Log log
= LogFactory
.getLog(FileHandler
.class);
39 public FileHandler(FileProvider provider
) {
40 ServiceHandler handler
= new DownloadServiceHandler(provider
);
42 RWT
.getServiceManager().registerServiceHandler(
43 DOWNLOAD_SERVICE_NAME
, handler
);
44 } catch (IllegalArgumentException iae
) {
45 log
.warn("Handler is already registered, clean this registering process");
49 public void openFile(String fileName
, String fileId
) {
51 String downloadUrl
= RWT
.getServiceManager().getServiceHandlerUrl(
52 DOWNLOAD_SERVICE_NAME
)
53 + createParamUrl(fileName
, fileId
);
54 if (log
.isTraceEnabled())
55 log
.debug("URL : " + downloadUrl
);
56 UrlLauncher launcher
= RWT
.getClient()
57 .getService(UrlLauncher
.class);
58 launcher
.openURL(downloadUrl
);
59 } catch (Exception e
) {
60 throw new ArgeoException("Unable to open file " + fileName
, e
);
62 // These lines are useless in the current use case but might be
63 // necessary with new browsers. Stored here for memo
64 // response.setContentType("application/force-download");
65 // response.setHeader("Content-Disposition", contentDisposition);
66 // response.setHeader("Content-Transfer-Encoding", "binary");
67 // response.setHeader("Pragma", "no-cache");
68 // response.setHeader("Cache-Control", "no-cache, must-revalidate");
71 private String
createParamUrl(String filename
, String fileId
) {
72 StringBuilder url
= new StringBuilder();
73 url
.append("&filename=");
75 url
.append("&fileid=");
77 return url
.toString();