📄 updatemanager.java
字号:
String pluginFilename = url.substring(url.lastIndexOf("/") + 1); return XMPPServer.getInstance().getPluginManager().isPluginDownloaded(pluginFilename); } /** * Returns the list of available plugins to install as reported by jivesoftware.org. * Currently installed plugins will not be included. * * @return the list of available plugins to install as reported by jivesoftware.org. */ public List<AvailablePlugin> getNotInstalledPlugins() { ArrayList<AvailablePlugin> plugins = new ArrayList<AvailablePlugin>(availablePlugins.values()); XMPPServer server = XMPPServer.getInstance(); // Remove installed plugins from the list of available plugins for (Plugin plugin : server.getPluginManager().getPlugins()) { String pluginName = server.getPluginManager().getName(plugin); for (Iterator<AvailablePlugin> it = plugins.iterator(); it.hasNext();) { AvailablePlugin availablePlugin = it.next(); if (availablePlugin.getName().equals(pluginName)) { it.remove(); break; } } } return plugins; } /** * Returns the message to send to admins when new updates are available. When sending * this message information about the new updates avaiable will be appended. * * @return the message to send to admins when new updates are available. */ public String getNotificationMessage() { return LocaleUtils.getLocalizedString("update.notification-message"); } /** * Returns true if the check for updates service is enabled. * * @return true if the check for updates service is enabled. */ public boolean isServiceEnabled() { return JiveGlobals.getBooleanProperty("update.service-enabled", true); } /** * Sets if the check for updates service is enabled. * * @param enabled true if the check for updates service is enabled. */ public void setServiceEnabled(boolean enabled) { JiveGlobals.setProperty("update.service-enabled", enabled ? "true" : "false"); if (enabled && thread == null) { startService(); } } /** * Returns true if admins should be notified by IM when new updates are available. * * @return true if admins should be notified by IM when new updates are available. */ public boolean isNotificationEnabled() { return JiveGlobals.getBooleanProperty("update.notify-admins", true); } /** * Sets if admins should be notified by IM when new updates are available. * * @param enabled true if admins should be notified by IM when new updates are available. */ public void setNotificationEnabled(boolean enabled) { JiveGlobals.setProperty("update.notify-admins", enabled ? "true" : "false"); } /** * Returns the frequency to check for updates. By default, this will happen every 48 hours. * The frequency returned will never be less than 12 hours. * * @return the frequency to check for updates in hours. */ public int getCheckFrequency() { int frequency = JiveGlobals.getIntProperty("update.frequency", 48); if (frequency < 12) { return 12; } else { return frequency; } } /** * Sets the frequency to check for updates. By default, this will happen every 48 hours. * * @param checkFrequency the frequency to check for updates. */ public void setCheckFrequency(int checkFrequency) { JiveGlobals.setProperty("update.frequency", Integer.toString(checkFrequency)); } /** * Returns true if a proxy is being used to connect to jivesoftware.org or false if * a direct connection should be attempted. * * @return true if a proxy is being used to connect to jivesoftware.org. */ public boolean isUsingProxy() { return getProxyHost() != null; } /** * Returns the host of the proxy to use to connect to jivesoftware.org or <tt>null</tt> * if no proxy is used. * * @return the host of the proxy or null if no proxy is used. */ public String getProxyHost() { return JiveGlobals.getProperty("update.proxy.host"); } /** * Sets the host of the proxy to use to connect to jivesoftware.org or <tt>null</tt> * if no proxy is used. * * @param host the host of the proxy or null if no proxy is used. */ public void setProxyHost(String host) { if (host == null) { // Remove the property JiveGlobals.deleteProperty("update.proxy.host"); } else { // Create or update the property JiveGlobals.setProperty("update.proxy.host", host); } } /** * Returns the port of the proxy to use to connect to jivesoftware.org or -1 if no * proxy is being used. * * @return the port of the proxy to use to connect to jivesoftware.org or -1 if no * proxy is being used. */ public int getProxyPort() { return JiveGlobals.getIntProperty("update.proxy.port", -1); } /** * Sets the port of the proxy to use to connect to jivesoftware.org or -1 if no * proxy is being used. * * @param port the port of the proxy to use to connect to jivesoftware.org or -1 if no * proxy is being used. */ public void setProxyPort(int port) { JiveGlobals.setProperty("update.proxy.port", Integer.toString(port)); } /** * Returns the server update or <tt>null</tt> if the server is up to date. * * @return the server update or null if the server is up to date. */ public Update getServerUpdate() { return serverUpdate; } /** * Returns the plugin update or <tt>null</tt> if the plugin is up to date. * * @param pluginName the name of the plugin (as described in the meta-data). * @param currentVersion current version of the plugin that is installed. * @return the plugin update or null if the plugin is up to date. */ public Update getPluginUpdate(String pluginName, String currentVersion) { for (Update update : pluginUpdates) { // Check if this is the requested plugin if (update.getComponentName().equals(pluginName)) { // Check if the plugin version is right if (update.getLatestVersion().compareTo(currentVersion) > 0) { return update; } } } return null; } private String getServerUpdateRequest() { XMPPServer server = XMPPServer.getInstance(); Element xmlRequest = docFactory.createDocument().addElement("version"); // Add current wildfire version Element wildfire = xmlRequest.addElement("wildfire"); wildfire.addAttribute("current", server.getServerInfo().getVersion().getVersionString()); return xmlRequest.asXML(); } private String getAvailablePluginsUpdateRequest() { Element xmlRequest = docFactory.createDocument().addElement("available"); // Add locale so we can get current name and description of plugins Element locale = xmlRequest.addElement("locale"); locale.addText(JiveGlobals.getLocale().toString()); return xmlRequest.asXML(); } private void processServerUpdateResponse(String response, boolean notificationsEnabled) throws DocumentException { // Reset last known update information serverUpdate = null; SAXReader xmlReader = new SAXReader(); xmlReader.setEncoding("UTF-8"); Element xmlResponse = xmlReader.read(new StringReader(response)).getRootElement(); // Parse response and keep info as Update objects Element wildfire = xmlResponse.element("wildfire"); if (wildfire != null) { // A new version of wildfire was found String latestVersion = wildfire.attributeValue("latest"); String changelog = wildfire.attributeValue("changelog"); String url = wildfire.attributeValue("url"); // Keep information about the available server update serverUpdate = new Update("Wildfire", latestVersion, changelog, url); } // Check if we need to send notifications to admins if (notificationsEnabled && isNotificationEnabled() && serverUpdate != null) { Collection<JID> admins = XMPPServer.getInstance().getAdmins(); Message notification = new Message(); notification.setFrom(serverName); notification.setBody(getNotificationMessage() + " " + serverUpdate.getComponentName() + " " + serverUpdate.getLatestVersion()); for (JID jid : admins) { notification.setTo(jid); router.route(notification); } } // Save response in a file for later retrieval saveLatestServerInfo(); } private void processAvailablePluginsResponse(String response, boolean notificationsEnabled) throws DocumentException { // Reset last known list of available plugins availablePlugins = new HashMap<String, AvailablePlugin>(); // Parse response and keep info as AvailablePlugin objects SAXReader xmlReader = new SAXReader(); xmlReader.setEncoding("UTF-8"); Element xmlResponse = xmlReader.read(new StringReader(response)).getRootElement(); Iterator plugins = xmlResponse.elementIterator("plugin"); while (plugins.hasNext()) { Element plugin = (Element) plugins.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); } // Figure out local plugins that need to be updated buildPluginsUpdateList();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -