KickJava   Java API By Example, From Geeks To Geeks.

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


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  
14 import java.util.HashMap JavaDoc;
15 import java.util.Map JavaDoc;
16
17 import org.eclipse.core.runtime.IProgressMonitor;
18 import org.eclipse.core.runtime.IStatus;
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 pares the output of the "cvs checkout -c" command which returns the list of modules
25  * defined in the CVSROOT/modules file.
26  */

27 public class ModuleDefinitionsListener extends CommandOutputListener {
28
29     // the last line read from the context (used to accumulate multi-line definitions)
30
private String JavaDoc lastLine = ""; //$NON-NLS-1$
31

32     private Map JavaDoc moduleMap;
33     
34     public ModuleDefinitionsListener() {
35         reset();
36     }
37     
38     /*
39      * @see ICommandOutputListener#messageLine(String, ICVSFolder, IProgressMonitor)
40      */

41     public IStatus messageLine(
42         String JavaDoc line,
43         ICVSRepositoryLocation location,
44         ICVSFolder commandRoot,
45         IProgressMonitor monitor) {
46         
47         // Lines that start with a space indicate a multi line entry
48
if( line.charAt(0) == ' ' ) {
49             lastLine += line;
50             line = lastLine;
51         }
52         else
53             lastLine = line;
54         
55         // Use the module name as the key so that multi-line modules will be recorded properly
56
int firstSpace = line.indexOf(" "); //$NON-NLS-1$
57
if (firstSpace > -1) {
58             String JavaDoc module = line.substring(0, firstSpace);
59             moduleMap.put(module, line);
60         }
61         return OK;
62     }
63     
64     public String JavaDoc[] getModuleExpansions() {
65         return (String JavaDoc[])moduleMap.values().toArray(new String JavaDoc[moduleMap.size()]);
66     }
67
68     public void reset() {
69         this.moduleMap = new HashMap JavaDoc();
70     }
71 }
72
Popular Tags