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