PluginDownloadManager.java 3.24 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 9 10 11 12 13 14 15 16 17 18
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
19
 */
Matt Tucker's avatar
Matt Tucker committed
20

21
package org.jivesoftware.openfire.update;
22

23
import org.jivesoftware.openfire.XMPPServer;
24 25 26
import org.jivesoftware.util.JiveGlobals;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
27 28

/**
29
 * Service that allow for aysynchrous calling of system managers.
30
 *
31
 * @author Derek DeMoro
32 33 34
 */
public class PluginDownloadManager {

35 36
	private static final Logger Log = LoggerFactory.getLogger(PluginDownloadManager.class);

37 38 39 40 41 42
    /**
     * Starts the download process of a given plugin with it's URL.
     *
     * @param url the url of the plugin to download.
     * @return the Update.
     */
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
    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;
    }

58
    /**
59
     * Installs a new plugin into Openfire.
60
     *
Matt Tucker's avatar
Matt Tucker committed
61
     * @param url the url of the plugin to install.
62 63 64
     * @param hashCode the matching hashcode of the <code>AvailablePlugin</code>.
     * @return the hashCode.
     */
65
    public DownloadStatus installPlugin(String url, int hashCode) {
66 67
        UpdateManager updateManager = XMPPServer.getInstance().getUpdateManager();

68 69 70 71 72 73
        boolean worked = updateManager.downloadPlugin(url);

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

75
        return status;
76
    }
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97

    /**
     * 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) {
98
            Log.error(e.getMessage(), e);
99 100 101 102
        }

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