KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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.listeners;
12
13 import java.util.Map JavaDoc;
14
15 import org.eclipse.core.runtime.IProgressMonitor;
16 import org.eclipse.core.runtime.IStatus;
17 import org.eclipse.team.internal.ccvs.core.CVSException;
18 import org.eclipse.team.internal.ccvs.core.CVSProviderPlugin;
19 import org.eclipse.team.internal.ccvs.core.ICVSFolder;
20 import org.eclipse.team.internal.ccvs.core.ICVSRepositoryLocation;
21 import org.eclipse.team.internal.ccvs.core.client.CommandOutputListener;
22
23 /**
24  * This class parses the messages recieved in response to an "cvs rdiff -s ..." command
25  */

26 public class RDiffSummaryListener extends CommandOutputListener {
27
28     private static final String JavaDoc RIGHT_REVISION_VARIABLE_NAME = "rightRevision"; //$NON-NLS-1$
29
private static final String JavaDoc LEFT_REVISION_VARIABLE_NAME = "leftRevision"; //$NON-NLS-1$
30
private static final String JavaDoc REMOTE_FILE_PATH_VARIABLE_NAME = "remoteFilePath"; //$NON-NLS-1$
31
private static final String JavaDoc REMOTE_FOLDER_PATH_VARIABLE_NAME = "remoteFolderPath"; //$NON-NLS-1$
32

33     private IFileDiffListener listener;
34     private static ServerMessageLineMatcher DIRECTORY_MATCHER;
35     private static ServerMessageLineMatcher FILE_DIFF_MATCHER;
36     private static ServerMessageLineMatcher NEW_FILE_MATCHER;
37     private static ServerMessageLineMatcher DELETED_FILE_MATCHER;
38     private static ServerMessageLineMatcher DELETED_FILE_MATCHER2;
39     
40     static {
41         // TODO: temprary until proper lifecycle is defined
42
initializePatterns();
43     }
44     public static void initializePatterns() {
45         try {
46             DIRECTORY_MATCHER = new ServerMessageLineMatcher(
47                 IMessagePatterns.RDIFF_DIRECTORY, new String JavaDoc[] {REMOTE_FOLDER_PATH_VARIABLE_NAME});
48             FILE_DIFF_MATCHER = new ServerMessageLineMatcher(
49                 IMessagePatterns.RDIFF_SUMMARY_FILE_DIFF, new String JavaDoc[] {REMOTE_FILE_PATH_VARIABLE_NAME, LEFT_REVISION_VARIABLE_NAME, RIGHT_REVISION_VARIABLE_NAME});
50             NEW_FILE_MATCHER = new ServerMessageLineMatcher(
51                 IMessagePatterns.RDIFF_SUMMARY_NEW_FILE, new String JavaDoc[] {REMOTE_FILE_PATH_VARIABLE_NAME, RIGHT_REVISION_VARIABLE_NAME});
52             DELETED_FILE_MATCHER = new ServerMessageLineMatcher(
53                 IMessagePatterns.RDIFF_SUMMARY_DELETED_FILE, new String JavaDoc[] {REMOTE_FILE_PATH_VARIABLE_NAME});
54             DELETED_FILE_MATCHER2 = new ServerMessageLineMatcher(
55                     IMessagePatterns.RDIFF_SUMMARY_DELETED_FILE2, new String JavaDoc[] {REMOTE_FILE_PATH_VARIABLE_NAME, LEFT_REVISION_VARIABLE_NAME});
56         } catch (CVSException e) {
57             // This is serious as the listener will not function properly
58
CVSProviderPlugin.log(e);
59         }
60     }
61     
62     public interface IFileDiffListener {
63         public void fileDiff(
64                 String JavaDoc remoteFilePath,
65                 String JavaDoc leftRevision,
66                 String JavaDoc rightRevision);
67         public void newFile(
68                 String JavaDoc remoteFilePath,
69                 String JavaDoc rightRevision);
70         public void deletedFile(
71                 String JavaDoc remoteFilePath,
72                 String JavaDoc leftRevision);
73         public void directory(String JavaDoc remoteFolderPath);
74     }
75     
76     public RDiffSummaryListener(IFileDiffListener listener) {
77         this.listener = listener;
78     }
79     
80     /* (non-Javadoc)
81      * @see org.eclipse.team.internal.ccvs.core.client.listeners.ICommandOutputListener#messageLine(java.lang.String, org.eclipse.team.internal.ccvs.core.ICVSRepositoryLocation, org.eclipse.team.internal.ccvs.core.ICVSFolder, org.eclipse.core.runtime.IProgressMonitor)
82      */

83     public IStatus messageLine(
84         String JavaDoc line,
85         ICVSRepositoryLocation location,
86         ICVSFolder commandRoot,
87         IProgressMonitor monitor) {
88         
89         Map JavaDoc variables = FILE_DIFF_MATCHER.processServerMessage(line);
90         if (variables != null) {
91             listener.fileDiff(
92                     (String JavaDoc)variables.get(REMOTE_FILE_PATH_VARIABLE_NAME),
93                     (String JavaDoc)variables.get(LEFT_REVISION_VARIABLE_NAME),
94                     (String JavaDoc)variables.get(RIGHT_REVISION_VARIABLE_NAME));
95             return OK;
96         }
97         
98         variables = NEW_FILE_MATCHER.processServerMessage(line);
99         if (variables != null) {
100             listener.newFile(
101                     (String JavaDoc)variables.get(REMOTE_FILE_PATH_VARIABLE_NAME),
102                     (String JavaDoc)variables.get(RIGHT_REVISION_VARIABLE_NAME));
103             return OK;
104         }
105         
106         variables = DELETED_FILE_MATCHER.processServerMessage(line);
107         if (variables != null) {
108             listener.deletedFile(
109                     (String JavaDoc)variables.get(REMOTE_FILE_PATH_VARIABLE_NAME),
110                     null);
111             return OK;
112         }
113         
114         variables = DELETED_FILE_MATCHER2.processServerMessage(line);
115         if (variables != null) {
116             listener.deletedFile(
117                     (String JavaDoc)variables.get(REMOTE_FILE_PATH_VARIABLE_NAME),
118                     (String JavaDoc)variables.get(LEFT_REVISION_VARIABLE_NAME));
119             return OK;
120         }
121         
122         return super.messageLine(line, location, commandRoot, monitor);
123     }
124
125     /* (non-Javadoc)
126      * @see org.eclipse.team.internal.ccvs.core.client.listeners.ICommandOutputListener#errorLine(java.lang.String, org.eclipse.team.internal.ccvs.core.ICVSRepositoryLocation, org.eclipse.team.internal.ccvs.core.ICVSFolder, org.eclipse.core.runtime.IProgressMonitor)
127      */

128     public IStatus errorLine(
129         String JavaDoc line,
130         ICVSRepositoryLocation location,
131         ICVSFolder commandRoot,
132         IProgressMonitor monitor) {
133         
134         Map JavaDoc variables = DIRECTORY_MATCHER.processServerMessage(line);
135         if (variables != null) {
136             listener.directory(
137                     (String JavaDoc)variables.get(REMOTE_FOLDER_PATH_VARIABLE_NAME));
138             return OK;
139         }
140             
141         return super.errorLine(line, location, commandRoot, monitor);
142     }
143
144 }
145
Popular Tags