- Timestamp:
- 2003-05-27T15:40:47+12:00 (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/util/GSDLSiteConfig.java
r4357 r4364 5 5 6 6 public class GSDLSiteConfig 7 8 9 10 7 extends LinkedHashMap { 8 private File gsdlsite_cfg; 9 private String autoenter_initial; 10 private String start_browser_initial; 11 11 12 13 14 12 static final public String ADD_COMMAND = "a=config&cmd=add-collection&c="; 13 static final public String RELEASE_COMMAND = "a=config&cmd=release-collection&c="; 14 static final public String QUIT_COMMAND = "a="; 15 15 16 17 18 19 20 21 22 23 24 25 26 16 static final private String AUTOENTER = "autoenter"; 17 static final private String COLON = ":"; 18 static final private String ENTERLIB = "enterlib"; 19 static final private String FALSE = "0"; 20 static final private String GSDL = "gsdl"; 21 static final private String GSDLSITE_CFG = "gsdlsite.cfg"; 22 static final private String PORTNUMBER = "portnumber"; 23 static final private String SEPARATOR = "/"; 24 static final private String STARTBROWSER = "start_browser"; 25 static final private String TRUE = "1"; 26 static final private String URL = "url"; 27 27 28 29 30 28 public GSDLSiteConfig(File server_exe) { 29 debug("New GSDLSiteConfig for: " + server_exe.getAbsolutePath()); 30 gsdlsite_cfg = new File(server_exe.getParentFile(), GSDLSITE_CFG); 31 31 32 33 34 35 32 autoenter_initial = null; 33 start_browser_initial = null; 34 load(); 35 } 36 36 37 38 39 37 public boolean exists() { 38 return gsdlsite_cfg.exists(); 39 } 40 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 41 public String getURL() { 42 // URL is made from url and portnumber 43 String url = (String) get(URL); 44 if(url != null) { 45 StringBuffer temp = new StringBuffer(url); 46 temp.append(COLON); 47 temp.append((String)get(PORTNUMBER)); 48 String enterlib = (String)get(ENTERLIB); 49 if(enterlib == null || enterlib.length() == 0) { 50 // Use the default /gsdl and hope for the best. 51 temp.append(SEPARATOR); 52 temp.append(GSDL); 53 } 54 else { 55 if(!enterlib.startsWith(SEPARATOR)) { 56 temp.append(SEPARATOR); 57 } 58 temp.append(enterlib); 59 } 60 enterlib = null; 61 url = temp.toString(); 62 } 63 debug("Found Local Library Address: " + url); 64 return url; 65 } 66 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 67 public void load() { 68 if(gsdlsite_cfg.exists()) { 69 debug("Load: " + gsdlsite_cfg.getAbsolutePath()); 70 clear(); 71 try { 72 BufferedReader in = new BufferedReader(new FileReader(gsdlsite_cfg)); 73 String line = null; 74 while((line = in.readLine()) != null) { 75 String key = null; 76 String value = null; 77 int index = -1; 78 if((index = line.indexOf("=")) != -1 && line.length() >= index + 1) { 79 key = line.substring(0, index); 80 value = line.substring(index + 1); 81 } 82 else { 83 key = line; 84 } 85 put(key, value); 86 } 87 } 88 catch (Exception error) { 89 error.printStackTrace(); 90 } 91 } 92 else { 93 debug("No GSDLsite.cfg file can be found!"); 94 } 95 } 96 96 97 98 99 100 101 102 103 104 97 /** Restore the autoenter value to its initial value, and remove url if present. */ 98 public void restore() { 99 debug("Restore Initial Settings"); 100 put(AUTOENTER, autoenter_initial); 101 put(STARTBROWSER, start_browser_initial); 102 remove(URL); 103 save(); 104 } 105 105 106 107 108 109 110 111 112 113 114 115 116 117 118 106 public void set() { 107 debug("Set Session Settings"); 108 if(autoenter_initial == null) { 109 autoenter_initial = (String) get(AUTOENTER); 110 debug("Remember autoenter was: " + autoenter_initial); 111 } 112 put(AUTOENTER, TRUE); 113 if(start_browser_initial == null) { 114 start_browser_initial = (String) get(STARTBROWSER); 115 debug("Remember start_browser was: " + start_browser_initial); 116 } 117 save(); 118 } 119 119 120 121 122 120 private void debug(String message) { 121 System.err.println(message); 122 } 123 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 124 private void save() { 125 debug("Save: " + gsdlsite_cfg.getAbsolutePath()); 126 try { 127 BufferedWriter out = new BufferedWriter(new FileWriter(gsdlsite_cfg, false)); 128 for(Iterator keys = keySet().iterator(); keys.hasNext(); ) { 129 String key = (String) keys.next(); 130 String value = (String) get(key); 131 out.write(key, 0, key.length()); 132 if(value != null) { 133 out.write('='); 134 out.write(value, 0, value.length()); 135 } 136 out.newLine(); 137 } 138 out.flush(); 139 out.close(); 140 } 141 catch (Exception error) { 142 error.printStackTrace(); 143 } 144 } 145 145 } 146 147 148 149 150
Note:
See TracChangeset
for help on using the changeset viewer.