Java Code Examples for org.jivesoftware.openfire.container.PluginManager#getPlugin()

The following examples show how to use org.jivesoftware.openfire.container.PluginManager#getPlugin() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LocaleUtils.java    From Openfire with Apache License 2.0 6 votes vote down vote up
/**
 * Retrieve the <code>ResourceBundle</code> that is used with this plugin.
 *
 * @param pluginName the name of the plugin.
 * @return the ResourceBundle used with this plugin.
 * @throws Exception thrown if an exception occurs.
 */
public static ResourceBundle getPluginResourceBundle(String pluginName) throws Exception {
    final Locale locale = JiveGlobals.getLocale();

    String i18nFile = getI18nFile(pluginName);

    // Retrieve classloader from pluginName.
    final XMPPServer xmppServer = XMPPServer.getInstance();
    PluginManager pluginManager = xmppServer.getPluginManager();
    Plugin plugin = pluginManager.getPlugin(pluginName);
    if (plugin == null) {
        throw new NullPointerException("Plugin could not be located.");
    }

    ClassLoader pluginClassLoader = pluginManager.getPluginClassloader(plugin);
    return ResourceBundle.getBundle(i18nFile, locale, pluginClassLoader);
}
 
Example 2
Source File: CacheFactory.java    From Openfire with Apache License 2.0 6 votes vote down vote up
private static ClassLoader getClusteredCacheStrategyClassLoader() {
    PluginManager pluginManager = XMPPServer.getInstance().getPluginManager();
    Plugin plugin = pluginManager.getPlugin("hazelcast");
    if (plugin == null) {
        plugin = pluginManager.getPlugin("clustering");
        if (plugin == null) {
            plugin = pluginManager.getPlugin("enterprise");
        }
    }
    PluginClassLoader pluginLoader = pluginManager.getPluginClassloader(plugin);
    if (pluginLoader != null) {
        if (log.isDebugEnabled()) {
            StringBuffer pluginLoaderDetails = new StringBuffer("Clustering plugin class loader: ");
            pluginLoaderDetails.append(pluginLoader.getClass().getName());
            for (URL url : pluginLoader.getURLs()) {
                pluginLoaderDetails.append("\n\t").append(url.toExternalForm());
            }
            log.debug(pluginLoaderDetails.toString());
        }
        return pluginLoader;
    }
    else {
        log.warn("CacheFactory - Unable to find a Plugin that provides clustering support.");
        return Thread.currentThread().getContextClassLoader();
    }
}
 
Example 3
Source File: LocaleUtils.java    From Openfire with Apache License 2.0 5 votes vote down vote up
/**
 * Returns an internationalized string loaded from a resource bundle from
 * the passed in plugin, using the passed in Locale.
 * 
 * If the plugin name is {@code null}, the key will be looked up using the
 * standard resource bundle.
 * 
 * If the locale is {@code null}, the Jive Global locale will be used.
 * 
 * @param key
 *            the key to use for retrieving the string from the appropriate
 *            resource bundle.
 * @param pluginName
 *            the name of the plugin to load the require resource bundle
 *            from.
 * @param arguments
 *            a list of objects to use which are formatted, then inserted
 *            into the pattern at the appropriate places.
 * @param locale
 *            the locale to use for retrieving the appropriate
 *            locale-specific string.
 * @param fallback
 *            if {@code true}, the global locale used by Openfire will be
 *            used if the requested locale is not available)
 * @return the localized string.
 */
public static String getLocalizedString(String key, String pluginName, List<?> arguments, Locale locale, boolean fallback) {
    if (pluginName == null) {
        return getLocalizedString(key, arguments);
    }

    if (locale == null) {
        locale = JiveGlobals.getLocale();
    }
    String i18nFile = getI18nFile(pluginName);

    // Retrieve classloader from pluginName.
    final XMPPServer xmppServer = XMPPServer.getInstance();
    PluginManager pluginManager = xmppServer.getPluginManager();
    Plugin plugin = pluginManager.getPlugin(pluginName);
    if (plugin == null) {
        throw new NullPointerException("Plugin could not be located: " + pluginName);
    }

    ClassLoader pluginClassLoader = pluginManager.getPluginClassloader(plugin);
    try {
        ResourceBundle bundle = ResourceBundle.getBundle(i18nFile, locale, pluginClassLoader);
        return getLocalizedString(key, locale, arguments, bundle);
    }
    catch (MissingResourceException mre) {
        Locale jivesLocale = JiveGlobals.getLocale();
        if (fallback && !jivesLocale.equals(locale)) {
            Log.info("Could not find the requested locale. Falling back to default locale.", mre);
            return getLocalizedString(key, pluginName, arguments, jivesLocale, false);
        }
        
        Log.error(mre.getMessage(), mre);
        return key;
    }
}