1 19 package org.netbeans.lib.cvsclient.command.annotate; 20 21 import java.io.*; 22 23 import org.netbeans.lib.cvsclient.command.*; 24 import org.netbeans.lib.cvsclient.event.*; 25 26 32 public class AnnotateBuilder implements Builder { 33 private static final String UNKNOWN = ": nothing known about"; private static final String ANNOTATING = "Annotations for "; private static final String STARS = "***************"; 37 40 private AnnotateInformation annotateInformation; 41 42 45 private final EventManager eventManager; 46 47 private final String localPath; 48 private String relativeDirectory; 49 private int lineNum; 50 private File tempDir; 51 52 public AnnotateBuilder(EventManager eventManager, BasicCommand annotateCommand) { 53 this.eventManager = eventManager; 54 this.localPath = annotateCommand.getLocalDirectory(); 55 tempDir = annotateCommand.getGlobalOptions().getTempDir(); 56 } 57 58 public void outputDone() { 59 if (annotateInformation == null) { 60 return; 61 } 62 63 try { 64 annotateInformation.closeTempFile(); 65 } 66 catch (IOException exc) { 67 } 69 eventManager.fireCVSEvent(new FileInfoEvent(this, annotateInformation)); 70 annotateInformation = null; 71 } 72 73 public void parseLine(String line, boolean isErrorMessage) { 74 if (isErrorMessage && line.startsWith(ANNOTATING)) { 75 outputDone(); 76 annotateInformation = new AnnotateInformation(tempDir); 77 annotateInformation.setFile(createFile(line.substring(ANNOTATING.length()))); 78 lineNum = 0; 79 return; 80 } 81 82 if (isErrorMessage && line.startsWith(STARS)) { 83 return; 85 } 86 87 if (!isErrorMessage) { 88 processLines(line); 89 } 90 } 91 92 private File createFile(String fileName) { 93 return new File(localPath, fileName); 94 } 95 96 public void parseEnhancedMessage(String key, Object value) { 97 } 98 99 private void processLines(String line) { 100 if (annotateInformation != null) { 101 try { 102 annotateInformation.addToTempFile(line); 103 } 104 catch (IOException exc) { 105 } 107 } 108 116 } 117 118 public static AnnotateLine processLine(String line) { 119 int indexOpeningBracket = line.indexOf('('); 120 int indexClosingBracket = line.indexOf(')'); 121 AnnotateLine annLine = null; 122 if (indexOpeningBracket > 0 && indexClosingBracket > indexOpeningBracket) { 123 String revision = line.substring(0, indexOpeningBracket).trim(); 124 String userDate = line.substring(indexOpeningBracket + 1, indexClosingBracket); 125 String contents = line.substring(indexClosingBracket + 3); 126 int lastSpace = userDate.lastIndexOf(' '); 127 String user = userDate; 128 String date = userDate; 129 if (lastSpace > 0) { 130 user = userDate.substring(0, lastSpace).trim(); 131 date = userDate.substring(lastSpace).trim(); 132 } 133 annLine = new AnnotateLine(); 134 annLine.setContent(contents); 135 annLine.setAuthor(user); 136 annLine.setDateString(date); 137 annLine.setRevision(revision); 138 } 139 return annLine; 140 } 141 } 142 | Popular Tags |