]> git.argeo.org Git - lgpl/argeo-commons.git/blob - OpenFile.java
46de2c9182e706f8fda7be59bb6783ebf2bad1be
[lgpl/argeo-commons.git] / OpenFile.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.rap.rwt.RWT;
21 import org.eclipse.rap.rwt.client.service.UrlLauncher;
22
23 /**
24 * RWT specific object to open a file retrieved from the server. It forwards the
25 * request to the correct service after encoding file name and path in the
26 * request URI.
27 *
28 * <p>
29 * The parameter "URI" is used to determine the correct file service, the path
30 * and the file name. An optional file name can be added to present the end user
31 * with a different file name as the one used to retrieve it.
32 * </p>
33 *
34 *
35 * <p>
36 * The instance specific service is called by its ID and must have been
37 * externally created
38 * </p>
39 */
40 public class OpenFile {
41 private final static Log log = LogFactory.getLog(OpenFile.class);
42
43 // /* DEPENDENCY INJECTION */
44 // private String openFileServiceId;
45 //
46 // public final static String PARAM_FILE_NAME =
47 // OpenFileService.PARAM_FILE_NAME;
48 // public final static String PARAM_FILE_URI =
49 // OpenFileService.PARAM_FILE_URI; // "param.fileURI";
50
51 public Object execute(String openFileServiceId, String fileUri,
52 String fileName) {
53 // // Sanity check
54 // if (fileUri == null || "".equals(fileUri.trim())
55 // || openFileServiceId == null
56 // || "".equals(openFileServiceId.trim()))
57 // return null;
58
59 StringBuilder url = new StringBuilder();
60 url.append(RWT.getServiceManager().getServiceHandlerUrl(
61 openFileServiceId));
62
63 url.append("&").append(OpenFileService.PARAM_FILE_NAME).append("=");
64 url.append(fileName);
65 url.append("&").append(OpenFileService.PARAM_FILE_URI).append("=");
66 url.append(fileUri);
67
68 String downloadUrl = url.toString();
69 if (log.isTraceEnabled())
70 log.debug("URL : " + downloadUrl);
71
72 UrlLauncher launcher = RWT.getClient().getService(UrlLauncher.class);
73 launcher.openURL(downloadUrl);
74 return null;
75 }
76
77 // /* DEPENDENCY INJECTION */
78 // public void setOpenFileServiceId(String openFileServiceId) {
79 // this.openFileServiceId = openFileServiceId;
80 // }
81 }