KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > subversion > OutputLogger


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.modules.subversion;
21
22 import java.io.File JavaDoc;
23 import java.io.IOException JavaDoc;
24 import org.openide.ErrorManager;
25 import org.openide.windows.IOProvider;
26 import org.openide.windows.InputOutput;
27 import org.openide.windows.OutputListener;
28 import org.tigris.subversion.svnclientadapter.ISVNNotifyListener;
29 import org.tigris.subversion.svnclientadapter.SVNNodeKind;
30 import org.tigris.subversion.svnclientadapter.SVNUrl;
31
32 /**
33  *
34  * @author Tomas Stupka
35  *
36  */

37 public class OutputLogger implements ISVNNotifyListener {
38
39     private InputOutput log;
40     private boolean ignoreCommand = false;
41     private String JavaDoc repositoryRootString;
42
43     public static OutputLogger getLogger(SVNUrl repositoryRoot) {
44         if (repositoryRoot != null) {
45             return new OutputLogger(repositoryRoot);
46         } else {
47             return new NullLogger();
48         }
49     }
50     
51     private OutputLogger(SVNUrl repositoryRoot) {
52         repositoryRootString = repositoryRoot.toString();
53         log = IOProvider.getDefault().getIO(repositoryRootString, false);
54     }
55
56     private OutputLogger() {
57     }
58     
59     public void logCommandLine(String JavaDoc commandLine) {
60         logln(commandLine, false);
61         flushLog();
62     }
63     
64     public void logCompleted(String JavaDoc message) {
65         logln(message, ignoreCommand);
66         flushLog();
67     }
68     
69     public void logError(String JavaDoc message) {
70         logln(message, false);
71         flushLog();
72     }
73     
74     public void logMessage(String JavaDoc message) {
75         logln(message, ignoreCommand);
76         flushLog();
77     }
78     
79     public void logRevision(long revision, String JavaDoc path) {
80        // logln(" revision " + revision + ", path = '" + path + "'");
81
}
82     
83     public void onNotify(File JavaDoc path, SVNNodeKind kind) {
84         //logln(" file " + path + ", kind " + kind);
85
}
86     
87     public void setCommand(int command) {
88         ignoreCommand = command == ISVNNotifyListener.Command.INFO ||
89                         command == ISVNNotifyListener.Command.STATUS ||
90                         command == ISVNNotifyListener.Command.ANNOTATE ||
91                         command == ISVNNotifyListener.Command.LOG ||
92                         command == ISVNNotifyListener.Command.LS;
93     }
94             
95     private void logln(String JavaDoc message, boolean ignore) {
96         log(message + "\n", null, ignore); // NOI18N
97
}
98     
99     private void log(String JavaDoc message, OutputListener hyperlinkListener, boolean ignore) {
100         if(ignore) {
101             return;
102         }
103         if (log.isClosed()) {
104             log = IOProvider.getDefault().getIO(repositoryRootString, false);
105             try {
106                 // HACK (mystic logic) workaround, otherwise it writes to nowhere
107
log.getOut().reset();
108             } catch (IOException JavaDoc e) {
109                 ErrorManager err = ErrorManager.getDefault();
110                 err.notify(e);
111             }
112             //log.select();
113
}
114         if (hyperlinkListener != null) {
115             try {
116                 log.getOut().println(message, hyperlinkListener);
117             } catch (IOException JavaDoc e) {
118                 log.getOut().write(message);
119             }
120         } else {
121             log.getOut().write(message);
122         }
123     }
124
125     public void closeLog() {
126         log.getOut().flush();
127         log.getOut().close();
128     }
129
130     public void flushLog() {
131         log.getOut().flush();
132     }
133     
134     private static class NullLogger extends OutputLogger {
135
136         public void logCommandLine(String JavaDoc commandLine) {
137         }
138
139         public void logCompleted(String JavaDoc message) {
140         }
141
142         public void logError(String JavaDoc message) {
143         }
144
145         public void logMessage(String JavaDoc message) {
146         }
147
148         public void logRevision(long revision, String JavaDoc path) {
149         }
150
151         public void onNotify(File JavaDoc path, SVNNodeKind kind) {
152         }
153
154         public void setCommand(int command) {
155         }
156
157         public void closeLog() {
158         }
159
160         public void flushLog() {
161         }
162     }
163 }
164
Popular Tags