1 18 19 package org.netbeans.modules.changelog; 20 21 22 import java.util.*; 23 import org.openide.windows.*; 24 import org.openide.*; 25 import java.io.*; 26 import java.text.SimpleDateFormat ; 27 28 import org.netbeans.modules.changelog.html.*; 29 30 35 public class LogPrinter_XML implements LogPrinter { 36 37 private java.io.PrintWriter writer; 38 private boolean includeSummary; 39 40 public LogPrinter_XML(File file) { 41 if (!file.exists()) { 42 try { 43 if (file.getParentFile() != null) { 44 file.getParentFile().mkdirs(); 45 } 46 file.createNewFile(); 47 } catch (IOException exc) { 48 org.openide.ErrorManager.getDefault().notify(exc); 49 System.out.println("error while creating file.."); 50 } 51 } 52 writer = null; 53 try { 54 writer = new PrintWriter(new FileOutputStream(file)); 55 } catch (IOException exc) { 56 org.openide.ErrorManager.getDefault().notify(exc); 57 System.out.println("error while opening file.."); 58 } 59 } 60 61 public void printHeader(ChangeLogProcessor processor) { 62 if (writer == null) { 63 return; 64 } 65 writer.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); 66 writer.println(); 67 writer.println("<changelog>"); 68 includeSummary = processor.isIncludeSummary(); 69 if (processor.isIncludeQueryDescription()) { 70 writer.println(); 71 writer.println("<query>"); 72 if (processor.getDateRange() != null) { 73 writer.println("<daterange>" + ChangeLogUtils.xmlescapeString(processor.getDateRange()) + "</daterange>"); 74 } 75 if (processor.getRevisionRange() != null) { 76 writer.println("<revisionfilter>" + ChangeLogUtils.xmlescapeString(processor.getRevisionRange()) + "</revisionfilter>"); 77 } 78 if (processor.getMessageFilter() != null) { 79 String messageType = ""; 80 if (processor.getMessageFilterType() == ChangeLogProcessor.MESSAGE_FILTER_SUBSTRING) { 81 messageType = "substring"; 82 } else if (processor.getMessageFilterType() == ChangeLogProcessor.MESSAGE_FILTER_SOME_WORDS) { 83 messageType = "anywords"; 84 } else if (processor.getMessageFilterType() == ChangeLogProcessor.MESSAGE_FILTER_ALL_WORDS) { 85 messageType = "allwords"; 86 } else if (processor.getMessageFilterType() == ChangeLogProcessor.MESSAGE_FILTER_REGEXP) { 87 messageType = "regexp"; 88 } 89 writer.println("<messagefilter messagetype=\"" + messageType + "\">" + ChangeLogUtils.xmlescapeString(processor.getMessageFilter()) + "</messagefilter>"); 90 } 91 if (processor.getFileFilter() != null) { 92 String fileType = ""; 93 if (processor.getFileFilterType() == ChangeLogProcessor.FILE_FILTER_SUBSTRING) { 94 fileType = "substring"; 95 } else if (processor.getFileFilterType() == ChangeLogProcessor.FILE_FILTER_REGEXP) { 96 fileType = "regexp"; 97 } 98 writer.println("<filefilter filetype=\"" + fileType + "\">" + ChangeLogUtils.xmlescapeString(processor.getFileFilter()) + "</filefilter>"); 99 } 100 if (processor.getSortMode() == ChangeLogProcessor.SORT_BY_DATE) { 101 writer.print("<sort orderby=\"date\""); 102 } else if (processor.getSortMode() == ChangeLogProcessor.SORT_BY_USER) { 103 writer.print("<sort orderby=\"user\""); 104 } 105 if (processor.isDescendingSort()) { 106 writer.println(" direction=\"descending\"/>"); 107 } else { 108 writer.println(" direction=\"ascending\"/>"); 109 } 110 writer.println("</query>"); 111 writer.println(); 112 } 113 } 114 115 public void printGroupHeader(RevisionsGroup group) { 116 if (writer == null) { 117 return; 118 } 119 writer.println("<entry>"); 120 writer.println("<author>" + ChangeLogUtils.xmlescapeString(group.getUser()) + "</author>"); 121 final String sdate = (new java.text.SimpleDateFormat ("yyyy-MM-dd")).format(group.getStartingDate()); 122 final String stime = (new java.text.SimpleDateFormat ("hh:mm:ss")).format(group.getStartingDate()); 123 writer.println("<date>" + ChangeLogUtils.xmlescapeString(sdate) + "</date>"); 124 writer.println("<time>" + ChangeLogUtils.xmlescapeString(stime) + "</time>"); 125 if ( group.getCommonBranch() != null) { 126 writer.println("<commonbranch>" + ChangeLogUtils.xmlescapeString(group.getCommonBranch()) + "</commonbranch>"); 127 } 128 writer.println("<msg>" + ChangeLogUtils.xmlescapeString(group.getMessage()).trim() + "</msg>"); 129 } 130 131 public void printSingleRevision(LogInfoRevision revision) { 132 if (writer == null ) { 133 return; 134 } 135 String repoFileName = revision.getLogInfoHeader().getRepositoryFilename(); 136 repoFileName = repoFileName.substring(0, repoFileName.length() - 2); 137 writer.println("<file>"); 138 writer.println("<name>" + ChangeLogUtils.xmlescapeString(repoFileName) + "</name>"); 139 writer.println("<revision>" + ChangeLogUtils.xmlescapeString(revision.getNumber()) + "</revision>"); 140 if ( revision.getBranch() != "" ) { 141 writer.println("<branch>" + ChangeLogUtils.xmlescapeString(revision.getBranch()) + "</branch>"); 142 } 143 writer.println("</file>"); 144 } 145 146 public void printGroupFooter(RevisionsGroup group) { 147 if (writer == null) { 148 return; 149 } 150 writer.println("</entry>"); 151 writer.println(); 152 } 153 154 public void printSummary(SummaryProcessor processor) { 155 if (writer == null) { 156 return; 157 } 158 if (includeSummary) { 159 writer.println("<summary>"); 160 writer.println("<changecount>" + ChangeLogUtils.xmlescapeString(String.valueOf(processor.getCommitCount())) + "</changecount>"); 161 writer.println("<developers>"); 162 String [] users = processor.getUserList(); 163 for (int i = 0; i < users.length; i++) { 164 writer.println("<developer>" + ChangeLogUtils.xmlescapeString(users[i]) + "</developer>"); 165 } 166 writer.println("</developers>"); 167 String [] mostChanged = processor.getMostChangedFiles(); 168 writer.println("<mostchangedfiles>"); 169 for (int j = 0; j < mostChanged.length; j++) { 170 writer.println("<mostchangedfile>" + ChangeLogUtils.xmlescapeString(mostChanged[j]) + "</mostchangedfile>"); 171 } 172 writer.println("</mostchangedfiles>"); 173 writer.println("<mostactivedevelopers>"); 174 String [] mostActive= processor.getMostActiveUsers(); 175 for (int k = 0; k < mostActive.length; k++) { 176 writer.println("<mostactivedeveloper>" + ChangeLogUtils.xmlescapeString(mostActive[k]) + "</mostactivedeveloper>"); 177 } 178 writer.println("</mostactivedevelopers>"); 179 writer.println("</summary>"); 180 writer.println(); 181 } 182 } 183 184 public void printFooter(ChangeLogProcessor processor) { 185 if (writer != null) { 187 writer.println("</changelog>"); 188 writer.println(); 189 writer.flush(); 190 writer.close(); 191 } 192 } 193 194 } 195 | Popular Tags |