001package jmri.web.servlet.json;
002
003import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
004import java.util.Locale;
005import javax.annotation.CheckReturnValue;
006import javax.annotation.CheckForNull;
007import javax.annotation.ParametersAreNonnullByDefault;
008
009@ParametersAreNonnullByDefault
010@CheckReturnValue
011
012@javax.annotation.concurrent.Immutable
013
014/**
015 * Provides standard access for resource bundles in a package.
016 * <p>
017 * Convention is to provide a subclass of this name in each package, working off
018 * the local resource bundle name.
019 * <p>
020 * This instance is named differently than usual since two Bundle classes exist
021 * for this package: one that inherits from jmri.web.servlet and one that
022 * inherits from jmri.server.json
023 *
024 * @author Bob Jacobsen Copyright (C) 2012
025 * @since 3.3.1
026 */
027@SuppressFBWarnings(value = {"HSM_HIDING_METHOD"},
028    justification = "Desired pattern is repeated classes with package-level access to members")
029public class JsonBundle extends jmri.server.json.Bundle {
030
031    @CheckForNull
032    private static final String name = null; // NOI18N
033
034    //
035    // below here is boilerplate to be copied exactly
036    //
037    /**
038     * Provides a translated string for a given key from the package resource
039     * bundle or parent.
040     * <p>
041     * Note that this is intentionally package-local access.
042     *
043     * @param key Bundle key to be translated
044     * @return Internationalized text
045     */
046    static String getMessage(String key) {
047        return getBundle().handleGetMessage(key);
048    }
049
050    /**
051     * Provides a translated string for a given key in a given locale from the
052     * package resource bundle or parent.
053     * <p>
054     * Note that this is intentionally package-local access.
055     *
056     * @param locale The locale to be used
057     * @param key    Bundle key to be translated
058     * @return Internationalized text
059     */
060    static String getMessage(Locale locale, String key) {
061        return getBundle().handleGetMessage(locale, key);
062    }
063
064    /**
065     * Merges user data with a translated string for a given key from the
066     * package resource bundle or parent.
067     * <p>
068     * Uses the transformation conventions of the Java MessageFormat utility.
069     * <p>
070     * Note that this is intentionally package-local access.
071     *
072     * @see java.text.MessageFormat
073     * @param key  Bundle key to be translated
074     * @param subs One or more objects to be inserted into the message
075     * @return Internationalized text
076     */
077    static String getMessage(String key, Object... subs) {
078        return getBundle().handleGetMessage(key, subs);
079    }
080
081    /**
082     * Merges user data with a translated string for a given key in a given
083     * locale from the package resource bundle or parent.
084     * <p>
085     * Uses the transformation conventions of the Java MessageFormat utility.
086     * <p>
087     * Note that this is intentionally package-local access.
088     *
089     * @see java.text.MessageFormat
090     * @param locale The locale to be used
091     * @param key    Bundle key to be translated
092     * @param subs   One or more objects to be inserted into the message
093     * @return Internationalized text
094     */
095    static String getMessage(Locale locale, String key, Object... subs) {
096        return getBundle().handleGetMessage(locale, key, subs);
097    }
098
099    private final static JsonBundle b = new JsonBundle();
100
101    @Override
102    @CheckForNull
103    protected String bundleName() {
104        return name;
105    }
106
107    protected static jmri.Bundle getBundle() {
108        return b;
109    }
110
111    @Override
112    protected String retry(Locale locale, String key) {
113        return super.getBundle().handleGetMessage(locale, key);
114    }
115
116}