JiveGlobals.java 25.6 KB
Newer Older
Matt Tucker's avatar
Matt Tucker committed
1 2 3 4 5
/**
 * $RCSfile$
 * $Revision$
 * $Date$
 *
Matt Tucker's avatar
Matt Tucker committed
6
 * Copyright (C) 2004 Jive Software. All rights reserved.
Matt Tucker's avatar
Matt Tucker committed
7
 *
Matt Tucker's avatar
Matt Tucker committed
8 9
 * This software is published under the terms of the GNU Public License (GPL),
 * a copy of which is included in this distribution.
Matt Tucker's avatar
Matt Tucker committed
10 11
 */

12
package org.jivesoftware.util;
Matt Tucker's avatar
Matt Tucker committed
13 14 15 16

import java.io.File;
import java.io.IOException;
import java.text.DateFormat;
17 18
import java.util.*;

Matt Tucker's avatar
Matt Tucker committed
19
/**
Matt Tucker's avatar
Matt Tucker committed
20
 * Controls Jive properties. Jive properties are only meant to be set and retrieved
Gaston Dombiak's avatar
Gaston Dombiak committed
21 22 23 24 25 26 27 28 29 30
 * by core Jive classes. Some properties may be stored in XML format while others in the
 * database.<p>
 *
 * When starting up the application this class needs to be configured so that the initial
 * configuration of the application may be loaded from the configuration file. The configuration
 * file holds properties stored in XML format, database configuration and user authentication
 * configuration. Use {@link #setHomeDirectory(String)} and {@link #setConfigName(String)} for
 * setting the home directory and path to the configuration file.<p>
 *
 * XML property names must be in the form <code>prop.name</code> - parts of the name must
Matt Tucker's avatar
Matt Tucker committed
31 32 33 34
 * be seperated by ".". The value can be any valid String, including strings with line breaks.
 */
public class JiveGlobals {

35
    private static String JIVE_CONFIG_FILENAME = "conf" + File.separator + "wildfire.xml";
36

Matt Tucker's avatar
Matt Tucker committed
37 38 39 40
    /**
     * Location of the jiveHome directory. All configuration files should be
     * located here.
     */
41
    private static String home = null;
Matt Tucker's avatar
Matt Tucker committed
42 43 44

    public static boolean failedLoading = false;

45 46
    private static XMLProperties xmlProperties = null;
    private static JiveProperties properties = null;
Matt Tucker's avatar
Matt Tucker committed
47 48 49 50 51

    private static Locale locale = null;
    private static TimeZone timeZone = null;
    private static DateFormat dateFormat = null;
    private static DateFormat dateTimeFormat = null;
52
    private static DateFormat timeFormat = null;
Matt Tucker's avatar
Matt Tucker committed
53 54 55 56 57 58 59 60 61 62

    /**
     * Returns the global Locale used by Jive. A locale specifies language
     * and country codes, and is used for internationalization. The default
     * locale is system dependant - Locale.getDefault().
     *
     * @return the global locale used by Jive.
     */
    public static Locale getLocale() {
        if (locale == null) {
Matt Tucker's avatar
Matt Tucker committed
63
            if (xmlProperties != null) {
64
                String [] localeArray;
65
                String localeProperty = xmlProperties.getProperty("locale");
66 67 68 69 70 71
                if (localeProperty != null) {
                    localeArray = localeProperty.split("_");
                }
                else {
                    localeArray = new String[] {"", ""};
                }
Matt Tucker's avatar
Matt Tucker committed
72 73

                String language = localeArray[0];
74 75 76
                if (language == null) {
                    language = "";
                }
Matt Tucker's avatar
Matt Tucker committed
77 78 79
                String country = "";
                if (localeArray.length == 2) {
                    country = localeArray[1];
80 81 82 83 84 85 86 87 88 89 90 91
                }
                // If no locale info is specified, return the system default Locale.
                if (language.equals("") && country.equals("")) {
                    locale = Locale.getDefault();
                }
                else {
                    locale = new Locale(language, country);
                }
            }
            else {
                return Locale.getDefault();
            }
Matt Tucker's avatar
Matt Tucker committed
92
        }
93
        return locale;
Matt Tucker's avatar
Matt Tucker committed
94 95 96 97 98 99 100 101 102 103 104 105
    }

