| | 218 | /*probably repeating alot of work, but I want to keep this separate... wendy*/ |
|---|
| | 219 | public void scheduleBuild(boolean incremental_build) |
|---|
| | 220 | { |
|---|
| | 221 | |
|---|
| | 222 | DebugStream.println("In CollectionManager.scheduleBuild(), incremental_build: " + incremental_build); |
|---|
| | 223 | DebugStream.println("Is event dispatch threa: " + SwingUtilities.isEventDispatchThread()); |
|---|
| | 224 | |
|---|
| | 225 | ArrayList sched_list = new ArrayList(); |
|---|
| | 226 | if ((Utility.isWindows()) && (!Gatherer.isGsdlRemote)) { |
|---|
| | 227 | sched_list.add(Configuration.perl_path); |
|---|
| | 228 | sched_list.add("-S"); |
|---|
| | 229 | } |
|---|
| | 230 | sched_list.add(LocalGreenstone.getBinScriptDirectoryPath() + "schedule.pl"); |
|---|
| | 231 | sched_list.add("-colname"); |
|---|
| | 232 | sched_list.add(collection.getName()); |
|---|
| | 233 | sched_list.add("-gli"); |
|---|
| | 234 | |
|---|
| | 235 | // First, generate the import.pl command, also converting to a string |
|---|
| | 236 | // Generate the import.pl command |
|---|
| | 237 | ArrayList import_list = new ArrayList(); |
|---|
| | 238 | if ((Utility.isWindows()) && (!Gatherer.isGsdlRemote)) { |
|---|
| | 239 | import_list.add(Configuration.perl_path); |
|---|
| | 240 | import_list.add("-S"); |
|---|
| | 241 | } |
|---|
| | 242 | import_list.add(LocalGreenstone.getBinScriptDirectoryPath() + "import.pl"); |
|---|
| | 243 | import_list.add("-language"); |
|---|
| | 244 | import_list.add(Configuration.getLanguage()); |
|---|
| | 245 | import_list.add("-collectdir"); |
|---|
| | 246 | import_list.add(getCollectDirectory()); |
|---|
| | 247 | |
|---|
| | 248 | String[] import_options = collection.import_options.getValues(); |
|---|
| | 249 | int i = 0; |
|---|
| | 250 | for (i = 0; i < import_options.length; i++) { |
|---|
| | 251 | import_list.add(import_options[i]); |
|---|
| | 252 | } |
|---|
| | 253 | |
|---|
| | 254 | import_list.add(collection.getName()); |
|---|
| | 255 | |
|---|
| | 256 | String[] import_parts = (String[]) import_list.toArray(new String[0]); |
|---|
| | 257 | String command = ""; |
|---|
| | 258 | i = 0; |
|---|
| | 259 | for (i = 0; i < import_parts.length-1; i++) { |
|---|
| | 260 | command = command + import_parts[i] + " "; |
|---|
| | 261 | } |
|---|
| | 262 | command = command + import_parts[i]; |
|---|
| | 263 | |
|---|
| | 264 | sched_list.add("-import"); |
|---|
| | 265 | sched_list.add("\"" + command + "\""); |
|---|
| | 266 | |
|---|
| | 267 | // Generate the buildcol.pl command, also converting to a string |
|---|
| | 268 | ArrayList build_list = new ArrayList(); |
|---|
| | 269 | |
|---|
| | 270 | // i'm not doing this in schedule.pl right now - should i be? |
|---|
| | 271 | if ((Utility.isWindows()) && (!Gatherer.isGsdlRemote)) { |
|---|
| | 272 | build_list.add(Configuration.perl_path); |
|---|
| | 273 | build_list.add("-S"); |
|---|
| | 274 | } |
|---|
| | 275 | build_list.add(LocalGreenstone.getBinScriptDirectoryPath() + "buildcol.pl"); |
|---|
| | 276 | build_list.add("-language"); |
|---|
| | 277 | build_list.add(Configuration.getLanguage()); |
|---|
| | 278 | build_list.add("-collectdir"); |
|---|
| | 279 | build_list.add(getCollectDirectory()); |
|---|
| | 280 | |
|---|
| | 281 | // If the user hasn't manually specified "-keepold" or "-removeold" then pick one based on incremental_build |
|---|
| | 282 | if (!collection.build_options.getValueEnabled("keepold") && !collection.build_options.getValueEnabled("removeold")) { |
|---|
| | 283 | build_list.add(incremental_build ? "-keepold" : "-removeold"); |
|---|
| | 284 | } |
|---|
| | 285 | |
|---|
| | 286 | String[] build_options = collection.build_options.getValues(); |
|---|
| | 287 | for (i = 0; i < build_options.length; i++) { |
|---|
| | 288 | build_list.add(build_options[i]); |
|---|
| | 289 | } |
|---|
| | 290 | |
|---|
| | 291 | build_list.add(collection.getName()); |
|---|
| | 292 | |
|---|
| | 293 | //build actual string |
|---|
| | 294 | String[] build_parts = (String[]) build_list.toArray(new String[0]); |
|---|
| | 295 | String command2 = ""; |
|---|
| | 296 | for(i = 0; i < build_parts.length-1; i++) { |
|---|
| | 297 | command2 = command2 + build_parts[i] + " "; |
|---|
| | 298 | } |
|---|
| | 299 | command2 = command2 + build_parts[i]; |
|---|
| | 300 | |
|---|
| | 301 | sched_list.add("-build"); |
|---|
| | 302 | sched_list.add("\"" + command2 + "\""); |
|---|
| | 303 | |
|---|
| | 304 | //next, the scheduling frequency goes here |
|---|
| | 305 | String[] schedule_options = collection.schedule_options.getValues(); |
|---|
| | 306 | for(i = 0; i < schedule_options.length; i++) { |
|---|
| | 307 | sched_list.add(schedule_options[i]); |
|---|
| | 308 | } |
|---|
| | 309 | |
|---|
| | 310 | //now, hope it will run. ;) |
|---|
| | 311 | String[] sched_parts = (String[]) sched_list.toArray(new String[0]); |
|---|
| | 312 | |
|---|
| | 313 | GShell shell = new GShell(sched_parts, GShell.SCHEDULE, SCHEDULING, this, schedule_monitor, GShell.GSHELL_SCHEDULE); |
|---|
| | 314 | shell.addGShellListener(Gatherer.g_man.create_pane); |
|---|
| | 315 | shell.addGShellListener(Gatherer.g_man.format_pane); |
|---|
| | 316 | shell.start(); |
|---|
| | 317 | } |
|---|
| | 559 | //try to obtain email address of collection owner if it exists... |
|---|
| | 560 | String stmp = Configuration.getEmail(); |
|---|
| | 561 | if(stmp != null) { |
|---|
| | 562 | collection.schedule_options.setValue("toaddr", false, Configuration.getEmail()); |
|---|
| | 563 | } |
|---|
| | 564 | |
|---|
| | 565 | //try to obtain email address of Greenstone installation webmaster for - used to indicate "sender". |
|---|
| | 566 | File mcfg = new File(LocalGreenstone.getDirectoryPath()+"etc" + File.separator + "main.cfg"); |
|---|
| | 567 | BufferedReader maincfg = new BufferedReader(new FileReader(mcfg)); |
|---|
| | 568 | stmp = ""; |
|---|
| | 569 | String fromaddr = ""; |
|---|
| | 570 | while((stmp = maincfg.readLine()) != null) { |
|---|
| | 571 | if(stmp.startsWith("maintainer")) { |
|---|
| | 572 | fromaddr = stmp.substring(10); //length of MailServer |
|---|
| | 573 | fromaddr = fromaddr.trim(); |
|---|
| | 574 | break; |
|---|
| | 575 | } |
|---|
| | 576 | } |
|---|
| | 577 | maincfg.close(); |
|---|
| | 578 | if(!fromaddr.equals("NULL") && !fromaddr.equals("null")) { |
|---|
| | 579 | collection.schedule_options.setValue("fromaddr", false, fromaddr); |
|---|
| | 580 | } |
|---|
| | 581 | |
|---|
| | 582 | //try to obtain an smtp server address from main.cfg. If that fails, |
|---|
| | 583 | //try mail.server if an email address exists. If that fails, |
|---|
| | 584 | //maybe a message to set attribute in main.cfg? |
|---|
| | 585 | //i'm pretty sure there exists functionality to do this, but |
|---|
| | 586 | //i'll finish this faster if I just wrote it |
|---|
| | 587 | |
|---|
| | 588 | |
|---|
| | 589 | maincfg = new BufferedReader(new FileReader(mcfg)); |
|---|
| | 590 | String smtptmp = "NULL"; |
|---|
| | 591 | while((stmp = maincfg.readLine()) != null) { |
|---|
| | 592 | if(stmp.startsWith("MailServer")) { |
|---|
| | 593 | smtptmp = stmp.substring(10); //length of MailServer |
|---|
| | 594 | smtptmp = smtptmp.trim(); |
|---|
| | 595 | break; |
|---|
| | 596 | } |
|---|
| | 597 | } |
|---|
| | 598 | maincfg.close(); |
|---|
| | 599 | |
|---|
| | 600 | //try if lookup failes |
|---|
| | 601 | if(smtptmp.equals("NULL") || smtptmp.equals("null")) { |
|---|
| | 602 | String email2=fromaddr; |
|---|
| | 603 | if(!email2.equals("NULL") && !email2.equals("null")) { |
|---|
| | 604 | int loc = email2.indexOf('@'); |
|---|
| | 605 | email2 = email2.substring(loc+1); |
|---|
| | 606 | smtptmp = "mail."+email2; |
|---|
| | 607 | } |
|---|
| | 608 | } |
|---|
| | 609 | if(!smtptmp.equals("NULL") && !smtptmp.equals("null")) { |
|---|
| | 610 | collection.schedule_options.setValue("smtp", false, smtptmp); |
|---|
| | 611 | } |
|---|
| | 612 | |
|---|
| | 1201 | //THIS LOOKS LIKE THE BEST PLACE TO TRY AND UPDATE .col FILES FOR EXISTING COLLECTIONS...Wendy |
|---|
| | 1202 | |
|---|
| | 1203 | //First, see if "Schedule" exists in the XMl File... |
|---|
| | 1204 | BufferedReader bir = new BufferedReader(new FileReader(collection_file)); |
|---|
| | 1205 | boolean flag = false; |
|---|
| | 1206 | try { |
|---|
| | 1207 | String stmp = new String(); |
|---|
| | 1208 | |
|---|
| | 1209 | while((stmp = bir.readLine()) != null) { |
|---|
| | 1210 | stmp = stmp.trim(); |
|---|
| | 1211 | if(stmp.equals("<Schedule>") || stmp.equals("<Schedule/>")) { |
|---|
| | 1212 | flag = true; |
|---|
| | 1213 | break; |
|---|
| | 1214 | } |
|---|
| | 1215 | } |
|---|
| | 1216 | bir.close(); |
|---|
| | 1217 | |
|---|
| | 1218 | } catch (IOException ioe) { |
|---|
| | 1219 | //do something here |
|---|
| | 1220 | } |
|---|
| | 1221 | |
|---|
| | 1222 | //modify if old .col (i.e. no Schedule exists in XML file) |
|---|
| | 1223 | if(!flag) { |
|---|
| | 1224 | File new_collection_file = new File(collection_directory.getAbsolutePath() + "/tmp.col"); |
|---|
| | 1225 | |
|---|
| | 1226 | |
|---|
| | 1227 | BufferedWriter bor = new BufferedWriter(new FileWriter(new_collection_file)); |
|---|
| | 1228 | bir = new BufferedReader(new FileReader(collection_file)); |
|---|
| | 1229 | |
|---|
| | 1230 | try { |
|---|
| | 1231 | String stmp = new String(); |
|---|
| | 1232 | while((stmp = bir.readLine()) != null) { |
|---|
| | 1233 | String stmp2 = stmp.trim(); |
|---|
| | 1234 | if(stmp2.startsWith("<!ELEMENT Argument")) { |
|---|
| | 1235 | bor.write(" <!ELEMENT Schedule (Arguments*)>\n"); |
|---|
| | 1236 | } |
|---|
| | 1237 | else if(stmp2.equals("</BuildConfig>")) { |
|---|
| | 1238 | bor.write(" <Schedule/>\n"); |
|---|
| | 1239 | } |
|---|
| | 1240 | |
|---|
| | 1241 | bor.write(stmp + "\n"); |
|---|
| | 1242 | |
|---|
| | 1243 | } |
|---|
| | 1244 | bir.close(); |
|---|
| | 1245 | bor.close(); |
|---|
| | 1246 | } catch (IOException ioe) { |
|---|
| | 1247 | //do something here |
|---|
| | 1248 | } |
|---|
| | 1249 | |
|---|
| | 1250 | //copy over tmp.col to replace |
|---|
| | 1251 | try { |
|---|
| | 1252 | collection_file.delete(); |
|---|
| | 1253 | new_collection_file.renameTo(collection_file); |
|---|
| | 1254 | } catch (Exception e) { |
|---|
| | 1255 | //do something here |
|---|
| | 1256 | } |
|---|
| | 1257 | } |
|---|
| | 1258 | |
|---|
| | 1269 | |
|---|
| | 1270 | |
|---|
| | 1271 | //try to obtain email address of collection owner if it exists... |
|---|
| | 1272 | String stmp = Configuration.getEmail(); |
|---|
| | 1273 | if(stmp != null) { |
|---|
| | 1274 | collection.schedule_options.setValue("toaddr", false, Configuration.getEmail()); |
|---|
| | 1275 | } |
|---|
| | 1276 | |
|---|
| | 1277 | |
|---|
| | 1278 | |
|---|
| | 1279 | //The next few items deal with updating the SMTP server, and the to: and from: addresses |
|---|
| | 1280 | //from main.cfg and the collection configuration. if no changes are made, or the |
|---|
| | 1281 | //values are result to NULL, any existing values are kept. |
|---|
| | 1282 | |
|---|
| | 1283 | //try to obtain email address of Greenstone installation webmaster for - used to indicate "sender". |
|---|
| | 1284 | File mcfg = new File(LocalGreenstone.getDirectoryPath()+"etc" + File.separator + "main.cfg"); |
|---|
| | 1285 | BufferedReader maincfg = new BufferedReader(new FileReader(mcfg)); |
|---|
| | 1286 | stmp = ""; |
|---|
| | 1287 | String fromaddr = ""; |
|---|
| | 1288 | while((stmp = maincfg.readLine()) != null) { |
|---|
| | 1289 | if(stmp.startsWith("maintainer")) { |
|---|
| | 1290 | fromaddr = stmp.substring(10); //length of MailServer |
|---|
| | 1291 | fromaddr = fromaddr.trim(); |
|---|
| | 1292 | break; |
|---|
| | 1293 | } |
|---|
| | 1294 | } |
|---|
| | 1295 | maincfg.close(); |
|---|
| | 1296 | if(!fromaddr.equals("NULL") && !fromaddr.equals("null")) { |
|---|
| | 1297 | collection.schedule_options.setValue("fromaddr", false, fromaddr); |
|---|
| | 1298 | } |
|---|
| | 1299 | |
|---|
| | 1300 | //try to obtain an smtp server address from main.cfg. If that fails, |
|---|
| | 1301 | //try mail.server if an email address exists. If that fails, |
|---|
| | 1302 | //maybe a message to set attribute in main.cfg? |
|---|
| | 1303 | //i'm pretty sure there exists functionality to do this, but |
|---|
| | 1304 | //i'll finish this faster if I just wrote it |
|---|
| | 1305 | |
|---|
| | 1306 | |
|---|
| | 1307 | maincfg = new BufferedReader(new FileReader(mcfg)); |
|---|
| | 1308 | String smtptmp = "NULL"; |
|---|
| | 1309 | while((stmp = maincfg.readLine()) != null) { |
|---|
| | 1310 | if(stmp.startsWith("MailServer")) { |
|---|
| | 1311 | smtptmp = stmp.substring(10); //length of MailServer |
|---|
| | 1312 | smtptmp = smtptmp.trim(); |
|---|
| | 1313 | break; |
|---|
| | 1314 | } |
|---|
| | 1315 | } |
|---|
| | 1316 | maincfg.close(); |
|---|
| | 1317 | |
|---|
| | 1318 | //try if lookup failes |
|---|
| | 1319 | if(smtptmp.equals("NULL") || smtptmp.equals("null")) { |
|---|
| | 1320 | String email2=fromaddr; |
|---|
| | 1321 | if(!email2.equals("NULL") && !email2.equals("null")) { |
|---|
| | 1322 | int loc = email2.indexOf('@'); |
|---|
| | 1323 | email2 = email2.substring(loc+1); |
|---|
| | 1324 | smtptmp = "mail."+email2; |
|---|
| | 1325 | } |
|---|
| | 1326 | } |
|---|
| | 1327 | if(!smtptmp.equals("NULL") && !smtptmp.equals("null")) { |
|---|
| | 1328 | collection.schedule_options.setValue("smtp", false, smtptmp); |
|---|
| | 1329 | } |
|---|
| | 1330 | |
|---|