]> git.argeo.org Git - gpl/argeo-slc.git/blob - plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/commands/PublishWorkspace.java
Add anonymous perspective
[gpl/argeo-slc.git] / plugins / org.argeo.slc.client.ui.dist / src / main / java / org / argeo / slc / client / ui / dist / commands / PublishWorkspace.java
1 /*
2 * Copyright (C) 2007-2012 Argeo GmbH
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16 package org.argeo.slc.client.ui.dist.commands;
17
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;
23
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;
35
36 /**
37 * Publish the current workspace by giving REOD_ONLY rights to anonymous.
38 */
39
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";
45
46 private String publicRole = "anonymous";
47
48 private String workspaceName;
49 private Repository repository;
50 private Credentials credentials;
51
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;
63 }
64 }
65
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);
72
73 if (result) {
74
75 Session session = null;
76 try {
77 session = repository.login(credentials, workspaceName);
78 JcrUtils.addPrivilege(session, "/", publicRole,
79 Privilege.JCR_READ);
80 JcrUtils.logoutQuietly(session);
81 // CommandHelpers.callCommand(RefreshDistributionsView.ID);
82 } catch (RepositoryException re) {
83 throw new ArgeoException(
84 "Unexpected error while publishing workspace "
85 + workspaceName, re);
86 } finally {
87 JcrUtils.logoutQuietly(session);
88 }
89 }
90 }
91 return null;
92 }
93
94 public void setRepository(Repository repository) {
95 this.repository = repository;
96 }
97
98 public void setWorkspaceName(String workspaceName) {
99 this.workspaceName = workspaceName;
100 }
101 }