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

📄 jiveglobals.java

📁 基于Jabber协议的即时消息服务器
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
     * &lt;foo&gt;     *     &lt;bar&gt;     *         &lt;prop&gt;some value&lt;/prop&gt;     *     &lt;/bar&gt;     * &lt;/foo&gt;     * </pre>     *     * @param name the name of the property being set.     * @param value the value of the property being set.     */    public static void setXMLProperty(String name, String value) {        if (xmlProperties == null) {            loadSetupProperties();        }        // jiveHome not loaded?        if (xmlProperties != null) {            xmlProperties.setProperty(name, value);        }    }    /**     * Sets multiple local properties at once. If a property doesn't already exists, a new     * one will be created. Local properties are stored in the file defined in     * <tt>JIVE_CONFIG_FILENAME</tt> that exists in the <tt>home</tt> directory.     * Properties are always specified as "foo.bar.prop", which would map to     * the following entry in the XML file:     * <pre>     * &lt;foo&gt;     *     &lt;bar&gt;     *         &lt;prop&gt;some value&lt;/prop&gt;     *     &lt;/bar&gt;     * &lt;/foo&gt;     * </pre>     *     * @param propertyMap a map of properties, keyed on property name.     */    public static void setXMLProperties(Map<String, String> propertyMap) {        if (xmlProperties == null) {            loadSetupProperties();        }        if (xmlProperties != null) {            xmlProperties.setProperties(propertyMap);        }    }    /**     * Return all immediate children property values of a parent local property as a list of strings,     * or an empty list if there are no children. For example, given     * the properties <tt>X.Y.A</tt>, <tt>X.Y.B</tt>, <tt>X.Y.C</tt> and <tt>X.Y.C.D</tt>, then     * the immediate child properties of <tt>X.Y</tt> are <tt>A</tt>, <tt>B</tt>, and     * <tt>C</tt> (the value of <tt>C.D</tt> would not be returned using this method).<p>     *     * Local properties are stored in the file defined in <tt>JIVE_CONFIG_FILENAME</tt> that exists     * in the <tt>home</tt> directory. Properties are always specified as "foo.bar.prop",     * which would map to the following entry in the XML file:     * <pre>     * &lt;foo&gt;     *     &lt;bar&gt;     *         &lt;prop&gt;some value&lt;/prop&gt;     *     &lt;/bar&gt;     * &lt;/foo&gt;     * </pre>     *     *     * @param parent the name of the parent property to return the children for.     * @return all child property values for the given parent.     */    public static List getXMLProperties(String parent) {        if (xmlProperties == null) {            loadSetupProperties();        }        // jiveHome not loaded?        if (xmlProperties == null) {            return Collections.EMPTY_LIST;        }        String[] propNames = xmlProperties.getChildrenProperties(parent);        List<String> values = new ArrayList<String>();        for (String propName : propNames) {            String value = getXMLProperty(parent + "." + propName);            if (value != null) {                values.add(value);            }        }        return values;    }    /**     * Deletes a locale property. If the property doesn't exist, the method     * does nothing.     *     * @param name the name of the property to delete.     */    public static void deleteXMLProperty(String name) {        if (xmlProperties == null) {            loadSetupProperties();        }        xmlProperties.deleteProperty(name);    }    /**     * Returns a Jive property.     *     * @param name the name of the property to return.     * @return the property value specified by name.     */    public static String getProperty(String name) {        if (properties == null) {            if (isSetupMode()) {                return null;            }            properties = JiveProperties.getInstance();        }        return properties.get(name);    }    /**     * Returns a Jive property. If the specified property doesn't exist, the     * <tt>defaultValue</tt> will be returned.     *     * @param name the name of the property to return.     * @param defaultValue value returned if the property doesn't exist.     * @return the property value specified by name.     */    public static String getProperty(String name, String defaultValue) {        if (properties == null) {            if (isSetupMode()) {                return defaultValue;            }            properties = JiveProperties.getInstance();        }        String value = properties.get(name);        if (value != null) {            return value;        }        else {            return defaultValue;        }    }    /**     * Returns an integer value Jive property. If the specified property doesn't exist, the     * <tt>defaultValue</tt> will be returned.     *     * @param name the name of the property to return.     * @param defaultValue value returned if the property doesn't exist or was not     *      a number.     * @return the property value specified by name or <tt>defaultValue</tt>.     */    public static int getIntProperty(String name, int defaultValue) {        String value = getProperty(name);        if (value != null) {            try {                return Integer.parseInt(value);            }            catch (NumberFormatException nfe) {                // Ignore.            }        }        return defaultValue;    }    /**     * Returns a long value Jive property. If the specified property doesn't exist, the     * <tt>defaultValue</tt> will be returned.     *     * @param name the name of the property to return.     * @param defaultValue value returned if the property doesn't exist or was not     *      a number.     * @return the property value specified by name or <tt>defaultValue</tt>.     */    public static long getLongProperty(String name, long defaultValue) {        String value = getProperty(name);        if (value != null) {            try {                return Long.parseLong(value);            }            catch (NumberFormatException nfe) {                // Ignore.            }        }        return defaultValue;    }    /**     * Returns a boolean value Jive property.     *     * @param name the name of the property to return.     * @return true if the property value exists and is set to <tt>"true"</tt> (ignoring case).     *      Otherwise <tt>false</tt> is returned.     */    public static boolean getBooleanProperty(String name) {        return Boolean.valueOf(getProperty(name));    }    /**     * Returns a boolean value Jive property. If the property doesn't exist, the <tt>defaultValue</tt>     * will be returned.     *     * If the specified property can't be found, or if the value is not a number, the     * <tt>defaultValue</tt> will be returned.     *     * @param name the name of the property to return.     * @param defaultValue value returned if the property doesn't exist.     * @return true if the property value exists and is set to <tt>"true"</tt> (ignoring case).     *      Otherwise <tt>false</tt> is returned.     */    public static boolean getBooleanProperty(String name, boolean defaultValue) {        String value = getProperty(name);        if (value != null) {            return Boolean.valueOf(value);        }        else {            return defaultValue;        }    }    /**     * Return all immediate children property names of a parent Jive property as a list of strings,     * or an empty list if there are no children. For example, given     * the properties <tt>X.Y.A</tt>, <tt>X.Y.B</tt>, <tt>X.Y.C</tt> and <tt>X.Y.C.D</tt>, then     * the immediate child properties of <tt>X.Y</tt> are <tt>A</tt>, <tt>B</tt>, and     * <tt>C</tt> (<tt>C.D</tt> would not be returned using this method).<p>     *     * @return a List of all immediate children property names (Strings).     */    public static List<String> getPropertyNames(String parent) {        if (properties == null) {            if (isSetupMode()) {                return new ArrayList<String>();            }            properties = JiveProperties.getInstance();        }        return new ArrayList<String>(properties.getChildrenNames(parent));    }    /**     * Return all immediate children property values of a parent Jive property as a list of strings,     * or an empty list if there are no children. For example, given     * the properties <tt>X.Y.A</tt>, <tt>X.Y.B</tt>, <tt>X.Y.C</tt> and <tt>X.Y.C.D</tt>, then     * the immediate child properties of <tt>X.Y</tt> are <tt>X.Y.A</tt>, <tt>X.Y.B</tt>, and     * <tt>X.Y.C</tt> (the value of <tt>X.Y.C.D</tt> would not be returned using this method).<p>     *     * @param parent the name of the parent property to return the children for.     * @return all child property values for the given parent.     */    public static List<String> getProperties(String parent) {        if (properties == null) {            if (isSetupMode()) {                return new ArrayList<String>();            }            properties = JiveProperties.getInstance();        }        Collection<String> propertyNames = properties.getChildrenNames(parent);        List<String> values = new ArrayList<String>();        for (String propertyName : propertyNames) {            String value = getProperty(propertyName);            if (value != null) {                values.add(value);            }        }        return values;    }    /**     * Returns all Jive property names.     *     * @return a List of all property names (Strings).     */    public static List<String> getPropertyNames() {        if (properties == null) {            if (isSetupMode()) {                return new ArrayList<String>();            }            properties = JiveProperties.getInstance();        }        return new ArrayList<String>(properties.getPropertyNames());    }    /**     * Sets a Jive property. If the property doesn't already exists, a new     * one will be created.     *     * @param name the name of the property being set.     * @param value the value of the property being set.     */    public static void setProperty(String name, String value) {        if (properties == null) {            if (isSetupMode()) {                return;            }            properties = JiveProperties.getInstance();        }        properties.put(name, value);    }   /**     * Sets multiple Jive properties at once. If a property doesn't already exists, a new     * one will be created.     *     * @param propertyMap a map of properties, keyed on property name.     */    public static void setProperties(Map<String, String> propertyMap) {        if (properties == null) {            if (isSetupMode()) {                return;            }            properties = JiveProperties.getInstance();        }        properties.putAll(propertyMap);    }    /**     * Deletes a Jive property. If the property doesn't exist, the method     * does nothing. All children of the property will be deleted as well.     *     * @param name the name of the property to delete.     */    public static void deleteProperty(String name) {        if (properties == null) {            if (isSetupMode()) {                return;            }            properties = JiveProperties.getInstance();        }        properties.remove(name);    }   /**    * Allows the name of the local config file name to be changed. The    * default is "wildfire.xml".    *    * @param configName the name of the config file.    */    public static void setConfigName(String configName) {        JIVE_CONFIG_FILENAME = configName;    }    /**     * Returns the name of the local config file name.     *     * @return the name of the config file.     */    static String getConfigName() {        return JIVE_CONFIG_FILENAME;    }    /**     * Returns true if in setup mode.     *     * @return true if in setup mode.     */    private static boolean isSetupMode() {        return !Boolean.valueOf(JiveGlobals.getXMLProperty("setup"));    }    /**     * Loads properties if necessary. Property loading must be done lazily so     * that we give outside classes a chance to set <tt>home</tt>.     */    private synchronized static void loadSetupProperties() {        if (xmlProperties == null) {            // If home is null then log that the application will not work correctly            if (home == null && !failedLoading) {                failedLoading = true;                StringBuilder msg = new StringBuilder();                msg.append("Critical Error! The home directory has not been configured, \n");                msg.append("which will prevent the application from working correctly.\n\n");                System.err.println(msg.toString());            }            // Create a manager with the full path to the xml config file.            else {                try {                    xmlProperties = new XMLProperties(home + File.separator + getConfigName());                }                catch (IOException ioe) {                    Log.error(ioe);                    failedLoading = true;                }            }        }    }}

⌨️ 快捷键说明

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