1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19 package org.apache.maven.scm.command.changelog;
20
21 import java.text.SimpleDateFormat;
22 import java.util.Date;
23 import java.util.List;
24
25 import org.apache.maven.scm.ChangeSet;
26 import org.apache.maven.scm.ScmVersion;
27
28 /**
29 * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
30 */
31 public class ChangeLogSet {
32 public static final String DEFAULT_ENCODING = "ISO-8859-1";
33
34 private List<ChangeSet> entries;
35
36 private Date startDate;
37
38 private Date endDate;
39
40 private ScmVersion startVersion;
41
42 private ScmVersion endVersion;
43
44 /**
45 * Initializes a new instance of this class.
46 *
47 * @param startDate the start date/tag for this set
48 * @param endDate the end date/tag for this set, or <code>null</code> if this set goes to the present time
49 */
50 public ChangeLogSet(Date startDate, Date endDate) {
51 this.startDate = startDate;
52 this.endDate = endDate;
53 }
54
55 /**
56 * Initializes a new instance of this class.
57 *
58 * @param entries collection of {@link org.apache.maven.scm.ChangeSet} objects for this set
59 * @param startDate the start date/tag for this set
60 * @param endDate the end date/tag for this set, or <code>null</code> if this set goes to the present time
61 */
62 public ChangeLogSet(List<ChangeSet> entries, Date startDate, Date endDate) {
63 this(startDate, endDate);
64 setChangeSets(entries);
65 }
66
67 /**
68 * Returns the start date.
69 *
70 * @return the start date
71 */
72 public Date getStartDate() {
73 return startDate;
74 }
75
76 /**
77 * Returns the end date for this set.
78 *
79 * @return the end date for this set, or <code>null</code> if this set goes to the present time
80 */
81 public Date getEndDate() {
82 return endDate;
83 }
84
85 /**
86 * Returns the start version (revision/branch/label) for this set.
87 *
88 * @return the start version (revision/branch/label) for this set, or <code>null</code>
89 */
90 public ScmVersion getStartVersion() {
91 return startVersion;
92 }
93
94 public void setStartVersion(ScmVersion startVersion) {
95 this.startVersion = startVersion;
96 }
97
98 /**
99 * Returns the end version (revision/branch/label) for this set.
100 *
101 * @return the end version (revision/branch/label) for this set, or <code>null</code>
102 */
103 public ScmVersion getEndVersion() {
104 return endVersion;
105 }
106
107 public void setEndVersion(ScmVersion endVersion) {
108 this.endVersion = endVersion;
109 }
110
111 /**
112 * Returns the collection of changeSet.
113 *
114 * @return the collection of {@link org.apache.maven.scm.ChangeSet} objects for this set
115 */
116 public List<ChangeSet> getChangeSets() {
117 return entries;
118 }
119
120 public void setChangeSets(List<ChangeSet> changeSets) {
121 this.entries = changeSets;
122 }
123
124 /**
125 * Creates an XML representation of this change log set with a default encoding (ISO-8859-1).
126 *
127 * @return TODO
128 */
129 public String toXML() {
130 return toXML(DEFAULT_ENCODING);
131 }
132
133 /**
134 * Creates an XML representation of this change log set.
135 *
136 * @param encoding encoding of output
137 * @return TODO
138 */
139 public String toXML(String encoding) {
140 String encodingString = encoding;
141
142 if (encodingString == null) {
143 encodingString = DEFAULT_ENCODING;
144 }
145
146 StringBuilder buffer = new StringBuilder();
147 String pattern = "yyyyMMdd HH:mm:ss z";
148 SimpleDateFormat formatter = new SimpleDateFormat(pattern);
149
150 buffer.append("<?xml version=\"1.0\" encoding=\"" + encodingString + "\"?>\n");
151 buffer.append("<changeset datePattern=\"").append(pattern).append("\"");
152
153 if (startDate != null) {
154 buffer.append(" start=\"").append(formatter.format(getStartDate())).append("\"");
155 }
156 if (endDate != null) {
157 buffer.append(" end=\"").append(formatter.format(getEndDate())).append("\"");
158 }
159
160 if (startVersion != null) {
161 buffer.append(" startVersion=\"").append(getStartVersion()).append("\"");
162 }
163 if (endVersion != null) {
164 buffer.append(" endVersion=\"").append(getEndVersion()).append("\"");
165 }
166
167 buffer.append(">\n");
168
169 // Write out the entries
170 for (ChangeSet changeSet : getChangeSets()) {
171 buffer.append(changeSet.toXML());
172 }
173
174 buffer.append("</changeset>\n");
175
176 return buffer.toString();
177 }
178 }