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
.dist
.commands
;
18 import javax
.jcr
.Credentials
;
19 import javax
.jcr
.Node
;
20 import javax
.jcr
.Repository
;
21 import javax
.jcr
.RepositoryException
;
22 import javax
.jcr
.RepositoryFactory
;
23 import javax
.jcr
.Session
;
24 import javax
.jcr
.security
.Privilege
;
26 import org
.argeo
.ArgeoException
;
27 import org
.argeo
.jcr
.JcrUtils
;
28 import org
.argeo
.slc
.SlcConstants
;
29 import org
.argeo
.slc
.client
.ui
.dist
.DistPlugin
;
30 import org
.argeo
.slc
.repo
.RepoUtils
;
31 import org
.argeo
.util
.security
.Keyring
;
32 import org
.eclipse
.core
.commands
.AbstractHandler
;
33 import org
.eclipse
.core
.commands
.ExecutionEvent
;
34 import org
.eclipse
.core
.commands
.ExecutionException
;
35 import org
.eclipse
.jface
.dialogs
.MessageDialog
;
36 import org
.eclipse
.jface
.resource
.ImageDescriptor
;
38 /** Publish the current workspace by giving READ_ONLY rights to anonymous */
39 public class PublishWorkspace
extends AbstractHandler
{
40 // private static final Log log = LogFactory.getLog(PublishWorkspace.class);
42 public final static String ID
= DistPlugin
.PLUGIN_ID
+ ".publishWorkspace";
43 public final static String DEFAULT_LABEL
= "Make Public";
44 public final static ImageDescriptor DEFAULT_ICON
= DistPlugin
45 .getImageDescriptor("icons/publish.gif");
47 public final static String PARAM_WORKSPACE_NAME
= "workspaceName";
48 public final static String PARAM_TARGET_REPO_PATH
= "targetRepoPath";
50 // DEPENDENCY INJECTION
51 private RepositoryFactory repositoryFactory
;
52 private Keyring keyring
;
53 private Repository nodeRepository
;
55 private String publicRole
= SlcConstants
.USER_ANONYMOUS
;
57 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
58 String targetRepoPath
= event
.getParameter(PARAM_TARGET_REPO_PATH
);
59 String workspaceName
= event
.getParameter(PARAM_WORKSPACE_NAME
);
61 Session nodeSession
= null;
62 Session session
= null;
65 nodeSession
= nodeRepository
.login();
66 Node repoNode
= nodeSession
.getNode(targetRepoPath
);
67 Repository repository
= RepoUtils
.getRepository(repositoryFactory
,
69 Credentials credentials
= RepoUtils
.getRepositoryCredentials(
72 String msg
= "Are you sure you want to publish this distribution: "
73 + workspaceName
+ " ?";
74 boolean result
= MessageDialog
.openConfirm(DistPlugin
.getDefault()
75 .getWorkbench().getDisplay().getActiveShell(),
76 "Confirm publication", msg
);
79 session
= repository
.login(credentials
, workspaceName
);
80 JcrUtils
.addPrivilege(session
, "/", publicRole
,
83 JcrUtils
.logoutQuietly(session
);
84 // CommandHelpers.callCommand(RefreshDistributionsView.ID);
86 } catch (RepositoryException re
) {
87 throw new ArgeoException(
88 "Unexpected error while publishing workspace "
91 JcrUtils
.logoutQuietly(session
);
92 JcrUtils
.logoutQuietly(nodeSession
);
97 /* DEPENDENCY INJECTION */
98 public void setNodeRepository(Repository nodeRepository
) {
99 this.nodeRepository
= nodeRepository
;
102 public void setRepositoryFactory(RepositoryFactory repositoryFactory
) {
103 this.repositoryFactory
= repositoryFactory
;
106 public void setKeyring(Keyring keyring
) {
107 this.keyring
= keyring
;