bug: org.netbeans.lib.cvsclient.response.RemovedResponse does not generate FileRemovedEvent
Jord Sonneveld <[email protected]> Fri, 06 Feb 2004 18:13:23 -0500
| Newsgroups | gmane.comp.java.netbeans.modules.javacvs.devel |
|---|---|
| Message-ID | <[email protected]> |
Howdy, Feature Request: org.netbeans.lib.cvsclient.event.FileRemovedEvent would benefit greatly from containing the name of the file that was just removed (a la FileUpdatedEvent and FileAddedEvent). Bug: org.netbeans.lib.cvsclient.response.RemovedResponse does not generate the above mentioned FileRemovedEvent. It would be marvelous if it could do so, and when doing so, have the event be generated /before/ the local file is deleted from the file system, so that an event handler could access the file before it is removed. I have attached the two files w/ code changes, please use as you see fit. Thanks, Jord. --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
RemovedResponse.java
(text/plain, 2.4 KB)
/*****************************************************************************
* Sun Public License Notice
*
* The contents of this file are subject to the Sun Public License Version
* 1.0 (the "License"). You may not use this file except in compliance with
* the License. A copy of the License is available at http://www.sun.com/
* The Original Code is the CVS Client Library.
* The Initial Developer of the Original Code is Robert Greig.
* Portions created by Robert Greig are Copyright (C) 2000.
* All Rights Reserved.
* Contributor(s): Robert Greig.
*****************************************************************************/
package org.netbeans.lib.cvsclient.response;
import java.io.*;
import org.netbeans.lib.cvsclient.event.FileRemovedEvent;
import org.netbeans.lib.cvsclient.util.*;
/**
* Indicates that a file has been removed from the repository.
* @author Robert Greig
*/
class RemovedResponse implements Response
{
/**
* Process the data for the response.
* @param dis the data inputstream allowing the client to read the server's
* response. Note that the actual response name has already been read
* and the input stream is positioned just before the first argument, if
* any.
*/
public void process(LoggedDataInputStream dis, ResponseServices services)
throws ResponseException
{
try
{
String localPath = dis.readLine();
String repositoryPath = dis.readLine();
final String filePath =
services.convertPathname(localPath, repositoryPath);
final File newFile = new File(filePath);
String localFile = newFile.getAbsolutePath();
FileRemovedEvent e = new FileRemovedEvent(this, localFile);
//Fire the event before removing the local file. This is done
//so that event listeners have a chance to access the file one
//last time before the file is removed.
services.getEventManager().fireCVSEvent(e);
services.removeLocalFile(localPath, repositoryPath);
}
catch (EOFException ex)
{
throw new ResponseException(
ex,
ResponseException.getLocalMessage(
"CommandException.EndOfFile",
null));
//NOI18N
}
catch (IOException ex)
{
throw new ResponseException(ex);
}
}
/**
* Is this a terminal response, i.e. should reading of responses stop
* after this response. This is true for responses such as OK or
* an error response
*/
public boolean isTerminalResponse()
{
return false;
}
}
FileRemovedEvent.java
(text/plain, 1.5 KB)
/*****************************************************************************
* Sun Public License Notice
*
* The contents of this file are subject to the Sun Public License Version
* 1.0 (the "License"). You may not use this file except in compliance with
* the License. A copy of the License is available at http://www.sun.com/
* The Original Code is the CVS Client Library.
* The Initial Developer of the Original Code is Robert Greig.
* Portions created by Robert Greig are Copyright (C) 2000.
* All Rights Reserved.
* Contributor(s): Robert Greig.
*****************************************************************************/
package org.netbeans.lib.cvsclient.event;
/**
* Indicates that a file has been removed.
* @author Robert Greig
*/
public class FileRemovedEvent extends CVSEvent
{
/**
* The path of the file that has been removed.
*/
protected String path;
/**
* Construct a FileRemovedEvent
* @param source the source of the event
* @param path The path of the file that has been removed
*/
public FileRemovedEvent(Object source, String path)
{
super(source);
this.path = path;
}
/**
* Get the path of the file that has been removed.
*/
public String getFilePath()
{
return path;
}
/**
* Fire the event to the event listener. Subclasses should call the
* appropriate method on the listener to dispatch this event.
* @param listener the event listener
*/
protected void fireEvent(CVSListener listener)
{
listener.fileRemoved(this);
}
}