KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > lib > cvsclient > command > remove > RemoveBuilder


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.lib.cvsclient.command.remove;
21
22 import java.io.*;
23
24 import org.netbeans.lib.cvsclient.command.*;
25 import org.netbeans.lib.cvsclient.event.*;
26
27 /**
28  * Handles the building of remove information object and the firing of
29  * events when complete objects are built.
30  *
31  * @author Milos Kleint
32  */

33 public class RemoveBuilder implements Builder {
34     private static final String JavaDoc UNKNOWN = ": nothing known about"; //NOI18N
35
private static final String JavaDoc WARNING = ": warning: "; //NOI18N
36
private static final String JavaDoc SCHEDULING = ": scheduling `"; //NOI18N
37
private static final String JavaDoc USE_COMMIT = ": use 'cvs commit' "; //NOI18N
38
private static final String JavaDoc DIRECTORY = ": Removing "; //NOI18N
39
private static final String JavaDoc STILL_IN_WORKING = ": file `"; //NOI18N
40
private static final String JavaDoc REMOVE_FIRST = "first"; //NOI18N
41
private static final String JavaDoc UNKNOWN_FILE = "?"; //NOI18N
42

43     /**
44      * The status object that is currently being built
45      */

46     private RemoveInformation removeInformation;
47
48     /**
49      * The directory in which the file being processed lives. This is
50      * relative to the local directory
51      */

52     private String JavaDoc fileDirectory;
53
54     /**
55      * The event manager to use
56      */

57     private final EventManager eventManager;
58
59     private final RemoveCommand removeCommand;
60
61     public RemoveBuilder(EventManager eventManager, RemoveCommand removeCommand) {
62         this.eventManager = eventManager;
63         this.removeCommand = removeCommand;
64     }
65
66     public void outputDone() {
67         if (removeInformation != null) {
68             eventManager.fireCVSEvent(new FileInfoEvent(this, removeInformation));
69             removeInformation = null;
70         }
71     }
72
73     public void parseLine(String JavaDoc line, boolean isErrorMessage) {
74         if (line.indexOf(SCHEDULING) >= 0) {
75             int endingIndex = line.indexOf('\'');
76             String JavaDoc fn = line.substring(line.indexOf(SCHEDULING) + SCHEDULING.length(), endingIndex).trim();
77             addFile(fn);
78             removeInformation.setRemoved(true);
79             outputDone();
80         }
81         if (line.startsWith(UNKNOWN_FILE)) {
82             addFile(line.substring(UNKNOWN_FILE.length()));
83             removeInformation.setRemoved(false);
84             outputDone();
85         }
86         if (line.indexOf(STILL_IN_WORKING) >= 0) {
87             int endingIndex = line.indexOf('\'');
88             String JavaDoc fn = line.substring(line.indexOf(STILL_IN_WORKING) + STILL_IN_WORKING.length(), endingIndex).trim();
89             addFile(fn);
90             removeInformation.setRemoved(false);
91             outputDone();
92         }
93         // ignore the rest..
94
}
95
96     protected File createFile(String JavaDoc fileName) {
97         StringBuffer JavaDoc path = new StringBuffer JavaDoc();
98         path.append(removeCommand.getLocalDirectory());
99         path.append(File.separator);
100         if (fileDirectory == null) {
101             // happens for single files only
102
// (for directories, the dir name is always sent before the actual files)
103
File locFile = removeCommand.getFileEndingWith(fileName);
104             if (locFile == null) {
105                 path.append(fileName);
106             }
107             else {
108                 path = new StringBuffer JavaDoc(locFile.getAbsolutePath());
109             }
110         }
111         else {
112 // path.append(fileDirectory);
113
// path.append(File.separator);
114
path.append(fileName);
115         }
116         String JavaDoc toReturn = path.toString();
117         toReturn = toReturn.replace('/', File.separatorChar);
118         return new File(path.toString());
119     }
120
121     protected void addFile(String JavaDoc name) {
122         removeInformation = new RemoveInformation();
123         removeInformation.setFile(createFile(name));
124     }
125
126     public void parseEnhancedMessage(String JavaDoc key, Object JavaDoc value) {
127     }
128 }
129
Popular Tags