Changeset 4332


Ignore:
Timestamp:
2003-05-26T16:22:56+12:00 (21 years ago)
Author:
jmt12
Message:

bug fix - John

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gli/src/org/greenstone/gatherer/util/GSDLSiteConfig.java

    r4298 r4332  
    22
    33import java.io.*;
    4 import java.util.LinkedHashMap;
     4import java.util.*;
    55
    66public class GSDLSiteConfig
     
    1212     static final private String ENTERLIB = "enterlib";
    1313     static final private String FALSE = "0";
     14     static final private String GSDL = "gsdl";
    1415     static final private String GSDLSITE_CFG = "gsdlsite.cfg";
    1516     static final private String PORTNUMBER = "portnumber";
     
    1819     static final private String URL = "url";
    1920     public GSDLSiteConfig(File server_exe) {
     21         System.err.println("New GSDLSiteConfig for: " + server_exe.getAbsolutePath());
    2022          gsdlsite_cfg = new File(server_exe.getParentFile(), GSDLSITE_CFG);
    2123
    2224          autoenter_initial = null;
    2325          load();
    24           if(autoenter_initial == null) {
    25                 autoenter_initial = get(AUTOENTER);
    26           }
    27           put(AUTOENTER, TRUE);
    28           save();
     26     }
     27
     28     public boolean exists() {
     29          return gsdlsite_cfg.exists();
    2930     }
    3031
    3132     public String getURL() {
    3233          // URL is made from url and portnumber
    33           String url = get(URL);
     34          String url = (String) get(URL);
    3435          if(url != null) {
    3536                StringBuffer temp = new StringBuffer(url);
    3637                temp.append(COLON);
    37                 temp.append(get(PORTNUMBER));
    38                 temp.append(SEPARATOR);
    39                 temp.append(ENTERLIB);
     38                temp.append((String)get(PORTNUMBER));
     39                String enterlib = (String)get(ENTERLIB);
     40                if(enterlib == null || enterlib.length() == 0) {
     41                    // Use the default /gsdl and hope for the best.
     42                    temp.append(SEPARATOR);
     43                    temp.append(GSDL);
     44                }
     45                else {
     46                    if(!enterlib.startsWith(SEPARATOR)) {
     47                        temp.append(SEPARATOR);
     48                    }
     49                    temp.append(enterlib);
     50                }
     51                enterlib = null;
    4052                url = temp.toString();
    4153          }
     54          System.err.println("Found Local Library Address: " + url);
    4255          return url;
    4356     }
    4457
    4558     public void load() {
     59            System.err.println("Load: " + gsdlsite_cfg.getAbsolutePath());
    4660          clear();
    4761          try {
     
    6882
    6983     /** Restore the autoenter value to its initial value, and remove url if present. */
    70      public void restore() {
     84     public void restoreAutoEnter() {
     85         System.err.println("Restore AutoEnter");
    7186          put(AUTOENTER, autoenter_initial);
    7287          remove(URL);
     
    7489     }
    7590
     91     public void setAutoEnter() {
     92         System.err.println("Set AutoEnter.");
     93          if(autoenter_initial == null) {
     94                autoenter_initial = (String) get(AUTOENTER);
     95                System.err.println("Remember autoenter was: " + autoenter_initial);
     96          }
     97          put(AUTOENTER, TRUE);
     98          save();
     99     }
     100
    76101     private void save() {
     102         System.err.println("Save: " + gsdlsite_cfg.getAbsolutePath());
    77103          try {
    78104                BufferedWriter out = new BufferedWriter(new FileWriter(gsdlsite_cfg, false));
    79105                for(Iterator keys = keySet().iterator(); keys.hasNext(); ) {
    80106                     String key = (String) keys.next();
    81                      String value = get(key);
     107                     String value = (String) get(key);
     108                     out.write(key, 0, key.length());
    82109                     if(value != null) {
    83                          
    84                      }
    85                      else {
    86 
     110                          out.write('=');
     111                          out.write(value, 0, value.length());
    87112                     }
    88113                     out.newLine();
     
    96121     }
    97122}
     123
     124
     125
     126
     127
Note: See TracChangeset for help on using the changeset viewer.