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
;
20 import javax
.jcr
.Session
;
22 import org
.apache
.commons
.logging
.Log
;
23 import org
.apache
.commons
.logging
.LogFactory
;
24 import org
.argeo
.jcr
.JcrUtils
;
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
.rwt
.RWT
;
32 import org
.eclipse
.rwt
.service
.IServiceHandler
;
33 import org
.eclipse
.ui
.PlatformUI
;
36 * Rap specific command handler to open a file retrieved from a distant JCR
37 * Repository. It forwards the request to the correct service after encoding
38 * file name and path in the request URI.
40 * This command and the corresponding service are specific for RAP version [1.3,
43 public class OpenJcrFile
extends AbstractHandler
{
44 private final static Log log
= LogFactory
.getLog(OpenJcrFile
.class);
46 public final static String ID
= SlcRapPlugin
.PLUGIN_ID
+ ".openJcrFile";
48 public final static String PARAM_REPO_NODE_PATH
= OpenJcrFileService
.PARAM_REPO_NODE_PATH
;
49 public final static String PARAM_REPO_URI
= OpenJcrFileService
.PARAM_REPO_URI
;
50 public final static String PARAM_WORKSPACE_NAME
= OpenJcrFileService
.PARAM_WORKSPACE_NAME
;
51 public final static String PARAM_FILE_PATH
= OpenJcrFileService
.PARAM_FILE_PATH
;
53 private RepoService repoService
;
55 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
57 String repoNodePath
= event
.getParameter(PARAM_REPO_NODE_PATH
);
58 String repoUri
= event
.getParameter(PARAM_REPO_URI
);
59 String wkspName
= event
.getParameter(PARAM_WORKSPACE_NAME
);
60 String filePath
= event
.getParameter(PARAM_FILE_PATH
);
63 Session session
= repoService
.getRemoteSession(repoNodePath
, repoUri
,
65 JcrUtils
.logoutQuietly(session
);
68 if (filePath
== null || "".equals(filePath
.trim()))
72 if (log
.isDebugEnabled())
74 + createFullDownloadUrl(repoNodePath
, repoUri
,
76 // RWT.getResponse().sendRedirect(createFullDownloadUrl(repoNodePath,
78 // wkspName, filePath));
80 URL url
= new URL(createFullDownloadUrl(repoNodePath
, repoUri
,
82 PlatformUI
.getWorkbench().getBrowserSupport()
83 .createBrowser("DownloadDialog").openURL(url
);
84 } catch (Exception e
) {
91 private String
createFullDownloadUrl(String repoNodePath
, String repoUri
,
92 String wkspName
, String filePath
) {
93 StringBuilder url
= new StringBuilder();
94 url
.append(RWT
.getRequest().getRequestURL());
96 StringBuilder params
= new StringBuilder();
98 params
.append(IServiceHandler
.REQUEST_PARAM
).append("=");
99 params
.append(OpenJcrFileService
.ID
);
100 if (repoNodePath
!= null)
101 params
.append("&").append(OpenJcrFileService
.PARAM_REPO_NODE_PATH
)
102 .append("=").append(repoNodePath
);
105 params
.append("&").append(OpenJcrFileService
.PARAM_REPO_URI
)
106 .append("=").append(repoUri
);
108 if (wkspName
!= null)
109 params
.append("&").append(OpenJcrFileService
.PARAM_WORKSPACE_NAME
)
110 .append("=").append(wkspName
);
112 if (filePath
!= null)
113 params
.append("&").append(OpenJcrFileService
.PARAM_FILE_PATH
)
114 .append("=").append(filePath
);
116 String encodedURL
= RWT
.getResponse().encodeURL(params
.toString());
117 url
.append(encodedURL
);
119 return url
.toString();
122 /* Dependency Injection */
123 // only used as a workaround to force the service instantiation
124 public void setOpenJcrFileService(OpenJcrFileService openJcrFileService
) {
128 public void setRepoService(RepoService repoService
) {
129 this.repoService
= repoService
;