001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *   http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied.  See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 */
019package org.apache.maven.plugin.plugin.report;
020
021import java.util.Locale;
022
023import org.apache.maven.doxia.sink.Sink;
024import org.apache.maven.project.MavenProject;
025import org.apache.maven.reporting.AbstractMavenReportRenderer;
026import org.codehaus.plexus.i18n.I18N;
027
028/** Base class for all reports generated by the plugin report plugin. */
029public abstract class AbstractPluginReportRenderer extends AbstractMavenReportRenderer {
030
031    private static final String RESOURCE_BASENAME = "plugin-report";
032
033    private final I18N i18n;
034
035    protected final Locale locale;
036
037    protected final MavenProject project;
038
039    protected AbstractPluginReportRenderer(Sink sink, Locale locale, I18N i18n, MavenProject project) {
040        super(sink);
041        this.i18n = i18n;
042        this.locale = locale;
043        this.project = project;
044    }
045
046    @Override
047    public String getTitle() {
048        return getI18nString("title");
049    }
050
051    /**
052     * Returns
053     * @param key The key .
054     * @return The translated string.
055     */
056    protected String getI18nString(String key) {
057        return getI18nString(getI18nSection(), key);
058    }
059
060    /**
061     * @param section The section.
062     * @param key The key to translate.
063     * @return the translated key.
064     */
065    protected String getI18nString(String section, String key) {
066        return i18n.getString(RESOURCE_BASENAME, locale, "report." + section + '.' + key);
067    }
068
069    /**
070     *
071     * @return the key prefix to be used with every key. Is prepended by {@code report.}.
072     */
073    protected abstract String getI18nSection();
074}