1. /*
  2. * Copyright 2002-2004 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. */
  17. package org.apache.tools.ant.taskdefs.cvslib;
  18. import java.io.PrintWriter;
  19. import java.text.SimpleDateFormat;
  20. import java.util.Enumeration;
  21. import java.util.TimeZone;
  22. /**
  23. * Class used to generate an XML changelog.
  24. *
  25. * @version $Revision: 1.10.2.4 $ $Date: 2004/03/09 17:01:40 $
  26. */
  27. class ChangeLogWriter {
  28. /** output format for dates written to xml file */
  29. private static final SimpleDateFormat c_outputDate
  30. = new SimpleDateFormat("yyyy-MM-dd");
  31. /** output format for times written to xml file */
  32. private static final SimpleDateFormat c_outputTime
  33. = new SimpleDateFormat("HH:mm");
  34. static {
  35. TimeZone utc = TimeZone.getTimeZone("UTC");
  36. c_outputDate.setTimeZone(utc);
  37. c_outputTime.setTimeZone(utc);
  38. }
  39. /**
  40. * Print out the specified entries.
  41. *
  42. * @param output writer to which to send output.
  43. * @param entries the entries to be written.
  44. */
  45. public void printChangeLog(final PrintWriter output,
  46. final CVSEntry[] entries) {
  47. output.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
  48. output.println("<changelog>");
  49. for (int i = 0; i < entries.length; i++) {
  50. final CVSEntry entry = entries[i];
  51. printEntry(output, entry);
  52. }
  53. output.println("</changelog>");
  54. output.flush();
  55. output.close();
  56. }
  57. /**
  58. * Print out an individual entry in changelog.
  59. *
  60. * @param entry the entry to print
  61. * @param output writer to which to send output.
  62. */
  63. private void printEntry(final PrintWriter output, final CVSEntry entry) {
  64. output.println("\t<entry>");
  65. output.println("\t\t<date>" + c_outputDate.format(entry.getDate())
  66. + "</date>");
  67. output.println("\t\t<time>" + c_outputTime.format(entry.getDate())
  68. + "</time>");
  69. output.println("\t\t<author><![CDATA[" + entry.getAuthor()
  70. + "]]></author>");
  71. final Enumeration enumeration = entry.getFiles().elements();
  72. while (enumeration.hasMoreElements()) {
  73. final RCSFile file = (RCSFile) enumeration.nextElement();
  74. output.println("\t\t<file>");
  75. output.println("\t\t\t<name>" + file.getName() + "</name>");
  76. output.println("\t\t\t<revision>" + file.getRevision()
  77. + "</revision>");
  78. final String previousRevision = file.getPreviousRevision();
  79. if (previousRevision != null) {
  80. output.println("\t\t\t<prevrevision>" + previousRevision
  81. + "</prevrevision>");
  82. }
  83. output.println("\t\t</file>");
  84. }
  85. output.println("\t\t<msg><![CDATA[" + entry.getComment() + "]]></msg>");
  86. output.println("\t</entry>");
  87. }
  88. }