Changeset 9095
- Timestamp:
- 2005-02-18T12:31:54+13:00 (19 years ago)
- Location:
- trunk/gli/src/org/greenstone/gatherer
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/GathererApplet.java
r9092 r9095 42 42 import org.greenstone.gatherer.gui.GUIManager; 43 43 import org.greenstone.gatherer.util.Utility; 44 import org.greenstone.gatherer.shell.GShell; 44 45 45 46 … … 208 209 209 210 210 static public void download_url_zip(String col_name, String dir )211 static public void download_url_zip(String col_name, String dir, GShell source) 211 212 { 212 213 try { … … 247 248 int len; 248 249 249 while ((len = dl_dbis.read(buf)) >= 0 ) {250 while ((len = dl_dbis.read(buf)) >= 0 && !source.hasSignalledStop()) { 250 251 zip_bfos.write(buf,0,len); 251 252 } … … 261 262 262 263 263 static public void upload_url_zip(String col_name, String dir )264 static public void upload_url_zip(String col_name, String dir, GShell source) 264 265 { 265 266 final String lineEnd = "\r\n"; … … 320 321 // read file and write it into form... 321 322 int bytesRead = fileInputStream.read(buffer, 0, bufferSize); 322 323 323 324 while (bytesRead > 0) { 325 // Check to see if action has been cancelled. 326 if (source != null && source.hasSignalledStop()) { 327 break; 328 } 324 329 dos.write(buffer, 0, bufferSize); 325 330 bytesAvailable = fileInputStream.available(); -
trunk/gli/src/org/greenstone/gatherer/cdm/CollectionDesignManager.java
r9045 r9095 216 216 if (formats_changed && Gatherer.c_man.built()) { 217 217 // upload etc/collect.cfg to server to reflect changes 218 Utility.zipup(Gatherer.getCollectDirectoryPath(), collection_name, Utility.CONFIG_FILE );219 GathererApplet.upload_url_zip(collection_name, "etc" );218 Utility.zipup(Gatherer.getCollectDirectoryPath(), collection_name, Utility.CONFIG_FILE, null); 219 GathererApplet.upload_url_zip(collection_name, "etc", null); 220 220 } 221 221 } -
trunk/gli/src/org/greenstone/gatherer/collection/CollectionManager.java
r9052 r9095 1066 1066 } 1067 1067 } 1068 else if(event.getStatus() == GShell.ERROR || event.getStatus() == GShell.CANCELLED) { 1068 else if (event.getStatus() == GShell.CANCELLED) { 1069 JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("CollectionManager.Build_Cancelled"), Dictionary.get("General.Error"), JOptionPane.ERROR_MESSAGE); 1070 Gatherer.g_man.repaint(); 1071 } 1072 else if (event.getStatus() == GShell.ERROR) { 1069 1073 DebugStream.println("There was an error in the gshell:"+ event.getMessage()); 1070 1074 if (event.getType() == GShell.NEW) { -
trunk/gli/src/org/greenstone/gatherer/shell/GShell.java
r9049 r9095 227 227 protected void runRemote(String[] args, BufferedOutputStream bos) 228 228 { 229 if(hasSignalledStop()) { return; } 230 int error_count = 0; 231 StringBuffer error_list = new StringBuffer(); 229 232 try { 230 233 if (type == IMPORT) { 234 String col_name = args[args.length-1]; 235 if (progress!=null) { 236 progress.messageOnProgressBar("Uploading data to server"); 237 } 238 239 String collect_directory_path = Gatherer.getCollectDirectoryPath(); 240 241 // zip up import folder 242 Utility.zipup(collect_directory_path, col_name, "import", this); 243 244 if(hasSignalledStop()) { return; } 245 // upload it to gsdl server 246 GathererApplet.upload_url_zip(col_name, "import", this); 247 248 if(hasSignalledStop()) { return; } 249 // upload etc folder to server (need collect.cfg and any hfiles) 250 Utility.zipup(collect_directory_path, col_name, "etc", this); 251 252 if(hasSignalledStop()) { return; } 253 GathererApplet.upload_url_zip(col_name, "etc", this); 254 255 String collection_directory_path = Gatherer.c_man.getCollectionDirectoryPath(col_name); 256 File img_dir = new File(Gatherer.c_man.getCollectionImagesDirectoryPath()); 257 if (img_dir.exists() && img_dir.list().length > 0) { 258 // upload images/ directory to server 259 if(hasSignalledStop()) { return; } 260 Utility.zipup(collect_directory_path, col_name, "images", this); 261 262 if(hasSignalledStop()) { return; } 263 GathererApplet.upload_url_zip(col_name, "images", this); 264 } 265 266 if(hasSignalledStop()) { return; } 267 // see if collection specific image needs uploading 268 CollectionMetaManager cmm 269 = CollectionDesignManager.collectionmeta_manager; 270 271 CollectionMeta icon_collection_collectionmeta 272 = cmm.getMetadatum(CollectionConfiguration.COLLECTIONMETADATA_ICONCOLLECTION_STR); 273 CollectionMeta icon_collection_small_collectionmeta 274 = cmm.getMetadatum(CollectionConfiguration.COLLECTIONMETADATA_ICONCOLLECTIONSMALL_STR); 275 276 String ics_text = icon_collection_collectionmeta.getValue(CollectionMeta.TEXT); 277 String icsc_text = icon_collection_small_collectionmeta.getValue(CollectionMeta.TEXT); 278 if ((ics_text != null) && (ics_text != "")) { 279 // Stub code for detecting when collectoin image changed 280 // => need to upload images 281 // System.err.println("**** ics_text = " + ics_text); 282 } 283 284 if (progress!=null) { 285 progress.messageOnProgressBar(""); 286 } 287 } 288 289 if(hasSignalledStop()) { return; } 231 290 String perl_cmd = args[0]; 232 291 int perl_cmd_root = perl_cmd.lastIndexOf(File.separator); 233 292 234 293 if (perl_cmd_root > 0) { 235 294 String perl_cmd_cut = perl_cmd.substring(perl_cmd_root+1); 236 295 perl_cmd = perl_cmd_cut; 237 296 } 238 297 239 298 String launch = Gatherer.cgiBase + "launch"; 240 299 launch = launch + "?cmd=" + perl_cmd; 241 300 242 301 for(int i = 1; i<args.length; i++) { 243 302 244 303 String arg = args[i]; 245 304 246 305 if (arg.equals("-collectdir") || arg.equals("-importdir") 247 306 || arg.equals("-builddir")) { … … 250 309 continue; 251 310 } 252 311 253 312 launch += "&"; 254 313 255 314 if(arg.startsWith(StaticStrings.MINUS_CHARACTER)) { 256 315 String name = arg.substring(1); … … 268 327 } 269 328 } 270 329 271 330 System.err.println("**** launch url = " + launch); 272 331 // fireMessage(type, Dictionary.get("GShell.Command") + ": " + launch, status, null); // **** 273 332 274 333 URL launch_url = new URL(launch); 275 334 URLConnection launch_connection = launch_url.openConnection(); 276 335 InputStream stdis = launch_connection.getInputStream(); 277 336 InputStreamReader stdisr = new InputStreamReader(stdis, "UTF-8"); 278 337 279 338 BufferedReader stdbr = new BufferedReader(stdisr); 280 281 StringBuffer error_list = new StringBuffer(); 282 int error_count = 0; 283 339 284 340 if (type == GShell.NEW) { 285 341 while(true) { … … 295 351 error_count = check_for_error(line,error_list,error_count); 296 352 fireMessage(type, typeAsString(type) + "> " + line, status, bos); 297 } 353 } 354 System.err.println("Wants to stop (1)."); 298 355 } 299 356 stdbr.close(); 300 357 301 358 if (error_count>0) { 302 359 status = ERROR; … … 305 362 fireMessage(type, typeAsString(type) + "> " + error_list, status, null); 306 363 } 364 } 365 else if(hasSignalledStop()) { 366 //User pressed the cancel button. 367 //Status already set in hasSignalledStop method. 307 368 } 308 369 else { … … 458 519 } 459 520 460 if (Gatherer.isGsdlRemote) {461 if (type == IMPORT) {462 if (progress!=null) {463 progress.messageOnProgressBar("Uploading data to server");464 }465 466 String collect_directory_path = Gatherer.getCollectDirectoryPath();467 468 // zip up import folder469 Utility.zipup(collect_directory_path, col_name, "import");470 // upload it to gsdl server471 GathererApplet.upload_url_zip(col_name, "import");472 473 // upload etc folder to server (need collect.cfg and any hfiles)474 Utility.zipup(collect_directory_path, col_name, "etc");475 GathererApplet.upload_url_zip(col_name, "etc");476 477 String collection_directory_path = Gatherer.c_man.getCollectionDirectoryPath(col_name);478 File img_dir = new File(Gatherer.c_man.getCollectionImagesDirectoryPath());479 if (img_dir.exists() && img_dir.list().length > 0) {480 // upload images/ directory to server481 Utility.zipup(collect_directory_path, col_name, "images");482 GathererApplet.upload_url_zip(col_name, "images");483 }484 485 // see if collection specific image needs uploading486 CollectionMetaManager cmm487 = CollectionDesignManager.collectionmeta_manager;488 489 CollectionMeta icon_collection_collectionmeta490 = cmm.getMetadatum(CollectionConfiguration.COLLECTIONMETADATA_ICONCOLLECTION_STR);491 CollectionMeta icon_collection_small_collectionmeta492 = cmm.getMetadatum(CollectionConfiguration.COLLECTIONMETADATA_ICONCOLLECTIONSMALL_STR);493 494 String ics_text = icon_collection_collectionmeta.getValue(CollectionMeta.TEXT);495 String icsc_text = icon_collection_small_collectionmeta.getValue(CollectionMeta.TEXT);496 if ((ics_text != null) && (ics_text != "")) {497 // Stub code for detecting when collectoin image changed498 // => need to upload images499 // System.err.println("**** ics_text = " + ics_text);500 }501 502 503 if (progress!=null) {504 progress.messageOnProgressBar("");505 }506 507 }508 }509 510 511 521 // Issue a processBegun event 512 522 fireProcessBegun(type, status); … … 521 531 if (type == NEW) { 522 532 if (Gatherer.isGsdlRemote) { 523 GathererApplet.download_url_zip(col_name,"."); 524 Utility.unzip(Gatherer.getCollectDirectoryPath(), col_name); 533 GathererApplet.download_url_zip(col_name, ".", this); 534 if (!hasSignalledStop()) { 535 Utility.unzip(Gatherer.getCollectDirectoryPath(), col_name); 536 } 525 537 } 526 538 } … … 535 547 536 548 Utility.delete(Gatherer.c_man.getCollectionArchivesDirectoryPath()); // remove current archives 537 GathererApplet.download_url_zip(col_name,"archives"); 538 Utility.unzip(Gatherer.getCollectDirectoryPath(), col_name); 539 540 if (progress!=null) { 541 progress.messageOnProgressBar(""); 542 } 549 GathererApplet.download_url_zip(col_name, "archives", this); 550 if (!hasSignalledStop()) { 551 Utility.unzip(Gatherer.getCollectDirectoryPath(), col_name); 552 } 553 if (progress!=null) { 554 progress.messageOnProgressBar(""); 555 } 543 556 } 544 557 … … 560 573 Utility.delete(buildDir); // remove current build dir 561 574 buildDir.mkdir(); //Make a clean dir 562 GathererApplet.download_url_zip(col_name,"building/build.cfg"); //Only need build.cfg 563 Utility.unzip(Gatherer.getCollectDirectoryPath(), col_name); 564 575 GathererApplet.download_url_zip(col_name, "building/build.cfg", this); //Only need build.cfg 576 if (!hasSignalledStop()) { 577 Utility.unzip(Gatherer.getCollectDirectoryPath(), col_name); 578 } 579 565 580 if (progress!=null) { 566 581 progress.messageOnProgressBar(""); … … 570 585 } 571 586 572 if(hasSignalledStop()) {573 status = CANCELLED;574 }575 587 // We're done. 576 588 fireProcessComplete(type, status); … … 678 690 * @return A <strong>boolean</strong> indicating if the user wanted to stop. 679 691 */ 680 p rivateboolean hasSignalledStop() {692 public boolean hasSignalledStop() { 681 693 boolean has_signalled_stop = false; 682 694 if(progress != null) { 683 695 has_signalled_stop = progress.hasSignalledStop(); 696 } 697 if(has_signalled_stop) { 698 status = CANCELLED; 684 699 } 685 700 return has_signalled_stop; -
trunk/gli/src/org/greenstone/gatherer/util/Utility.java
r9045 r9095 49 49 import org.greenstone.gatherer.DebugStream; 50 50 import org.greenstone.gatherer.Dictionary; 51 import org.greenstone.gatherer.shell.GShell; 51 52 // Don't even think about adding import org.greenstone.gatherer.Gatherer in here! 52 53 // The functions in this class should be independent of the Gatherer class. Put your function somewhere else buster! … … 601 602 } 602 603 603 static protected void zipFunc (ZipOutputStream zos, String file_path, int prefix_strip )604 static protected void zipFunc (ZipOutputStream zos, String file_path, int prefix_strip, GShell source) 604 605 { 605 606 // Using try is required because of file io. 606 607 try { 608 // Exit if pressed cancel. 609 if (source != null && source.hasSignalledStop()) { 610 return; 611 } 607 612 // Create a Zip Entry and put it into the archive (no data yet). 608 613 … … 624 629 // to the zip output stream until the bis has been entirely read. 625 630 while ((byteCount = bis.read(data, 0, 1024)) > -1) { 631 //Check for cancell 632 if(source != null) { 633 if(source.hasSignalledStop()) { 634 break; 635 } 636 } 626 637 zos.write(data, 0, byteCount); 627 638 } … … 634 645 } 635 646 636 static protected void dirFunc (ZipOutputStream zos, String dir_name, int prefix_strip )647 static protected void dirFunc (ZipOutputStream zos, String dir_name, int prefix_strip, GShell source) 637 648 { 638 649 File dirObj = new File(dir_name); … … 645 656 // Loop through File array and display. 646 657 for (int i = 0; i < fileList.length; i++) { 658 if(source != null) { 659 if(source.hasSignalledStop()) { 660 break; 661 } 662 } 647 663 File file = fileList[i]; 648 664 if (file.isDirectory()) { … … 661 677 } 662 678 663 dirFunc(zos,dir_path,prefix_strip );679 dirFunc(zos,dir_path,prefix_strip, source); 664 680 } else if (file.isFile()) { 665 681 // Call the zipFunc function 666 682 String file_path = fileList[i].getPath(); 667 zipFunc(zos,file_path,prefix_strip );683 zipFunc(zos,file_path,prefix_strip, source); 668 684 } 669 685 } … … 680 696 681 697 682 static public void zipup(String col_dir, String col_name, String dir_or_file )698 static public void zipup(String col_dir, String col_name, String dir_or_file, GShell source) 683 699 { 684 700 int prefix_strip = col_dir.length(); … … 695 711 if (zip_dof.isDirectory()) { 696 712 String zip_dir = zip_dir_or_file; 697 dirFunc(zos,zip_dir,prefix_strip );713 dirFunc(zos,zip_dir,prefix_strip, source); 698 714 } 699 715 else { … … 714 730 } 715 731 } 716 zipFunc(zos,zip_full_file,prefix_strip );732 zipFunc(zos,zip_full_file,prefix_strip, source); 717 733 } 718 734 } … … 728 744 catch (IOException exception) { 729 745 DebugStream.printStackTrace(exception); 730 } 746 } 731 747 } 732 748
Note:
See TracChangeset
for help on using the changeset viewer.