001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 */ 019package org.apache.maven.scm.command.changelog; 020 021import java.text.SimpleDateFormat; 022import java.util.Date; 023import java.util.List; 024 025import org.apache.maven.scm.ChangeSet; 026import org.apache.maven.scm.ScmVersion; 027 028/** 029 * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a> 030 * 031 */ 032public class ChangeLogSet { 033 public static final String DEFAULT_ENCODING = "ISO-8859-1"; 034 035 private List<ChangeSet> entries; 036 037 private Date startDate; 038 039 private Date endDate; 040 041 private ScmVersion startVersion; 042 043 private ScmVersion endVersion; 044 045 /** 046 * Initializes a new instance of this class. 047 * 048 * @param startDate the start date/tag for this set. 049 * @param endDate the end date/tag for this set, or <code>null</code> if this set goes to the present time. 050 */ 051 public ChangeLogSet(Date startDate, Date endDate) { 052 this.startDate = startDate; 053 this.endDate = endDate; 054 } 055 056 /** 057 * Initializes a new instance of this class. 058 * 059 * @param entries collection of {@link org.apache.maven.scm.ChangeSet} objects for this set. 060 * @param startDate the start date/tag for this set. 061 * @param endDate the end date/tag for this set, or <code>null</code> if this set goes to the present time. 062 */ 063 public ChangeLogSet(List<ChangeSet> entries, Date startDate, Date endDate) { 064 this(startDate, endDate); 065 setChangeSets(entries); 066 } 067 068 /** 069 * Returns the start date. 070 * 071 * @return the start date. 072 */ 073 public Date getStartDate() { 074 return startDate; 075 } 076 077 /** 078 * Returns the end date for this set. 079 * 080 * @return the end date for this set, or <code>null</code> if this set goes to the present time. 081 */ 082 public Date getEndDate() { 083 return endDate; 084 } 085 086 /** 087 * Returns the start version (revision/branch/label) for this set. 088 * 089 * @return the start version (revision/branch/label) for this set, or <code>null</code>. 090 */ 091 public ScmVersion getStartVersion() { 092 return startVersion; 093 } 094 095 public void setStartVersion(ScmVersion startVersion) { 096 this.startVersion = startVersion; 097 } 098 099 /** 100 * Returns the end version (revision/branch/label) for this set. 101 * 102 * @return the end version (revision/branch/label) for this set, or <code>null</code>. 103 */ 104 public ScmVersion getEndVersion() { 105 return endVersion; 106 } 107 108 public void setEndVersion(ScmVersion endVersion) { 109 this.endVersion = endVersion; 110 } 111 112 /** 113 * Returns the collection of changeSet. 114 * 115 * @return the collection of {@link org.apache.maven.scm.ChangeSet} objects for this set. 116 */ 117 public List<ChangeSet> getChangeSets() { 118 return entries; 119 } 120 121 public void setChangeSets(List<ChangeSet> changeSets) { 122 this.entries = changeSets; 123 } 124 125 /** 126 * Creates an XML representation of this change log set with a default encoding (ISO-8859-1). 127 * 128 * @return TODO 129 */ 130 public String toXML() { 131 return toXML(DEFAULT_ENCODING); 132 } 133 134 /** 135 * Creates an XML representation of this change log set. 136 * 137 * @param encoding encoding of output 138 * @return TODO 139 */ 140 public String toXML(String encoding) { 141 String encodingString = encoding; 142 143 if (encodingString == null) { 144 encodingString = DEFAULT_ENCODING; 145 } 146 147 StringBuilder buffer = new StringBuilder(); 148 String pattern = "yyyyMMdd HH:mm:ss z"; 149 SimpleDateFormat formatter = new SimpleDateFormat(pattern); 150 151 buffer.append("<?xml version=\"1.0\" encoding=\"" + encodingString + "\"?>\n"); 152 buffer.append("<changeset datePattern=\"").append(pattern).append("\""); 153 154 if (startDate != null) { 155 buffer.append(" start=\"").append(formatter.format(getStartDate())).append("\""); 156 } 157 if (endDate != null) { 158 buffer.append(" end=\"").append(formatter.format(getEndDate())).append("\""); 159 } 160 161 if (startVersion != null) { 162 buffer.append(" startVersion=\"").append(getStartVersion()).append("\""); 163 } 164 if (endVersion != null) { 165 buffer.append(" endVersion=\"").append(getEndVersion()).append("\""); 166 } 167 168 buffer.append(">\n"); 169 170 // Write out the entries 171 for (ChangeSet changeSet : getChangeSets()) { 172 buffer.append(changeSet.toXML()); 173 } 174 175 buffer.append("</changeset>\n"); 176 177 return buffer.toString(); 178 } 179}