View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.plugin.plugin.report;
20  
21  import java.util.Locale;
22  
23  import org.apache.maven.doxia.sink.Sink;
24  import org.apache.maven.project.MavenProject;
25  import org.apache.maven.reporting.AbstractMavenReportRenderer;
26  import org.codehaus.plexus.i18n.I18N;
27  
28  /** Base class for all reports generated by the plugin report plugin. */
29  public abstract class AbstractPluginReportRenderer extends AbstractMavenReportRenderer {
30  
31      private static final String RESOURCE_BASENAME = "plugin-report";
32  
33      private final I18N i18n;
34  
35      protected final Locale locale;
36  
37      protected final MavenProject project;
38  
39      protected AbstractPluginReportRenderer(Sink sink, Locale locale, I18N i18n, MavenProject project) {
40          super(sink);
41          this.i18n = i18n;
42          this.locale = locale;
43          this.project = project;
44      }
45  
46      @Override
47      public String getTitle() {
48          return getI18nString("title");
49      }
50  
51      /**
52       * Returns
53       * @param key The key .
54       * @return The translated string.
55       */
56      protected String getI18nString(String key) {
57          return getI18nString(getI18nSection(), key);
58      }
59  
60      /**
61       * @param section The section.
62       * @param key The key to translate.
63       * @return the translated key.
64       */
65      protected String getI18nString(String section, String key) {
66          return i18n.getString(RESOURCE_BASENAME, locale, "report." + section + '.' + key);
67      }
68  
69      /**
70       *
71       * @return the key prefix to be used with every key. Is prepended by {@code report.}.
72       */
73      protected abstract String getI18nSection();
74  }