1 18 package org.apache.tools.ant.taskdefs.cvslib; 19 20 import java.io.IOException ; 21 import java.io.PrintWriter ; 22 import java.text.SimpleDateFormat ; 23 import java.util.Enumeration ; 24 import java.util.TimeZone ; 25 26 import org.apache.tools.ant.util.DOMElementWriter; 27 import org.apache.tools.ant.util.DOMUtils; 28 29 import org.w3c.dom.Document ; 30 import org.w3c.dom.Element ; 31 32 36 public class ChangeLogWriter { 37 38 private static final SimpleDateFormat OUTPUT_DATE 39 = new SimpleDateFormat ("yyyy-MM-dd"); 40 41 private static final SimpleDateFormat OUTPUT_TIME 42 = new SimpleDateFormat ("HH:mm"); 43 44 private static final DOMElementWriter DOM_WRITER = new DOMElementWriter(); 45 46 static { 47 TimeZone utc = TimeZone.getTimeZone("UTC"); 48 OUTPUT_DATE.setTimeZone(utc); 49 OUTPUT_TIME.setTimeZone(utc); 50 } 51 52 58 public void printChangeLog(final PrintWriter output, 59 final CVSEntry[] entries) { 60 try { 61 output.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); 62 Document doc = DOMUtils.newDocument(); 63 Element root = doc.createElement("changelog"); 64 DOM_WRITER.openElement(root, output, 0, "\t"); 65 output.println(); 66 for (int i = 0; i < entries.length; i++) { 67 final CVSEntry entry = entries[i]; 68 69 printEntry(doc, output, entry); 70 } 71 DOM_WRITER.closeElement(root, output, 0, "\t", true); 72 output.flush(); 73 output.close(); 74 } catch (IOException e) { 75 throw new org.apache.tools.ant.BuildException(e); 76 } 77 } 78 79 80 87 private void printEntry(Document doc, final PrintWriter output, 88 final CVSEntry entry) throws IOException { 89 Element ent = doc.createElement("entry"); 90 DOMUtils.appendTextElement(ent, "date", 91 OUTPUT_DATE.format(entry.getDate())); 92 DOMUtils.appendTextElement(ent, "time", 93 OUTPUT_TIME.format(entry.getDate())); 94 DOMUtils.appendCDATAElement(ent, "author", entry.getAuthor()); 95 96 final Enumeration enumeration = entry.getFiles().elements(); 97 98 while (enumeration.hasMoreElements()) { 99 final RCSFile file = (RCSFile) enumeration.nextElement(); 100 101 Element f = DOMUtils.createChildElement(ent, "file"); 102 DOMUtils.appendCDATAElement(f, "name", file.getName()); 103 DOMUtils.appendTextElement(f, "revision", file.getRevision()); 104 105 final String previousRevision = file.getPreviousRevision(); 106 if (previousRevision != null) { 107 DOMUtils.appendTextElement(f, "prevrevision", 108 previousRevision); 109 } 110 } 111 DOMUtils.appendCDATAElement(ent, "msg", entry.getComment()); 112 DOM_WRITER.write(ent, output, 1, "\t"); 113 } 114 } 115 116 | Popular Tags |