1 package org.apache.maven.scm.command.changelog;
2
3 /*
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
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 * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
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 * Initializes a new instance of this class.
49 *
50 * @param startDate the start date/tag for this set.
51 * @param endDate the end date/tag for this set, or <code>null</code> if this set goes to the present time.
52 */
53 public ChangeLogSet( Date startDate, Date endDate )
54 {
55 this.startDate = startDate;
56 this.endDate = endDate;
57 }
58
59 /**
60 * Initializes a new instance of this class.
61 *
62 * @param entries collection of {@link org.apache.maven.scm.ChangeSet} objects for this set.
63 * @param startDate the start date/tag for this set.
64 * @param endDate the end date/tag for this set, or <code>null</code> if this set goes to the present time.
65 */
66 public ChangeLogSet( List<ChangeSet> entries, Date startDate, Date endDate )
67 {
68 this( startDate, endDate );
69 setChangeSets( entries );
70 }
71
72 /**
73 * Returns the start date.
74 *
75 * @return the start date.
76 */
77 public Date getStartDate()
78 {
79 return startDate;
80 }
81
82 /**
83 * Returns the end date for this set.
84 *
85 * @return the end date for this set, or <code>null</code> if this set goes to the present time.
86 */
87 public Date getEndDate()
88 {
89 return endDate;
90 }
91
92 /**
93 * Returns the start version (revision/branch/label) for this set.
94 *
95 * @return the start version (revision/branch/label) for this set, or <code>null</code>.
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 * Returns the end version (revision/branch/label) for this set.
109 *
110 * @return the end version (revision/branch/label) for this set, or <code>null</code>.
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 * Returns the collection of changeSet.
124 *
125 * @return the collection of {@link org.apache.maven.scm.ChangeSet} objects for this set.
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 * Creates an XML representation of this change log set with a default encoding (ISO-8859-1).
139 *
140 * @return TODO
141 */
142 public String toXML()
143 {
144 return toXML( DEFAULT_ENCODING );
145 }
146
147 /**
148 * Creates an XML representation of this change log set.
149 *
150 * @param encoding encoding of output
151 * @return TODO
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 // Write out the entries
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 }