1 18 19 package org.netbeans.modules.changelog; 20 21 22 import java.util.*; 23 import org.openide.*; 24 import java.io.*; 25 26 import org.netbeans.modules.changelog.html.*; 27 28 32 public class LogPrinter_HTML implements LogPrinter { 33 34 private static final String SPECIAL_KEY = "SPECIAL"; private static final String PREV_REVISION = "previous_revision"; private static final String FILE_PATH = "file_path"; private static final String CURR_REVISION = "current_revision"; 39 40 private java.io.PrintWriter writer; 41 42 private File file; 43 44 private boolean view; 45 46 private boolean includeSummary; 47 48 private boolean hasCommonBranch; 49 50 private ChangeLogHTMLService service; 51 52 public LogPrinter_HTML(File fileParam, boolean view) { 53 this.file = fileParam; 54 this.view = view; 55 writer = null; 56 try { 57 if (this.file == null) { 58 this.file = File.createTempFile("chlog", ".html"); 59 file.deleteOnExit(); 60 } 61 if (!file.exists()) { 62 try { 63 if (file.getParentFile() != null) { 64 file.getParentFile().mkdirs(); 65 } 66 file.createNewFile(); 67 } catch (IOException exc) { 68 org.openide.ErrorManager.getDefault().notify(exc); 69 System.out.println("error while creating file.."); 70 } 71 } 72 writer = new PrintWriter(new FileOutputStream(file)); 73 74 } catch (IOException exc) { 75 org.openide.ErrorManager.getDefault().notify(exc); 76 System.out.println("error while opening file.."); 77 } 78 } 79 80 public LogPrinter_HTML(File file, boolean view, ChangeLogHTMLService service) { 81 this(file, view); 82 this.service = service; 83 } 84 85 public void printHeader(ChangeLogProcessor processor) { 86 includeSummary = processor.isIncludeSummary(); 87 if (writer == null) { 88 return; 89 } 90 writer.println("<HTML>"); 91 writer.println("<HEAD>"); 92 writer.println("<TITLE> CVS Repository Query Results </TITLE>"); 93 writer.println("</HEAD>"); 94 writer.println("<BODY>"); 95 96 97 if (processor.isIncludeQueryDescription()) { 98 writer.println("<H1> Query: </H1>"); 99 if (processor.getDateRange() != null) { 100 writer.println(" Date Range: " + ChangeLogUtils.escapeString(processor.getDateRange())); 101 writer.println("<P>"); 102 } 103 if (processor.getRevisionRange() != null) { 104 writer.println(" Revision Filter:" + ChangeLogUtils.escapeString(processor.getRevisionRange())); 105 writer.println("<P>"); 106 } 107 if (processor.getUser() != null) { 108 writer.println(" User Filter:" + ChangeLogUtils.escapeString(processor.getUser())); 109 writer.println("<P>"); 110 } 111 if (processor.getMessageFilter() != null) { 112 String messageType = ""; 113 if (processor.getMessageFilterType() == ChangeLogProcessor.MESSAGE_FILTER_SUBSTRING) { 114 messageType = "Substring"; 115 } else if (processor.getMessageFilterType() == ChangeLogProcessor.MESSAGE_FILTER_SOME_WORDS) { 116 messageType = "Any of words"; 117 } else if (processor.getMessageFilterType() == ChangeLogProcessor.MESSAGE_FILTER_ALL_WORDS) { 118 messageType = "All of words"; 119 } else if (processor.getMessageFilterType() == ChangeLogProcessor.MESSAGE_FILTER_REGEXP) { 120 messageType = "Regular expression"; 121 } 122 writer.println(" Message Filter (" + ChangeLogUtils.escapeString(messageType) + "):" + ChangeLogUtils.escapeString(processor.getMessageFilter())); 123 writer.println("<P>"); 124 } 125 if (processor.getFileFilter() != null) { 126 String fileType = ""; 127 if (processor.getFileFilterType() == ChangeLogProcessor.FILE_FILTER_SUBSTRING) { 128 fileType = "Substring"; 129 } else if (processor.getFileFilterType() == ChangeLogProcessor.FILE_FILTER_REGEXP) { 130 fileType = "Regular expression"; 131 } 132 writer.println(" Contained Files Filter (" + ChangeLogUtils.escapeString(fileType) + "):" + ChangeLogUtils.escapeString(processor.getFileFilter())); 133 writer.println("<P>"); 134 } 135 if (processor.getSortMode() == ChangeLogProcessor.SORT_BY_DATE) { 136 writer.print(" Sort: by Date"); 137 } else if (processor.getSortMode() == ChangeLogProcessor.SORT_BY_USER) { 138 writer.print(" Sort: by User"); 139 } 140 if (processor.isDescendingSort()) { 141 writer.println(" (Descending)"); 142 } else { 143 writer.println(" (Ascending)"); 144 } 145 writer.println("<P>"); 146 if (processor.isIncludeBranchNames()) { 147 writer.println("Includes Branch Names Information <P>"); 148 } 149 writer.println("<BR>"); 150 writer.println("<BR>"); 151 } 152 writer.println("<H1> Results: </H1>"); 153 } 154 155 public void printGroupHeader(RevisionsGroup group) { 156 if (writer == null) { 157 return; 158 } 159 hasCommonBranch = false; 160 writer.println("<UL>"); 161 writer.println("--------------------------------------------------"); 162 writer.println("<LI>User: <I>" + ChangeLogUtils.escapeString(group.getUser()) + "</I>"); 163 writer.println("<LI>Date: <I>" + ChangeLogUtils.escapeString(group.getStartingDate().toString()) + "</I>"); 164 if (group.getCommonBranch() != null) { 165 writer.println("<LI>Branch: <B><I>" + ChangeLogUtils.escapeString(group.getCommonBranch()) + "</I></B>"); 166 hasCommonBranch = true; 167 } 168 writer.println("<LI>Message: <B>" + ChangeLogUtils.escapeString(group.getMessage()) + "</B>"); 169 writer.println("<UL>"); 170 } 171 172 public void printSingleRevision(LogInfoRevision revision) { 173 if (writer == null ) { 174 return; 175 } 176 String repoFileName = revision.getLogInfoHeader().getRepositoryFilename(); 177 repoFileName = repoFileName.substring(0, repoFileName.length() - 2); 179 180 writer.println("<LI>"); HashMap replacementMap = computeReplacements(revision); 182 if (service != null) { 183 String url = ChangeLogUtils.replaceArguments(service.getRevisionURL(), replacementMap); 184 writer.println("<A HREF='" + url + "'>" + revision.getNumber() + "</A> "); } else { 186 writer.println(revision.getNumber()); 187 } 188 writer.println(" " + repoFileName); 189 if ((!replacementMap.containsKey(SPECIAL_KEY)) && replacementMap.containsKey(PREV_REVISION) && service != null) { 192 String diffUrl = ChangeLogUtils.replaceArguments(service.getDiffURL(), replacementMap); 193 writer.println("[<A HREF='" + diffUrl + "'> Diff </A>]"); 196 } else { 197 } 199 if (replacementMap.containsKey(SPECIAL_KEY)) { writer.println(" ["+ replacementMap.get(SPECIAL_KEY) + "]"); 201 } 202 if (!revision.getBranch().equals("") && !hasCommonBranch) { 203 writer.println(" On Branch: <B>" + revision.getBranch() + "</B>"); 204 } 205 } 206 207 private HashMap computeReplacements(LogInfoRevision revision) { 208 String repoFileName = revision.getLogInfoHeader().getRepositoryFilename(); 209 repoFileName = repoFileName.substring(0, repoFileName.length() - 2); 211 HashMap replacementMap = new HashMap(); 212 if (service != null) { 213 String reducedRepoFileName; 214 if (repoFileName.startsWith(service.getCvsRootPrefix())) { 215 reducedRepoFileName = repoFileName.substring(service.getCvsRootPrefix().length() + 1); 216 } else { 217 reducedRepoFileName = repoFileName; 218 } 219 replacementMap.put(FILE_PATH, reducedRepoFileName); } else { 221 replacementMap.put(FILE_PATH, repoFileName); 222 } 223 replacementMap.put(CURR_REVISION, revision.getNumber()); String revNumber = revision.getNumber(); 225 if (revision.getState().equals("dead")) { replacementMap.put(SPECIAL_KEY, "Removed"); } else { 228 int[] revNumbers = ChangeLogUtils.convertRevisionToIntArray(revision.getNumber()); 229 if (revNumbers[revNumbers.length - 2] % 2 != 0 && revNumbers.length != 2) { 230 replacementMap.put(SPECIAL_KEY, "Imported"); } else { 232 if (revNumbers[revNumbers.length - 1] == 1) { 233 if (revNumbers.length == 2) { 234 replacementMap.put(SPECIAL_KEY, "Added"); } else { 236 revNumbers[revNumbers.length - 1] = 0; 237 revNumbers[revNumbers.length - 2] = 0; 238 String prevrev = ChangeLogUtils.convertIntArrayToRevision(revNumbers); 239 replacementMap.put(PREV_REVISION, prevrev); 240 } 241 } else { 242 revNumbers[revNumbers.length - 1] = revNumbers[revNumbers.length - 1] - 1; 243 String prevrev = ChangeLogUtils.convertIntArrayToRevision(revNumbers); 244 replacementMap.put(PREV_REVISION, prevrev); 245 } 246 } 247 } 248 return replacementMap; 249 250 } 251 252 253 public void printGroupFooter(RevisionsGroup group) { 254 if (writer == null) { 255 return; 256 } 257 writer.println("</UL>"); 258 writer.println("</UL>"); 259 } 260 261 public void printSummary(SummaryProcessor processor) { 262 if (writer == null) { 263 return; 264 } 265 if (includeSummary) { 266 writer.println("=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-="); 267 writer.println("<H1>Summary:</H1>"); 268 writer.println("<B>Number of changes: " + processor.getCommitCount() + "</B>"); 269 writer.println("<P>"); 270 writer.print("<B>Developers: </B>"); 271 String [] users = processor.getUserList(); 272 for (int i = 0; i < users.length; i++) { 273 if (i != users.length - 1) { 274 writer.print(ChangeLogUtils.escapeString(users[i]) + ", "); 275 } else { 276 writer.print(ChangeLogUtils.escapeString(users[i])); 277 } 278 } 279 writer.println("<P> <BR>"); 280 String [] mostChanged = processor.getMostChangedFiles(); 281 writer.println("<B>Most frequently changed files:</B>"); 282 writer.println("<UL>"); 283 for (int j = 0; j < mostChanged.length; j++) { 284 writer.println("<LI>" + ChangeLogUtils.escapeString(mostChanged[j])); 285 } 286 writer.println("</UL>"); 287 writer.println("<P> <BR>"); 288 writer.println("<B>Most active developers (based on number of commits): </B>"); 289 String [] mostActive= processor.getMostActiveUsers(); 290 writer.println("<UL>"); 291 for (int k = 0; k < mostActive.length; k++) { 292 writer.println("<LI>" + ChangeLogUtils.escapeString(mostActive[k])); 293 } 294 writer.println("</UL>"); 295 writer.println("<P> <BR>"); 296 } 297 } 298 299 public void printFooter(ChangeLogProcessor processor) { 300 if (writer == null) { 301 return; 302 } 303 writer.println("</BODY>"); 304 writer.println("</HTML>"); 305 writer.flush(); 306 writer.close(); 307 if (view) { 308 try { 309 TopManager.getDefault().showUrl(file.toURL()); 310 } catch (java.net.MalformedURLException exc) { 311 System.out.println("malformed URL."); 312 } 313 } 314 315 316 } 317 318 } 319 | Popular Tags |