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