i18nStatistic.java 1.69 KB
Newer Older
Alex Wenckus's avatar
Alex Wenckus committed
1 2 3 4 5
/**
 * $RCSfile  $
 * $Revision  $
 * $Date  $
 *
6
 * Copyright (C) 1999-2008 Jive Software. All rights reserved.
Alex Wenckus's avatar
Alex Wenckus committed
7 8
 *
 * This software is published under the terms of the GNU Public License (GPL),
9 10
 * a copy of which is included in this distribution, or a commercial license
 * agreement with Jive.
Alex Wenckus's avatar
Alex Wenckus committed
11
 */
12

13
package org.jivesoftware.openfire.stats;
Alex Wenckus's avatar
Alex Wenckus committed
14 15 16 17 18 19 20 21 22

import org.jivesoftware.util.LocaleUtils;

/**
 *  A convience class to build statistic parameters out of a resource bundle.
 *
 * @author Alexander Wenckus
 */
public abstract class i18nStatistic implements Statistic {
23

Alex Wenckus's avatar
Alex Wenckus committed
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
    private String resourceKey;
    private String pluginName;
    private Type statisticType;

    public i18nStatistic(String resourceKey, Statistic.Type statisticType) {
        this(resourceKey, null, statisticType);
    }

    public i18nStatistic(String resourceKey, String pluginName, Statistic.Type statisticType) {
        this.resourceKey = resourceKey;
        this.pluginName = pluginName;
        this.statisticType = statisticType;
    }

    public final String getName() {
        return retrieveValue("name");
    }

    public final Type getStatType() {
        return statisticType;
    }

    public final String getDescription() {
        return retrieveValue("desc");
    }

    public final String getUnits() {
        return retrieveValue("units");
    }

    private String retrieveValue(String key) {
        String wholeKey = "stat." + resourceKey + "." + key;
56
        if (pluginName != null) {
Alex Wenckus's avatar
Alex Wenckus committed
57 58 59 60 61 62 63
            return LocaleUtils.getLocalizedString(wholeKey, pluginName);
        }
        else {
            return LocaleUtils.getLocalizedString(wholeKey);
        }
    }
}