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

📄 adminconsole.java

📁 基于Jabber协议的即时消息服务器
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/** * $RCSfile$ * $Revision: 5883 $ * $Date: 2006-10-27 13:38:01 -0700 (Fri, 27 Oct 2006) $ * * Copyright (C) 2004 Jive Software. All rights reserved. * * This software is published under the terms of the GNU Public License (GPL), * a copy of which is included in this distribution. */package org.jivesoftware.admin;import org.jivesoftware.util.*;import org.jivesoftware.wildfire.XMPPServer;import org.jivesoftware.wildfire.container.PluginManager;import org.dom4j.Document;import org.dom4j.Element;import org.dom4j.DocumentFactory;import org.dom4j.io.SAXReader;import java.util.*;import java.io.InputStream;import java.net.URL;/** * A model for admin tab and sidebar info. This class loads in XML definitions of the * data and produces an in-memory model.<p> * * This class loads its data from the <tt>admin-sidebar.xml</tt> file which is assumed * to be in the main application jar file. In addition, it will load files from * <tt>META-INF/admin-sidebar.xml</tt> if they're found. This allows developers to * extend the functionality of the admin console to provide more options. See the main * <tt>admin-sidebar.xml</tt> file for documentation of its format. */public class AdminConsole {    private static Element coreModel;    private static Map<String,Element> overrideModels;    private static Element generatedModel;    static {        overrideModels = new LinkedHashMap<String,Element>();        load();        // The admin console model has special logic to include an informational        // Enterprise tab when the Enterprise plugin is not installed. A property        // controls whether to show that tab. Listen for the property value changing        // and rebuild the model when that happens.        PropertyEventDispatcher.addListener(new PropertyEventListener() {            public void propertySet(String property, Map params) {                if ("enterpriseInfoEnabled".equals(property)) {                    rebuildModel();                }            }            public void propertyDeleted(String property, Map params) {                if ("enterpriseInfoEnabled".equals(property)) {                    rebuildModel();                }            }            public void xmlPropertySet(String property, Map params) {                // Do nothing            }            public void xmlPropertyDeleted(String property, Map params) {                // Do nothing                }        });    }    /** Not instantiatable */    private AdminConsole() {    }    /**     * Adds XML stream to the tabs/sidebar model.     *     * @param name the name.     * @param in the XML input stream.     * @throws Exception if an error occurs when parsing the XML or adding it to the model.     */    public static void addModel(String name, InputStream in) throws Exception {        SAXReader saxReader = new SAXReader();        Document doc = saxReader.read(in);        addModel(name, (Element)doc.selectSingleNode("/adminconsole"));    }    /**     * Adds an &lt;adminconsole&gt; Element to the tabs/sidebar model.     *     * @param name the name.     * @param element the Element     * @throws Exception if an error occurs.     */    public static void addModel(String name, Element element) throws Exception {        overrideModels.put(name, element);        rebuildModel();    }    /**     * Removes an &lt;adminconsole&gt; Element from the tabs/sidebar model.     *     * @param name the name.     */    public static void removeModel(String name) {        overrideModels.remove(name);        rebuildModel();    }    /**     * Returns the name of the application.     *     * @return the name of the application.     */    public static synchronized String getAppName() {        Element appName = (Element)generatedModel.selectSingleNode("//adminconsole/global/appname");        if (appName != null) {            String pluginName = appName.attributeValue("plugin");            return getAdminText(appName.getText(), pluginName);        }        else {            return null;        }    }    /**     * Returns the URL of the main logo image for the admin console.     *     * @return the logo image.     */    public static synchronized String getLogoImage() {        Element globalLogoImage = (Element)generatedModel.selectSingleNode(                "//adminconsole/global/logo-image");        if (globalLogoImage != null) {            String pluginName = globalLogoImage.attributeValue("plugin");            return getAdminText(globalLogoImage.getText(), pluginName);        }        else {            return null;        }    }    /**     * Returns the URL of the login image for the admin console.     *     * @return the login image.     */    public static synchronized String getLoginLogoImage() {        Element globalLoginLogoImage = (Element)generatedModel.selectSingleNode(                "//adminconsole/global/login-image");        if (globalLoginLogoImage != null) {            String pluginName = globalLoginLogoImage.attributeValue("plugin");            return getAdminText(globalLoginLogoImage.getText(), pluginName);        }        else {            return null;        }    }    /**     * Returns the version string displayed in the admin console.     *     * @return the version string.     */    public static synchronized String getVersionString() {        Element globalVersion = (Element)generatedModel.selectSingleNode(                "//adminconsole/global/version");        if (globalVersion != null) {            String pluginName = globalVersion.attributeValue("plugin");            return getAdminText(globalVersion.getText(), pluginName);        }        else {            // Default to the Wildfire version if none has been provided via XML.            XMPPServer xmppServer = XMPPServer.getInstance();            return xmppServer.getServerInfo().getVersion().getVersionString();        }    }    /**     * Returns the model. The model should be considered read-only.     *     * @return the model.     */    public static synchronized Element getModel() {        return generatedModel;    }    /**     * Convenience method to select an element from the model by its ID. If an     * element with a matching ID is not found, <tt>null</tt> will be returned.     *     * @param id the ID.     * @return the element.     */    public static synchronized Element getElemnetByID(String id) {        return (Element)generatedModel.selectSingleNode("//*[@id='" + id + "']");    }    /**     * Returns a text element for the admin console, applying the appropriate locale.     * Internationalization logic will only be applied if the String is specially encoded     * in the format "${key.name}". If it is, the String is pulled from the resource bundle.     * If the pluginName is not <tt>null</tt>, the plugin's resource bundle will be used     * to look up the key.     *     * @param string the String.     * @param pluginName the name of the plugin that the i18n String can be found in,     *      or <tt>null</tt> if the standard Wildfire resource bundle should be used.     * @return the string, or if the string is encoded as an i18n key, the value from     *      the appropriate resource bundle.     */    public static String getAdminText(String string, String pluginName) {        if (string == null) {            return null;        }        // Look for the key symbol:        if (string.indexOf("${") == 0 && string.indexOf("}") == string.length()-1) {            return LocaleUtils.getLocalizedString(string.substring(2, string.length()-1), pluginName);        }        return string;    }    private static void load() {        // Load the core model as the admin-sidebar.xml file from the classpath.        InputStream in = ClassUtils.getResourceAsStream("/admin-sidebar.xml");        if (in == null) {            Log.error("Failed to load admin-sidebar.xml file from Wildfire classes - admin "                    + "console will not work correctly.");            return;        }        try {            SAXReader saxReader = new SAXReader();            Document doc = saxReader.read(in);            coreModel = (Element)doc.selectSingleNode("/adminconsole");        }        catch (Exception e) {            Log.error("Failure when parsing main admin-sidebar.xml file", e);        }        try {            in.close();

⌨️ 快捷键说明

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