01: /*
02: * ====================================================================
03: * Copyright (c) 2004-2008 TMate Software Ltd. All rights reserved.
04: *
05: * This software is licensed as described in the file COPYING, which
06: * you should have received as part of this distribution. The terms
07: * are also available at http://svnkit.com/license.html
08: * If newer versions of this license are posted there, you may use a
09: * newer version instead, at your option.
10: * ====================================================================
11: */
12: package org.tmatesoft.svn.examples.wc;
13:
14: import org.tmatesoft.svn.core.SVNCancelException;
15: import org.tmatesoft.svn.core.SVNProperty;
16: import org.tmatesoft.svn.core.wc.ISVNEventHandler;
17: import org.tmatesoft.svn.core.wc.SVNEvent;
18: import org.tmatesoft.svn.core.wc.SVNEventAction;
19:
20: /*
21: * This class is an implementation of ISVNEventHandler intended for processing
22: * events generated by do*() methods of an SVNCommitClient object. An instance
23: * of this handler will be provided to an SVNCommitClient. When calling, for
24: * example, SVNCommitClient.doCommit(..) on a WC path, this method will
25: * generate an event for each 'adding'/'deleting'/'sending'/.. action it will
26: * perform upon every path being committed. And this event is passed to
27: *
28: * ISVNEventHandler.handleEvent(SVNEvent event, double progress)
29: *
30: * to notify the handler. The event contains detailed information about the
31: * path, action performed upon the path and some other.
32: */
33: public class CommitEventHandler implements ISVNEventHandler {
34: /*
35: * progress is currently reserved for future purposes and now is always
36: * ISVNEventHandler.UNKNOWN
37: */
38: public void handleEvent(SVNEvent event, double progress) {
39: /*
40: * Gets the current action. An action is represented by SVNEventAction.
41: * In case of a commit an action can be determined via comparing
42: * SVNEvent.getAction() with SVNEventAction.COMMIT_-like constants.
43: */
44: SVNEventAction action = event.getAction();
45: if (action == SVNEventAction.COMMIT_MODIFIED) {
46: System.out.println("Sending " + event.getPath());
47: } else if (action == SVNEventAction.COMMIT_DELETED) {
48: System.out.println("Deleting " + event.getPath());
49: } else if (action == SVNEventAction.COMMIT_REPLACED) {
50: System.out.println("Replacing " + event.getPath());
51: } else if (action == SVNEventAction.COMMIT_DELTA_SENT) {
52: System.out.println("Transmitting file data....");
53: } else if (action == SVNEventAction.COMMIT_ADDED) {
54: /*
55: * Gets the MIME-type of the item.
56: */
57: String mimeType = event.getMimeType();
58: if (SVNProperty.isBinaryMimeType(mimeType)) {
59: /*
60: * If the item is a binary file
61: */
62: System.out.println("Adding (bin) " + event.getPath());
63: } else {
64: System.out.println("Adding " + event.getPath());
65: }
66: }
67:
68: }
69:
70: /*
71: * Should be implemented to check if the current operation is cancelled. If
72: * it is, this method should throw an SVNCancelException.
73: */
74: public void checkCancelled() throws SVNCancelException {
75: }
76:
77: }
|