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