Changeset 5296


Ignore:
Timestamp:
2003-08-27T15:05:14+12:00 (21 years ago)
Author:
jmt12
Message:

Added keylist functionality

Location:
trunk/gli/src/org/greenstone/gatherer
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/gli/src/org/greenstone/gatherer/Dictionary.java

    r5164 r5296  
    3636 *########################################################################
    3737 */
     38import java.io.*;
    3839import java.util.*;
    3940import javax.swing.*;
     
    6970public class Dictionary
    7071    extends HashMap {
     72
     73    static final private boolean KEY_LIST_DEBUG = true;
     74    static final private String KEY_LIST_FILENAME = "keylist.txt";
     75
    7176    /** A String which more explicitly states the Locale of this dictionary. */
    7277    public String language = null;
     
    7984    /** The ResourceBundle which contains the raw key-value mappings. Loaded from a file named "dictionary<I>locale</I>.properties*/
    8085    private ResourceBundle dictionary = null;
     86
     87    private TreeSet key_list = null;;
     88
    8189    /**  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.
    8290     * @param locale The <strong>Locale</strong> used to load the desired dictionary resource bundle.
     
    8593    super();
    8694    this.self = this;
     95
     96    if(KEY_LIST_DEBUG) {
     97        // Reload the keylist
     98        File file = new File(KEY_LIST_FILENAME);
     99        key_list = new TreeSet();
     100        try {
     101        BufferedReader br = new BufferedReader(new FileReader(file));
     102        String line;
     103        while((line = br.readLine()) != null) {
     104            key_list.add(line);
     105        }
     106        br.close();
     107        br = null;
     108        }
     109        catch(Exception error) {
     110        error.printStackTrace();
     111        }
     112    }
     113
    87114    // Initialize.
    88115    this.font = font;
     
    146173    }
    147174
     175    public void destroy() {
     176    if(key_list != null) {
     177        try {
     178        FileOutputStream fos = new FileOutputStream(KEY_LIST_FILENAME);
     179        for(Iterator iter = key_list.iterator(); iter.hasNext(); ) {
     180            String value = (String) iter.next();
     181            fos.write(value.getBytes());
     182            fos.write('\n');
     183            value = null;
     184        }
     185        fos.close();
     186        fos = null;
     187        }
     188        catch(Exception error) {
     189        error.printStackTrace();
     190        }
     191    }
     192    }
     193
    148194    /** Overloaded to call get with both a key and an empty argument array.
    149195      * @param key A <strong>String</strong> which is mapped to a initial String within the ResourceBundle.
     
    166212      */
    167213    public String get(String key, String args[]) {
     214    if(key_list != null) {
     215        synchronized(this) {
     216        key_list.add(key);
     217        }
     218    }
    168219    try {
    169220        String initial = dictionary.getString(key);
  • trunk/gli/src/org/greenstone/gatherer/Gatherer.java

    r5253 r5296  
    341341    // Save configuration.
    342342    saveConfig();
     343
     344    // Flush dictionary
     345    dictionary.destroy();
     346
    343347    // Flush debug
    344348    if(debug != null) {
     
    593597    // Splash screen.
    594598    Splash splash = new Splash();
    595 
     599    dictionary.destroy();
    596600    gatherer.run(size, gsdl_path, exec_path, debug, perl_path, no_load, splash, filename);
    597601    }
Note: See TracChangeset for help on using the changeset viewer.