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