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