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
.NodeIterator
;
21 import javax
.jcr
.Repository
;
22 import javax
.jcr
.RepositoryException
;
23 import javax
.jcr
.RepositoryFactory
;
24 import javax
.jcr
.Session
;
25 import javax
.jcr
.nodetype
.NodeType
;
27 import org
.argeo
.jcr
.JcrUtils
;
28 import org
.argeo
.slc
.SlcException
;
29 import org
.argeo
.slc
.client
.ui
.dist
.DistPlugin
;
30 import org
.argeo
.slc
.client
.ui
.dist
.utils
.CommandHelpers
;
31 import org
.argeo
.slc
.repo
.RepoUtils
;
32 import org
.argeo
.util
.security
.Keyring
;
33 import org
.eclipse
.core
.commands
.AbstractHandler
;
34 import org
.eclipse
.core
.commands
.ExecutionEvent
;
35 import org
.eclipse
.core
.commands
.ExecutionException
;
36 import org
.eclipse
.jface
.dialogs
.MessageDialog
;
37 import org
.eclipse
.jface
.resource
.ImageDescriptor
;
40 * Delete chosen workspace in the current repository.
42 * Due to current version of JackRabbit, it only cleans it for the time being,
43 * removing all nodes of type {@code NodeType.NT_FOLDER} and
44 * {@code NodeType.NT_UNSTRUCTURED}
46 public class DeleteWorkspace
extends AbstractHandler
{
47 // private static final Log log = LogFactory.getLog(DeleteWorkspace.class);
49 public final static String ID
= DistPlugin
.ID
+ ".deleteWorkspace";
50 public final static String DEFAULT_LABEL
= "Clear";
51 public final static ImageDescriptor DEFAULT_ICON
= DistPlugin
52 .getImageDescriptor("icons/removeItem.gif");
54 public final static String PARAM_WORKSPACE_NAME
= "workspaceName";
55 public final static String PARAM_TARGET_REPO_PATH
= "targetRepoPath";
57 // DEPENDENCY INJECTION
58 private RepositoryFactory repositoryFactory
;
59 private Keyring keyring
;
60 private Repository nodeRepository
;
62 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
64 String targetRepoPath
= event
.getParameter(PARAM_TARGET_REPO_PATH
);
65 String workspaceName
= event
.getParameter(PARAM_WORKSPACE_NAME
);
67 Session nodeSession
= null;
68 Session session
= null;
70 nodeSession
= nodeRepository
.login();
71 Node repoNode
= nodeSession
.getNode(targetRepoPath
);
72 Repository repository
= RepoUtils
.getRepository(repositoryFactory
,
74 Credentials credentials
= RepoUtils
.getRepositoryCredentials(
77 String msg
= "Your are about to completely delete workspace ["
78 + workspaceName
+ "].\n Do you really want to proceed?";
79 boolean result
= MessageDialog
.openConfirm(DistPlugin
.getDefault()
80 .getWorkbench().getDisplay().getActiveShell(),
81 "Confirm workspace deletion", msg
);
85 // "There is no possible turning back, are your REALLY sure you want to proceed ?";
86 msg
= "WARNING: \nCurrent Jackrabbit version used does "
87 + "not support workspace deletion.\n"
88 + "Thus, the workspace will only be cleaned so "
89 + "that you can launch fetch process again.\n\n"
90 + "Do you still want to proceed?";
91 result
= MessageDialog
.openConfirm(DistPlugin
.getDefault()
92 .getWorkbench().getDisplay().getActiveShell(),
93 "Confirm workspace deletion", msg
);
97 session
= repository
.login(credentials
, workspaceName
);
98 // TODO use this with a newer version of Jackrabbit
99 // Workspace wsp = session.getWorkspace();
100 // wsp.deleteWorkspace(workspaceName);
101 NodeIterator nit
= session
.getRootNode().getNodes();
102 while (nit
.hasNext()) {
103 Node node
= nit
.nextNode();
104 if (node
.isNodeType(NodeType
.NT_FOLDER
)
105 || node
.isNodeType(NodeType
.NT_UNSTRUCTURED
)) {
106 // String path = node.getPath();
111 CommandHelpers
.callCommand(RefreshDistributionsView
.ID
);
113 } catch (RepositoryException re
) {
114 throw new SlcException(
115 "Unexpected error while deleting workspace ["
116 + workspaceName
+ "].", re
);
118 JcrUtils
.logoutQuietly(session
);
119 JcrUtils
.logoutQuietly(nodeSession
);
124 /* DEPENDENCY INJECTION */
125 public void setNodeRepository(Repository nodeRepository
) {
126 this.nodeRepository
= nodeRepository
;
129 public void setRepositoryFactory(RepositoryFactory repositoryFactory
) {
130 this.repositoryFactory
= repositoryFactory
;
133 public void setKeyring(Keyring keyring
) {
134 this.keyring
= keyring
;