Return-Path: Delivered-To: apmail-ant-dev-archive@www.apache.org Received: (qmail 8094 invoked from network); 31 Mar 2005 06:51:10 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 31 Mar 2005 06:51:10 -0000 Received: (qmail 5792 invoked by uid 500); 31 Mar 2005 06:51:08 -0000 Delivered-To: apmail-ant-dev-archive@ant.apache.org Received: (qmail 5754 invoked by uid 500); 31 Mar 2005 06:51:08 -0000 Mailing-List: contact dev-help@ant.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Ant Developers List" Reply-To: "Ant Developers List" Delivered-To: mailing list dev@ant.apache.org Received: (qmail 5737 invoked by uid 500); 31 Mar 2005 06:51:08 -0000 Received: (qmail 5730 invoked by uid 99); 31 Mar 2005 06:51:08 -0000 X-ASF-Spam-Status: No, hits=-9.8 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from minotaur.apache.org (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.28) with SMTP; Wed, 30 Mar 2005 22:51:07 -0800 Received: (qmail 8081 invoked by uid 1146); 31 Mar 2005 06:51:06 -0000 Date: 31 Mar 2005 06:51:06 -0000 Message-ID: <20050331065106.8080.qmail@minotaur.apache.org> From: bodewig@apache.org To: ant-cvs@apache.org Subject: cvs commit: ant/src/main/org/apache/tools/ant/util DOMUtils.java DOMElementWriter.java X-Virus-Checked: Checked X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N bodewig 2005/03/30 22:51:06 Modified: src/main/org/apache/tools/ant/taskdefs/cvslib Tag: ANT_16_BRANCH ChangeLogWriter.java CvsTagDiff.java src/main/org/apache/tools/ant/util Tag: ANT_16_BRANCH DOMElementWriter.java Added: src/main/org/apache/tools/ant/util Tag: ANT_16_BRANCH DOMUtils.java Log: Merge fix for 24281 Revision Changes Path No revision No revision 1.10.2.6 +40 -26 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.10.2.5 retrieving revision 1.10.2.6 diff -u -r1.10.2.5 -r1.10.2.6 --- ChangeLogWriter.java 9 Mar 2005 18:56:24 -0000 1.10.2.5 +++ ChangeLogWriter.java 31 Mar 2005 06:51:05 -0000 1.10.2.6 @@ -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 c_outputTime = 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,60 @@ */ public void printChangeLog(final PrintWriter output, final CVSEntry[] entries) { - output.println(""); - output.println(""); - for (int i = 0; i < entries.length; i++) { - final CVSEntry entry = entries[i]; + try { + output.println(""); + 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); + } + DOM_WRITER.closeElement(root, output, 0, "\t", true); + output.flush(); + output.close(); + } catch (IOException e) { + throw new org.apache.tools.ant.BuildException(e); } - output.println(""); - output.flush(); - output.close(); } /** * 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"); - output.println("\t\t" + c_outputDate.format(entry.getDate()) - + ""); - output.println("\t\t"); - output.println("\t\t"); + private void printEntry(Document doc, final PrintWriter output, + final CVSEntry entry) throws IOException { + Element ent = doc.createElement("entry"); + DOMUtils.appendTextElement(ent, "date", + c_outputDate.format(entry.getDate())); + DOMUtils.appendTextElement(ent, "time", + c_outputTime.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"); - output.println("\t\t\t" + file.getName() + ""); - output.println("\t\t\t" + file.getRevision() - + ""); + 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" + previousRevision - + ""); + DOMUtils.appendTextElement(f, "prevrevision", + previousRevision); } - - output.println("\t\t"); } - output.println("\t\t"); - output.println("\t"); + DOMUtils.appendCDATAElement(ent, "msg", entry.getComment()); + DOM_WRITER.write(ent, output, 1, "\t"); } } 1.16.2.9 +37 -25 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.16.2.8 retrieving revision 1.16.2.9 diff -u -r1.16.2.8 -r1.16.2.9 --- CvsTagDiff.java 9 Mar 2005 18:56:24 -0000 1.16.2.8 +++ CvsTagDiff.java 31 Mar 2005 06:51:05 -0000 1.16.2.9 @@ -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. * @@ -64,6 +69,15 @@ * @ant.task name="cvstagdiff" */ public class CvsTagDiff extends AbstractCvsTask { + + /** + * Used to create the temp file for cvs log + */ + 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 */ @@ -280,10 +294,6 @@ } if ((index = line.indexOf(FILE_IS_NEW)) != -1) { -//CVS 1.11 -//File apps/websphere/lib/something.jar is new; current revision 1.2 -//CVS 1.11.9 -//File apps/websphere/lib/something.jar is new; cvstag_2003_11_03_2 revision 1.2 // it is a new file // set the revision but not the prevrevision String filename = line.substring(0, index); @@ -355,26 +365,27 @@ PrintWriter writer = new PrintWriter( new OutputStreamWriter(output, "UTF-8")); writer.println(""); - writer.print(""); + 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(""); + DOM_WRITER.closeElement(root, writer, 0, "\t", true); writer.flush(); writer.close(); } catch (UnsupportedEncodingException uee) { @@ -395,23 +406,24 @@ /** * Write a single entry to the given writer. * + * @param doc Document used to create elements. * @param writer a PrintWriter value * @param entry a CvsTagEntry value */ - private void writeTagEntry(PrintWriter writer, CvsTagEntry entry) { - writer.println("\t"); - writer.println("\t\t"); - writer.println("\t\t\t" + entry.getFile() + ""); + 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()); if (entry.getRevision() != null) { - writer.println("\t\t\t" + entry.getRevision() - + ""); + DOMUtils.appendTextElement(f, "revision", entry.getRevision()); } if (entry.getPreviousRevision() != null) { - writer.println("\t\t\t" - + entry.getPreviousRevision() + ""); + DOMUtils.appendTextElement(f, "prevrevision", + entry.getPreviousRevision()); } - writer.println("\t\t"); - writer.println("\t"); + DOM_WRITER.write(ent, writer, 1, "\t"); } /** No revision No revision 1.20.2.6 +54 -21 ant/src/main/org/apache/tools/ant/util/DOMElementWriter.java Index: DOMElementWriter.java =================================================================== RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/util/DOMElementWriter.java,v retrieving revision 1.20.2.5 retrieving revision 1.20.2.6 diff -u -r1.20.2.5 -r1.20.2.6 --- DOMElementWriter.java 17 May 2004 13:43:53 -0000 1.20.2.5 +++ DOMElementWriter.java 31 Mar 2005 06:51:05 -0000 1.20.2.6 @@ -1,5 +1,5 @@ /* - * Copyright 2000-2004 The Apache Software Foundation + * Copyright 2000-2005 The Apache Software Foundation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -76,26 +76,7 @@ String indentWith) throws IOException { - // Write indent characters - for (int i = 0; i < indent; i++) { - out.write(indentWith); - } - - // Write element - out.write("<"); - out.write(element.getTagName()); - - // Write attributes - NamedNodeMap attrs = element.getAttributes(); - for (int i = 0; i < attrs.getLength(); i++) { - Attr attr = (Attr) attrs.item(i); - out.write(" "); - out.write(attr.getName()); - out.write("=\""); - out.write(encode(attr.getValue())); - out.write("\""); - } - out.write(">"); + openElement(element, out, indent, indentWith); // Write child elements and text boolean hasChildren = false; @@ -148,6 +129,58 @@ } } + closeElement(element, out, indent, indentWith, hasChildren); + } + + /** + * Writes the opening tag - including all attributes - + * correspondong to a DOM element. + * + * @param element the DOM element to write + * @param out where to send the output + * @param indent number of + * @param indentWith string that should be used to indent the + * corresponding tag. + * @throws IOException if an error happens while writing to the stream. + */ + public void openElement(Element element, Writer out, int indent, + String indentWith) + throws IOException { + // Write indent characters + for (int i = 0; i < indent; i++) { + out.write(indentWith); + } + + // Write element + out.write("<"); + out.write(element.getTagName()); + + // Write attributes + NamedNodeMap attrs = element.getAttributes(); + for (int i = 0; i < attrs.getLength(); i++) { + Attr attr = (Attr) attrs.item(i); + out.write(" "); + out.write(attr.getName()); + out.write("=\""); + out.write(encode(attr.getValue())); + out.write("\""); + } + out.write(">"); + } + + /** + * Writes a DOM tree to a stream. + * + * @param element the Root DOM element of the tree + * @param out where to send the output + * @param indent number of + * @param indentWith string that should be used to indent the + * corresponding tag. + * @throws IOException if an error happens while writing to the stream. + */ + public void closeElement(Element element, Writer out, int indent, + String indentWith, boolean hasChildren) + throws IOException { // If we had child elements, we need to indent before we close // the element, otherwise we're on the same line and don't need // to indent No revision Index: DOMElementWriter.java =================================================================== RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/util/DOMElementWriter.java,v retrieving revision 1.20.2.5 retrieving revision 1.20.2.6 diff -u -r1.20.2.5 -r1.20.2.6 --- DOMElementWriter.java 17 May 2004 13:43:53 -0000 1.20.2.5 +++ DOMElementWriter.java 31 Mar 2005 06:51:05 -0000 1.20.2.6 @@ -1,5 +1,5 @@ /* - * Copyright 2000-2004 The Apache Software Foundation + * Copyright 2000-2005 The Apache Software Foundation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -76,26 +76,7 @@ String indentWith) throws IOException { - // Write indent characters - for (int i = 0; i < indent; i++) { - out.write(indentWith); - } - - // Write element - out.write("<"); - out.write(element.getTagName()); - - // Write attributes - NamedNodeMap attrs = element.getAttributes(); - for (int i = 0; i < attrs.getLength(); i++) { - Attr attr = (Attr) attrs.item(i); - out.write(" "); - out.write(attr.getName()); - out.write("=\""); - out.write(encode(attr.getValue())); - out.write("\""); - } - out.write(">"); + openElement(element, out, indent, indentWith); // Write child elements and text boolean hasChildren = false; @@ -148,6 +129,58 @@ } } + closeElement(element, out, indent, indentWith, hasChildren); + } + + /** + * Writes the opening tag - including all attributes - + * correspondong to a DOM element. + * + * @param element the DOM element to write + * @param out where to send the output + * @param indent number of + * @param indentWith string that should be used to indent the + * corresponding tag. + * @throws IOException if an error happens while writing to the stream. + */ + public void openElement(Element element, Writer out, int indent, + String indentWith) + throws IOException { + // Write indent characters + for (int i = 0; i < indent; i++) { + out.write(indentWith); + } + + // Write element + out.write("<"); + out.write(element.getTagName()); + + // Write attributes + NamedNodeMap attrs = element.getAttributes(); + for (int i = 0; i < attrs.getLength(); i++) { + Attr attr = (Attr) attrs.item(i); + out.write(" "); + out.write(attr.getName()); + out.write("=\""); + out.write(encode(attr.getValue())); + out.write("\""); + } + out.write(">"); + } + + /** + * Writes a DOM tree to a stream. + * + * @param element the Root DOM element of the tree + * @param out where to send the output + * @param indent number of + * @param indentWith string that should be used to indent the + * corresponding tag. + * @throws IOException if an error happens while writing to the stream. + */ + public void closeElement(Element element, Writer out, int indent, + String indentWith, boolean hasChildren) + throws IOException { // If we had child elements, we need to indent before we close // the element, otherwise we're on the same line and don't need // to indent No revision Index: DOMElementWriter.java =================================================================== RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/util/DOMElementWriter.java,v retrieving revision 1.20.2.5 retrieving revision 1.20.2.6 diff -u -r1.20.2.5 -r1.20.2.6 --- DOMElementWriter.java 17 May 2004 13:43:53 -0000 1.20.2.5 +++ DOMElementWriter.java 31 Mar 2005 06:51:05 -0000 1.20.2.6 @@ -1,5 +1,5 @@ /* - * Copyright 2000-2004 The Apache Software Foundation + * Copyright 2000-2005 The Apache Software Foundation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -76,26 +76,7 @@ String indentWith) throws IOException { - // Write indent characters - for (int i = 0; i < indent; i++) { - out.write(indentWith); - } - - // Write element - out.write("<"); - out.write(element.getTagName()); - - // Write attributes - NamedNodeMap attrs = element.getAttributes(); - for (int i = 0; i < attrs.getLength(); i++) { - Attr attr = (Attr) attrs.item(i); - out.write(" "); - out.write(attr.getName()); - out.write("=\""); - out.write(encode(attr.getValue())); - out.write("\""); - } - out.write(">"); + openElement(element, out, indent, indentWith); // Write child elements and text boolean hasChildren = false; @@ -148,6 +129,58 @@ } } + closeElement(element, out, indent, indentWith, hasChildren); + } + + /** + * Writes the opening tag - including all attributes - + * correspondong to a DOM element. + * + * @param element the DOM element to write + * @param out where to send the output + * @param indent number of + * @param indentWith string that should be used to indent the + * corresponding tag. + * @throws IOException if an error happens while writing to the stream. + */ + public void openElement(Element element, Writer out, int indent, + String indentWith) + throws IOException { + // Write indent characters + for (int i = 0; i < indent; i++) { + out.write(indentWith); + } + + // Write element + out.write("<"); + out.write(element.getTagName()); + + // Write attributes + NamedNodeMap attrs = element.getAttributes(); + for (int i = 0; i < attrs.getLength(); i++) { + Attr attr = (Attr) attrs.item(i); + out.write(" "); + out.write(attr.getName()); + out.write("=\""); + out.write(encode(attr.getValue())); + out.write("\""); + } + out.write(">"); + } + + /** + * Writes a DOM tree to a stream. + * + * @param element the Root DOM element of the tree + * @param out where to send the output + * @param indent number of + * @param indentWith string that should be used to indent the + * corresponding tag. + * @throws IOException if an error happens while writing to the stream. + */ + public void closeElement(Element element, Writer out, int indent, + String indentWith, boolean hasChildren) + throws IOException { // If we had child elements, we need to indent before we close // the element, otherwise we're on the same line and don't need // to indent 1.1.2.1 +0 -0 ant/src/main/org/apache/tools/ant/util/DOMUtils.java --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org For additional commands, e-mail: dev-help@ant.apache.org