⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 updatemanager.java

📁 openfire 服务器源码下载
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
        // Check if we need to send notifications to admins        if (notificationsEnabled && isNotificationEnabled() && !pluginUpdates.isEmpty()) {            Collection<JID> admins = XMPPServer.getInstance().getAdmins();            for (Update update : pluginUpdates) {                Message notification = new Message();                notification.setFrom(serverName);                notification.setBody(getNotificationMessage() + " " + update.getComponentName() +                        " " + update.getLatestVersion());                for (JID jid : admins) {                    notification.setTo(jid);                    router.route(notification);                }            }        }        // Save information of available plugins        saveAvailablePluginsInfo();    }    /**     * Recreate the list of plugins that need to be updated based on the list of     * available plugins at igniterealtime.org.     */    private void buildPluginsUpdateList() {        // Reset list of plugins that need to be updated        pluginUpdates = new ArrayList<Update>();        XMPPServer server = XMPPServer.getInstance();        // Compare local plugins versions with latest ones        for (Plugin plugin : server.getPluginManager().getPlugins()) {            String pluginName = server.getPluginManager().getName(plugin);            AvailablePlugin latestPlugin = availablePlugins.get(pluginName);            String currentVersion = server.getPluginManager().getVersion(plugin);            if (latestPlugin != null &&                    latestPlugin.getLatestVersion().compareTo(currentVersion) > 0) {                // Check if the update can run in the current version of the server                String serverVersion =                        XMPPServer.getInstance().getServerInfo().getVersion().getVersionString();                if (serverVersion.compareTo(latestPlugin.getMinServerVersion()) >= 0) {                    Update update = new Update(pluginName, latestPlugin.getLatestVersion(),                            latestPlugin.getChangelog(), latestPlugin.getURL());                    pluginUpdates.add(update);                }            }        }    }    /**     * Saves to conf/server-update.xml information about the latest Openfire release that is     * available for download.     */    private void saveLatestServerInfo() {        Element xmlResponse = docFactory.createDocument().addElement("version");        if (serverUpdate != null) {            Element component = xmlResponse.addElement("openfire");            component.addAttribute("latest", serverUpdate.getLatestVersion());            component.addAttribute("changelog", serverUpdate.getChangelog());            component.addAttribute("url", serverUpdate.getURL());        }        // Write data out to conf/server-update.xml file.        Writer writer = null;        try {            // Create the conf folder if required            File file = new File(JiveGlobals.getHomeDirectory(), "conf");            if (!file.exists()) {                file.mkdir();            }            file = new File(JiveGlobals.getHomeDirectory() + File.separator + "conf",                    "server-update.xml");            // Delete the old server-update.xml file if it exists            if (file.exists()) {                file.delete();            }            // Create new version.xml with returned data            writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), "UTF-8"));            OutputFormat prettyPrinter = OutputFormat.createPrettyPrint();            XMLWriter xmlWriter = new XMLWriter(writer, prettyPrinter);            xmlWriter.write(xmlResponse);        }        catch (Exception e) {            Log.error(e);        }        finally {            if (writer != null) {                try {                    writer.close();                }                catch (IOException e1) {                    Log.error(e1);                }            }        }    }    /**     * Saves to conf/available-plugins.xml the list of plugins that are available     * at igniterealtime.org.     */    private void saveAvailablePluginsInfo() {        //  XML to store in the file        Element xml = docFactory.createDocument().addElement("available");        for (AvailablePlugin plugin : availablePlugins.values()) {            Element component = xml.addElement("plugin");            component.addAttribute("name", plugin.getName());            component.addAttribute("latest", plugin.getLatestVersion());            component.addAttribute("changelog", plugin.getChangelog());            component.addAttribute("url", plugin.getURL());            component.addAttribute("author", plugin.getAuthor());            component.addAttribute("description", plugin.getDescription());            component.addAttribute("icon", plugin.getIcon());            component.addAttribute("minServerVersion", plugin.getMinServerVersion());            component.addAttribute("readme", plugin.getReadme());            component.addAttribute("licenseType", plugin.getLicenseType());            component.addAttribute("fileSize", Long.toString(plugin.getFileSize()));        }        // Write data out to conf/available-plugins.xml file.        Writer writer = null;        try {            // Create the conf folder if required            File file = new File(JiveGlobals.getHomeDirectory(), "conf");            if (!file.exists()) {                file.mkdir();            }            file = new File(JiveGlobals.getHomeDirectory() + File.separator + "conf",                    "available-plugins.xml");            // Delete the old version.xml file if it exists            if (file.exists()) {                file.delete();            }            // Create new version.xml with returned data            writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), "UTF-8"));            OutputFormat prettyPrinter = OutputFormat.createPrettyPrint();            XMLWriter xmlWriter = new XMLWriter(writer, prettyPrinter);            xmlWriter.write(xml);        }        catch (Exception e) {            Log.error(e);        }        finally {            if (writer != null) {                try {                    writer.close();                }                catch (IOException e1) {                    Log.error(e1);                }            }        }    }    /**     * Loads list of available plugins and latest available server version from     * conf/available-plugins.xml and conf/server-update.xml respectively.     */    private void loadSavedInfo() {        // Load server update information        loadLatestServerInfo();        // Load available plugins information        loadAvailablePluginsInfo();        // Recreate list of plugins to update        buildPluginsUpdateList();    }    private void loadLatestServerInfo() {        Document xmlResponse;        File file = new File(JiveGlobals.getHomeDirectory() + File.separator + "conf",                "server-update.xml");        if (!file.exists()) {            return;        }        // Check read privs.        if (!file.canRead()) {            Log.warn("Cannot retrieve server updates. File must be readable: " + file.getName());            return;        }        FileReader reader = null;        try {            reader = new FileReader(file);            SAXReader xmlReader = new SAXReader();            xmlReader.setEncoding("UTF-8");            xmlResponse = xmlReader.read(reader);        }        catch (Exception e) {            Log.error("Error reading server-update.xml", e);            return;        }        finally {            if (reader != null) {                try {                    reader.close();                }                catch (Exception e) {                    // Do nothing                }            }        }        // Parse info and recreate update information (if still required)        Element openfire = xmlResponse.getRootElement().element("openfire");        if (openfire != null) {            String latestVersion = openfire.attributeValue("latest");            String changelog = openfire.attributeValue("changelog");            String url = openfire.attributeValue("url");            // Check if current server version is correct            String serverVersion =                    XMPPServer.getInstance().getServerInfo().getVersion().getVersionString();            if (serverVersion.compareTo(latestVersion) < 0) {                serverUpdate = new Update("Openfire", latestVersion, changelog, url);            }        }    }    private void loadAvailablePluginsInfo() {        Document xmlResponse;        File file = new File(JiveGlobals.getHomeDirectory() + File.separator + "conf",                "available-plugins.xml");        if (!file.exists()) {            return;        }        // Check read privs.        if (!file.canRead()) {            Log.warn("Cannot retrieve available plugins. File must be readable: " + file.getName());            return;        }        FileReader reader = null;        try {            reader = new FileReader(file);            SAXReader xmlReader = new SAXReader();            xmlReader.setEncoding("UTF-8");            xmlResponse = xmlReader.read(reader);        }        catch (Exception e) {            Log.error("Error reading available-plugins.xml", e);            return;        }        finally {            if (reader != null) {                try {                    reader.close();                }                catch (Exception e) {                    // Do nothing                }            }        }        // Parse info and recreate available plugins        Iterator it = xmlResponse.getRootElement().elementIterator("plugin");        while (it.hasNext()) {            Element plugin = (Element) it.next();            String pluginName = plugin.attributeValue("name");            String latestVersion = plugin.attributeValue("latest");            String icon = plugin.attributeValue("icon");            String readme = plugin.attributeValue("readme");            String changelog = plugin.attributeValue("changelog");            String url = plugin.attributeValue("url");            String licenseType = plugin.attributeValue("licenseType");            String description = plugin.attributeValue("description");            String author = plugin.attributeValue("author");            String minServerVersion = plugin.attributeValue("minServerVersion");            String fileSize = plugin.attributeValue("fileSize");            AvailablePlugin available = new AvailablePlugin(pluginName, description, latestVersion,                    author, icon, changelog, readme, licenseType, minServerVersion, url, fileSize);            // Add plugin to the list of available plugins at js.org            availablePlugins.put(pluginName, available);        }    }    /**     * Returns a previously fetched list of updates.     *     * @return a previously fetched list of updates.     */    public Collection<Update> getPluginUpdates() {        return pluginUpdates;    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -