Changeset 9424


Ignore:
Timestamp:
2005-03-15T13:50:09+13:00 (19 years ago)
Author:
kjdon
Message:

added a new constructor that takes a specified classloader which is used to try and load the resource bundle

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/util/Dictionary.java

    r9050 r9424  
     1/*
     2 *    Dictionary.java
     3 *    Copyright (C) 2005 New Zealand Digital Library, http://www.nzdl.org
     4 *
     5 *    This program is free software; you can redistribute it and/or modify
     6 *    it under the terms of the GNU General Public License as published by
     7 *    the Free Software Foundation; either version 2 of the License, or
     8 *    (at your option) any later version.
     9 *
     10 *    This program is distributed in the hope that it will be useful,
     11 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
     12 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     13 *    GNU General Public License for more details.
     14 *
     15 *    You should have received a copy of the GNU General Public License
     16 *    along with this program; if not, write to the Free Software
     17 *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
     18 */
    119package org.greenstone.gsdl3.util;
    220
     
    1634    private ResourceBundle raw = null;
    1735
    18     /**  Constructs the Dictionary class by first checking if a Locale has been set. If not the default locale is used, and a ResourceBundle is created. Finally a single important String, Language, is made available outside the class so a more read-able version of the Locale of this Dictionary is present.
    19      * @param locale The <strong>Locale</strong> used to load the desired dictionary resource bundle.
     36    /**  Constructs the Dictionary class by first creating a locale from the specified language, (or using the default locale if this didn't work), then loading a resource bundle based on this locale.
    2037     */
    2138    public Dictionary(String resource, String lang) {
     
    3451    }
    3552
     53    /**  Constructs the Dictionary class by first creating a locale from the specified language, (or using the default locale if this didn't work), then loading a resource bundle based on this locale. A classloader is specified which can be used to find the resource.
     54     */
     55    public Dictionary(String resource, String lang, ClassLoader loader) {
     56    // Initialize.
     57   
     58    this.locale = new Locale(lang);
     59    this.resource = resource;
     60    if (this.locale == null) {
     61        this.locale = Locale.getDefault();
     62    }
     63    // try the specified class loader
     64    try {
     65        this.raw = ResourceBundle.getBundle(this.resource, this.locale, loader);
     66        return;
     67    } catch (Exception e) {};
     68   
     69    try {
     70        this.raw = ResourceBundle.getBundle(this.resource, this.locale);
     71    } catch (Exception ex) {
     72        System.err.println("Dictionary: couldn't locate a resource bundle for "+resource);
     73    }
     74   
     75    }
     76
     77   
    3678    public Enumeration getKeys() {
    3779    if (this.raw != null) {
Note: See TracChangeset for help on using the changeset viewer.