]>
git.argeo.org Git - gpl/argeo-slc.git/blob - legacy/argeo-commons/org.argeo.cms.ui.workbench/src/org/argeo/cms/ui/workbench/legacy/rap/OpenFile.java
616dadcf66fe2fb10845f20e0e67501343854c29
1 package org
.argeo
.cms
.ui
.workbench
.legacy
.rap
;
3 import org
.argeo
.api
.cms
.CmsLog
;
4 import org
.eclipse
.core
.commands
.AbstractHandler
;
5 import org
.eclipse
.core
.commands
.ExecutionEvent
;
6 import org
.eclipse
.rap
.rwt
.RWT
;
7 import org
.eclipse
.rap
.rwt
.client
.service
.UrlLauncher
;
10 * RWT specific object to open a file retrieved from the server. It forwards the
11 * request to the correct service after encoding file name and path in the
15 * The parameter "URI" is used to determine the correct file service, the path
16 * and the file name. An optional file name can be added to present the end user
17 * with a different file name as the one used to retrieve it.
22 * The instance specific service is called by its ID and must have been
26 public class OpenFile
extends AbstractHandler
{
27 private final static CmsLog log
= CmsLog
.getLog(OpenFile
.class);
29 public final static String ID
= SingleSourcingConstants
.OPEN_FILE_CMD_ID
;
30 public final static String PARAM_FILE_NAME
= SingleSourcingConstants
.PARAM_FILE_NAME
;
31 public final static String PARAM_FILE_URI
= SingleSourcingConstants
.PARAM_FILE_URI
;;
33 /* DEPENDENCY INJECTION */
34 private String openFileServiceId
;
36 public Object
execute(ExecutionEvent event
) {
37 String fileName
= event
.getParameter(PARAM_FILE_NAME
);
38 String fileUri
= event
.getParameter(PARAM_FILE_URI
);
40 if (fileUri
== null || "".equals(fileUri
.trim()) || openFileServiceId
== null
41 || "".equals(openFileServiceId
.trim()))
44 org
.argeo
.cms
.ui
.workbench
.legacy
.rap
.OpenFile openFileClient
= new org
.argeo
.cms
.ui
.workbench
.legacy
.rap
.OpenFile();
45 openFileClient
.execute(openFileServiceId
, fileUri
, fileName
);
49 public Object
execute(String openFileServiceId
, String fileUri
, String fileName
) {
50 StringBuilder url
= new StringBuilder();
51 url
.append(RWT
.getServiceManager().getServiceHandlerUrl(openFileServiceId
));
53 if (notEmpty(fileName
))
54 url
.append("&").append(SingleSourcingConstants
.PARAM_FILE_NAME
).append("=").append(fileName
);
55 url
.append("&").append(SingleSourcingConstants
.PARAM_FILE_URI
).append("=").append(fileUri
);
57 String downloadUrl
= url
.toString();
58 if (log
.isTraceEnabled())
59 log
.trace("Calling OpenFileService with ID: " + openFileServiceId
+ " , with download URL: " + downloadUrl
);
61 UrlLauncher launcher
= RWT
.getClient().getService(UrlLauncher
.class);
62 launcher
.openURL(downloadUrl
);
66 /* DEPENDENCY INJECTION */
67 public void setOpenFileServiceId(String openFileServiceId
) {
68 this.openFileServiceId
= openFileServiceId
;
71 /** Simply checks if a string is not null nor empty */
72 public static boolean notEmpty(String stringToTest
) {
73 return !(stringToTest
== null || "".equals(stringToTest
.trim()));
76 /** Simply checks if a string is null or empty */
77 public static boolean isEmpty(String stringToTest
) {
78 return stringToTest
== null || "".equals(stringToTest
.trim());