Changeset 8084


Ignore:
Timestamp:
2004-08-27T13:29:00+12:00 (20 years ago)
Author:
mdewsnip
Message:

Fixed the help file loading so it works with the stand-alone version of the GLI as well as with the applet version.

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

Legend:

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

    r7740 r8084  
    303303
    304304        if (name != null && !name.equals(NULL_STRING)) {
    305         try {
    306             url = Utility.base.getResource("/"+help_file);
    307         }
    308         catch (Exception error) {
    309             // Most likely file name.
     305        url = Utility.base.getResource("/" + help_file);
     306        if (url == null) {
     307            File file = new File(Utility.BASE_DIR + help_file);
    310308            try {
    311             File file = new File(Utility.BASE_DIR + help_file);
    312309            url = file.toURL();
    313 
    314310            }
    315             catch (Exception e) {
    316             Gatherer.printStackTrace(e);
     311            catch (Exception ex) {
     312            ex.printStackTrace();
    317313            }
    318314        }
    319315        }
     316
    320317        return url;
    321318    }
  • trunk/gli/src/org/greenstone/gatherer/util/Utility.java

    r7980 r8084  
    585585
    586586    String help_folder = "help/" + Gatherer.config.getLanguage() + "/";
    587     URL help_folder_url = base.getResource("/"+help_folder);
    588 
    589     // If that file can't be found, default to english
    590     if(help_folder_url==null) {
    591         help_folder = "help/" + StaticStrings.ENGLISH_LANGUAGE_STR  + "/";
    592     }
    593 
    594     return help_folder;
     587
     588    // Try in the JAR/classes directory first
     589    URL help_folder_url = base.getResource("/" + help_folder);
     590    if (help_folder_url != null) {
     591        return help_folder;
     592    }
     593
     594    // Look in the base directory next
     595    File help_folder_file = new File(help_folder);
     596    if (help_folder_file.exists()) {
     597        return help_folder;
     598    }
     599
     600    // Resort to English
     601    return "help/" + StaticStrings.ENGLISH_LANGUAGE_STR  + "/";
    595602    }
    596603
     
    12781285    }
    12791286
     1287
    12801288    /** Parse in a xml document from a given filename. Note that this filename may need to be resolved by the class loader, especially for template files within a jar. */
    1281     static public Document parse(String filename, boolean use_classloader) {
    1282     File file = null;
    1283     if(use_classloader) {
    1284         try {
    1285         // ****
    1286         // URL url = ClassLoader.getSystemResource(filename);
    1287         // URL url = base.getResource("/"+filename);
    1288         // System.err.println("*** looking for resource as stream: " + filename);
    1289         InputStream is = base.getResourceAsStream("/"+filename);
    1290 
    1291         // file = new File(URLDecoder.decode(url.getFile(), ENCODING));
    1292         // url = null;
    1293 
    1294         //FileInputStream fis   = new FileInputStream(file);       
    1295         return parse(is,true);
    1296         }
    1297         catch (Exception error) {
    1298         // Most likely file name.
    1299         /* String prefix = "";
    1300         if (!filename.startsWith("/")) {
    1301             prefix = "/research/code/gsdl/gli/";
    1302             }*/
    1303         file = new File("classes" + File.separator + filename);
    1304         //Gatherer.printStackTrace(error);
    1305         }
    1306     }
    1307     if(file == null) {
    1308         file = new File(filename);
    1309     }
    1310     return parse(file, true);
     1289    static public Document parse(String filename, boolean use_classloader)
     1290    {
     1291    // Try the class loader if desired (for the applet JAR file)
     1292    if (use_classloader) {
     1293        InputStream is = base.getResourceAsStream("/" + filename);
     1294        if (is != null) {
     1295        return parse(is, true);
     1296        }
     1297    }
     1298
     1299    // Try the file outside the classes directory
     1300    return parse(new File(filename), true);
    13111301    }
    13121302
Note: See TracChangeset for help on using the changeset viewer.