PluginDownloadManager.java 2.75 KB
Newer Older
1
/**
Matt Tucker's avatar
Matt Tucker committed
2 3 4
 * $RCSfile$
 * $Revision: 3191 $
 * $Date: 2005-12-12 13:41:22 -0300 (Mon, 12 Dec 2005) $
5
 *
6
 * Copyright (C) 2005-2008 Jive Software. All rights reserved.
Matt Tucker's avatar
Matt Tucker committed
7 8
 *
 * This software is published under the terms of the GNU Public License (GPL),
9 10
 * a copy of which is included in this distribution, or a commercial license
 * agreement with Jive.
11
 */
Matt Tucker's avatar
Matt Tucker committed
12

13
package org.jivesoftware.openfire.update;
14

15 16
import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.util.Log;
17
import org.jivesoftware.openfire.XMPPServer;
18 19

/**
20
 * Service that allow for aysynchrous calling of system managers.
21
 *
22
 * @author Derek DeMoro
23 24 25
 */
public class PluginDownloadManager {

26 27 28 29 30 31
    /**
     * Starts the download process of a given plugin with it's URL.
     *
     * @param url the url of the plugin to download.
     * @return the Update.
     */
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
    public Update downloadPlugin(String url) {
        UpdateManager updateManager = XMPPServer.getInstance().getUpdateManager();
        updateManager.downloadPlugin(url);

        Update returnUpdate = null;
        for (Update update : updateManager.getPluginUpdates()) {
            if (update.getURL().equals(url)) {
                returnUpdate = update;
                break;
            }
        }

        return returnUpdate;
    }

47
    /**
48
     * Installs a new plugin into Openfire.
49
     *
Matt Tucker's avatar
Matt Tucker committed
50
     * @param url the url of the plugin to install.
51 52 53
     * @param hashCode the matching hashcode of the <code>AvailablePlugin</code>.
     * @return the hashCode.
     */
54
    public DownloadStatus installPlugin(String url, int hashCode) {
55 56
        UpdateManager updateManager = XMPPServer.getInstance().getUpdateManager();

57 58 59 60 61 62
        boolean worked = updateManager.downloadPlugin(url);

        final DownloadStatus status = new DownloadStatus();
        status.setHashCode(hashCode);
        status.setSuccessfull(worked);
        status.setUrl(url);
63

64
        return status;
65
    }
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91

    /**
     * Updates the PluginList from the server. Please note, this method is used with javascript calls and will not
     * be found with a find usages.
     *
     * @return true if the plugin list was updated.
     */
    public boolean updatePluginsList() {
        UpdateManager updateManager = XMPPServer.getInstance().getUpdateManager();
        try {
            // Todo: Unify update checking into one xml file. Have the update check set the last check property.
            updateManager.checkForServerUpdate(true);
            updateManager.checkForPluginsUpdates(true);

            // Keep track of the last time we checked for updates
            JiveGlobals.setProperty("update.lastCheck",
                    String.valueOf(System.currentTimeMillis()));

            return true;
        }
        catch (Exception e) {
            Log.error(e);
        }

        return false;
    }
Matt Tucker's avatar
Matt Tucker committed
92
}