1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package net.sf.mgaip;
17
18 import java.io.File;
19 import java.io.FilenameFilter;
20 import java.util.Locale;
21
22 import org.apache.maven.doxia.sink.Sink;
23 import org.apache.maven.doxia.siterenderer.Renderer;
24 import org.apache.maven.project.MavenProject;
25 import org.apache.maven.reporting.AbstractMavenReport;
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43 public final class AdInserterMojo extends AbstractMavenReport {
44
45
46
47
48
49
50
51 String customPoweredBy;
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66 String facebookLink;
67
68
69
70
71
72
73 String googleId;
74
75
76
77
78
79 boolean googlePlusOne;
80
81
82
83
84
85
86 int horizontalAdHeight;
87
88
89
90
91
92
93
94 String horizontalAdId;
95
96
97
98
99
100 int horizontalAdWidth;
101
102
103
104
105
106 int logoAdHeight;
107
108
109
110
111
112
113
114 String logoAdId;
115
116
117
118
119
120 int logoAdWidth;
121
122
123
124
125
126
127
128 private File outputDirectory;
129
130
131
132
133
134 private MavenProject project;
135
136
137
138
139
140 private Renderer siteRenderer;
141
142
143
144
145
146 int uniqueAdHeight;
147
148
149
150
151
152
153
154 String uniqueAdId;
155
156
157
158
159
160 int uniqueAdWidth;
161
162
163
164
165
166 int verticalAdHeight;
167
168
169
170
171
172
173
174
175 String verticalAdId;
176
177
178
179
180
181 int verticalAdWidth;
182
183
184
185
186 private void createReport() {
187
188
189
190 Sink sink = (Sink) getSink();
191
192
193 sink.head();
194 sink.title();
195 sink.text("mgaip plugin configuration");
196 sink.title_();
197 sink.head_();
198
199
200
201 sink.body();
202 sink.section1();
203 sink.sectionTitle1();
204 sink.text("Google Ads");
205 sink.sectionTitle1_();
206
207 sink.paragraph();
208 sink.text("These are the configured ads for user ");
209 sink.bold();
210 sink.text(this.googleId);
211 sink.bold_();
212 sink.paragraph_();
213
214 sink.table();
215
216 sink.tableRow();
217 sink.tableHeaderCell();
218 sink.text("Ad type");
219 sink.tableHeaderCell_();
220 sink.tableHeaderCell();
221 sink.text("Slot");
222 sink.tableHeaderCell_();
223 sink.tableHeaderCell();
224 sink.text("Width");
225 sink.tableHeaderCell_();
226 sink.tableHeaderCell();
227 sink.text("Height");
228 sink.tableHeaderCell_();
229 sink.tableRow_();
230
231 sink.tableRow();
232 sink.tableCell();
233 sink.text("Horizontal");
234 sink.tableCell_();
235 sink.tableCell();
236 sink.text(this.horizontalAdId);
237 sink.tableCell_();
238 sink.tableCell();
239 sink.text("" + this.horizontalAdWidth);
240 sink.tableCell_();
241 sink.tableCell();
242 sink.text("" + this.horizontalAdHeight);
243 sink.tableCell_();
244 sink.tableRow_();
245
246 sink.tableRow();
247 sink.tableCell();
248 sink.text("Logo");
249 sink.tableCell_();
250 sink.tableCell();
251 sink.text(this.logoAdId);
252 sink.tableCell_();
253 sink.tableCell();
254 sink.text("" + this.logoAdWidth);
255 sink.tableCell_();
256 sink.tableCell();
257 sink.text("" + this.logoAdHeight);
258 sink.tableCell_();
259 sink.tableRow_();
260
261 sink.tableRow();
262 sink.tableCell();
263 sink.text("Unique");
264 sink.tableCell_();
265 sink.tableCell();
266 sink.text(this.uniqueAdId);
267 sink.tableCell_();
268 sink.tableCell();
269 sink.text("" + this.uniqueAdWidth);
270 sink.tableCell_();
271 sink.tableCell();
272 sink.text("" + this.uniqueAdHeight);
273 sink.tableCell_();
274 sink.tableRow_();
275
276 sink.tableRow();
277 sink.tableCell();
278 sink.text("Vertical");
279 sink.tableCell_();
280 sink.tableCell();
281 sink.text(this.verticalAdId);
282 sink.tableCell_();
283 sink.tableCell();
284 sink.text("" + this.verticalAdWidth);
285 sink.tableCell_();
286 sink.tableCell();
287 sink.text("" + this.verticalAdHeight);
288 sink.tableCell_();
289 sink.tableRow_();
290
291 sink.table_();
292
293 sink.section1_();
294
295
296 if (this.facebookLink != null && !this.facebookLink.equals("")) {
297 sink.section1();
298 sink.sectionTitle1();
299 sink.text("Facebook I Like");
300 sink.sectionTitle1_();
301
302 sink.paragraph();
303 sink.text("This is the configuration for the Facebook I Like "
304 + "buttom.");
305 sink.lineBreak();
306 sink.text("Link: ");
307 sink.bold();
308 sink.link(this.facebookLink);
309 sink.text(this.facebookLink);
310 sink.link_();
311 sink.bold_();
312 sink.paragraph_();
313 sink.section1_();
314 }
315
316
317 if (this.customPoweredBy != null && !this.customPoweredBy.equals("")) {
318 sink.section1();
319 sink.sectionTitle1();
320 sink.text("Custom Powered By");
321 sink.sectionTitle1_();
322
323 sink.paragraph();
324 sink.text("This is the custom configuration:");
325 sink.paragraph_();
326
327 sink.paragraph();
328 sink.monospaced();
329 sink.rawText(this.customPoweredBy);
330 sink.monospaced_();
331 sink.paragraph_();
332 sink.section1_();
333 }
334
335 sink.body_();
336
337 sink.flush();
338 sink.close();
339 }
340
341
342
343
344
345
346 public void executeReport(final Locale
347
348
349
350 this.getLog().info("Starting mgaip");
351 this.getLog().info("Google Id: " + this.googleId);
352 this.getLog().debug("Vertical Ad: " + this.verticalAdId);
353 this.getLog().debug("Horizontal Ad: " + this.horizontalAdId);
354 this.getLog().debug("Unique Ad: " + this.uniqueAdId);
355 this.getLog().debug("Logo Ad: " + this.logoAdId);
356
357 this.createReport();
358
359 this.replaceFiles(this.outputDirectory.getPath());
360 }
361
362
363
364
365
366
367
368 public String getDescription(final Locale
369 return "Includes Google publicity in the generated site.";
370 }
371
372
373
374
375
376
377 public String
378 return "Mgaip";
379 }
380
381
382
383
384
385
386 protected String
387 return outputDirectory.getAbsolutePath();
388 }
389
390
391
392
393
394
395 public String
396 return "mgaip";
397 }
398
399
400
401
402
403
404 protected MavenProject
405 return this.project;
406 }
407
408
409
410
411
412
413 protected Renderer
414 return this.siteRenderer;
415 }
416
417
418
419
420
421
422
423
424
425 void log(final int level, final String
426 switch (level) {
427 case 1:
428 this.getLog().debug(message);
429 break;
430 case 2:
431 this.getLog().info(message);
432 break;
433 case 3:
434 this.getLog().warn(message);
435 break;
436 case 4:
437 this.getLog().error(message);
438 break;
439 default:
440 this.getLog().info(message);
441 break;
442 }
443 }
444
445
446
447
448
449
450
451 void log(final Throwable
452 this.getLog().debug(exception);
453 }
454
455
456
457
458 private void replaceFiles(final String
459
460 final File file = new File(directory);
461 String[] files = file.list(new FilenameFilter() {
462
463
464
465
466
467
468
469 public boolean accept(File dir, String name) {
470 boolean ret = false;
471 if (name.startsWith("mgaip")) {
472 ret = false;
473 } else if (name.endsWith("html")) {
474 ret = true;
475 }
476 return ret;
477 }
478
479 }
480
481 );
482
483 Replacer replacer = new Replacer(this);
484
485 if (files != null) {
486 this.getLog().debug("Files to process:");
487 for (int i = 0; i < files.length; i++) {
488 final String filename = files[i];
489 replacer.replace(directory, filename);
490 }
491 } else {
492 this.getLog().warn("No files to process in " + directory);
493 }
494
495
496 String[] directories = file.list(new FilenameFilter() {
497
498
499
500
501
502
503
504 public boolean accept(File dir, String name) {
505 boolean ret = false;
506 File file = new File(dir.getPath() + File.separatorChar + name);
507 if (file.isDirectory()) {
508 ret = true;
509 }
510 return ret;
511 }
512 });
513 int size = directories.length;
514 for (int i = 0; i < size; i++) {
515 this.getLog().info(
516 "Directory to process: " + directory + File.separatorChar
517 + directories[i]);
518 this.replaceFiles(directory + File.separatorChar + directories[i]);
519 }
520 }
521 }