    /**
     * Sets the global locale used by Jive. A locale specifies language
     * and country codes, and is used for formatting dates and numbers.
     * The default locale is Locale.US.
     *
     * @param newLocale the global Locale for Jive.
     */
    public static void setLocale(Locale newLocale) {
        locale = newLocale;
        // Save values to Jive properties.
Matt Tucker's avatar
Matt Tucker committed
106 107
        setXMLProperty("locale", locale.toString());

Matt Tucker's avatar
Matt Tucker committed
108
        // Reset the date formatter objects
109 110 111
        timeFormat = null;
        dateFormat = null;
        dateTimeFormat = null;
Matt Tucker's avatar
Matt Tucker committed
112 113 114 115 116 117 118 119 120
    }

    /**
     * Returns the global TimeZone used by Jive. The default is the VM's
     * default time zone.
     *
     * @return the global time zone used by Jive.
     */
    public static TimeZone getTimeZone() {
121 122 123 124 125 126 127 128 129 130 131 132 133
        if (timeZone == null) {
            if (properties != null) {
                String timeZoneID = (String)properties.get("locale.timeZone");
                if (timeZoneID == null) {
                    timeZone = TimeZone.getDefault();
                }
                else {
                    timeZone = TimeZone.getTimeZone(timeZoneID);
                }
            }
            else {
                return TimeZone.getDefault();
            }
Matt Tucker's avatar
Matt Tucker committed
134 135 136 137 138 139 140 141 142 143
        }
        return timeZone;
    }

    /**
     * Sets the global time zone used by Jive. The default time zone is the VM's
     * time zone.
     */
    public static void setTimeZone(TimeZone newTimeZone) {
        timeZone = newTimeZone;
144 145 146 147 148 149 150 151 152
        if (timeFormat != null) {
            timeFormat.setTimeZone(timeZone);
        }
        if (dateFormat != null) {
            dateFormat.setTimeZone(timeZone);
        }
        if (dateTimeFormat != null) {
            dateTimeFormat.setTimeZone(timeZone);
        }
153
        setProperty("locale.timeZone", timeZone.getID());
Matt Tucker's avatar
Matt Tucker committed
154 155
    }

156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
    /**
     * Formats a Date object to return a time using the global locale.
     *
     * @param date the Date to format.
     * @return a String representing the time.
     */
    public static String formatTime(Date date) {
        if (timeFormat == null) {
            if (properties != null) {
                timeFormat = DateFormat.getTimeInstance(DateFormat.SHORT, getLocale());
                timeFormat.setTimeZone(getTimeZone());
            }
            else {
                DateFormat instance = DateFormat.getTimeInstance(DateFormat.SHORT, getLocale());
                instance.setTimeZone(getTimeZone());
                return instance.format(date);
            }
        }
        return timeFormat.format(date);
    }

Matt Tucker's avatar
Matt Tucker committed
177 178 179 180 181 182 183
    /**
     * Formats a Date object to return a date using the global locale.
     *
     * @param date the Date to format.
     * @return a String representing the date.
     */
    public static String formatDate(Date date) {
184 185 186 187 188 189 190 191 192 193
        if (dateFormat == null) {
            if (properties != null) {
                dateFormat = DateFormat.getDateInstance(DateFormat.MEDIUM, getLocale());
                dateFormat.setTimeZone(getTimeZone());
            }
            else {
                DateFormat instance = DateFormat.getDateInstance(DateFormat.MEDIUM, getLocale());
                instance.setTimeZone(getTimeZone());
                return instance.format(date);
            }
Matt Tucker's avatar
Matt Tucker committed
194 195 196 197 198 199 200 201 202 203 204
        }
        return dateFormat.format(date);
    }

    /**
     * Formats a Date object to return a date and time using the global locale.
     *
     * @param date the Date to format.
     * @return a String representing the date and time.
     */
    public static String formatDateTime(Date date) {
205 206 207 208 209 210 211 212 213 214 215 216
        if (dateTimeFormat == null) {
            if (properties != null) {
                dateTimeFormat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM,
                        DateFormat.MEDIUM, getLocale());
                dateTimeFormat.setTimeZone(getTimeZone());
            }
            else {
                DateFormat instance = DateFormat.getDateTimeInstance(DateFormat.MEDIUM,
                        DateFormat.MEDIUM, getLocale());
                instance.setTimeZone(getTimeZone());
                return instance.format(date);
            }
Matt Tucker's avatar
Matt Tucker committed
217 218 219 220 221
        }
        return dateTimeFormat.format(date);
    }

    /**
222
     * Returns the location of the <code>home</code> directory.
Matt Tucker's avatar
Matt Tucker committed
223
     *
224
     * @return the location of the home dir.
Matt Tucker's avatar
Matt Tucker committed
225
     */
