]> git.argeo.org Git - gpl/argeo-slc.git/blob - org.argeo.slc.client.rap/src/org/argeo/slc/client/ui/specific/OpenJcrFile.java
Add doAs in RCP CmsView.
[gpl/argeo-slc.git] / org.argeo.slc.client.rap / src / org / argeo / slc / client / ui / specific / OpenJcrFile.java
1 package org.argeo.slc.client.ui.specific;
2
3 import java.net.URL;
4 import java.util.UUID;
5
6 import javax.jcr.Node;
7 import javax.jcr.Session;
8
9 import org.argeo.slc.SlcException;
10 import org.argeo.slc.client.rap.OpenJcrFileService;
11 import org.argeo.slc.repo.RepoService;
12 import org.eclipse.core.commands.AbstractHandler;
13 import org.eclipse.core.commands.ExecutionEvent;
14 import org.eclipse.core.commands.ExecutionException;
15 import org.eclipse.rap.rwt.RWT;
16 //import org.eclipse.rap.rwt.service.IServiceHandler;
17 //import org.eclipse.rap.rwt.service.IServiceManager;
18 import org.eclipse.ui.PlatformUI;
19
20 /**
21 * Rap specific command handler to open a file retrieved from a distant JCR
22 * Repository. It creates and register a service instantiated with the
23 * corresponding JCR node, forwards the request, and un register the service on
24 * dispose
25 *
26 * This command and the corresponding service are specific for RAP version [1.3,
27 * 2)
28 */
29 public class OpenJcrFile extends AbstractHandler {
30
31 // Use (new OpenJcrFileCmdId()).getCmdId() instead.
32 // public final String ID = SlcRapPlugin.PLUGIN_ID + ".openJcrFile";
33
34 public final static String PARAM_REPO_NODE_PATH = "param.repoNodePath";
35 public final static String PARAM_REPO_URI = "param.repoUri";
36 public final static String PARAM_WORKSPACE_NAME = "param.workspaceName";
37 public final static String PARAM_FILE_PATH = "param.filePath";
38
39 private RepoService repoService;
40 private String currentServiceId;
41
42 public Object execute(ExecutionEvent event) throws ExecutionException {
43
44 String repoNodePath = event.getParameter(PARAM_REPO_NODE_PATH);
45 String repoUri = event.getParameter(PARAM_REPO_URI);
46 String wkspName = event.getParameter(PARAM_WORKSPACE_NAME);
47 String filePath = event.getParameter(PARAM_FILE_PATH);
48
49 // TODO sanity check
50 if (filePath == null || "".equals(filePath.trim()))
51 return null;
52 Session businessSession = null;
53 try {
54 businessSession = repoService.getRemoteSession(repoNodePath,
55 repoUri, wkspName);
56 Node result = businessSession.getNode(filePath);
57
58 // Create a temporary service. No better solution has been found
59 // yet.
60 currentServiceId = UUID.randomUUID().toString();
61 OpenJcrFileService ojfs = new OpenJcrFileService(result);
62 // FIXME replace it
63 // IServiceManager manager = RWT.getServiceManager();
64 // manager.registerServiceHandler(currentServiceId, ojfs);
65 String urlStr = createFullDownloadUrl(currentServiceId);
66 URL url = new URL(urlStr);
67 PlatformUI.getWorkbench().getBrowserSupport()
68 .createBrowser("DownloadDialog").openURL(url);
69 } catch (Exception e) {
70 throw new SlcException("Unable to open Jcr File for path "
71 + filePath, e);
72 }
73
74 return null;
75 }
76
77 @Override
78 public void dispose() {
79 // IServiceManager manager = RWT.getServiceManager();
80 // manager.unregisterServiceHandler(currentServiceId);
81 super.dispose();
82 }
83
84 private String createFullDownloadUrl(String serviceId) {
85 StringBuilder url = new StringBuilder();
86 url.append(RWT.getRequest().getRequestURL());
87
88 StringBuilder params = new StringBuilder();
89 params.append("?");
90 // FIXME commented out so that it builds
91 //params.append(IServiceHandler.REQUEST_PARAM).append("=");
92 params.append(serviceId);
93 String encodedURL = RWT.getResponse().encodeURL(params.toString());
94 url.append(encodedURL);
95 return url.toString();
96 }
97
98 /* Dependency Injection */
99 public void setRepoService(RepoService repoService) {
100 this.repoService = repoService;
101 }
102 }