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
.slc
.client
.ui
.specific
;
19 import java
.util
.UUID
;
21 import javax
.jcr
.Node
;
22 import javax
.jcr
.Session
;
24 import org
.argeo
.slc
.SlcException
;
25 import org
.argeo
.slc
.client
.rap
.OpenJcrFileService
;
26 import org
.argeo
.slc
.client
.rap
.SlcRapPlugin
;
27 import org
.argeo
.slc
.repo
.RepoService
;
28 import org
.eclipse
.core
.commands
.AbstractHandler
;
29 import org
.eclipse
.core
.commands
.ExecutionEvent
;
30 import org
.eclipse
.core
.commands
.ExecutionException
;
31 import org
.eclipse
.rap
.rwt
.RWT
;
32 import org
.eclipse
.rap
.rwt
.service
.IServiceHandler
;
33 import org
.eclipse
.rap
.rwt
.service
.IServiceManager
;
34 import org
.eclipse
.ui
.PlatformUI
;
37 * Rap specific command handler to open a file retrieved from a distant JCR
38 * Repository. It creates and register a service instantiated with the
39 * corresponding JCR node, forwards the request, and un register the service on
42 * This command and the corresponding service are specific for RAP version [1.3,
45 public class OpenJcrFile
extends AbstractHandler
{
47 // Use (new OpenJcrFileCmdId()).getCmdId() instead.
48 // public final String ID = SlcRapPlugin.PLUGIN_ID + ".openJcrFile";
50 public final static String PARAM_REPO_NODE_PATH
= "param.repoNodePath";
51 public final static String PARAM_REPO_URI
= "param.repoUri";
52 public final static String PARAM_WORKSPACE_NAME
= "param.workspaceName";
53 public final static String PARAM_FILE_PATH
= "param.filePath";
55 private RepoService repoService
;
56 private String currentServiceId
;
58 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
60 String repoNodePath
= event
.getParameter(PARAM_REPO_NODE_PATH
);
61 String repoUri
= event
.getParameter(PARAM_REPO_URI
);
62 String wkspName
= event
.getParameter(PARAM_WORKSPACE_NAME
);
63 String filePath
= event
.getParameter(PARAM_FILE_PATH
);
66 if (filePath
== null || "".equals(filePath
.trim()))
68 Session businessSession
= null;
70 businessSession
= repoService
.getRemoteSession(repoNodePath
,
72 Node result
= businessSession
.getNode(filePath
);
74 // Create a temporary service. No better solution has been found
76 currentServiceId
= UUID
.randomUUID().toString();
77 OpenJcrFileService ojfs
= new OpenJcrFileService(result
);
78 IServiceManager manager
= RWT
.getServiceManager();
79 manager
.registerServiceHandler(currentServiceId
, ojfs
);
80 String urlStr
= createFullDownloadUrl(currentServiceId
);
81 URL url
= new URL(urlStr
);
82 PlatformUI
.getWorkbench().getBrowserSupport()
83 .createBrowser("DownloadDialog").openURL(url
);
84 } catch (Exception e
) {
85 throw new SlcException("Unable to open Jcr File for path "
93 public void dispose() {
94 IServiceManager manager
= RWT
.getServiceManager();
95 manager
.unregisterServiceHandler(currentServiceId
);
99 private String
createFullDownloadUrl(String serviceId
) {
100 StringBuilder url
= new StringBuilder();
101 url
.append(RWT
.getRequest().getRequestURL());
103 StringBuilder params
= new StringBuilder();
105 // FIXME commented out so that it builds
106 //params.append(IServiceHandler.REQUEST_PARAM).append("=");
107 params
.append(serviceId
);
108 String encodedURL
= RWT
.getResponse().encodeURL(params
.toString());
109 url
.append(encodedURL
);
110 return url
.toString();
113 /* Dependency Injection */
114 public void setRepoService(RepoService repoService
) {
115 this.repoService
= repoService
;