Changeset 7207
- Timestamp:
- 2004-04-20T09:26:32+12:00 (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/collection/CollectionManager.java
r7168 r7207 49 49 import org.greenstone.gatherer.cdm.CollectionMeta; 50 50 import org.greenstone.gatherer.cdm.CollectionMetaManager; 51 import org.greenstone.gatherer.cdm.CommandTokenizer; 51 52 import org.greenstone.gatherer.collection.BasicCollectionConfiguration; 52 53 import org.greenstone.gatherer.collection.Collection; … … 256 257 makeCollection(description, email, name, title); 257 258 progress.setProgress(1); 258 259 259 String a_dir = Utility.getCollectionDir(Gatherer.config.gsdl_path) + name + File.separator; 260 260 … … 1037 1037 process.addGShellListener(this); 1038 1038 process.run(); // Don't bother threading this... yet 1039 1039 1040 } 1040 1041 … … 1105 1106 } 1106 1107 else if(event.getStatus() == GShell.ERROR || event.getStatus() == GShell.CANCELLED) { 1108 Gatherer.println("There was an error in the gshell:"+ event.getMessage()); 1107 1109 JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("CollectionManager.Preview_Ready_Failed"), Dictionary.get("CollectionManager.Preview_Ready_Title"), JOptionPane.ERROR_MESSAGE); 1108 1110 Gatherer.g_man.collectionChanged(ready()); … … 1367 1369 String command = null; 1368 1370 while((command = in.readLine()) != null) { 1371 if (command.length()==0) { 1372 // output a new line 1373 out.newLine(); 1374 continue; 1375 } 1369 1376 // We have to test the end of command for the special character '\'. If found, remove it and append the next line, then repeat. 1370 1377 while(command.trim().endsWith("\\")) { … … 1375 1382 } 1376 1383 } 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()); 1388 1397 } 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); 1394 1409 // Read in the classifier command watching for hfile, metadata and sort arguments. 1395 1410 String buttonname = null; … … 1397 1412 String new_metadata = null; 1398 1413 String old_metadata = null; 1414 1399 1415 while(tokenizer.hasMoreTokens()) { 1400 1416 String token = tokenizer.nextToken(); … … 1454 1470 token = null; 1455 1471 } 1456 tokenizer = null; 1457 1472 1458 1473 // 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)! 1459 1474 if(old_metadata != null && new_metadata != null && buttonname == null) { … … 1468 1483 command = command.replaceAll(hfile, new_metadata + ".txt"); 1469 1484 } 1485 1470 1486 buttonname = null; 1471 1487 hfile = null; … … 1473 1489 old_metadata = null; 1474 1490 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 1477 1501 // 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); 1479 1504 // Replace mapping strings 1480 1505 if(mappings != null) { … … 1490 1515 } 1491 1516 write(out, command); 1492 } 1517 } 1518 tokenizer = null; 1493 1519 } 1494 1520 in.close(); … … 1506 1532 private void write(BufferedWriter out, String message) 1507 1533 throws Exception { 1508 ///ystem.err.println("Writing: " + message);1509 1534 out.write(message, 0, message.length()); 1510 1535 out.newLine();
Note:
See TracChangeset
for help on using the changeset viewer.