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
;
39 * Delete chosen workspace in the current repository.
41 * Due to current version of JackRabbit, it only cleans it for the time being,
42 * removing all nodes of type {@code NodeType.NT_FOLDER} and
43 * {@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 String DEFAULT_ICON_PATH
= "icons/removeItem.gif";
52 public final static String PARAM_WORKSPACE_NAME
= "workspaceName";
53 public final static String PARAM_TARGET_REPO_PATH
= "targetRepoPath";
55 // DEPENDENCY INJECTION
56 private RepositoryFactory repositoryFactory
;
57 private Keyring keyring
;
58 private Repository nodeRepository
;
60 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
62 String targetRepoPath
= event
.getParameter(PARAM_TARGET_REPO_PATH
);
63 String workspaceName
= event
.getParameter(PARAM_WORKSPACE_NAME
);
65 Session nodeSession
= null;
66 Session session
= null;
69 nodeSession
= nodeRepository
.login();
70 Node repoNode
= nodeSession
.getNode(targetRepoPath
);
71 Repository repository
= RepoUtils
.getRepository(repositoryFactory
,
73 Credentials credentials
= RepoUtils
.getRepositoryCredentials(
76 String msg
= "Your are about to completely delete workspace ["
77 + workspaceName
+ "].\n Do you really want to proceed ?";
78 boolean result
= MessageDialog
.openConfirm(DistPlugin
.getDefault()
79 .getWorkbench().getDisplay().getActiveShell(),
80 "Confirm workspace deletion", msg
);
84 // "There is no possible turning back, are your REALLY sure you want to proceed ?";
85 msg
= "WARNING: \nCurrent Jackrabbit version used does "
86 + "not support workspace management.\n"
87 + "Thus, the workspace will only be cleaned so "
88 + "that you can launch fetch process again.\n\n"
89 + "Do you still want to proceed ?";
90 result
= MessageDialog
.openConfirm(DistPlugin
.getDefault()
91 .getWorkbench().getDisplay().getActiveShell(),
92 "Confirm workspace deletion", msg
);
96 session
= repository
.login(credentials
, workspaceName
);
98 // TODO use this with a newer version of Jackrabbit
99 // Workspace wsp = session.getWorkspace();
100 // wsp.deleteWorkspace(workspaceName);
102 NodeIterator nit
= session
.getRootNode().getNodes();
103 while (nit
.hasNext()) {
104 Node node
= nit
.nextNode();
105 if (node
.isNodeType(NodeType
.NT_FOLDER
)
106 || node
.isNodeType(NodeType
.NT_UNSTRUCTURED
)) {
107 // String path = node.getPath();
112 CommandHelpers
.callCommand(RefreshDistributionsView
.ID
);
114 } catch (RepositoryException re
) {
115 throw new SlcException(
116 "Unexpected error while deleting workspace ["
117 + workspaceName
+ "].", re
);
119 JcrUtils
.logoutQuietly(session
);
120 JcrUtils
.logoutQuietly(nodeSession
);
125 /* DEPENDENCY INJECTION */
126 public void setNodeRepository(Repository nodeRepository
) {
127 this.nodeRepository
= nodeRepository
;
130 public void setRepositoryFactory(RepositoryFactory repositoryFactory
) {
131 this.repositoryFactory
= repositoryFactory
;
134 public void setKeyring(Keyring keyring
) {
135 this.keyring
= keyring
;