- Timestamp:
- 2009-05-20T18:50:16+12:00 (15 years ago)
- Location:
- gli/trunk/src/org/greenstone/gatherer
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
gli/trunk/src/org/greenstone/gatherer/Gatherer.java
r19513 r19544 367 367 368 368 // Check that we now know the Greenstone library URL, since we need this for previewing collections 369 // It is not necessary if an independent GSI was launched and the user hasn't pressed Enter Library yet 369 370 DebugStream.println("Configuration.library_url = " + Configuration.library_url); 370 if (Configuration.library_url == null ) {371 if (Configuration.library_url == null && !LocalLibraryServer.isURLPending()) { 371 372 missingEXEC(); 372 373 } -
gli/trunk/src/org/greenstone/gatherer/greenstone/LocalLibraryServer.java
r19513 r19544 140 140 static public boolean isRunning() 141 141 { 142 if (!running) return false; 142 if (!running) return false; // if the url is pending, then running would also be false (server not started up yet) 143 143 144 llssite_cfg_file.load(true); 144 if (llssite_cfg_file.getURL() == null) return false; 145 String url = llssite_cfg_file.getURL(); 146 if (url == null) return false; 147 148 // Called by Gatherer to check whether we need to stop the server. 149 // if the url is pending, then the GSI hasn't started the server up yet 150 // Already covered in !running 151 //if (url.equals(LLSSiteConfig.URL_PENDING)) return false; 152 145 153 return true; 146 154 } … … 184 192 185 193 llssite_cfg_file = new LLSSiteConfig(local_library_server_file); 186 194 195 // If the user launched the GSI independent of GLI, but user has not pressed 196 // Enter Library yet, then we will obtain the previewURL later. 197 if(LocalLibraryServer.isURLPending()) { 198 // running is still false when the URL is pending because only GSI is running, not the server 199 return; 200 } else if(llssite_cfg_file.isIndependentGSI()) { 201 // there is a url, it's not pending, and it is llssite.cfg: meaning GSI has started up 202 return; 203 } 204 187 205 // Spawn local library server process 188 206 String local_library_server_command = local_library_server_file.getAbsolutePath() + getExtraLaunchArguments(llssite_cfg_file); … … 215 233 // Wait until program has started 216 234 try { 217 testServerRunning(); // will set running = true when the server is up and running successfully 235 testServerRunning(); // will set running = true when the server is up and running successfully 218 236 } catch (IOException bad_url_connection) { 219 237 try { … … 236 254 static public void stop() 237 255 { 238 if (running == false) { 256 if (!running) { 257 // also the case if the URL is pending in an independently launched GSI 258 return; 259 } 260 261 // don't (can't) shutdown the GSI/server if it was launched independent of GLI 262 if(llssite_cfg_file.isIndependentGSI()) { 239 263 return; 240 264 } … … 255 279 llssite_cfg_file.load(false); 256 280 int attempt_count = 0; 257 while (llssite_cfg_file.getURL() != null) { 281 String url = llssite_cfg_file.getURL(); 282 while (url != null && !url.equals(LLSSiteConfig.URL_PENDING)) { // if pending, the server is already stopped (not running) 258 283 new OneSecondWait(); // Wait one second (give or take) 259 284 llssite_cfg_file.load(false); … … 269 294 attempt_count = 0; 270 295 } 296 // read the url again to see if it's updated 297 url = llssite_cfg_file.getURL(); 271 298 } 272 299 … … 275 302 276 303 // If the local server is still running then our changed values will get overwritten. 277 if (llssite_cfg_file.getURL() != null) { 304 url = llssite_cfg_file.getURL(); 305 if (url != null && !url.equals(LLSSiteConfig.URL_PENDING)) { 278 306 JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("Server.QuitManual"), Dictionary.get("General.Error"), JOptionPane.ERROR_MESSAGE); 279 307 } … … 346 374 } 347 375 376 /** Returns true if we're waiting on the user to click on Enter Library button 377 * in an independently launched GSI (one not launched by GLI). */ 378 static public boolean isURLPending() { 379 /*if(Configuration.library_url != null) { 380 System.err.println("**** Configuration.library_url: " + Configuration.library_url ); 381 return false; // don't need to do anything as we already have the url 382 }*/ 383 384 llssite_cfg_file.load(true); // don't force reload, load only if modified 385 386 String url = llssite_cfg_file.getURL(); 387 388 if(url != null) { 389 if(url.equals(LLSSiteConfig.URL_PENDING)) { 390 running = false; // imagine if they restarted an external GSI 391 return true; 392 } else { 393 // a valid URL at last 394 try { 395 Configuration.library_url = new URL(url); 396 running = true; 397 } 398 catch (MalformedURLException exception) { 399 exception.printStackTrace(); 400 DebugStream.printStackTrace(exception); 401 } 402 return false; 403 } 404 } 405 406 // If either the URL is null--which means no independent GSI (Greenstone server interface 407 // app) was launched--or if the 'URL' doesn't say it's pending, then we're not waiting 408 return false; 409 } 410 348 411 static public void checkServerRunning() { 349 if (!running) return; // don't worry about it if it s not supposed to be running412 if (!running) return; // don't worry about it if it's not supposed to be running 350 413 llssite_cfg_file.load(true); // don't force reload, load only if modified 351 414 352 415 String url = llssite_cfg_file.getURL(); 353 416 if(url != null) { … … 357 420 catch (MalformedURLException exception) { 358 421 DebugStream.printStackTrace(exception); 422 exception.printStackTrace(); 359 423 } 360 424 } else { 361 425 // need to restart the server again 362 llssite_cfg_file.set(); 363 426 427 // if we were running an independently launched GSI before, but the GSI has been 428 // exited, it would need to be relaunched, but from within GLI (dependent) this time. 429 if(llssite_cfg_file.isIndependentGSI()) { 430 // first save the current configFile (llssite.cfg), then set to use glisite.cfg 431 llssite_cfg_file.save(); 432 llssite_cfg_file.relaunchAsDependentGSI(local_library_server_file); 433 } else { 434 // We were using glisite.cfg before, don't need to swap config files 435 llssite_cfg_file.set(); 436 } 364 437 // Spawn local library server process 365 438 String local_library_server_command = local_library_server_file.getAbsolutePath() + getExtraLaunchArguments(llssite_cfg_file); … … 391 464 392 465 static public class LLSSiteConfig 393 extends LinkedHashMap { 466 extends LinkedHashMap 467 { 468 private File configFile; 469 394 470 private File llssite_cfg; 395 471 private File glisite_cfg; … … 414 490 static final private String URL = "url"; 415 491 492 static final public String URL_PENDING = "URL_pending"; 493 416 494 public LLSSiteConfig(File server_exe) { 417 495 debug("New LLSSiteConfig for: " + server_exe.getAbsolutePath()); … … 420 498 glisite_cfg = new File(server_exe.getParentFile(), GLISITE_CFG); 421 499 422 File configFile = null; 500 configFile = null; 501 502 autoenter_initial = null; 503 start_browser_initial = null; 504 505 // first test if server was started independently of GLI 506 // if so, the config file we'd be using would be llssite.cfg 507 if(!usingLLS_configFile()) { // if we were using llssite_cfg, this would have loaded it in 508 // else we try using the glisite configfile 509 useGLISiteCfg(server_exe); 510 } 511 512 if(configFile != null && configFile.exists()) { 513 System.err.println("Using configfile: " + configFile); 514 lastModified = configFile.lastModified(); 515 } 516 } 517 518 /** Tries to get a glisite.cfg file and then loads it, setting it as the configFile */ 519 public void useGLISiteCfg(File server_exe) { 423 520 if(!glisite_cfg.exists()) { // create it from the templates or the llssite.cfg file 424 521 425 522 File llssite_cfg_in = new File(server_exe.getParentFile(), LLSSITE_CFG+".in"); 426 523 File glisite_cfg_in = new File(server_exe.getParentFile(), GLISITE_CFG+".in"); 427 524 428 525 // need to generate glisite_cfg from glisite_cfg_in, llssite_cfg or llssite.cfg.in 429 526 if(glisite_cfg_in.exists()) { … … 441 538 } 442 539 } 443 540 // use the config file now 444 541 if(glisite_cfg.exists()) { 445 542 configFile = glisite_cfg; 543 load(false); // force reload 446 544 } 447 448 autoenter_initial = null; 449 start_browser_initial = null; 450 if(configFile != null) { 545 } 546 547 /** Tests whether the server interface is up, running independently of GLI 548 * If so, we don't need to launch the server interface. 549 * The server interface may not have started up the server itself though 550 * (in which case the server URL would be URL_PENDING). 551 * This method returns true if the server interface has already started 552 * and, if so, it would have loaded in the llssite_cfg configFile. 553 */ 554 private boolean usingLLS_configFile() { 555 if(!llssite_cfg.exists()) { 556 return false; 557 } 558 559 // check if the configfile contains the URL line 560 configFile = llssite_cfg; 561 load(false); // force load 562 563 if(getURL() == null) { 564 configFile = null; 565 clear(); // we're not using llssite_cfg, so clear the values we just read 566 return false; 567 } 568 569 //System.err.println("***** we're using llssite_configfile, url:" + getURL()); 570 return true; 571 } 572 573 /** @return true if GSI was started up independently and outside of GLI. 574 * In such a case, GLI would be using llssite_cfg. */ 575 public boolean isIndependentGSI() { 576 return (configFile == llssite_cfg); 577 } 578 579 /** Call this when an independently launched GSI server has been stopped 580 * (one using llssite_cfg) and GLI needs to next launch another server. 581 * In such a case, since GLI itself is relaunching the GSI, we use glisite_cfg. 582 */ 583 public void relaunchAsDependentGSI(File server_exe) { 584 useGLISiteCfg(server_exe); 585 } 586 587 public boolean exists() { 588 return configFile.exists(); 589 } 590 591 public String getLocalHostURL() { 592 StringBuffer url = new StringBuffer(LOCAL_HOST); 593 url.append(COLON); 594 url.append((String)get(PORTNUMBER)); 595 String enterlib = (String)get(ENTERLIB); 596 if(enterlib == null || enterlib.length() == 0) { 597 // Use the default /gsdl and hope for the best. 598 url.append(SEPARATOR); 599 url.append(GSDL); 600 } 601 else { 602 if(!enterlib.startsWith(SEPARATOR)) { 603 url.append(SEPARATOR); 604 } 605 url.append(enterlib); 606 } 607 enterlib = null; 608 debug("Found Local Library Address: " + url.toString()); 609 return url.toString(); 610 } 611 612 /** @return the cmd-line parameter for the configfile used to launch 613 * the server through GLI: --config <glisite.cfg/llssite.cfg file path>. */ 614 public String getSiteConfigFilename() { 615 return SPECIFIC_CONFIG + configFile.getAbsolutePath(); 616 } 617 618 public String getURL() { 619 // URL is made from url and portnumber 620 String url = (String) get(URL); 621 622 // server interface is already up, independent of GLI 623 // but it has not started the server (hence URL is pending) 624 if(url != null && url.equals(URL_PENDING)) { 625 return url; 626 } 627 628 if(!Utility.isWindows()) { 629 return url; 630 } 631 632 if(url != null) { 633 StringBuffer temp = new StringBuffer(url); 634 temp.append(COLON); 635 temp.append((String)get(PORTNUMBER)); 636 String enterlib = (String)get(ENTERLIB); 637 if(enterlib == null || enterlib.length() == 0) { 638 // Use the default /greenstone prefix and hope for the best. 639 temp.append(SEPARATOR); 640 temp.append(GSDL); 641 } 642 else { 643 if(!enterlib.startsWith(SEPARATOR)) { 644 temp.append(SEPARATOR); 645 } 646 temp.append(enterlib); 647 } 648 enterlib = null; 649 url = temp.toString(); 650 } 651 debug("Found Local Library Address: " + url); 652 return url; 653 } 654 655 public boolean isModified() { 656 return (lastModified != configFile.lastModified()); 657 } 658 659 public void load(boolean reloadOnlyIfModified) { 660 661 if(configFile == null) { 662 debug(configFile.getAbsolutePath() + " cannot be found!"); 663 } 664 665 if(isModified()) { 666 lastModified = configFile.lastModified(); 667 } else if(reloadOnlyIfModified) { 668 return; // asked to reload only if modified. Don't reload since not modified 669 } 670 671 if(configFile.exists()) { 451 672 debug("Load: " + configFile.getAbsolutePath()); 452 673 clear(); … … 473 694 } 474 695 } 475 476 if(glisite_cfg.exists()) {477 lastModified = glisite_cfg.lastModified();478 }479 }480 481 public boolean exists() {482 return llssite_cfg.exists();483 }484 485 public String getLocalHostURL() {486 StringBuffer url = new StringBuffer(LOCAL_HOST);487 url.append(COLON);488 url.append((String)get(PORTNUMBER));489 String enterlib = (String)get(ENTERLIB);490 if(enterlib == null || enterlib.length() == 0) {491 // Use the default /gsdl and hope for the best.492 url.append(SEPARATOR);493 url.append(GSDL);494 }495 696 else { 496 if(!enterlib.startsWith(SEPARATOR)) { 497 url.append(SEPARATOR); 498 } 499 url.append(enterlib); 500 } 501 enterlib = null; 502 debug("Found Local Library Address: " + url.toString()); 503 return url.toString(); 504 } 505 506 public String getSiteConfigFilename() { 507 return SPECIFIC_CONFIG + glisite_cfg.getAbsolutePath(); 508 } 509 510 public String getURL() { 511 // URL is made from url and portnumber 512 String url = (String) get(URL); 513 514 if(!Utility.isWindows()) { 515 return url; 516 } 517 518 if(url != null) { 519 StringBuffer temp = new StringBuffer(url); 520 temp.append(COLON); 521 temp.append((String)get(PORTNUMBER)); 522 String enterlib = (String)get(ENTERLIB); 523 if(enterlib == null || enterlib.length() == 0) { 524 // Use the default /gsdl and hope for the best. 525 temp.append(SEPARATOR); 526 temp.append(GSDL); 527 } 528 else { 529 if(!enterlib.startsWith(SEPARATOR)) { 530 temp.append(SEPARATOR); 531 } 532 temp.append(enterlib); 533 } 534 enterlib = null; 535 url = temp.toString(); 536 } 537 debug("Found Local Library Address: " + url); 538 return url; 539 } 540 541 public boolean isModified() { 542 return (lastModified != glisite_cfg.lastModified()); 543 } 544 545 public void load(boolean reloadOnlyIfModified) { 546 547 if(isModified()) { 548 lastModified = glisite_cfg.lastModified(); 549 } else if(reloadOnlyIfModified) { 550 return; // asked to reload only if modified. Don't reload since not modified 551 } 552 553 if(glisite_cfg.exists()) { 554 debug("Load: " + glisite_cfg.getAbsolutePath()); 555 clear(); 556 try { 557 BufferedReader in = new BufferedReader(new FileReader(glisite_cfg)); 558 String line = null; 559 while((line = in.readLine()) != null) { 560 String key = null; 561 String value = null; 562 int index = -1; 563 if((index = line.indexOf("=")) != -1 && line.length() >= index + 1) { 564 key = line.substring(0, index); 565 value = line.substring(index + 1); 566 } 567 else { 568 key = line; 569 } 570 put(key, value); 571 } 572 in.close(); 573 } 574 catch (Exception error) { 575 error.printStackTrace(); 576 } 577 } 578 else { 579 debug("No glisite.cfg file can be found!"); 697 debug(configFile.getAbsolutePath() + " cannot be found!"); 580 698 } 581 699 } … … 583 701 /** Restore the autoenter value to its initial value, and remove url if present. */ 584 702 public void restore() { 585 if( glisite_cfg!= null) {703 if(configFile != null) { 586 704 // Delete the file 587 glisite_cfg.delete();705 configFile.delete(); 588 706 } 589 707 else { … … 617 735 private void save() { 618 736 //debug("Save: " + llssite_cfg.getAbsolutePath()); 619 debug("Save: " + glisite_cfg.getAbsolutePath());737 debug("Save: " + configFile.getAbsolutePath()); 620 738 try { 621 739 //BufferedWriter out = new BufferedWriter(new FileWriter(llssite_cfg, false)); 622 BufferedWriter out = new BufferedWriter(new FileWriter( glisite_cfg, false));740 BufferedWriter out = new BufferedWriter(new FileWriter(configFile, false)); 623 741 for(Iterator keys = keySet().iterator(); keys.hasNext(); ) { 624 742 String key = (String) keys.next(); … … 627 745 if(value != null) { 628 746 out.write('='); 629 out.write(value, 0, value.length()); 747 748 // if the server is using llssite.cfg, don't overwrite its default 749 // autoenter and startbrowser values 750 if(configFile == llssite_cfg && (key == AUTOENTER || key == STARTBROWSER)) { 751 if(key == AUTOENTER) { 752 out.write(autoenter_initial, 0, autoenter_initial.length()); 753 } else { // STARTBROWSER 754 out.write(start_browser_initial, 0, start_browser_initial.length()); 755 } 756 } else { 757 out.write(value, 0, value.length()); 758 } 630 759 } 631 760 out.newLine(); -
gli/trunk/src/org/greenstone/gatherer/gui/PreviewButton.java
r19513 r19544 35 35 import javax.swing.*; 36 36 import org.greenstone.gatherer.Configuration; 37 import org.greenstone.gatherer.Dictionary; 37 38 import org.greenstone.gatherer.Gatherer; 38 39 import org.greenstone.gatherer.collection.CollectionManager; … … 134 135 Gatherer.c_man.saveCollection(); 135 136 136 configureHomeURL(); 137 if(LocalLibraryServer.isURLPending()) { 138 // Remind the user to press Enter Library, and return from this method 139 JOptionPane.showMessageDialog(Gatherer.g_man, 140 Dictionary.get("General.LLS_Not_Started"), 141 Dictionary.get("General.LLS_Not_Started_Title"), 142 JOptionPane.ERROR_MESSAGE); 143 return; 144 145 } else { 146 configureHomeURL(); 147 } 137 148 138 149 if (Gatherer.GS3) {
Note:
See TracChangeset
for help on using the changeset viewer.