1 19 package org.netbeans.lib.cvsclient.command.editors; 20 21 import java.io.*; 22 import java.text.*; 23 import java.util.*; 24 25 import org.netbeans.lib.cvsclient.command.*; 26 import org.netbeans.lib.cvsclient.event.*; 27 28 32 public class EditorsBuilder 33 implements Builder { 34 36 private static final DateFormat DATE_FORMAT = new SimpleDateFormat("MMM dd hh:mm:ss yyyy"); 37 39 41 private final EventManager eventManager; 42 43 private String editorsFileName; 44 45 47 EditorsBuilder(EventManager eventManager) { 48 this.editorsFileName=null; 49 this.eventManager = eventManager; 50 } 51 52 54 public void parseLine(String line, boolean isErrorMessage) { 55 if (!isErrorMessage) { 56 parseLine(line); 57 } 58 } 59 60 public void parseEnhancedMessage(String key, Object value) { 61 } 62 63 public void outputDone() { 64 } 65 66 68 private boolean parseLine(String line) { 69 StringTokenizer tokenizer = new StringTokenizer(line, "\t"); 70 if (!tokenizer.hasMoreTokens()) { 71 return false; 72 } 73 74 if(!line.startsWith("\t")) { 77 editorsFileName = tokenizer.nextToken(); 78 if (!tokenizer.hasMoreTokens()) { 79 return false; 80 } 81 } 82 else if(editorsFileName==null) { 85 return false; 86 } 87 88 final String user = tokenizer.nextToken(); 89 if (!tokenizer.hasMoreTokens()) { 90 return false; 91 } 92 93 final String dateString = tokenizer.nextToken(); 94 if (!tokenizer.hasMoreTokens()) { 95 return false; 96 } 97 98 final String clientName = tokenizer.nextToken(); 99 if (!tokenizer.hasMoreTokens()) { 100 return false; 101 } 102 103 final String localDirectory = tokenizer.nextToken(); 104 105 try { 106 FileInfoContainer fileInfoContainer = parseEntries(localDirectory, 107 editorsFileName, 108 user, 109 dateString, 110 clientName); 111 final CVSEvent event = new FileInfoEvent(this, fileInfoContainer); 112 eventManager.fireCVSEvent(event); 113 return true; 114 } 115 catch (ParseException ex) { 116 return false; 117 } 118 } 119 120 private EditorsFileInfoContainer parseEntries(String localDirectory, 121 String fileName, 122 String user, 123 String dateString, 124 String clientName) throws ParseException { 125 int lastSlashIndex = fileName.lastIndexOf('/'); 126 if (lastSlashIndex >= 0) { 127 fileName = fileName.substring(lastSlashIndex + 1); 128 } 129 130 final Date date = parseDate(dateString); 131 final File file = new File(localDirectory, fileName); 132 return new EditorsFileInfoContainer(file, 133 user, 134 date, 135 clientName); 136 } 137 138 private Date parseDate(String dateString) throws ParseException { 139 int firstSpaceIndex = Math.max(dateString.indexOf(' '), 0); 140 int lastSpaceIndex = Math.min(dateString.lastIndexOf(' '), dateString.length()); 141 142 dateString = dateString.substring(firstSpaceIndex, lastSpaceIndex).trim(); 144 145 return DATE_FORMAT.parse(dateString); 146 } 147 } 148 | Popular Tags |