ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject cvs commit: ant/src/main/org/apache/tools/ant/taskdefs/cvslib ChangeLogWriter.java CvsTagDiff.java
Date Tue, 15 Mar 2005 14:54:32 GMT
bodewig     2005/03/15 06:54:32

  Modified:    src/main/org/apache/tools/ant/taskdefs/cvslib
                        ChangeLogWriter.java CvsTagDiff.java
  Log:
  Use DOM utility classes
  
  Revision  Changes    Path
  1.19      +35 -22    ant/src/main/org/apache/tools/ant/taskdefs/cvslib/ChangeLogWriter.java
  
  Index: ChangeLogWriter.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/cvslib/ChangeLogWriter.java,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- ChangeLogWriter.java	9 Mar 2005 00:20:38 -0000	1.18
  +++ ChangeLogWriter.java	15 Mar 2005 14:54:32 -0000	1.19
  @@ -16,11 +16,18 @@
    */
   package org.apache.tools.ant.taskdefs.cvslib;
   
  +import java.io.IOException;
   import java.io.PrintWriter;
   import java.text.SimpleDateFormat;
   import java.util.Enumeration;
   import java.util.TimeZone;
   
  +import org.apache.tools.ant.util.DOMElementWriter;
  +import org.apache.tools.ant.util.DOMUtils;
  +
  +import org.w3c.dom.Document;
  +import org.w3c.dom.Element;
  +
   /**
    * Class used to generate an XML changelog.
    *
  @@ -32,6 +39,8 @@
       /** output format for times written to xml file */
       private static final SimpleDateFormat OUTPUT_TIME
           = new SimpleDateFormat("HH:mm");
  +    /** stateless helper for writing the XML document */
  +    private static final DOMElementWriter DOM_WRITER = new DOMElementWriter();
   
       static {
           TimeZone utc = TimeZone.getTimeZone("UTC");
  @@ -47,55 +56,59 @@
        */
       public void printChangeLog(final PrintWriter output,
                                  final CVSEntry[] entries) {
  +        try {
           output.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
  -        output.println("<changelog>");
  +        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(output, entry);
  +            printEntry(doc, output, entry);
           }
  -        output.println("</changelog>");
  +        DOM_WRITER.closeElement(root, output, 0, "\t", true);
           output.flush();
           output.close();
  +        } catch (IOException e) {
  +            throw new org.apache.tools.ant.BuildException(e);
  +        }
       }
   
   
       /**
        * 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.
        */
  -    private void printEntry(final PrintWriter output, final CVSEntry entry) {
  -        output.println("\t<entry>");
  -        output.println("\t\t<date>" + OUTPUT_DATE.format(entry.getDate())
  -            + "</date>");
  -        output.println("\t\t<time>" + OUTPUT_TIME.format(entry.getDate())
  -            + "</time>");
  -        output.println("\t\t<author><![CDATA[" + entry.getAuthor()
  -            + "]]></author>");
  +    private void printEntry(Document doc, final PrintWriter output,
  +                            final CVSEntry entry) throws IOException {
  +        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();
   
  -            output.println("\t\t<file>");
  -            output.println("\t\t\t<name><![CDATA[" + file.getName() + "]]></name>");
  -            output.println("\t\t\t<revision>" + file.getRevision()
  -                + "</revision>");
  +            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) {
  -                output.println("\t\t\t<prevrevision>" + previousRevision
  -                    + "</prevrevision>");
  +                DOMUtils.appendTextElement(f, "prevrevision",
  +                                           previousRevision);
               }
  -
  -            output.println("\t\t</file>");
           }
  -        output.println("\t\t<msg><![CDATA[" + entry.getComment() + "]]></msg>");
  -        output.println("\t</entry>");
  +        DOMUtils.appendCDATAElement(ent, "msg", entry.getComment());
  +        DOM_WRITER.write(ent, output, 1, "\t");
       }
   }
   
  
  
  
  1.26      +31 -23    ant/src/main/org/apache/tools/ant/taskdefs/cvslib/CvsTagDiff.java
  
  Index: CvsTagDiff.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/cvslib/CvsTagDiff.java,v
  retrieving revision 1.25
  retrieving revision 1.26
  diff -u -r1.25 -r1.26
  --- CvsTagDiff.java	9 Mar 2005 00:20:38 -0000	1.25
  +++ CvsTagDiff.java	15 Mar 2005 14:54:32 -0000	1.26
  @@ -30,8 +30,13 @@
   import org.apache.tools.ant.BuildException;
   import org.apache.tools.ant.Project;
   import org.apache.tools.ant.taskdefs.AbstractCvsTask;
  +import org.apache.tools.ant.util.DOMElementWriter;
  +import org.apache.tools.ant.util.DOMUtils;
   import org.apache.tools.ant.util.FileUtils;
   
  +import org.w3c.dom.Document;
  +import org.w3c.dom.Element;
  +
   /**
    * Examines the output of cvs rdiff between two tags.
    *
  @@ -70,6 +75,9 @@
        */
       private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
   
  +    /** stateless helper for writing the XML document */
  +    private static final DOMElementWriter DOM_WRITER = new DOMElementWriter();
  +
       /**
        * Token to identify the word file in the rdiff log
        */
  @@ -352,26 +360,27 @@
               PrintWriter writer = new PrintWriter(
                                        new OutputStreamWriter(output, "UTF-8"));
               writer.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
  -            writer.print("<tagdiff ");
  +            Document doc = DOMUtils.newDocument();
  +            Element root = doc.createElement("tagdiff");
               if (mystartTag != null) {
  -                writer.print("startTag=\"" + mystartTag + "\" ");
  +                root.setAttribute("startTag", mystartTag);
               } else {
  -                writer.print("startDate=\"" + mystartDate + "\" ");
  +                root.setAttribute("startDate", mystartDate);
               }
               if (myendTag != null) {
  -                writer.print("endTag=\"" + myendTag + "\" ");
  +                root.setAttribute("endTag", myendTag);
               } else {
  -                writer.print("endDate=\"" + myendDate + "\" ");
  +                root.setAttribute("endDate", myendDate);
               }
   
  -            writer.print("cvsroot=\"" + getCvsRoot() + "\" ");
  -            writer.print("package=\"" + mypackage + "\" ");
  -
  -            writer.println(">");
  +            root.setAttribute("cvsroot", getCvsRoot());
  +            root.setAttribute("package", mypackage);
  +            DOM_WRITER.openElement(root, writer, 0, "\t");
  +            writer.println();
               for (int i = 0, c = entries.length; i < c; i++) {
  -                writeTagEntry(writer, entries[i]);
  +                writeTagEntry(doc, writer, entries[i]);
               }
  -            writer.println("</tagdiff>");
  +            DOM_WRITER.closeElement(root, writer, 0, "\t", true);
               writer.flush();
               writer.close();
           } catch (UnsupportedEncodingException uee) {
  @@ -392,23 +401,22 @@
       /**
        * Write a single entry to the given writer.
        *
  +     * @param doc Document used to create elements.
        * @param writer a <code>PrintWriter</code> value
        * @param entry a <code>CvsTagEntry</code> value
        */
  -    private void writeTagEntry(PrintWriter writer, CvsTagEntry entry) {
  -        writer.println("\t<entry>");
  -        writer.println("\t\t<file>");
  -        writer.println("\t\t\t<name>" + entry.getFile() + "</name>");
  -        if (entry.getRevision() != null) {
  -            writer.println("\t\t\t<revision>" + entry.getRevision()
  -                           + "</revision>");
  -        }
  +    private void writeTagEntry(Document doc, PrintWriter writer,
  +                               CvsTagEntry entry)
  +        throws IOException {
  +        Element ent = doc.createElement("entry");
  +        Element f = DOMUtils.createChildElement(ent, "file");
  +        DOMUtils.appendCDATAElement(f, "name", entry.getFile());
  +        DOMUtils.appendTextElement(f, "revision", entry.getRevision());
           if (entry.getPreviousRevision() != null) {
  -            writer.println("\t\t\t<prevrevision>"
  -                           + entry.getPreviousRevision() + "</prevrevision>");
  +            DOMUtils.appendTextElement(f, "prevrevision",
  +                                       entry.getPreviousRevision());
           }
  -        writer.println("\t\t</file>");
  -        writer.println("\t</entry>");
  +        DOM_WRITER.write(ent, writer, 1, "\t");
       }
   
       /**
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Mime
View raw message