1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.report.projectinfo;
20
21 import java.util.Locale;
22 import java.util.regex.Pattern;
23
24 import org.apache.maven.doxia.sink.Sink;
25 import org.apache.maven.reporting.AbstractMavenReportRenderer;
26 import org.codehaus.plexus.i18n.I18N;
27
28
29
30
31
32 public abstract class AbstractProjectInfoRenderer extends AbstractMavenReportRenderer {
33
34
35
36 protected I18N i18n;
37
38
39
40
41 protected Locale locale;
42
43
44
45
46
47
48 public AbstractProjectInfoRenderer(Sink sink, I18N i18n, Locale locale) {
49 super(sink);
50
51 this.i18n = i18n;
52
53 this.locale = locale;
54 }
55
56 @Override
57 public String getTitle() {
58 return getI18nString("title");
59 }
60
61
62
63
64
65 protected String getI18nString(String key) {
66 return getI18nString(getI18Nsection(), key);
67 }
68
69
70
71
72
73
74 protected String getI18nString(String section, String key) {
75 return i18n.getString("project-info-reports", locale, "report." + section + '.' + key);
76 }
77
78 @Override
79 protected void text(String text) {
80 if (text == null || text.isEmpty())
81 {
82 sink.text("-");
83 } else {
84
85 String regex = "(.+?)<(\"[^\"]*\"|'[^']*'|[^'\">])*>(.+?)";
86 if (Pattern.matches(regex, text)) {
87 sink.rawText(text);
88 } else {
89 sink.text(text);
90 }
91 }
92 }
93
94
95
96
97
98
99
100 @Override
101 protected void verbatimText(String text) {
102 sink.verbatim(null);
103
104 text(text);
105
106 sink.verbatim_();
107 }
108
109
110
111
112 @Override
113 protected void verbatimLink(String text, String href) {
114 if (href == null || href.isEmpty()) {
115 verbatimText(text);
116 } else {
117 sink.verbatim(null);
118
119 link(href, text);
120
121 sink.verbatim_();
122 }
123 }
124
125 protected abstract String getI18Nsection();
126 }