KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > lib > cvsclient > command > tag > TagBuilder


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

29 public class TagBuilder
30         implements Builder {
31
32     public static final String JavaDoc STATES = "T D ? "; //NOI18N
33
public static final String JavaDoc CVS_SERVER = "server: "; //NOI18N
34
public static final String JavaDoc EXAM_DIR = "server: "; //NOI18N
35

36     /**
37      * The status object that is currently being built.
38      */

39     private DefaultFileInfoContainer fileInfoContainer;
40
41     /**
42      * The event manager to use.
43      */

44     private EventManager eventManager;
45
46     /**
47      * The local path the command run in.
48      */

49     private String JavaDoc localPath;
50
51     public TagBuilder(EventManager eventManager, String JavaDoc localPath) {
52         this.eventManager = eventManager;
53         this.localPath = localPath;
54     }
55
56     public void outputDone() {
57         if (fileInfoContainer != null) {
58             eventManager.fireCVSEvent(new FileInfoEvent(this, fileInfoContainer));
59             fileInfoContainer = null;
60         }
61     }
62
63     public void parseLine(String JavaDoc line, boolean isErrorMessage) {
64         if (isErrorMessage) {
65             return;
66         }
67
68         if (line.indexOf(CVS_SERVER) < 0) {
69             if (line.length() < 3) {
70                 return;
71             }
72
73             String JavaDoc firstChar = line.substring(0, 2);
74             if (STATES.indexOf(firstChar) >= 0) {
75                 processFile(line);
76             }
77         }
78     }
79
80     private void processFile(String JavaDoc line) {
81         if (fileInfoContainer == null) {
82             fileInfoContainer = new DefaultFileInfoContainer();
83         }
84         fileInfoContainer.setType(line.substring(0, 1));
85
86         String JavaDoc fileName = line.substring(2).trim();
87         if (fileName.startsWith("no file")) { //NOI18N
88
fileName = fileName.substring(8);
89         }
90         fileInfoContainer.setFile(createFile(fileName));
91         eventManager.fireCVSEvent(new FileInfoEvent(this, fileInfoContainer));
92         fileInfoContainer = null;
93     }
94
95     private File createFile(String JavaDoc fileName) {
96         return new File(localPath, fileName);
97     }
98
99     public void parseEnhancedMessage(String JavaDoc key, Object JavaDoc value) {
100     }
101 }
102
Popular Tags