FileDocCategorySizeDatePackage
ChangeLogWriter.javaAPI DocApache Ant 1.704325Wed Dec 13 06:16:20 GMT 2006org.apache.tools.ant.taskdefs.cvslib

ChangeLogWriter

public class ChangeLogWriter extends Object
Class used to generate an XML changelog.

Fields Summary
private static final SimpleDateFormat
OUTPUT_DATE
output format for dates written to xml file
private static final SimpleDateFormat
OUTPUT_TIME
output format for times written to xml file
private static final org.apache.tools.ant.util.DOMElementWriter
DOM_WRITER
stateless helper for writing the XML document
Constructors Summary
Methods Summary
public voidprintChangeLog(java.io.PrintWriter output, CVSEntry[] entries)
Print out the specified entries.

param
output writer to which to send output.
param
entries the entries to be written.


     
        TimeZone utc = TimeZone.getTimeZone("UTC");
        OUTPUT_DATE.setTimeZone(utc);
        OUTPUT_TIME.setTimeZone(utc);
    
        try {
            output.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
            Document doc = DOMUtils.newDocument();
            Element root = doc.createElement("changelog");
            DOM_WRITER.openElement(root, output, 0, "\t");
            output.println();
            for (int i = 0; i < entries.length; i++) {
                final CVSEntry entry = entries[i];

                printEntry(doc, output, entry);
            }
            DOM_WRITER.closeElement(root, output, 0, "\t", true);
            output.flush();
            output.close();
        } catch (IOException e) {
            throw new org.apache.tools.ant.BuildException(e);
        }
    
private voidprintEntry(org.w3c.dom.Document doc, java.io.PrintWriter output, CVSEntry entry)
Print out an individual entry in changelog.

param
doc Document used to create elements.
param
entry the entry to print
param
output writer to which to send output.

        Element ent = doc.createElement("entry");
        DOMUtils.appendTextElement(ent, "date",
                                   OUTPUT_DATE.format(entry.getDate()));
        DOMUtils.appendTextElement(ent, "time",
                                   OUTPUT_TIME.format(entry.getDate()));
        DOMUtils.appendCDATAElement(ent, "author", entry.getAuthor());

        final Enumeration enumeration = entry.getFiles().elements();

        while (enumeration.hasMoreElements()) {
            final RCSFile file = (RCSFile) enumeration.nextElement();

            Element f = DOMUtils.createChildElement(ent, "file");
            DOMUtils.appendCDATAElement(f, "name", file.getName());
            DOMUtils.appendTextElement(f, "revision", file.getRevision());

            final String previousRevision = file.getPreviousRevision();
            if (previousRevision != null) {
                DOMUtils.appendTextElement(f, "prevrevision",
                                           previousRevision);
            }
        }
        DOMUtils.appendCDATAElement(ent, "msg", entry.getComment());
        DOM_WRITER.write(ent, output, 1, "\t");