1 22 package org.netbeans.lib.cvsclient.response; 23 24 import java.io.*; 25 import java.util.*; 26 import java.text.*; 27 28 import org.netbeans.lib.cvsclient.admin.*; 29 import org.netbeans.lib.cvsclient.event.*; 30 import org.netbeans.lib.cvsclient.file.*; 31 import org.netbeans.lib.cvsclient.util.*; 32 import org.netbeans.lib.cvsclient.command.DefaultFileInfoContainer; 33 34 39 class UpdatedResponse implements Response { 40 private static final boolean DEBUG = false; 41 42 45 private String localPath; 46 47 50 private String repositoryPath; 51 52 55 private String entryLine; 56 57 60 private String mode; 61 62 65 protected String localFile; 66 67 71 private DateFormat dateFormatter; 72 73 81 public void process(LoggedDataInputStream dis, ResponseServices services) 82 throws ResponseException { 83 try { 84 localPath = dis.readLine(); 85 repositoryPath = dis.readLine(); 86 entryLine = dis.readLine(); 87 mode = dis.readLine(); 88 89 String nextLine = dis.readLine(); 90 91 boolean useGzip = (nextLine.charAt(0) == 'z'); 92 93 int length = Integer.parseInt(useGzip ? nextLine.substring(1) 94 : nextLine); 95 96 if (DEBUG) { 97 System.err.println("Got update response."); System.err.println("LocalPath is : " + localPath); System.err.println("Repository path is : " + repositoryPath); System.err.println("Entries line is : " + entryLine); System.err.println("Mode is : " + mode); System.err.println("Next line (length) is : " + nextLine); System.err.println("File length is : " + length); } 105 106 final String filePath = services.convertPathname(localPath, 108 repositoryPath); 109 110 final File newFile = new File(filePath); 111 112 if (services.getGlobalOptions().isExcluded(newFile)) { 113 skip(dis, length); 114 return; 115 } 116 117 if (this instanceof CreatedResponse) { 118 if (newFile.exists()) { 119 skip(dis, length); 120 DefaultFileInfoContainer fic = new DefaultFileInfoContainer(); 122 fic.setType("C"); 123 fic.setFile(newFile); 124 services.getEventManager().fireCVSEvent(new FileInfoEvent(this, fic)); 125 return; 126 } 127 } 128 129 localFile = newFile.getAbsolutePath(); 130 final Entry entry = new Entry(entryLine); 131 132 FileHandler fileHandler = useGzip ? services.getGzipFileHandler() 133 : services.getUncompressedFileHandler(); 134 fileHandler.setNextFileDate(services.getNextFileDate()); 135 136 if (entry.isBinary()) { 138 fileHandler.writeBinaryFile(filePath, mode, dis, length); 139 } 140 else { 141 fileHandler.writeTextFile(filePath, mode, dis, length); 142 } 143 144 String conflictString = null; 149 if ((entry.getConflict() != null) && 150 (entry.getConflict().charAt(0) == Entry.HAD_CONFLICTS)) { 151 if (entry.getConflict().charAt(1) == 152 Entry.TIMESTAMP_MATCHES_FILE) { 153 final Date d = new Date(newFile.lastModified()); 154 conflictString = getEntryConflict(d, true); 155 } 156 else { 157 conflictString = entry.getConflict().substring(1); 158 } 159 } 160 else { 161 final Date d = new Date(newFile.lastModified()); 162 conflictString = getEntryConflict(d, false); 163 } 164 entry.setConflict(conflictString); 165 if (entry.isNewUserFile()) { 167 entry.setConflict(Entry.DUMMY_TIMESTAMP); 168 } 169 services.updateAdminData(localPath, repositoryPath, entry); 171 172 if (newFile.exists()) { 174 FileAddedEvent e = new FileAddedEvent(this, filePath); 175 services.getEventManager().fireCVSEvent(e); 176 } 177 else { 178 FileUpdatedEvent e = new FileUpdatedEvent(this, filePath); 179 services.getEventManager().fireCVSEvent(e); 180 } 181 } 183 catch (IOException e) { 184 throw new ResponseException(e); 185 } 186 } 187 188 private void skip(LoggedDataInputStream dis, int length) throws IOException { 189 while (length > 0) { 190 length -= dis.skip(length); 191 192 } 193 } 194 195 203 protected String getEntryConflict(Date date, boolean hadConflicts) { 204 return getDateFormatter().format(date); 205 } 206 207 212 protected DateFormat getDateFormatter() { 213 if (dateFormatter == null) { 214 dateFormatter = new SimpleDateFormat(Entry.getLastModifiedDateFormatter().toPattern(), Locale.US); 215 dateFormatter.setTimeZone(Entry.getTimeZone()); 216 217 } 218 return dateFormatter; 219 } 220 221 226 public boolean isTerminalResponse() { 227 return false; 228 } 229 } 230 | Popular Tags |