1 package org.apache.maven.scm.command.changelog;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.text.SimpleDateFormat;
23 import java.util.Date;
24 import java.util.List;
25
26 import org.apache.maven.scm.ChangeSet;
27 import org.apache.maven.scm.ScmVersion;
28
29
30
31
32
33 public class ChangeLogSet
34 {
35 public static final String DEFAULT_ENCODING = "ISO-8859-1";
36
37 private List<ChangeSet> entries;
38
39 private Date startDate;
40
41 private Date endDate;
42
43 private ScmVersion startVersion;
44
45 private ScmVersion endVersion;
46
47
48
49
50
51
52
53 public ChangeLogSet( Date startDate, Date endDate )
54 {
55 this.startDate = startDate;
56 this.endDate = endDate;
57 }
58
59
60
61
62
63
64
65
66 public ChangeLogSet( List<ChangeSet> entries, Date startDate, Date endDate )
67 {
68 this( startDate, endDate );
69 setChangeSets( entries );
70 }
71
72
73
74
75
76
77 public Date getStartDate()
78 {
79 return startDate;
80 }
81
82
83
84
85
86
87 public Date getEndDate()
88 {
89 return endDate;
90 }
91
92
93
94
95
96
97 public ScmVersion getStartVersion()
98 {
99 return startVersion;
100 }
101
102 public void setStartVersion( ScmVersion startVersion )
103 {
104 this.startVersion = startVersion;
105 }
106
107
108
109
110
111
112 public ScmVersion getEndVersion()
113 {
114 return endVersion;
115 }
116
117 public void setEndVersion( ScmVersion endVersion )
118 {
119 this.endVersion = endVersion;
120 }
121
122
123
124
125
126
127 public List<ChangeSet> getChangeSets()
128 {
129 return entries;
130 }
131
132 public void setChangeSets( List<ChangeSet> changeSets )
133 {
134 this.entries = changeSets;
135 }
136
137
138
139
140
141
142 public String toXML()
143 {
144 return toXML( DEFAULT_ENCODING );
145 }
146
147
148
149
150
151
152
153 public String toXML( String encoding )
154 {
155 String encodingString = encoding;
156
157 if ( encodingString == null )
158 {
159 encodingString = DEFAULT_ENCODING;
160 }
161
162 StringBuilder buffer = new StringBuilder();
163 String pattern = "yyyyMMdd HH:mm:ss z";
164 SimpleDateFormat formatter = new SimpleDateFormat( pattern );
165
166 buffer.append( "<?xml version=\"1.0\" encoding=\"" + encodingString + "\"?>\n" );
167 buffer.append( "<changeset datePattern=\"" )
168 .append( pattern )
169 .append( "\"" );
170
171 if ( startDate != null )
172 {
173 buffer.append( " start=\"" )
174 .append( formatter.format( getStartDate() ) )
175 .append( "\"" );
176 }
177 if ( endDate != null )
178 {
179 buffer.append( " end=\"" )
180 .append( formatter.format( getEndDate() ) )
181 .append( "\"" );
182 }
183
184 if ( startVersion != null )
185 {
186 buffer.append( " startVersion=\"" )
187 .append( getStartVersion() )
188 .append( "\"" );
189 }
190 if ( endVersion != null )
191 {
192 buffer.append( " endVersion=\"" )
193 .append( getEndVersion() )
194 .append( "\"" );
195 }
196
197 buffer.append( ">\n" );
198
199
200 for ( ChangeSet changeSet : getChangeSets() )
201 {
202 buffer.append( changeSet.toXML() );
203 }
204
205 buffer.append( "</changeset>\n" );
206
207 return buffer.toString();
208 }
209 }