1 package org.apache.maven.report.projectinfo;
2
3 /*
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
20 */
21
22 import java.util.Locale;
23 import java.util.regex.Pattern;
24
25 import org.apache.maven.doxia.sink.Sink;
26 import org.apache.maven.reporting.AbstractMavenReportRenderer;
27 import org.codehaus.plexus.i18n.I18N;
28 import org.codehaus.plexus.util.StringUtils;
29
30 /**
31 * @author Hervé Boutemy
32 *
33 */
34 public abstract class AbstractProjectInfoRenderer
35 extends AbstractMavenReportRenderer
36 {
37 /**
38 * {@link I18N}.
39 */
40 protected I18N i18n;
41
42 /**
43 * The {@link Locale}
44 */
45 protected Locale locale;
46
47 /**
48 * @param sink {@link Sink}
49 * @param i18n {@link I18N}
50 * @param locale {@link Locale}
51 */
52 public AbstractProjectInfoRenderer( Sink sink, I18N i18n, Locale locale )
53 {
54 super( sink );
55
56 this.i18n = i18n;
57
58 this.locale = locale;
59 }
60
61 @Override
62 public String getTitle()
63 {
64 return getI18nString( "title" );
65 }
66
67 /**
68 * @param key The key.
69 * @return The translated string.
70 */
71 protected String getI18nString( String key )
72 {
73 return getI18nString( getI18Nsection(), key );
74 }
75
76 /**
77 * @param section The section.
78 * @param key The key to translate.
79 * @return the translated key.
80 */
81 protected String getI18nString( String section, String key )
82 {
83 return i18n.getString( "project-info-reports", locale, "report." + section + '.' + key );
84 }
85
86 @Override
87 protected void text( String text )
88 {
89 if ( StringUtils.isEmpty( text ) ) // Take care of spaces
90 {
91 sink.text( "-" );
92 }
93 else
94 {
95 // custombundle text with xml?
96 String regex = "(.+?)<(\"[^\"]*\"|'[^']*'|[^'\">])*>(.+?)";
97 if ( Pattern.matches( regex, text ) )
98 {
99 sink.rawText( text );
100 }
101 else
102 {
103 sink.text( text );
104 }
105 }
106 }
107
108 protected abstract String getI18Nsection();
109 }