/** Message formatter * @param messageKey the message key * @return the resolved message text */ public String msg (String messageKey) { assertBundle (messageKey); return getMessage (bundle, messageKey); }
/** An instance bound to a bundle. This method figures out the bundle name * for the class object's package and uses the class' class loader to * find the bundle. Note, the specified class object must not be * <code>null</code>. * @param cls the class object from which to load the resource bundle * @return the helper instance bound to the bundle */ public static I18NHelper getInstance (final Class cls) { ClassLoader classLoader = AccessController.doPrivileged ( new PrivilegedAction<ClassLoader> () { public ClassLoader run () { return cls.getClassLoader(); } } ); String bundle = getPackageName (cls.getName()) + bundleSuffix; return getInstance (bundle, classLoader); }
/** Constructor for an instance bound to a bundle. * @param bundleName the name of the resource bundle * @param loader the class loader from which to load the resource * bundle */ private I18NHelper (String bundleName, ClassLoader loader) { try { bundle = loadBundle (bundleName, loader); } catch (Throwable e) { failure = e; } }
/** Add a message to the verbose message buffer. * * @param msgId the message id */ private void addVerboseMessage(String msgId) { verboseBuffer.append(msg.msg(msgId)); verboseBuffer.append(NL); }
/** * Formats message by adding an <code>Object</code> argument. * @param messages the resource bundle * @param messageKey the message key * @param arg the argument * @return the resolved message text */ final private static String getMessage(ResourceBundle messages, String messageKey, Object arg) { Object []args = {arg}; return getMessage(messages, messageKey, args); }
/** An instance bound to a bundle. This method uses the current class * loader to find the bundle. * @param bundleName the name of the bundle * @return the helper instance bound to the bundle */ public static I18NHelper getInstance (String bundleName) { return getInstance (bundleName, I18NHelper.class.getClassLoader()); }
/** Returns the resource bundle used by this I18NHelper. * @return the associated resource bundle * @since 1.1 */ public ResourceBundle getResourceBundle () { assertBundle (); return bundle; }
/** An instance bound to a bundle. This method uses the specified class * loader to find the bundle. Note, the specified class loader must not * be <code>null</code>. * @param bundleName the name of the bundle * @param loader the class loader from which to load the resource * bundle * @return the helper instance bound to the bundle */ public static I18NHelper getInstance (String bundleName, ClassLoader loader) { I18NHelper helper = (I18NHelper) helpers.get (bundleName); if (helper != null) { return helper; } helper = new I18NHelper(bundleName, loader); helpers.put (bundleName, helper); // if two threads simultaneously create the same helper, return the first // one to be put into the Hashtable. The other will be garbage collected. return (I18NHelper) helpers.get (bundleName); }
/** * Load ResourceBundle by bundle name * @param bundleName the name of the bundle * @param loader the class loader from which to load the resource bundle * @return the ResourceBundle */ final private static ResourceBundle loadBundle( String bundleName, ClassLoader loader) { ResourceBundle messages = (ResourceBundle)bundles.get(bundleName); if (messages == null) //not found as loaded - add { if (loader != null) { messages = ResourceBundle.getBundle(bundleName, locale, loader); } else { // the JDO library is loaded by the boostrap class loader messages = ResourceBundle.getBundle(bundleName, locale, getSystemClassLoaderPrivileged()); } bundles.put(bundleName, messages); } return messages; }
/** Add a message to the verbose message buffer. * * @param msgId the message id * @param where the parameter */ private void addVerboseMessage(String msgId, String where) { verboseBuffer.append(msg.msg(msgId, where)); verboseBuffer.append(NL); }
/** * Formats message by adding an <code>Object</code> argument. * @param messages the resource bundle * @param messageKey the message key * @param arg the argument * @return the resolved message text */ final private static String getMessage(ResourceBundle messages, String messageKey, Object arg) { Object []args = {arg}; return getMessage(messages, messageKey, args); }
/** An instance bound to a bundle. This method uses the current class * loader to find the bundle. * @param bundleName the name of the bundle * @return the helper instance bound to the bundle */ public static I18NHelper getInstance (String bundleName) { return getInstance (bundleName, I18NHelper.class.getClassLoader()); }
/** Returns the resource bundle used by this I18NHelper. * @return the associated resource bundle * @since 1.1 */ public ResourceBundle getResourceBundle () { assertBundle (); return bundle; }
/** An instance bound to a bundle. This method uses the specified class * loader to find the bundle. Note, the specified class loader must not * be <code>null</code>. * @param bundleName the name of the bundle * @param loader the class loader from which to load the resource * bundle * @return the helper instance bound to the bundle */ public static I18NHelper getInstance (String bundleName, ClassLoader loader) { I18NHelper helper = (I18NHelper) helpers.get (bundleName); if (helper != null) { return helper; } helper = new I18NHelper(bundleName, loader); helpers.put (bundleName, helper); // if two threads simultaneously create the same helper, return the first // one to be put into the Hashtable. The other will be garbage collected. return (I18NHelper) helpers.get (bundleName); }
/** * Load ResourceBundle by bundle name * @param bundleName the name of the bundle * @param loader the class loader from which to load the resource bundle * @return the ResourceBundle */ final private static ResourceBundle loadBundle( String bundleName, ClassLoader loader) { ResourceBundle messages = (ResourceBundle)bundles.get(bundleName); if (messages == null) //not found as loaded - add { if (loader != null) { messages = ResourceBundle.getBundle(bundleName, locale, loader); } else { // the JDO library is loaded by the boostrap class loader messages = ResourceBundle.getBundle(bundleName, locale, getSystemClassLoaderPrivileged()); } bundles.put(bundleName, messages); } return messages; }
/** Add a message to the verbose message buffer. * * @param msgId the message id * @param where the parameter */ private void addVerboseMessage(String msgId, String... where) { verboseBuffer.append(msg.msg(msgId, where)); verboseBuffer.append(NL); }
/** Message formatter * @param messageKey the message key * @param arg1 the first argument * @return the resolved message text */ public String msg (String messageKey, Object arg1) { assertBundle (messageKey); return getMessage (bundle, messageKey, arg1); }
/** * Formats message by adding two <code>Object</code> arguments. * @param messages the resource bundle * @param messageKey the message key * @param arg1 the first argument * @param arg2 the second argument * @return the resolved message text */ final private static String getMessage(ResourceBundle messages, String messageKey, Object arg1, Object arg2) { Object []args = {arg1, arg2}; return getMessage(messages, messageKey, args); }
/** An instance bound to a bundle. This method figures out the bundle name * for the class object's package and uses the class' class loader to * find the bundle. Note, the specified class object must not be * <code>null</code>. * @param cls the class object from which to load the resource bundle * @return the helper instance bound to the bundle */ public static I18NHelper getInstance (final Class cls) { ClassLoader classLoader = AccessController.doPrivileged ( new PrivilegedAction<ClassLoader> () { public ClassLoader run () { return cls.getClassLoader(); } } ); String bundle = getPackageName (cls.getName()) + bundleSuffix; return getInstance (bundle, classLoader); }
/** Constructor for an instance bound to a bundle. * @param bundleName the name of the resource bundle * @param loader the class loader from which to load the resource * bundle */ private I18NHelper (String bundleName, ClassLoader loader) { try { bundle = loadBundle (bundleName, loader); } catch (Throwable e) { failure = e; } }