Ignore:
Timestamp:
2004-04-20T09:26:32+12:00 (20 years ago)
Author:
kjdon
Message:

the updateCollectionCFG method now uses a CommandTokenizer to read in the base coll cfg file - allows collectionmeta and format statements to extend over more than one line

File:
1 edited

Legend:

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

    r7168 r7207  
    4949import org.greenstone.gatherer.cdm.CollectionMeta;
    5050import org.greenstone.gatherer.cdm.CollectionMetaManager;
     51import org.greenstone.gatherer.cdm.CommandTokenizer;
    5152import org.greenstone.gatherer.collection.BasicCollectionConfiguration;
    5253import org.greenstone.gatherer.collection.Collection;
     
    256257        makeCollection(description, email, name, title);
    257258        progress.setProgress(1);
    258 
    259259        String a_dir = Utility.getCollectionDir(Gatherer.config.gsdl_path) + name + File.separator;
    260260
     
    10371037    process.addGShellListener(this);
    10381038    process.run(); // Don't bother threading this... yet
     1039       
    10391040    }
    10401041
     
    11051106    }
    11061107    else if(event.getStatus() == GShell.ERROR || event.getStatus() == GShell.CANCELLED) {
     1108        Gatherer.println("There was an error in the gshell:"+ event.getMessage());
    11071109        JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("CollectionManager.Preview_Ready_Failed"), Dictionary.get("CollectionManager.Preview_Ready_Title"), JOptionPane.ERROR_MESSAGE);
    11081110        Gatherer.g_man.collectionChanged(ready());
     
    13671369        String command = null;
    13681370        while((command = in.readLine()) != null) {
     1371        if (command.length()==0) {
     1372            // output a new line
     1373            out.newLine();
     1374            continue;
     1375        }
    13691376        // We have to test the end of command for the special character '\'. If found, remove it and append the next line, then repeat.
    13701377        while(command.trim().endsWith("\\")) {
     
    13751382            }
    13761383        }
    1377         ///ystem.err.println("Read: " + command);
    1378         // Now we've finished parsing a line, determine what to do with it.
    1379         String command_lc = command.toLowerCase();
    1380         if (command_lc.startsWith(StaticStrings.COLLECTIONMETADATA_STR)) {
    1381             // we don't want to import collectionname, collectionextra, iconcollection, iconcollectionsmall from the base collection
    1382             StringTokenizer tokeniser = new StringTokenizer(command_lc);
    1383             tokeniser.nextToken(); // remove the first one
    1384             String meta_name = tokeniser.nextToken();
    1385             tokeniser = null;
    1386             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) ) {
    1387             continue;
     1384        // commands can extend over more than one line so use the CommandTokenizer which takes care of that
     1385        CommandTokenizer tokenizer = new CommandTokenizer(command, in, false);
     1386        String command_type_str = tokenizer.nextToken().toLowerCase();
     1387
     1388        if (command_type_str.equals(StaticStrings.COLLECTIONMETADATA_STR)) {
     1389            // read the whole thing in, but for collectionname, collectionextra, iconcollection, iconcollectionsmall we will ignore them
     1390            StringBuffer new_command = new StringBuffer(command_type_str);
     1391            String meta_name = tokenizer.nextToken();
     1392            new_command.append(' ');
     1393            new_command.append(meta_name);
     1394            while (tokenizer.hasMoreTokens()) {
     1395            new_command.append(' ');
     1396            new_command.append(tokenizer.nextToken());
    13881397            }
    1389         }
    1390         // 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.
    1391         if(command_lc.startsWith(Utility.CFG_CLASSIFY)) {
    1392             StringTokenizer tokenizer = new StringTokenizer(command);
    1393             StringBuffer text = new StringBuffer(tokenizer.nextToken());
     1398            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)) {
     1399            // dont save
     1400            } else {
     1401            write(out, new_command.toString());
     1402            }
     1403            new_command = null;
     1404            continue;
     1405        } // if collectionmeta
     1406
     1407        if(command_type_str.equals(Utility.CFG_CLASSIFY)) {
     1408            StringBuffer text = new StringBuffer(command_type_str);
    13941409            // Read in the classifier command watching for hfile, metadata and sort arguments.
    13951410            String buttonname = null;
     
    13971412            String new_metadata = null;
    13981413            String old_metadata = null;
     1414       
    13991415            while(tokenizer.hasMoreTokens()) {
    14001416            String token = tokenizer.nextToken();
     
    14541470            token = null;
    14551471            }
    1456             tokenizer = null;
    1457            
     1472           
    14581473            // 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)!
    14591474            if(old_metadata != null && new_metadata != null && buttonname == null) {
     
    14681483            command = command.replaceAll(hfile, new_metadata + ".txt");
    14691484            }
     1485       
    14701486            buttonname = null;
    14711487            hfile = null;
     
    14731489            old_metadata = null;
    14741490            write(out, command);
    1475         }
    1476         else {
     1491         } else {
     1492             // the rest of the commands just want a string - we read in all the tokens from the tokeniser and get rid of it.
     1493            StringBuffer new_command = new StringBuffer(command_type_str);
     1494            while (tokenizer.hasMoreTokens()) {
     1495            new_command.append(' ');
     1496            new_command.append(tokenizer.nextToken());
     1497            }
     1498
     1499            command = new_command.toString();
     1500           
    14771501            // There is still one special case, that of the format command. In such a command we have to search for [<target>] to ensure we don't change parts of the format which have nothing to do with the metadata elements.
    1478             boolean format_command = command_lc.startsWith(Utility.CFG_FORMAT);
     1502            // we really want to build up the whole command here
     1503            boolean format_command = command_type_str.equals(Utility.CFG_FORMAT);
    14791504            // Replace mapping strings
    14801505            if(mappings != null) {
     
    14901515            }
    14911516            write(out, command);
    1492         }
     1517         }
     1518        tokenizer = null;
    14931519        }
    14941520        in.close();
     
    15061532    private void write(BufferedWriter out, String message)
    15071533    throws Exception {
    1508     ///ystem.err.println("Writing: " + message);
    15091534    out.write(message, 0, message.length());
    15101535    out.newLine();
Note: See TracChangeset for help on using the changeset viewer.