1 11 package org.eclipse.team.internal.ccvs.core.syncinfo; 12 13 import java.net.InetAddress ; 14 import java.net.UnknownHostException ; 15 import java.text.ParseException ; 16 import java.util.Date ; 17 18 import org.eclipse.core.resources.IContainer; 19 import org.eclipse.core.runtime.IStatus; 20 import org.eclipse.osgi.util.NLS; 21 import org.eclipse.team.internal.ccvs.core.*; 22 import org.eclipse.team.internal.ccvs.core.util.CVSDateFormatter; 23 import org.eclipse.team.internal.ccvs.core.util.Util; 24 25 28 public class NotifyInfo { 29 30 public static final char EDIT = 'E'; 32 public static final char UNEDIT = 'U'; 33 public static final char COMMIT = 'C'; 34 public static final char[] ALL = new char[] {EDIT, UNEDIT, COMMIT}; 35 36 protected static final String TAB_SEPARATOR = "\t"; 38 private String filename; 39 private char notificationType; 40 private Date timeStamp; 41 private char[] watches; 42 43 46 public NotifyInfo(String filename, char notificationType, Date timeStamp, char[] watches) { 47 48 this.filename = filename; 49 this.notificationType = notificationType; 50 this.timeStamp = timeStamp; 51 this.watches = watches; 52 } 53 54 58 public NotifyInfo(IContainer parent, String line) throws CVSException { 59 String [] strings = Util.parseIntoSubstrings(line, ResourceSyncInfo.SEPARATOR); 60 if(strings.length != 4) { 61 IStatus status = new CVSStatus(IStatus.ERROR, CVSStatus.ERROR_LINE, NLS.bind(CVSMessages.NotifyInfo_MalformedLine, new String [] { line }), parent); 62 throw new CVSException(status); 63 } 64 this.filename = strings[0]; 65 66 String type = strings[1]; 67 if (type.length() != 1) { 68 IStatus status = new CVSStatus(IStatus.ERROR, CVSStatus.ERROR_LINE, NLS.bind(CVSMessages.NotifyInfo_MalformedNotificationType, new String [] { line }), parent); 69 throw new CVSException(status); 70 } 71 this.notificationType = type.charAt(0); 72 73 String date = strings[2]; 74 try { 75 this.timeStamp = CVSDateFormatter.entryLineToDate(date); 76 } catch(ParseException e) { 77 IStatus status = new CVSStatus(IStatus.ERROR, CVSStatus.ERROR_LINE, NLS.bind(CVSMessages.NotifyInfo_MalformedNotifyDate, new String [] { line }), parent); 78 throw new CVSException(status); 79 } 80 81 String watchesString = strings[3]; 82 if (watchesString.length() > 0) { 83 this.watches = new char[watchesString.length()]; 84 for (int i = 0; i < watchesString.length(); i++) { 85 watches[i] = watchesString.charAt(i); 86 } 87 } else { 88 this.watches = null; 89 } 90 } 91 92 99 public String getNotifyLine() { 100 StringBuffer buffer = new StringBuffer (); 101 buffer.append(getName()); 102 buffer.append(ResourceSyncInfo.SEPARATOR); 103 buffer.append(notificationType); 104 buffer.append(ResourceSyncInfo.SEPARATOR); 105 buffer.append(CVSDateFormatter.dateToEntryLine(timeStamp)); 106 buffer.append(ResourceSyncInfo.SEPARATOR); 107 if (watches != null) { 108 for (int i = 0; i < watches.length; i++) { 109 char c = watches[i]; 110 buffer.append(c); 111 } 112 } 113 return buffer.toString(); 114 } 115 116 121 public String getServerLine(ICVSFolder parent) throws CVSException { 122 StringBuffer buffer = new StringBuffer (); 123 buffer.append(notificationType); 124 buffer.append(TAB_SEPARATOR); 125 buffer.append(getServerTimestamp()); 126 buffer.append(TAB_SEPARATOR); 127 buffer.append(getHost()); 128 buffer.append(TAB_SEPARATOR); 129 buffer.append(getWorkingDirectory(parent)); 130 buffer.append(TAB_SEPARATOR); 131 if (watches != null) { 132 for (int i = 0; i < watches.length; i++) { 133 char c = watches[i]; 134 buffer.append(c); 135 } 136 } 137 return buffer.toString(); 138 } 139 140 144 private String getServerTimestamp() { 145 return CVSDateFormatter.dateToNotifyServer(timeStamp); 146 } 147 148 154 private String getWorkingDirectory(ICVSFolder parent) throws CVSException { 155 return parent.getIResource().getLocation().toString(); 156 } 157 158 162 private String getHost() throws CVSException { 163 try { 164 return InetAddress.getLocalHost().getHostName(); 165 } catch (UnknownHostException e) { 166 throw CVSException.wrapException(e); 167 } 168 } 169 170 174 public String getName() { 175 return filename; 176 } 177 178 182 public char getNotificationType() { 183 return notificationType; 184 } 185 186 } 187 | Popular Tags |