226
    public static String getHomeDirectory() {
227
        if (xmlProperties == null) {
228
            loadSetupProperties();
Matt Tucker's avatar
Matt Tucker committed
229
        }
230
        return home;
Matt Tucker's avatar
Matt Tucker committed
231 232
    }

233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255
    /**
     * Sets the location of the <code>home</code> directory. The directory must exist and the
     * user running the application must have read and write permissions over the specified
     * directory.
     *
     * @param pathname the location of the home dir.
     */
    public static void setHomeDirectory(String pathname) {
        File mh = new File(pathname);
        // Do a permission check on the new home directory
        if (!mh.exists()) {
            Log.error("Error - the specified home directory does not exist (" + pathname + ")");
        }
        else if (!mh.canRead() || !mh.canWrite()) {
                Log.error("Error - the user running this application can not read " +
                        "and write to the specified home directory (" + pathname + "). " +
                        "Please grant the executing user read and write permissions.");
        }
        else {
            home = pathname;
        }
    }

Matt Tucker's avatar
Matt Tucker committed
256
    /**
257 258
     * Returns a local property. Local properties are stored in the file defined in
     * <tt>JIVE_CONFIG_FILENAME</tt> that exists in the <tt>home</tt> directory.
Matt Tucker's avatar
Matt Tucker committed
259 260 261 262 263 264 265 266 267 268 269 270 271
     * 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 name the name of the property to return.
     * @return the property value specified by name.
     */
272 273 274
    public static String getXMLProperty(String name) {
        if (xmlProperties == null) {
            loadSetupProperties();
Matt Tucker's avatar
Matt Tucker committed
275 276
        }

277
        // home not loaded?
278
        if (xmlProperties == null) {
Matt Tucker's avatar
Matt Tucker committed
279 280 281
            return null;
        }

282
        return xmlProperties.getProperty(name);
Matt Tucker's avatar
Matt Tucker committed
283 284
    }

Matt Tucker's avatar
Matt Tucker committed
285
    /**
286 287
     * Returns a local property. Local properties are stored in the file defined in
     * <tt>JIVE_CONFIG_FILENAME</tt> that exists in the <tt>home</tt> directory.
Matt Tucker's avatar
Matt Tucker committed
288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308
     * 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>
     *
     * If the specified property can't be found, the <tt>defaultValue</tt> will be returned.
     *
     * @param name the name of the property to return.
     * @param defaultValue the default value for the property.
     * @return the property value specified by name.
     */
    public static String getXMLProperty(String name, String defaultValue) {
        if (xmlProperties == null) {
            loadSetupProperties();
        }

309
        // home not loaded?
Matt Tucker's avatar
Matt Tucker committed
310 311 312 313 314 315 316 317 318 319 320
        if (xmlProperties == null) {
            return null;
        }

        String value = xmlProperties.getProperty(name);
        if (value == null) {
            value = defaultValue;
        }
        return value;
    }

Matt Tucker's avatar
Matt Tucker committed
321
    /**
322 323
     * Returns an integer value local property. Local properties are stored in the file defined in
     * <tt>JIVE_CONFIG_FILENAME</tt> that exists in the <tt>home</tt> directory.
Matt Tucker's avatar
Matt Tucker committed
324 325 326 327 328 329 330 331 332 333
     * 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>
     *
334 335 336 337 338 339 340 341 342
     * 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 could not be loaded or was not
     *      a number.
     * @return the property value specified by name or <tt>defaultValue</tt>.
     */
    public static int getXMLProperty(String name, int defaultValue) {
343
        String value = getXMLProperty(name);
344 345 346 347
        if (value != null) {
            try {
                return Integer.parseInt(value);
            }
348 349 350
            catch (NumberFormatException nfe) {
                // Ignore.
            }
351 352 353 354
        }
        return defaultValue;
    }

