1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
30
31
32 public class ChangeLogSet {
33 public static final String DEFAULT_ENCODING = "ISO-8859-1";
34
35 private List<ChangeSet> entries;
36
37 private Date startDate;
38
39 private Date endDate;
40
41 private ScmVersion startVersion;
42
43 private ScmVersion endVersion;
44
45
46
47
48
49
50
51 public ChangeLogSet(Date startDate, Date endDate) {
52 this.startDate = startDate;
53 this.endDate = endDate;
54 }
55
56
57
58
59
60
61
62
63 public ChangeLogSet(List<ChangeSet> entries, Date startDate, Date endDate) {
64 this(startDate, endDate);
65 setChangeSets(entries);
66 }
67
68
69
70
71
72
73 public Date getStartDate() {
74 return startDate;
75 }
76
77
78
79
80
81
82 public Date getEndDate() {
83 return endDate;
84 }
85
86
87
88
89
90
91 public ScmVersion getStartVersion() {
92 return startVersion;
93 }
94
95 public void setStartVersion(ScmVersion startVersion) {
96 this.startVersion = startVersion;
97 }
98
99
100
101
102
103
104 public ScmVersion getEndVersion() {
105 return endVersion;
106 }
107
108 public void setEndVersion(ScmVersion endVersion) {
109 this.endVersion = endVersion;
110 }
111
112
113
114
115
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
127
128
129
130 public String toXML() {
131 return toXML(DEFAULT_ENCODING);
132 }
133
134
135
136
137
138
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
171 for (ChangeSet changeSet : getChangeSets()) {
172 buffer.append(changeSet.toXML());
173 }
174
175 buffer.append("</changeset>\n");
176
177 return buffer.toString();
178 }
179 }