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
.Repository
;
20 import javax
.jcr
.RepositoryException
;
21 import javax
.jcr
.Session
;
22 import javax
.jcr
.security
.Privilege
;
24 import org
.argeo
.ArgeoException
;
25 import org
.argeo
.jcr
.JcrUtils
;
26 import org
.argeo
.slc
.client
.ui
.dist
.DistPlugin
;
27 import org
.argeo
.slc
.client
.ui
.dist
.views
.DistributionsView
;
28 import org
.argeo
.slc
.client
.ui
.dist
.views
.DistributionsView
.DistributionViewSelectedElement
;
29 import org
.eclipse
.core
.commands
.AbstractHandler
;
30 import org
.eclipse
.core
.commands
.ExecutionEvent
;
31 import org
.eclipse
.core
.commands
.ExecutionException
;
32 import org
.eclipse
.jface
.dialogs
.MessageDialog
;
33 import org
.eclipse
.ui
.IWorkbenchPart
;
34 import org
.eclipse
.ui
.IWorkbenchWindow
;
37 * Publish the current workspace by giving REOD_ONLY rights to anonymous.
40 public class PublishWorkspace
extends AbstractHandler
{
41 // private static final Log log = LogFactory.getLog(PublishWorkspace.class);
42 public final static String ID
= DistPlugin
.ID
+ ".publishWorkspace";
43 public final static String DEFAULT_LABEL
= "Publish workspace";
44 public final static String DEFAULT_ICON_PATH
= "icons/publish.gif";
46 private String publicRole
= "anonymous";
48 private String workspaceName
;
49 private Repository repository
;
50 private Credentials credentials
;
52 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
53 IWorkbenchWindow iww
= DistPlugin
.getDefault().getWorkbench()
54 .getActiveWorkbenchWindow();
55 IWorkbenchPart view
= iww
.getActivePage().getActivePart();
56 if (view
instanceof DistributionsView
) {
57 DistributionViewSelectedElement dvse
= ((DistributionsView
) view
)
58 .getSelectedElement();
59 if (dvse
!= null && dvse
.isWorkspace
) {
60 repository
= dvse
.repository
;
61 credentials
= dvse
.credentials
;
62 workspaceName
= dvse
.wkspName
;
66 if (repository
!= null && workspaceName
!= null) {
67 String msg
= "Are you sure you want to publish this distribution: "
68 + workspaceName
+ " ?";
69 boolean result
= MessageDialog
.openConfirm(DistPlugin
.getDefault()
70 .getWorkbench().getDisplay().getActiveShell(),
71 "Confirm publication", msg
);
75 Session session
= null;
77 session
= repository
.login(credentials
, workspaceName
);
78 JcrUtils
.addPrivilege(session
, "/", publicRole
,
80 JcrUtils
.logoutQuietly(session
);
81 // CommandHelpers.callCommand(RefreshDistributionsView.ID);
82 } catch (RepositoryException re
) {
83 throw new ArgeoException(
84 "Unexpected error while publishing workspace "
87 JcrUtils
.logoutQuietly(session
);
94 public void setRepository(Repository repository
) {
95 this.repository
= repository
;
98 public void setWorkspaceName(String workspaceName
) {
99 this.workspaceName
= workspaceName
;