355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383
    /**
     * Returns a boolean value local property. 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>
     *
     * If the specified property can't be found, the <tt>defaultValue</tt> will be returned.
     * If the property is found, it will be parsed using {@link Boolean#valueOf(String)}.  
     *
     * @param name the name of the property to return.
     * @param defaultValue value returned if the property could not be loaded or was not
     *      a number.
     * @return the property value specified by name or <tt>defaultValue</tt>.
     */
    public static boolean getXMLProperty(String name, boolean defaultValue) {
        String value = getXMLProperty(name);
        if (value != null) {
            return Boolean.valueOf(value);
        }
        return defaultValue;
    }

384 385
    /**
     * Sets a local property. If the property doesn't already exists, a new
386 387
     * 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.
388 389 390 391 392 393 394 395 396 397 398
     * 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 name the name of the property being set.
Matt Tucker's avatar
Matt Tucker committed
399 400
     * @param value the value of the property being set.
     */
401 402 403
    public static void setXMLProperty(String name, String value) {
        if (xmlProperties == null) {
            loadSetupProperties();
Matt Tucker's avatar
Matt Tucker committed
404 405
        }

406 407 408
        // jiveHome not loaded?
        if (xmlProperties != null) {
            xmlProperties.setProperty(name, value);
Matt Tucker's avatar
Matt Tucker committed
409 410 411 412
        }
    }

    /**
413
     * Sets multiple local properties at once. If a property doesn't already exists, a new
414 415
     * 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.
416 417 418 419 420 421 422 423 424 425 426 427
     * 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.
     */
Matt Tucker's avatar
Matt Tucker committed
428
    public static void setXMLProperties(Map<String, String> propertyMap) {
429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444
        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>
     *
445 446
     * 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",
447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470
     * 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);
Matt Tucker's avatar
Matt Tucker committed
471
        List<String> values = new ArrayList<String>();
472
        for (String propName : propNames) {
473
            String value = getXMLProperty(parent + "." + propName);
474 475 476 477 478 479 480 481 482 483
            if (value != null) {
                values.add(value);
            }
        }

        return values;
    }

    /**
     * Deletes a locale property. If the property doesn't exist, the method
Matt Tucker's avatar
Matt Tucker committed
484 485 486 487
     * does nothing.
     *
     * @param name the name of the property to delete.
     */
488 489 490 491 492 493
    public static void deleteXMLProperty(String name) {
        if (xmlProperties == null) {
            loadSetupProperties();
        }
        xmlProperties.deleteProperty(name);
    }
Matt Tucker's avatar
Matt Tucker committed
494

495 496 497 498 499 500 501 502
    /**
     * 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) {
Matt Tucker's avatar
Matt Tucker committed
503 504 505
            if (isSetupMode()) {
                return null;
            }
506 507 508 509 510 511 512 513 514 515 516 517 518 519 520
            properties = JiveProperties.getInstance();
        }
        return (String)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) {
Matt Tucker's avatar
Matt Tucker committed
521 522 523
            if (isSetupMode()) {
                return defaultValue;
            }
524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549
            properties = JiveProperties.getInstance();
        }
        String value = (String)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);
            }
550 551 552
            catch (NumberFormatException nfe) {
                // Ignore.
            }
553 554 555 556 557 558 559 560 561 562 563 564
        }
        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) {
565
        return Boolean.valueOf(getProperty(name));
566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582
    }

    /**
     * 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) {
Gaston Dombiak's avatar
Gaston Dombiak committed
583
            return Boolean.valueOf(value);
584 585 586 587 588 589 590 591 592 593 594 595 596 597 598
        }
        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).
     */
Matt Tucker's avatar
Matt Tucker committed
599
    public static List<String> getPropertyNames(String parent) {
600
        if (properties == null) {
Matt Tucker's avatar
Matt Tucker committed
601 602 603
            if (isSetupMode()) {
                return new ArrayList<String>();
            }
604 605
            properties = JiveProperties.getInstance();
        }
Matt Tucker's avatar
Matt Tucker committed
606
        return new ArrayList<String>(properties.getChildrenNames(parent));
607 608 609 610 611 612 613 614 615 616 617 618
    }

    /**
     * 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.
     */
