source: other-projects/trunk/gs3-release-maker/apache-ant-1.6.5/src/main/org/apache/tools/ant/taskdefs/cvslib/ChangeLogWriter.java@ 14627

Last change on this file since 14627 was 14627, checked in by oranfry, 17 years ago

initial import of the gs3-release-maker

File size: 4.2 KB
Line 
1/*
2 * Copyright 2002-2005 The Apache Software Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 */
17package org.apache.tools.ant.taskdefs.cvslib;
18
19import java.io.IOException;
20import java.io.PrintWriter;
21import java.text.SimpleDateFormat;
22import java.util.Enumeration;
23import java.util.TimeZone;
24
25import org.apache.tools.ant.util.DOMElementWriter;
26import org.apache.tools.ant.util.DOMUtils;
27
28import org.w3c.dom.Document;
29import org.w3c.dom.Element;
30
31/**
32 * Class used to generate an XML changelog.
33 *
34 */
35class ChangeLogWriter {
36 /** output format for dates written to xml file */
37 private static final SimpleDateFormat c_outputDate
38 = new SimpleDateFormat("yyyy-MM-dd");
39 /** output format for times written to xml file */
40 private static final SimpleDateFormat c_outputTime
41 = new SimpleDateFormat("HH:mm");
42 /** stateless helper for writing the XML document */
43 private static final DOMElementWriter DOM_WRITER = new DOMElementWriter();
44
45 static {
46 TimeZone utc = TimeZone.getTimeZone("UTC");
47 c_outputDate.setTimeZone(utc);
48 c_outputTime.setTimeZone(utc);
49 }
50
51 /**
52 * Print out the specified entries.
53 *
54 * @param output writer to which to send output.
55 * @param entries the entries to be written.
56 */
57 public void printChangeLog(final PrintWriter output,
58 final CVSEntry[] entries) {
59 try {
60 output.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
61 Document doc = DOMUtils.newDocument();
62 Element root = doc.createElement("changelog");
63 DOM_WRITER.openElement(root, output, 0, "\t");
64 output.println();
65 for (int i = 0; i < entries.length; i++) {
66 final CVSEntry entry = entries[i];
67
68 printEntry(doc, output, entry);
69 }
70 DOM_WRITER.closeElement(root, output, 0, "\t", true);
71 output.flush();
72 output.close();
73 } catch (IOException e) {
74 throw new org.apache.tools.ant.BuildException(e);
75 }
76 }
77
78
79 /**
80 * Print out an individual entry in changelog.
81 *
82 * @param doc Document used to create elements.
83 * @param entry the entry to print
84 * @param output writer to which to send output.
85 */
86 private void printEntry(Document doc, final PrintWriter output,
87 final CVSEntry entry) throws IOException {
88 Element ent = doc.createElement("entry");
89 DOMUtils.appendTextElement(ent, "date",
90 c_outputDate.format(entry.getDate()));
91 DOMUtils.appendTextElement(ent, "time",
92 c_outputTime.format(entry.getDate()));
93 DOMUtils.appendCDATAElement(ent, "author", entry.getAuthor());
94
95 final Enumeration enumeration = entry.getFiles().elements();
96
97 while (enumeration.hasMoreElements()) {
98 final RCSFile file = (RCSFile) enumeration.nextElement();
99
100 Element f = DOMUtils.createChildElement(ent, "file");
101 DOMUtils.appendCDATAElement(f, "name", file.getName());
102 DOMUtils.appendTextElement(f, "revision", file.getRevision());
103
104 final String previousRevision = file.getPreviousRevision();
105
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
Note: See TracBrowser for help on using the repository browser.