Changeset 24505 for main/trunk/gli/src
- Timestamp:
- 2011-08-27T19:47:40+12:00 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/gli/src/org/greenstone/gatherer/greenstone/LocalLibraryServer.java
r24499 r24505 1 /**2 1 /** 3 2 *############################################################################ … … 237 236 return true; 238 237 } else if(llssite_cfg_file.isIndependentGSI()) { 239 // there is a url, it's not pending, and it is llssite.cfg: meaning GSI has started up 238 // There is already a url and it's not pending: meaning the server 239 // has started up and that GSI was launched outside of GLI 240 240 running = true; 241 241 return true; … … 254 254 // If it is already running then set the Greenstone web server address and we're done 255 255 // E.g. if previously GLI was not properly shut down, the URL property (signifying 256 // the server is still running) would still be in the glisite_cfg file.256 // the server is still running) would still be in the config file. 257 257 try { 258 258 Configuration.library_url = new URL(url); … … 582 582 } 583 583 } 584 else { // NO URL in current ConfigFile, check the other configfile for a URL 585 // to see if the server was restarted using that file. 586 // Otherwise need to restart the server again with GLIsite.cfg 587 llssite_cfg_file.save(); // save the configfile, because we may be reloading another 588 589 if(llssite_cfg_file.usingLLS_configFile()) { // if a GSI is already using llssite_cfg, this would have loaded it in 584 else { // NO URL in current mode of configFile, try other mode (e.g. "gli.url") 585 586 if(llssite_cfg_file.usingGSImode()) { // if a GSI is already using llssite_cfg, this would have loaded it in 590 587 url = llssite_cfg_file.getURL(); //if(isURLPending()) { 591 588 if(url.equals(LLSSiteConfig.URL_PENDING)) { … … 597 594 } else { 598 595 // else we try using the glisite configfile 599 llssite_cfg_file.useGLI SiteCfg(local_library_server_file);596 llssite_cfg_file.useGLImode(); 600 597 //llssite_cfg_file.set(); 601 598 602 599 // since we're going to restart the server, make sure to reset all 603 600 // the client socket and its writer (for communicating with the web server) … … 657 654 private File configFile; 658 655 659 private File llssite_cfg;660 private File glisite_cfg;661 656 private String autoenter_initial; 662 657 private String start_browser_initial; 663 658 664 659 private long lastModified = 0; 665 660 private boolean isIndependentGSI; 661 666 662 static final private String GLI_PREFIX = "gli"; 667 663 static final private String GSI_AUTOENTER = "autoenter"; … … 670 666 static final private String ENTERLIB = "enterlib"; 671 667 static final private String FALSE = "0"; 672 static final private String GLISITE_CFG = "glisite.cfg";673 668 static final private String GSDL = "greenstone"; // httpprefix is no longer /gsdl but /greenstone 674 669 static final private String LLSSITE_CFG = "llssite.cfg"; … … 680 675 static final private String GSI_STARTBROWSER = "start_browser"; 681 676 static final private String TRUE = "1"; 682 static final private String URL = "url"; 677 static final private String URL = GLI_PREFIX+"."+"url"; 678 static final private String GSI_URL = "url"; 683 679 static final private String COLLECTHOME = "collecthome"; 684 680 static final private String GLIMODE = "--mode="+GLI_PREFIX; … … 689 685 public LLSSiteConfig(File server_exe) { 690 686 debug("New LLSSiteConfig for: " + server_exe.getAbsolutePath()); 691 692 llssite_cfg = new File(server_exe.getParentFile(), LLSSITE_CFG); 693 glisite_cfg = new File(server_exe.getParentFile(), GLISITE_CFG); 694 695 configFile = null; 687 688 configFile = new File(server_exe.getParentFile(), LLSSITE_CFG); 689 if(!configFile.exists()) { // create it from the template 690 File llssite_cfg_in = new File(server_exe.getParentFile(), LLSSITE_CFG+".in"); 691 692 // need to generate llssite_cfg from llssite_cfg_in 693 if(llssite_cfg_in.exists()) { 694 copyConfigFile(llssite_cfg_in, configFile, true); // adjust for gli 695 } 696 else { 697 debug("File llssite.cfg.in can't be found. Can't create llssite.cfg frrom llssite.cfg.in."); 698 } 699 } 700 701 // use the config file now 702 if(configFile.exists()) { 703 // first test if server was started independently of GLI 704 // if so, the config file we'd be using would be llssite.cfg 705 if(!usingGSImode()) { // if we were using llssite_cfg, this would have loaded it in 706 // else we try using the glisite configfile 707 useGLImode(); 708 } 709 710 } else { 711 System.err.println("**** ERROR. Configfile is null."); 712 configFile = null; 713 } 696 714 697 715 autoenter_initial = null; 698 716 start_browser_initial = null; 699 700 // first test if server was started independently of GLI701 // if so, the config file we'd be using would be llssite.cfg702 if(!usingLLS_configFile()) { // if we were using llssite_cfg, this would have loaded it in703 // else we try using the glisite configfile704 useGLISiteCfg(server_exe);705 }706 717 707 718 // GS2. We're in the constructor, so we'll be running the LLS the first time … … 733 744 734 745 /** Tries to get a glisite.cfg file and then loads it, setting it as the configFile */ 735 public void useGLI SiteCfg(File server_exe)746 public void useGLImode() 736 747 { 737 if(!glisite_cfg.exists()) { // create it from the templates or the llssite.cfg file 738 739 File llssite_cfg_in = new File(server_exe.getParentFile(), LLSSITE_CFG+".in"); 740 File glisite_cfg_in = new File(server_exe.getParentFile(), GLISITE_CFG+".in"); 741 742 // need to generate glisite_cfg from glisite_cfg_in, llssite_cfg or llssite.cfg.in 743 if(glisite_cfg_in.exists()) { 744 copyConfigFile(glisite_cfg_in, glisite_cfg, false); 745 } 746 else if(llssite_cfg_in.exists()) { 747 copyConfigFile(llssite_cfg_in, glisite_cfg_in, true); // adjust for glisite.cfg 748 copyConfigFile(glisite_cfg_in, glisite_cfg, false); 749 } 750 else if(llssite_cfg.exists()) { 751 copyConfigFile(llssite_cfg, glisite_cfg, true); // adjust for glisite.cfg 752 } 753 else { 754 debug("Neither the file glisite.cfg nor llssite.cfg can be found!"); 755 } 756 } 757 // use the config file now 758 if(glisite_cfg.exists()) { 759 configFile = glisite_cfg; 760 load(false); // force reload 761 lastModified = configFile.lastModified(); 762 } 748 isIndependentGSI = false; 749 load(true); // reload if modified 763 750 } 764 751 … … 770 757 * and, if so, it would have loaded in the llssite_cfg configFile. 771 758 */ 772 public boolean usingLLS_configFile() { 773 if(!llssite_cfg.exists()) { 774 return false; 775 } 776 777 // Now to check if the configfile contains the URL line 778 configFile = llssite_cfg; 759 public boolean usingGSImode() { 760 // Now to check if the configfile contains the GSI_URL line 779 761 load(false); // force load 780 762 isIndependentGSI = true; 781 763 if(getURL() == null) { 782 configFile = null; 783 clear(); // we're not using llssite_cfg, so clear the values we just read 784 return false; 764 isIndependentGSI = false; 765 return false; 785 766 } 786 767 … … 797 778 * In such a case, GLI would be using llssite_cfg. */ 798 779 public boolean isIndependentGSI() { 799 return (configFile == llssite_cfg);780 return isIndependentGSI; 800 781 } 801 782 … … 832 813 833 814 public String getURL() { 815 String urlPropertyName = isIndependentGSI() ? GSI_URL : URL; 834 816 // URL is made from url and portnumber 835 String url = (String) get( URL);817 String url = (String) get(urlPropertyName); 836 818 837 819 // server interface is already up, independent of GLI … … 928 910 } 929 911 else { 912 String urlPropertyName = isIndependentGSI() ? GSI_URL : URL; 930 913 debug("Restore Initial Settings"); 931 914 put(AUTOENTER, autoenter_initial); 932 915 put(STARTBROWSER, start_browser_initial); 933 remove( URL);916 remove(urlPropertyName); 934 917 save(); 935 918 } … … 956 939 957 940 private void save() { 958 //debug("Save: " + llssite_cfg.getAbsolutePath());959 941 debug("Save: " + configFile.getAbsolutePath()); 960 942 try { 961 //BufferedWriter out = new BufferedWriter(new FileWriter(llssite_cfg, false));962 943 BufferedWriter out = new BufferedWriter(new FileWriter(configFile, false)); 963 944 for(Iterator keys = keySet().iterator(); keys.hasNext(); ) { … … 968 949 out.write('='); 969 950 970 // if the server is using llssite.cfg, don't overwrite its default951 // if the GSI was launched outside of GLI, don't overwrite its default 971 952 // autoenter and startbrowser values 972 if( configFile == llssite_cfg&& (key == GSI_AUTOENTER || key == GSI_STARTBROWSER)) {953 if(isIndependentGSI && (key == GSI_AUTOENTER || key == GSI_STARTBROWSER)) { 973 954 if(key == GSI_AUTOENTER) { 974 955 out.write(autoenter_initial, 0, autoenter_initial.length()); … … 994 975 // dest_cfg file should not yet exist 995 976 // If setToGliSiteDefaults is true, then GLIsite.cfg's default configuration 996 // is applied to concerned lines: autoenter=1, andstartbrowser=0977 // is applied to concerned lines: gli.autoenter=1, and gli.startbrowser=0 997 978 998 979 try {
Note:
See TracChangeset
for help on using the changeset viewer.