1 22 package org.netbeans.lib.cvsclient.command; 23 24 import java.io.*; 25 26 import org.netbeans.lib.cvsclient.*; 27 import org.netbeans.lib.cvsclient.connection.*; 28 import org.netbeans.lib.cvsclient.event.*; 29 30 41 public abstract class Command 42 implements CVSListener, Cloneable { 43 49 protected String localDirectory; 50 51 54 private GlobalOptions globalOptions; 55 56 private boolean failed = false; 57 58 private String displayName; 59 60 69 public void execute(ClientServices client, EventManager eventManager) 70 throws CommandException, CommandAbortedException, AuthenticationException { 71 setLocalDirectory(client.getLocalPath()); 72 this.globalOptions = client.getGlobalOptions(); 73 } 74 75 83 public abstract String getCVSCommand(); 84 85 89 public abstract String getCVSArguments(); 90 91 97 public abstract boolean setCVSCommand(char opt, String optArg); 98 99 103 public abstract void resetCVSCommand(); 104 105 109 public abstract String getOptString(); 110 111 114 public Object clone() { 115 try { 116 return super.clone(); 117 } 118 catch (CloneNotSupportedException ex) { 119 return null; 120 } 121 } 122 123 public boolean hasFailed() { 124 return failed; 125 } 126 127 133 public void messageSent(MessageEvent e) { 134 if (e.isError() && (e.getSource() instanceof org.netbeans.lib.cvsclient.response.ErrorResponse) 135 || e.getSource() == this) { 136 failed = true; 138 } 139 } 140 141 public void messageSent(BinaryMessageEvent e) { 142 143 } 144 145 149 public void fileAdded(FileAddedEvent e) { 150 } 151 152 156 public void fileToRemove(FileToRemoveEvent e) { 157 } 158 159 163 public void fileRemoved(FileRemovedEvent e) { 164 } 165 166 170 public void fileUpdated(FileUpdatedEvent e) { 171 } 172 173 176 public void fileInfoGenerated(FileInfoEvent e) { 177 } 178 179 182 public void commandTerminated(TerminationEvent e) { 183 } 184 185 189 public void moduleExpanded(ModuleExpansionEvent e) { 190 } 191 192 195 public final String getLocalDirectory() { 196 return localDirectory; 197 } 198 199 203 public final String getLocalPath() { 204 return localDirectory; 205 } 206 207 210 public final GlobalOptions getGlobalOptions() { 211 return globalOptions; 212 } 213 214 219 public final String getRelativeToLocalPathInUnixStyle(File file) { 220 String filePath = file.getAbsolutePath(); 221 int startIndex = localDirectory.length() + 1; 222 if (startIndex >= filePath.length()) { 223 return "."; } 225 String relativePath = filePath.substring(startIndex); 226 return relativePath.replace('\\', '/'); 227 } 228 229 232 protected final void setLocalDirectory(String localDirectory) { 233 this.localDirectory = localDirectory; 234 } 235 236 241 protected static final String getTrimmedString(String s) { 242 if (s == null) { 243 return null; 244 } 245 246 s = s.trim(); 247 if (s.length() == 0) { 248 return null; 249 } 250 251 return s; 252 } 253 254 261 public void setDisplayName(String name) { 262 this.displayName = name; 263 } 264 265 271 public String getDisplayName() { 272 return displayName; 273 } 274 } 275 | Popular Tags |