Changeset 7115


Ignore:
Timestamp:
2004-03-24T10:36:09+12:00 (20 years ago)
Author:
kjdon
Message:

fixed bugs in updateCollectionCFG when baseing a colleciton on an old one: now reads the config files in UTF-8, and doesn't copy across collectionname, collectionextra, iconcollection and iconcollectionsmall

File:
1 edited

Legend:

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

    r7104 r7115  
    13411341       return success;
    13421342     }
    1343 
    1344     private void updateCollectionCFG(File base_cfg, File new_cfg, String description, String email, String title) {
    1345         boolean first_name = true;
    1346         boolean first_extra = true;
    1347         String collection_path = (base_cfg.getParentFile().getParentFile()).getAbsolutePath();
    1348 
    1349         HashMap mappings = collection.msm.profiler.getActions(collection_path);
    1350         if(mappings == null) {
    1351             Gatherer.println("Mappings is null, which is odd. Leaving all configuration commands which use metadata as they are.");
     1343   
     1344    private void updateCollectionCFG(File base_cfg, File new_cfg, String description, String email, String title) {
     1345    boolean first_name = true;
     1346    boolean first_extra = true;
     1347    String collection_path = (base_cfg.getParentFile().getParentFile()).getAbsolutePath();
     1348   
     1349    HashMap mappings = collection.msm.profiler.getActions(collection_path);
     1350    if(mappings == null) {
     1351        Gatherer.println("Mappings is null, which is odd. Leaving all configuration commands which use metadata as they are.");
     1352    }
     1353   
     1354    // Now read in base_cfg line by line, parsing important onces and/or replacing them with information pertinent to our collection. Each line is then written back out to the new collect.cfg file.
     1355    try {
     1356        BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(base_cfg), "UTF-8"));
     1357        BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new_cfg), "UTF-8"));
     1358        String command = null;
     1359        while((command = in.readLine()) != null) {
     1360        // We have to test the end of command for the special character '\'. If found, remove it and append the next line, then repeat.
     1361        while(command.trim().endsWith("\\")) {
     1362            command = command.substring(0, command.lastIndexOf("\\"));
     1363            String next_line = in.readLine();
     1364            if(next_line != null) {
     1365            command = command + next_line;
     1366            }
    13521367        }
    1353 
    1354         // Now read in base_cfg line by line, parsing important onces and/or replacing them with information pertinent to our collection. Each line is then written back out to the new collect.cfg file.
    1355         try {
    1356             BufferedReader in = new BufferedReader(new FileReader(base_cfg));
    1357             BufferedWriter out = new BufferedWriter(new FileWriter(new_cfg, false)); // Overwrite whats there.
    1358             String command = null;
    1359             while((command = in.readLine()) != null) {
    1360             // We have to test the end of command for the special character '\'. If found, remove it and append the next line, then repeat.
    1361             while(command.trim().endsWith("\\")) {
    1362                 command = command.substring(0, command.lastIndexOf("\\"));
    1363                 String next_line = in.readLine();
    1364                 if(next_line != null) {
    1365                 command = command + next_line;
    1366                 }
    1367             }
    1368             ///ystem.err.println("Read: " + command);
    1369             // Now we've finished parsing a line, determine what to do with it.
    1370             String command_lc = command.toLowerCase();
    1371             // We replace the creator string with our own.
    1372             /*
    1373             if(command_lc.startsWith(Utility.CFG_CREATOR)) {
    1374                 ///ystem.err.println("Found creator - replace with current");
    1375                 write(out, Utility.CFG_CREATOR + " " + email);
    1376             }
    1377             else if(command_lc.startsWith(Utility.CFG_MAINTAINER)) {
    1378                 ///ystem.err.println("Found maintainer - replace with current");
    1379                 write(out, Utility.CFG_MAINTAINER + " " + email);
    1380             }
    1381             else if(command_lc.startsWith(Utility.CFG_COLLECTIONMETA_COLLECTIONNAME)) {
    1382                 if(first_name) {
    1383                     write(out, Utility.CFG_COLLECTIONMETA_COLLECTIONNAME + " \"" + title + "\"");
    1384                     first_name = false;
    1385                 }
    1386             }
    1387             else if(command_lc.startsWith(Utility.CFG_COLLECTIONMETA_COLLECTIONEXTRA)) {
    1388                 if(first_extra) {
    1389                     write(out, Utility.CFG_COLLECTIONMETA_COLLECTIONEXTRA + " \"" + description + "\"");
    1390                     first_extra = false;
    1391                 }
    1392             }
    1393             else if(command_lc.startsWith(Utility.CFG_COLLECTIONMETA_ICONCOLLECTION)) {
    1394                 write(out, Utility.CFG_COLLECTIONMETA_ICONCOLLECTION + " \"\"");
    1395             }
    1396             */
    1397             // Just before we try more general parsing there are the special cases to check. These are explicit changes required by some collections to produce sensible results.
    1398             if(command_lc.startsWith(Utility.CFG_CLASSIFY)) {
     1368        ///ystem.err.println("Read: " + command);
     1369        // Now we've finished parsing a line, determine what to do with it.
     1370        String command_lc = command.toLowerCase();
     1371        if (command_lc.startsWith(StaticStrings.COLLECTIONMETADATA_STR)) {
     1372            // we don't want to import collectionname, collectionextra, iconcollection, iconcollectionsmall from the base collection
     1373            StringTokenizer tokeniser = new StringTokenizer(command_lc);
     1374            tokeniser.nextToken(); // remove the first one
     1375            String meta_name = tokeniser.nextToken();
     1376            tokeniser = null;
     1377            if (meta_name.equals(StaticStrings.COLLECTIONMETADATA_COLLECTIONNAME_STR) || meta_name.equals(StaticStrings.COLLECTIONMETADATA_COLLECTIONEXTRA_STR) || meta_name.equals(StaticStrings.COLLECTIONMETADATA_ICONCOLLECTION_STR) || meta_name.equals(StaticStrings.COLLECTIONMETADATA_ICONCOLLECTIONSMALL_STR) ) {
     1378            continue;
     1379            }
     1380        }
     1381        // Just before we try more general parsing there are the special cases to check. These are explicit changes required by some collections to produce sensible results.
     1382        if(command_lc.startsWith(Utility.CFG_CLASSIFY)) {
    13991383            StringTokenizer tokenizer = new StringTokenizer(command);
    14001384            StringBuffer text = new StringBuffer(tokenizer.nextToken());
     
    14621446            }
    14631447            tokenizer = null;
    1464 
     1448           
    14651449            // If we replaced the metadata argument and didn't encounter a buttonname, then add one now pointing back to the old metadata name in order to accomodate macro files which required such names (buttonname is metadata name by default)!
    14661450            if(old_metadata != null && new_metadata != null && buttonname == null) {
     
    15101494    // All done, I hope.
    15111495    }
    1512 
     1496   
    15131497    private void write(BufferedWriter out, String message)
    15141498    throws Exception {
Note: See TracChangeset for help on using the changeset viewer.