619
    public static List<String> getProperties(String parent) {
Matt Tucker's avatar
Matt Tucker committed
620
        if (properties == null) {
Matt Tucker's avatar
Matt Tucker committed
621 622 623
            if (isSetupMode()) {
                return new ArrayList<String>();
            }
624 625 626
            properties = JiveProperties.getInstance();
        }

627 628
        Collection<String> propertyNames = properties.getChildrenNames(parent);
        List<String> values = new ArrayList<String>();
629 630
        for (String propertyName : propertyNames) {
            String value = getProperty(propertyName);
631 632 633
            if (value != null) {
                values.add(value);
            }
Matt Tucker's avatar
Matt Tucker committed
634
        }
635 636 637 638 639 640 641 642 643

        return values;
    }

    /**
     * Returns all Jive property names.
     *
     * @return a List of all property names (Strings).
     */
Matt Tucker's avatar
Matt Tucker committed
644
    public static List<String> getPropertyNames() {
645
        if (properties == null) {
Matt Tucker's avatar
Matt Tucker committed
646 647 648
            if (isSetupMode()) {
                return new ArrayList<String>();
            }
649
            properties = JiveProperties.getInstance();
Matt Tucker's avatar
Matt Tucker committed
650
        }
Matt Tucker's avatar
Matt Tucker committed
651
        return new ArrayList<String>(properties.getPropertyNames());
652 653 654 655 656 657 658 659 660 661 662
    }

    /**
     * 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) {
Matt Tucker's avatar
Matt Tucker committed
663 664 665
            if (isSetupMode()) {
                return;
            }
666 667 668 669 670 671 672 673 674 675 676 677 678
            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 propertyMap) {
        if (properties == null) {
Matt Tucker's avatar
Matt Tucker committed
679 680 681
            if (isSetupMode()) {
                return;
            }
682 683 684 685 686 687 688 689 690 691 692 693 694 695
            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) {
Matt Tucker's avatar
Matt Tucker committed
696 697 698
            if (isSetupMode()) {
                return;
            }
699
            properties = JiveProperties.getInstance();
700 701 702 703 704 705
        }
        properties.remove(name);
    }

   /**
    * Allows the name of the local config file name to be changed. The
706
    * default is "wildfire.xml".
707 708 709 710 711
    *
    * @param configName the name of the config file.
    */
    public static void setConfigName(String configName) {
        JIVE_CONFIG_FILENAME = configName;
Matt Tucker's avatar
Matt Tucker committed
712 713
    }

714 715 716 717 718
    /**
     * Returns the name of the local config file name.
     *
     * @return the name of the config file.
     */
719
    static String getConfigName() {
720
        return JIVE_CONFIG_FILENAME;
721
    }
722

Matt Tucker's avatar
Matt Tucker committed
723 724 725 726 727 728
    /**
     * Returns true if in setup mode.
     *
     * @return true if in setup mode.
     */
    private static boolean isSetupMode() {
729
        return !Boolean.valueOf(JiveGlobals.getXMLProperty("setup"));
Matt Tucker's avatar
Matt Tucker committed
730 731
    }

Matt Tucker's avatar
Matt Tucker committed
732 733
    /**
     * Loads properties if necessary. Property loading must be done lazily so
734
     * that we give outside classes a chance to set <tt>home</tt>.
Matt Tucker's avatar
Matt Tucker committed
735
     */
736 737
    private synchronized static void loadSetupProperties() {
        if (xmlProperties == null) {
738 739
            // If home is null then log that the application will not work correctly
            if (home == null && !failedLoading) {
Matt Tucker's avatar
Matt Tucker committed
740
                failedLoading = true;
741
                StringBuilder msg = new StringBuilder();
742
                msg.append("Critical Error! The home directory has not been configured, \n");
743 744
                msg.append("which will prevent the application from working correctly.\n\n");
                System.err.println(msg.toString());
Matt Tucker's avatar
Matt Tucker committed
745
            }
746
            // Create a manager with the full path to the xml config file.
747 748 749
            else {
                try {
                    xmlProperties = new XMLProperties(home + File.separator + getConfigName());
Matt Tucker's avatar
Matt Tucker committed
750
                }
751 752 753
                catch (IOException ioe) {
                    Log.error(ioe);
                    failedLoading = true;
Matt Tucker's avatar
Matt Tucker committed
754 755 756 757
                }
            }
        }
    }
758
}