Changeset 13792
- Timestamp:
- 2007-01-25T13:37:46+13:00 (17 years ago)
- Location:
- trunk/gli/src/org/greenstone/gatherer/greenstone
- Files:
-
- 1 deleted
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/greenstone/LocalLibraryServer.java
r13779 r13792 31 31 import java.lang.*; 32 32 import java.net.*; 33 import java.util.*; 33 34 import javax.swing.*; 34 35 import org.greenstone.gatherer.Configuration; … … 259 260 } 260 261 } 262 263 264 static public class GSDLSiteConfig 265 extends LinkedHashMap { 266 private File gsdlsite_cfg; 267 private File glisite_cfg; 268 private String autoenter_initial; 269 private String start_browser_initial; 270 271 static final private String AUTOENTER = "autoenter"; 272 static final private String COLON = ":"; 273 static final private String ENTERLIB = "enterlib"; 274 static final private String FALSE = "0"; 275 static final private String GLISITE_CFG = "glisite.cfg"; 276 static final private String GSDL = "gsdl"; 277 static final private String GSDLSITE_CFG = "gsdlsite.cfg"; 278 static final private String LOCAL_HOST = "http://localhost"; 279 static final private String PORTNUMBER = "portnumber"; 280 static final private String SEPARATOR = "/"; 281 static final private String SPECIFIC_CONFIG = "--config="; 282 static final private String STARTBROWSER = "start_browser"; 283 static final private String TRUE = "1"; 284 static final private String URL = "url"; 285 286 public GSDLSiteConfig(File server_exe) { 287 debug("New GSDLSiteConfig for: " + server_exe.getAbsolutePath()); 288 gsdlsite_cfg = new File(server_exe.getParentFile(), GSDLSITE_CFG); 289 glisite_cfg = new File(server_exe.getParentFile(), GLISITE_CFG); 290 autoenter_initial = null; 291 start_browser_initial = null; 292 if(gsdlsite_cfg.exists()) { 293 debug("Load: " + gsdlsite_cfg.getAbsolutePath()); 294 clear(); 295 try { 296 BufferedReader in = new BufferedReader(new FileReader(gsdlsite_cfg)); 297 String line = null; 298 while((line = in.readLine()) != null) { 299 String key = null; 300 String value = null; 301 int index = -1; 302 if((index = line.indexOf("=")) != -1 && line.length() >= index + 1) { 303 key = line.substring(0, index); 304 value = line.substring(index + 1); 305 } 306 else { 307 key = line; 308 } 309 put(key, value); 310 } 311 in.close(); 312 } 313 catch (Exception error) { 314 error.printStackTrace(); 315 } 316 } 317 else { 318 debug("No GSDLsite.cfg file can be found!"); 319 } 320 } 321 322 public boolean exists() { 323 return gsdlsite_cfg.exists(); 324 } 325 326 public String getLocalHostURL() { 327 StringBuffer url = new StringBuffer(LOCAL_HOST); 328 url.append(COLON); 329 url.append((String)get(PORTNUMBER)); 330 String enterlib = (String)get(ENTERLIB); 331 if(enterlib == null || enterlib.length() == 0) { 332 // Use the default /gsdl and hope for the best. 333 url.append(SEPARATOR); 334 url.append(GSDL); 335 } 336 else { 337 if(!enterlib.startsWith(SEPARATOR)) { 338 url.append(SEPARATOR); 339 } 340 url.append(enterlib); 341 } 342 enterlib = null; 343 debug("Found Local Library Address: " + url.toString()); 344 return url.toString(); 345 } 346 347 public String getSiteConfigFilename() { 348 return SPECIFIC_CONFIG + glisite_cfg.getAbsolutePath(); 349 } 350 351 public String getURL() { 352 // URL is made from url and portnumber 353 String url = (String) get(URL); 354 if(url != null) { 355 StringBuffer temp = new StringBuffer(url); 356 temp.append(COLON); 357 temp.append((String)get(PORTNUMBER)); 358 String enterlib = (String)get(ENTERLIB); 359 if(enterlib == null || enterlib.length() == 0) { 360 // Use the default /gsdl and hope for the best. 361 temp.append(SEPARATOR); 362 temp.append(GSDL); 363 } 364 else { 365 if(!enterlib.startsWith(SEPARATOR)) { 366 temp.append(SEPARATOR); 367 } 368 temp.append(enterlib); 369 } 370 enterlib = null; 371 url = temp.toString(); 372 } 373 debug("Found Local Library Address: " + url); 374 return url; 375 } 376 377 public void load() { 378 if(glisite_cfg.exists()) { 379 debug("Load: " + glisite_cfg.getAbsolutePath()); 380 clear(); 381 try { 382 BufferedReader in = new BufferedReader(new FileReader(glisite_cfg)); 383 String line = null; 384 while((line = in.readLine()) != null) { 385 String key = null; 386 String value = null; 387 int index = -1; 388 if((index = line.indexOf("=")) != -1 && line.length() >= index + 1) { 389 key = line.substring(0, index); 390 value = line.substring(index + 1); 391 } 392 else { 393 key = line; 394 } 395 put(key, value); 396 } 397 in.close(); 398 } 399 catch (Exception error) { 400 error.printStackTrace(); 401 } 402 } 403 else { 404 debug("No GSDLsite.cfg file can be found!"); 405 } 406 } 407 408 /** Restore the autoenter value to its initial value, and remove url if present. */ 409 public void restore() { 410 if(glisite_cfg != null) { 411 // Delete the file 412 glisite_cfg.delete(); 413 } 414 else { 415 debug("Restore Initial Settings"); 416 put(AUTOENTER, autoenter_initial); 417 put(STARTBROWSER, start_browser_initial); 418 remove(URL); 419 save(); 420 } 421 } 422 423 public void set() { 424 debug("Set Session Settings"); 425 if(autoenter_initial == null) { 426 autoenter_initial = (String) get(AUTOENTER); 427 debug("Remember autoenter was: " + autoenter_initial); 428 } 429 put(AUTOENTER, TRUE); 430 if(start_browser_initial == null) { 431 start_browser_initial = (String) get(STARTBROWSER); 432 debug("Remember start_browser was: " + start_browser_initial); 433 } 434 put(STARTBROWSER, FALSE); 435 save(); 436 } 437 438 private void debug(String message) { 439 ///ystem.err.println(message); 440 } 441 442 private void save() { 443 //debug("Save: " + gsdlsite_cfg.getAbsolutePath()); 444 debug("Save: " + glisite_cfg.getAbsolutePath()); 445 try { 446 //BufferedWriter out = new BufferedWriter(new FileWriter(gsdlsite_cfg, false)); 447 BufferedWriter out = new BufferedWriter(new FileWriter(glisite_cfg, false)); 448 for(Iterator keys = keySet().iterator(); keys.hasNext(); ) { 449 String key = (String) keys.next(); 450 String value = (String) get(key); 451 out.write(key, 0, key.length()); 452 if(value != null) { 453 out.write('='); 454 out.write(value, 0, value.length()); 455 } 456 out.newLine(); 457 } 458 out.flush(); 459 out.close(); 460 } 461 catch (Exception error) { 462 error.printStackTrace(); 463 } 464 } 465 } 261 466 }
Note:
See TracChangeset
for help on using the changeset viewer.