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 public String toXML()
141 {
142 return toXML( DEFAULT_ENCODING );
143 }
144
145
146
147
148 public String toXML( String encoding )
149 {
150 String encodingString = encoding;
151
152 if ( encodingString == null )
153 {
154 encodingString = DEFAULT_ENCODING;
155 }
156
157 StringBuilder buffer = new StringBuilder();
158 String pattern = "yyyyMMdd HH:mm:ss z";
159 SimpleDateFormat formatter = new SimpleDateFormat( pattern );
160
161 buffer.append( "<?xml version=\"1.0\" encoding=\"" + encodingString + "\"?>\n" );
162 buffer.append( "<changeset datePattern=\"" )
163 .append( pattern )
164 .append( "\"" );
165
166 if ( startDate != null )
167 {
168 buffer.append( " start=\"" )
169 .append( formatter.format( getStartDate() ) )
170 .append( "\"" );
171 }
172 if ( endDate != null )
173 {
174 buffer.append( " end=\"" )
175 .append( formatter.format( getEndDate() ) )
176 .append( "\"" );
177 }
178
179 if ( startVersion != null )
180 {
181 buffer.append( " startVersion=\"" )
182 .append( getStartVersion() )
183 .append( "\"" );
184 }
185 if ( endVersion != null )
186 {
187 buffer.append( " endVersion=\"" )
188 .append( getEndVersion() )
189 .append( "\"" );
190 }
191
192 buffer.append( ">\n" );
193
194
195 for ( ChangeSet changeSet : getChangeSets() )
196 {
197 buffer.append( changeSet.toXML() );
198 }
199
200 buffer.append( "</changeset>\n" );
201
202 return buffer.toString();
203 }
204 }