1 package org.apache.maven.report.projectinfo;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.doxia.sink.Sink;
23 import org.apache.maven.model.MailingList;
24 import org.apache.maven.model.Model;
25 import org.apache.maven.reporting.AbstractMavenReportRenderer;
26 import org.codehaus.plexus.i18n.I18N;
27 import org.codehaus.plexus.util.StringUtils;
28
29 import java.util.ArrayList;
30 import java.util.Iterator;
31 import java.util.List;
32 import java.util.Locale;
33
34
35
36
37
38
39
40
41
42
43 public class MailingListsReport
44 extends AbstractProjectInfoReport
45 {
46
47
48
49
50
51 public String getName( Locale locale )
52 {
53 return i18n.getString( "project-info-report", locale, "report.mailing-lists.name" );
54 }
55
56
57 public String getDescription( Locale locale )
58 {
59 return i18n.getString( "project-info-report", locale, "report.mailing-lists.description" );
60 }
61
62
63 public void executeReport( Locale locale )
64 {
65 MailingListsRenderer r = new MailingListsRenderer( getSink(), getProject().getModel(), i18n, locale );
66
67 r.render();
68 }
69
70
71 public String getOutputName()
72 {
73 return "mail-lists";
74 }
75
76
77
78
79
80
81
82
83 protected static class MailingListsRenderer
84 extends AbstractMavenReportRenderer
85 {
86 private Model model;
87
88 private I18N i18n;
89
90 private Locale locale;
91
92 private static final String[] EMPTY_STRING_ARRAY = new String[0];
93
94 MailingListsRenderer( Sink sink, Model model, I18N i18n, Locale locale )
95 {
96 super( sink );
97
98 this.model = model;
99
100 this.i18n = i18n;
101
102 this.locale = locale;
103 }
104
105
106 public String getTitle()
107 {
108 return i18n.getString( "project-info-report", locale, "report.mailing-lists.title" );
109 }
110
111
112 public void renderBody()
113 {
114 List mailingLists = model.getMailingLists();
115
116 if ( mailingLists == null || mailingLists.isEmpty() )
117 {
118 startSection( getTitle() );
119
120
121 paragraph( i18n.getString( "project-info-report", locale, "report.mailing-lists.nolist" ) );
122
123 endSection();
124
125 return;
126 }
127
128 startSection( getTitle() );
129
130 paragraph( i18n.getString( "project-info-report", locale, "report.mailing-lists.intro" ) );
131
132 startTable();
133
134
135 boolean otherArchives = false;
136 for ( Iterator i = mailingLists.iterator(); i.hasNext(); )
137 {
138 MailingList m = (MailingList) i.next();
139
140 if ( m.getOtherArchives() != null && !m.getOtherArchives().isEmpty() )
141 {
142 otherArchives = true;
143 }
144 }
145
146 String name = i18n.getString( "project-info-report", locale, "report.mailing-lists.column.name" );
147 String subscribe = i18n.getString( "project-info-report", locale, "report.mailing-lists.column.subscribe" );
148 String unsubscribe =
149 i18n.getString( "project-info-report", locale, "report.mailing-lists.column.unsubscribe" );
150 String post = i18n.getString( "project-info-report", locale, "report.mailing-lists.column.post" );
151 String archive = i18n.getString( "project-info-report", locale, "report.mailing-lists.column.archive" );
152 String archivesOther =
153 i18n.getString( "project-info-report", locale, "report.mailing-lists.column.otherArchives" );
154
155 if ( otherArchives )
156 {
157 tableHeader( new String[]{name, subscribe, unsubscribe, post, archive, archivesOther} );
158 }
159 else
160 {
161 tableHeader( new String[]{name, subscribe, unsubscribe, post, archive} );
162 }
163
164 for ( Iterator i = model.getMailingLists().iterator(); i.hasNext(); )
165 {
166 MailingList mailingList = (MailingList) i.next();
167
168 List textRow = new ArrayList();
169
170
171 textRow.add( mailingList.getName() );
172
173 textRow.add( createLinkPatternedText( subscribe, mailingList.getSubscribe() ) );
174
175 textRow.add( createLinkPatternedText( unsubscribe, mailingList.getUnsubscribe() ) );
176
177 if ( mailingList.getPost() != null && mailingList.getPost().length() > 0 )
178 {
179 textRow.add( createLinkPatternedText( post, mailingList.getPost() ) );
180 }
181 else
182 {
183 textRow.add( "-" );
184 }
185
186 if ( mailingList.getArchive() != null && mailingList.getArchive().length() > 0 )
187 {
188 textRow.add( createLinkPatternedText( getArchiveServer( mailingList.getArchive() ),
189 mailingList.getArchive() ) );
190 }
191 else
192 {
193 textRow.add( "-" );
194 }
195
196 if ( mailingList.getOtherArchives() != null && !mailingList.getOtherArchives().isEmpty() )
197 {
198
199 Iterator it = mailingList.getOtherArchives().iterator();
200 String otherArchive = it.next().toString();
201
202 textRow.add( createLinkPatternedText( getArchiveServer( otherArchive ), otherArchive ) );
203
204 tableRow( (String[]) textRow.toArray( EMPTY_STRING_ARRAY ) );
205
206
207 while ( it.hasNext() )
208 {
209 otherArchive = (String) it.next();
210
211
212 textRow = new ArrayList();
213
214
215 textRow.add( " " );
216
217
218 textRow.add( " " );
219
220
221 textRow.add( " " );
222
223
224 textRow.add( " " );
225
226
227 textRow.add( " " );
228
229 textRow.add( createLinkPatternedText( getArchiveServer( otherArchive ), otherArchive ) );
230
231 tableRow( (String[]) textRow.toArray( EMPTY_STRING_ARRAY ) );
232 }
233 }
234 else
235 {
236 if ( otherArchives )
237 {
238 textRow.add( null );
239 }
240
241 tableRow( (String[]) textRow.toArray( EMPTY_STRING_ARRAY ) );
242 }
243 }
244
245 endTable();
246
247 endSection();
248 }
249
250
251
252
253
254
255
256
257
258
259
260 private static String getArchiveServer( String uri )
261 {
262 if ( StringUtils.isEmpty( uri ) )
263 {
264 return "???UNKNOWN???";
265 }
266
267 int at = uri.indexOf( "//" );
268 int fromIndex;
269 if ( at >= 0 )
270 {
271 fromIndex = uri.lastIndexOf( "/", at - 1 ) >= 0 ? 0 : at + 2;
272 }
273 else
274 {
275 fromIndex = 0;
276 }
277
278 int from = uri.indexOf( "/", fromIndex );
279
280 if ( from == -1 )
281 {
282 return uri.substring( at + 2 );
283 }
284
285 return uri.substring( at + 2, from );
286 }
287 }
288 }