Search in sources :

Example 11 with PluginManager

use of org.jivesoftware.openfire.container.PluginManager in project Openfire by igniterealtime.

the class ClusterClassLoader method getResources.

public Enumeration<URL> getResources(String name) throws IOException {
    Enumeration<URL> answer = null;
    try {
        answer = hazelcastClassloader.getResources(name);
    } catch (IOException e) {
    // Ignore
    }
    if (answer == null || !answer.hasMoreElements()) {
        PluginManager pluginManager = XMPPServer.getInstance().getPluginManager();
        for (Plugin plugin : pluginManager.getPlugins()) {
            String pluginName = pluginManager.getPluginDirectory(plugin).getName();
            if ("hazelcast".equals(pluginName) || "admin".equals(pluginName)) {
                continue;
            }
            PluginClassLoader pluginClassloader = pluginManager.getPluginClassloader(plugin);
            try {
                answer = pluginClassloader.getResources(name);
            } catch (IOException e) {
            // Ignore
            }
            if (answer != null && answer.hasMoreElements()) {
                return answer;
            }
        }
    }
    return answer;
}
Also used : PluginManager(org.jivesoftware.openfire.container.PluginManager) IOException(java.io.IOException) URL(java.net.URL) Plugin(org.jivesoftware.openfire.container.Plugin) PluginClassLoader(org.jivesoftware.openfire.container.PluginClassLoader)

Example 12 with PluginManager

use of org.jivesoftware.openfire.container.PluginManager in project Openfire by igniterealtime.

the class SchemaManager method checkPluginSchema.

/**
     * Checks the plugin's database schema (if one is required) to ensure that it's
     * installed and up to date. If the schema isn't present or up to date, an automatic
     * update will be attempted.
     *
     * @param plugin the plugin.
     * @return true if database schema checked out fine, or was automatically installed
     *      or updated successfully, or if it isn't needed. False will only be returned
     *      if there is an error.
     */
public boolean checkPluginSchema(final Plugin plugin) {
    final PluginManager pluginManager = XMPPServer.getInstance().getPluginManager();
    String schemaKey = pluginManager.getDatabaseKey(plugin);
    int schemaVersion = pluginManager.getDatabaseVersion(plugin);
    // need database tables.
    if (schemaKey == null || schemaVersion == -1) {
        return true;
    }
    Connection con = null;
    try {
        con = DbConnectionManager.getConnection();
        return checkSchema(con, schemaKey, schemaVersion, new ResourceLoader() {

            @Override
            public InputStream loadResource(String resourceName) {
                File file = new File(pluginManager.getPluginDirectory(plugin) + File.separator + "database", resourceName);
                try {
                    return new FileInputStream(file);
                } catch (FileNotFoundException e) {
                    return null;
                }
            }
        });
    } catch (Exception e) {
        Log.error(LocaleUtils.getLocalizedString("upgrade.database.failure"), e);
        System.out.println(LocaleUtils.getLocalizedString("upgrade.database.failure"));
    } finally {
        DbConnectionManager.closeConnection(con);
    }
    return false;
}
Also used : PluginManager(org.jivesoftware.openfire.container.PluginManager) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Connection(java.sql.Connection) FileNotFoundException(java.io.FileNotFoundException) File(java.io.File) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) SQLException(java.sql.SQLException)

Example 13 with PluginManager

use of org.jivesoftware.openfire.container.PluginManager in project Openfire by igniterealtime.

the class ConnectionManagerImpl method startListeners.

/**
     * Starts all listeners. This ensures that all those that are enabled will start accept connections.
     */
private synchronized void startListeners() {
    // Check if plugins have been loaded
    Log.debug("Received a request to start listeners. Have plugins been loaded?");
    PluginManager pluginManager = XMPPServer.getInstance().getPluginManager();
    if (!pluginManager.isExecuted()) {
        Log.debug("Plugins not yet loaded. Waiting for plugins to be loaded...");
        pluginManager.addPluginManagerListener(new PluginManagerListener() {

            public void pluginsMonitored() {
                Log.debug("Received plugin monitor event! Plugins should now be loaded.");
                // Stop listening for plugin events
                XMPPServer.getInstance().getPluginManager().removePluginManagerListener(this);
                // Start listeners
                startListeners();
            }
        });
        return;
    }
    Log.debug("Starting listeners...");
    for (final ConnectionListener listener : getListeners()) {
        try {
            listener.start();
            Log.debug("Started '{}' (port {}) listener.", listener.getType(), listener.getPort());
        } catch (RuntimeException ex) {
            Log.error("An exception occurred while starting listener " + listener, ex);
        }
    }
    // Start the HTTP client listener.
    try {
        HttpBindManager.getInstance().start();
        Log.debug("Started HTTP client listener.");
    } catch (RuntimeException ex) {
        Log.error("An exception occurred while starting HTTP Bind listener ", ex);
    }
}
Also used : PluginManager(org.jivesoftware.openfire.container.PluginManager) PluginManagerListener(org.jivesoftware.openfire.container.PluginManagerListener)

Example 14 with PluginManager

use of org.jivesoftware.openfire.container.PluginManager in project Openfire by igniterealtime.

the class LocaleUtils method getLocalizedString.

/**
	 * Returns an internationalized string loaded from a resource bundle from
	 * the passed in plugin, using the passed in Locale.
	 * 
	 * If the plugin name is <tt>null</tt>, the key will be looked up using the
	 * standard resource bundle.
	 * 
	 * If the locale is <tt>null</tt>, 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 <tt>true</tt>, 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;
    }
}
Also used : PluginManager(org.jivesoftware.openfire.container.PluginManager) Locale(java.util.Locale) XMPPServer(org.jivesoftware.openfire.XMPPServer) MissingResourceException(java.util.MissingResourceException) ResourceBundle(java.util.ResourceBundle) Plugin(org.jivesoftware.openfire.container.Plugin)

Example 15 with PluginManager

use of org.jivesoftware.openfire.container.PluginManager in project Openfire by igniterealtime.

the class CacheFactory method getClusteredCacheStrategyClassLoader.

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();
    }
}
Also used : PluginManager(org.jivesoftware.openfire.container.PluginManager) URL(java.net.URL) Plugin(org.jivesoftware.openfire.container.Plugin) PluginClassLoader(org.jivesoftware.openfire.container.PluginClassLoader)

Aggregations

PluginManager (org.jivesoftware.openfire.container.PluginManager)20 Plugin (org.jivesoftware.openfire.container.Plugin)8 KrakenPlugin (net.sf.kraken.KrakenPlugin)7 IOException (java.io.IOException)5 URL (java.net.URL)5 PluginClassLoader (org.jivesoftware.openfire.container.PluginClassLoader)5 UserNotFoundException (org.jivesoftware.openfire.user.UserNotFoundException)4 Registration (net.sf.kraken.registration.Registration)3 GroupNotFoundException (org.jivesoftware.openfire.group.GroupNotFoundException)3 NotFoundException (org.jivesoftware.util.NotFoundException)3 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 FileNotFoundException (java.io.FileNotFoundException)2 Locale (java.util.Locale)2 BaseTransport (net.sf.kraken.BaseTransport)2 RegistrationHandler (net.sf.kraken.registration.RegistrationHandler)2 Element (org.dom4j.Element)2 XMPPServer (org.jivesoftware.openfire.XMPPServer)2 JID (org.xmpp.packet.JID)2 InputStream (java.io.InputStream)1