KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > lib > cvsclient > command > importcmd > ImportBuilder


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.importcmd;
21
22 import java.io.*;
23
24 import org.netbeans.lib.cvsclient.command.*;
25 import org.netbeans.lib.cvsclient.event.*;
26
27 /**
28  * @author Thomas Singer
29  */

30 public class ImportBuilder
31         implements Builder {
32
33     private static final String JavaDoc NO_CONFLICTS = "No conflicts created by this import"; //NOI18N
34
private static final String JavaDoc FILE_INFOS = "NUCIL?"; //NOI18N
35

36     private final EventManager eventManager;
37     private final String JavaDoc localPath;
38     private final String JavaDoc module;
39
40     private DefaultFileInfoContainer fileInfoContainer;
41
42     public ImportBuilder(EventManager eventManager, ImportCommand importCommand) {
43         this.eventManager = eventManager;
44
45         this.localPath = importCommand.getLocalDirectory();
46         this.module = importCommand.getModule();
47     }
48
49     public void outputDone() {
50         if (fileInfoContainer == null) {
51             return;
52         }
53
54         FileInfoEvent event = new FileInfoEvent(this, fileInfoContainer);
55         eventManager.fireCVSEvent(event);
56
57         fileInfoContainer = null;
58     }
59
60     public void parseLine(String JavaDoc line, boolean isErrorMessage) {
61         if (line.length() > 2 && line.charAt(1) == ' ') {
62             String JavaDoc firstChar = line.substring(0, 1);
63             if (FILE_INFOS.indexOf(firstChar) >= 0) {
64                 String JavaDoc filename = line.substring(2).trim();
65                 processFile(firstChar, filename);
66             }
67             else {
68                 error(line);
69             }
70         }
71         else if (line.startsWith(NO_CONFLICTS)) {
72             outputDone();
73         }
74     }
75
76     public void parseEnhancedMessage(String JavaDoc key, Object JavaDoc value) {
77     }
78
79     private void error(String JavaDoc line) {
80         System.err.println("Don't know anything about: " + line);
81     }
82
83     private void processFile(String JavaDoc type, String JavaDoc filename) {
84         outputDone();
85
86         filename = filename.substring(module.length());
87         File file = new File(localPath, filename);
88
89         fileInfoContainer = new DefaultFileInfoContainer();
90         fileInfoContainer.setType(type);
91         fileInfoContainer.setFile(file);
92
93         outputDone();
94     }
95 }
96
Popular Tags