KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ccvs > core > client > RemovedHandler


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.team.internal.ccvs.core.client;
12
13
14 import org.eclipse.core.resources.IResource;
15 import org.eclipse.core.runtime.*;
16 import org.eclipse.osgi.util.NLS;
17 import org.eclipse.team.internal.ccvs.core.*;
18
19 /**
20  * Handles a "Removed" response from the CVS server.
21  * <p>
22  * Suppose as a result of performing a command the CVS server responds
23  * as follows:<br>
24  * <pre>
25  * [...]
26  * Removed ??? \n
27  * [...]
28  * </pre>
29  * Then
30  * </p>
31  */

32
33 /**
34  * It removes the file from both the entries of the parent-folder
35  * and from the local filesystem.
36  */

37 class RemovedHandler extends ResponseHandler {
38     public String JavaDoc getResponseID() {
39         return "Removed"; //$NON-NLS-1$
40
}
41
42     public void handle(Session session, String JavaDoc localDir, IProgressMonitor monitor) throws CVSException {
43         
44         // read additional data for the response
45
String JavaDoc repositoryFile = session.readLine();
46
47         // Get the local file
48
String JavaDoc fileName = repositoryFile.substring(repositoryFile.lastIndexOf("/") + 1); //$NON-NLS-1$
49
ICVSFolder mParent = session.getLocalRoot().getFolder(localDir);
50         ICVSFile mFile = mParent.getFile(fileName);
51         
52         if ( ! mFile.isManaged()) {
53             IStatus status = new CVSStatus(IStatus.ERROR,CVSStatus.ERROR,NLS.bind(CVSMessages.RemovedHandler_invalid, new String JavaDoc[] { new Path(null, localDir).append(fileName).toString() }),session.getLocalRoot());
54             throw new CVSException(status);
55         }
56         
57         // delete then unmanage the file
58
try {
59             if (mFile.isReadOnly()) mFile.setReadOnly(false);
60             mFile.delete();
61             mFile.unmanage(null);
62         } catch (CVSException e) {
63             IStatus status = new CVSStatus(IStatus.ERROR, CVSStatus.RESPONSE_HANDLING_FAILURE, NLS.bind(CVSMessages.RemovedHandler_0, new String JavaDoc[] { getPath(mFile) }), e, session.getLocalRoot());
64             session.handleResponseError(status);
65         }
66     }
67
68     private String JavaDoc getPath(ICVSFile file) {
69         IResource resource = file.getIResource();
70         if (resource != null) {
71             return resource.getFullPath().toString();
72         }
73         try {
74             return file.getRepositoryRelativePath();
75         } catch (CVSException e1) {
76             return file.getName();
77         }
78     }
79 }
80
81
Popular Tags