Changeset 20604 for greenstone3

Show
Ignore:
Timestamp:
15.09.2009 20:16:08 (11 years ago)
Author:
ak19
Message:

Changes to Server.jar files and affected files to add address_resolution options so that the GSI dialog for GS2 looks and behaves more like server.exe.

Location:
greenstone3/trunk/src/java/org/greenstone/server
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • greenstone3/trunk/src/java/org/greenstone/server/BaseServerSettings.java

    r18969 r20604  
    2626    protected Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); 
    2727 
    28     static final private Dimension SIZE = new Dimension(300, 350); 
     28    static final private Dimension SIZE = new Dimension(300, 450); 
    2929    static final Color bg_color = Color.white;  
    3030 
     
    111111    port_panel.setBackground(bg_color); 
    112112 
     113    JPanel top_panel = new JPanel(new GridLayout(2,1)); 
     114    top_panel.add(port_panel); 
     115    top_panel.add(autoEnter); 
     116 
    113117    JPanel comb_panel = createServletPanel(); 
    114118    comb_panel.setBackground(bg_color); 
    115          
    116     JPanel check_panel = new JPanel();  
    117         check_panel.setLayout(new FlowLayout(FlowLayout.LEFT)); 
    118         check_panel.add(autoEnter); 
    119         check_panel.setBackground(bg_color); 
    120119 
    121120    JPanel mid_panel = new JPanel(); 
    122         mid_panel.setLayout(new GridLayout(3,1)); 
    123     mid_panel.add(port_panel); 
    124     mid_panel.add(check_panel); 
    125     mid_panel.add(comb_panel); 
     121    mid_panel.setLayout(new BorderLayout()); 
     122    mid_panel.add(top_panel, BorderLayout.NORTH); 
     123    mid_panel.add(comb_panel, BorderLayout.CENTER); 
    126124    mid_panel.setBackground(bg_color); 
    127125    mid_panel.setBorder(BorderFactory.createEmptyBorder(5,10,5,10)); 
     
    181179 
    182180 
    183     protected String onSave() { return ""; } 
     181    protected boolean[] onSave() { 
     182    boolean[] returnValues = { false, false }; // hasChanged, requireRestart 
     183    return returnValues; 
     184    } 
    184185    protected void save(ScriptReadWrite scriptReadWrite, ArrayList newFileLines) {} 
    185186    protected abstract JPanel createServletPanel(); 
     
    223224    public void actionPerformed(ActionEvent ev) { 
    224225        // save everything to config_properties if things have changed 
    225          boolean has_changed = false; 
    226              boolean require_restart = false; 
     226        boolean has_changed = false; 
     227            boolean require_restart = false; 
     228 
    227229        if (portNum != ((Integer)portNumber_spinner.getValue()).intValue()) { 
    228230        has_changed = true; 
    229                 require_restart = true;  
     231                require_restart = true; 
    230232                server.reconfigRequired(); 
    231233                portNum = ((Integer)portNumber_spinner.getValue()).intValue(); 
     
    236238        } 
    237239 
    238         // call subclass' onSave method 
    239         String result = onSave(); 
    240         if(result.indexOf("changed") != -1) { 
    241         has_changed = true; 
    242         } 
    243         if(result.indexOf("restart") != -1) { 
    244         require_restart = true; 
    245         } 
     240        // call subclass' onSave method, which may indicate (further) changes, 
     241        // and which may or may not require a restart 
     242        boolean[] returnValues = onSave(); 
     243        has_changed = has_changed || returnValues[0]; 
     244        require_restart = require_restart || returnValues[1]; 
    246245 
    247246            //changed to use other browser 
     
    251250        }  
    252251        //the browser path has been changed  
    253         if ( !useDefaultBrowser && !browserPath.equals(program_path_field.getText())){ 
     252        if (!useDefaultBrowser && !browserPath.equals(program_path_field.getText())){ 
    254253        browserPath = program_path_field.getText(); 
    255          has_changed = true; 
     254        has_changed = true; 
    256255        } 
    257256         
    258257            //changed to use the default browser 
    259         if ( default_browser_button.isSelected() && !useDefaultBrowser){ 
     258        if (default_browser_button.isSelected() && !useDefaultBrowser){ 
    260259        browserPath = ""; 
    261260        has_changed = true; 
     
    286285        server.reload(); // work out the URL again in case it has changed 
    287286        if (require_restart){ 
    288             JOptionPane.showMessageDialog(null,server.dictionary.get("ServerSetting.SettingChanged"),"Info", JOptionPane.INFORMATION_MESSAGE); 
     287            JOptionPane.showMessageDialog(null,server.dictionary.get("ServerSettings.SettingChanged"),"Info", JOptionPane.INFORMATION_MESSAGE); 
    289288            if(autoStart) { 
    290289            server.autoStart(); 
  • greenstone3/trunk/src/java/org/greenstone/server/Server2.java

    r20433 r20604  
    186186    String suffix = "/cgi-bin/library.cgi"; 
    187187 
    188     // get the prefix from the gsdlsite.cfg and build.properties files 
    189     // (port number and servername) 
     188    // get the prefix from the gsdlsite.cfg and build.properties files (port number and servername) 
    190189    try{ 
    191190        File gsdlsite_cfg = new File(gsdl_home + File.separator + "cgi-bin" + File.separator + "gsdlsite.cfg"); 
     
    208207        //reloadConfigProperties(); 
    209208        port = config_properties.getProperty("portnumber", port); 
     209        host = config_properties.getProperty("host", host); 
     210 
    210211    } catch(Exception e) { 
    211212        recordError("Exception trying to load properties from gsdlsite_cfg. Using default library prefix.", e); 
  • greenstone3/trunk/src/java/org/greenstone/server/Server2Settings.java

    r18969 r20604  
    22 
    33import java.awt.BorderLayout; 
     4import java.awt.FlowLayout; 
     5import java.awt.GridLayout; 
    46import java.awt.event.*; 
     7import java.net.InetAddress; 
     8import java.net.UnknownHostException; 
    59import java.util.ArrayList; 
    610import javax.swing.*; 
     
    913import org.greenstone.server.BaseServerSettings; 
    1014 
    11 public class Server2Settings extends BaseServerSettings implements ChangeListener, ActionListener 
     15public class Server2Settings extends BaseServerSettings implements ActionListener 
    1216{ 
    1317    protected JComboBox prefix_combobox; 
     18    protected JCheckBox allowConnections; 
     19    protected JRadioButton[] hostRadioButtons = new JRadioButton[4]; 
     20 
     21    // 0 to 3: 0 is resolve (hostname) from local IP, 1 is local IP address, 2 is localhost, 3 is 127.0.0.1 
     22    protected int address_resolution_method = 2; 
     23    protected int externalaccess = 0; 
    1424 
    1525    public Server2Settings(BaseServer server)  
    1626    { 
    17     super(server); 
     27    super(server);   
    1828    } 
    1929 
    2030    protected JPanel createServletPanel() 
    2131    { 
    22     portNumber_spinner.addChangeListener(this); 
     32    JPanel server2panel = new JPanel(); 
     33    server2panel.setLayout(new BorderLayout()); 
    2334 
    24     JLabel prefix_label = new JLabel(server.dictionary.get(BaseServer.Property.SERVER_SETTINGS+".URL")); 
     35    boolean allowCons = false; 
     36    String externalAccess = server.config_properties.getProperty("externalaccess").trim(); 
     37    if(externalAccess != null && externalAccess.equals("1")) { 
     38        this.externalaccess = 1; 
     39        allowCons = true; 
     40    } 
     41    allowConnections = new JCheckBox(server.dictionary.get(BaseServer.Property.SERVER_SETTINGS+".ExternalAccess"), allowCons); 
     42    allowConnections.setBackground(bg_color); 
     43    allowConnections.addActionListener(this); 
     44     
     45    JPanel connect_panel = new JPanel(new GridLayout(4, 1)); 
     46    connect_panel.setBackground(bg_color); 
     47    connect_panel.setBorder(BorderFactory.createTitledBorder("Connection configuration")); 
    2548 
    26     prefix_combobox = new JComboBox(); 
    27     prefix_combobox.setEditable(true); 
    28     prefix_combobox.addItem(server.getBrowserURL()); 
    29     prefix_combobox.addActionListener(this); 
     49    hostRadioButtons = new JRadioButton[4]; 
     50    hostRadioButtons[0] = new JRadioButton(server.dictionary.get(BaseServer.Property.SERVER_SETTINGS+".ResolveIP")); 
     51    hostRadioButtons[1] = new JRadioButton(server.dictionary.get(BaseServer.Property.SERVER_SETTINGS+".LocalIP")); 
     52    hostRadioButtons[2] = new JRadioButton(server.dictionary.get(BaseServer.Property.SERVER_SETTINGS+".AlwaysUse")+" localhost"); 
     53    hostRadioButtons[3] = new JRadioButton(server.dictionary.get(BaseServer.Property.SERVER_SETTINGS+".AlwaysUse")+" 127.0.0.1"); 
    3054 
    31     JPanel comb_panel = new JPanel(); 
    32     comb_panel.setLayout(new BorderLayout()); 
    33     comb_panel.add(prefix_label, BorderLayout.NORTH); 
    34     comb_panel.add(prefix_combobox, BorderLayout.CENTER); 
     55    ButtonGroup hostGroup = new ButtonGroup(); 
     56    for(int i = 0; i < hostRadioButtons.length; i ++) { 
     57        connect_panel.add(hostRadioButtons[i]); 
     58        hostGroup.add(hostRadioButtons[i]); 
     59        hostRadioButtons[i].setBackground(bg_color); 
     60        hostRadioButtons[i].setEnabled(!allowCons); 
     61    } 
     62     
     63 
     64    String addressResolutionMethod = server.config_properties.getProperty("address_resolution_method").trim(); 
     65    if(addressResolutionMethod != null) { 
     66        this.address_resolution_method = Integer.parseInt(addressResolutionMethod); 
     67    } 
     68    hostRadioButtons[address_resolution_method].setSelected(true); 
     69 
     70    JPanel comb_panel = new JPanel(new BorderLayout());  
     71    comb_panel.add(allowConnections, BorderLayout.NORTH); 
     72    comb_panel.add(connect_panel, BorderLayout.CENTER); 
    3573    return comb_panel; 
    3674    } 
    3775 
    38     public String onSave()  
     76    public boolean[] onSave() 
    3977    { 
    40     String result = ""; 
    41     if (!server.getBrowserURL().equals(prefix_combobox.getSelectedItem())) { 
    42         result += "changed"; 
    43         result += "restart"; 
     78    // superclass detects changes to port and autoenter 
     79    // handle changes to address_resolution_method and externalAccess/allowConnections here 
     80 
     81    boolean hasChanged = false; 
     82    boolean requireRestart = false; 
     83     
     84    for(int i = 0; i < hostRadioButtons.length; i++) { 
     85        if(hostRadioButtons[i].isSelected() && address_resolution_method != i) { 
     86        address_resolution_method = i; 
     87        hasChanged = true; 
     88        requireRestart = true; 
     89        } 
    4490    } 
    45     return result; 
     91 
     92    int oldExternalAccess = externalaccess; 
     93    externalaccess = allowConnections.isSelected() ? 1 : 0; 
     94    if (oldExternalAccess != externalaccess) { 
     95        hasChanged = true; 
     96        requireRestart = true; 
     97    } 
     98 
     99    boolean[] returnValues = { hasChanged, requireRestart }; 
     100    return returnValues; 
    46101    } 
    47102 
    48103    public void save(ScriptReadWrite scriptReadWrite, ArrayList newFileLines)  
    49104    { 
     105    // write only 1 or 0 (and not true or false) for Server2 
    50106    boolean auto_enter = autoEnter.isSelected(); 
    51107    if(autoStart != auto_enter) { 
     
    53109        newFileLines = scriptReadWrite.queryReplace(newFileLines, BaseServer.Property.AUTOSTART, newAutoEnter); 
    54110    } 
    55     } 
    56111 
    57     public void stateChanged(ChangeEvent e) { 
    58     int portNumber = ((Integer)portNumber_spinner.getValue()).intValue(); 
    59     String url = (String)prefix_combobox.getSelectedItem(); 
    60     url.replace('\\', '/'); 
    61     String pre = ""; 
    62     if(url.indexOf("http://") != -1) { 
    63         pre = "http://"; 
    64         url = url.substring(7); 
     112    // external access - onSave() would have updated this value 
     113    newFileLines = scriptReadWrite.queryReplace(newFileLines, "externalaccess", Integer.toString(externalaccess)); 
     114     
     115    // work out the host (default is address_resolution_method 2: localhost) 
     116    String host = "localhost"; 
     117    InetAddress inetAddress = null; 
     118    try { 
     119        inetAddress = InetAddress.getLocalHost(); 
     120    } catch(UnknownHostException e) { 
     121        logger.error(e); 
     122        logger.info("Server2.java reload(): Defaulting host IP to "+ host); // use the default       
     123        address_resolution_method = 2; 
    65124    } 
     125    switch(address_resolution_method) { 
     126    case 0: 
     127        host = inetAddress.getHostName(); 
     128        break; 
     129    case 1: 
     130        host = inetAddress.getHostAddress(); 
     131        break; 
     132    case 3: 
     133        host = "127.0.0.1"; 
     134        break; 
     135    case 2: default: 
     136        host = "localhost";          
     137    } 
     138    newFileLines = scriptReadWrite.queryReplace(newFileLines, "host", host); 
    66139 
    67     String[] parts = url.split("/"); 
    68     String prefix = parts[0]; 
    69  
    70     int colon = prefix.indexOf(':'); 
    71     if(colon != -1) { 
    72         prefix = prefix.substring(0, colon); 
    73     }  
     140    // address resolution method - onSave() would have updated 
     141    // this value (or the UnknownHostException above might have) 
     142    newFileLines = scriptReadWrite.queryReplace(newFileLines, "address_resolution_method", Integer.toString(address_resolution_method)); 
    74143     
    75     url = pre + prefix + ":" + portNumber; 
    76     for(int i = 1; i < parts.length; i++) { 
    77         url = url + "/" + parts[i]; 
    78     } 
    79  
    80     prefix_combobox.setSelectedItem(url);    
    81144    } 
    82145 
    83146    public void actionPerformed(ActionEvent e) { 
    84     String url = (String)prefix_combobox.getSelectedItem(); 
    85     int portNumber = 80; 
    86  
    87     String oldUrl = url; 
    88     if(url.indexOf("http://") != -1) { 
    89         url = url.substring(7); 
    90     } 
    91     int colon = url.indexOf(':'); 
    92     int slash = url.indexOf('/'); 
    93     if(slash == -1) { 
    94         slash = url.length(); 
    95     } 
    96     if(colon != -1) { 
    97         url = url.substring(colon+1, slash); 
    98         try {  
    99         portNumber_spinner.setValue(Integer.decode(url)); 
    100         } catch(NumberFormatException nfe) { // couldn't parse port number 
    101         // not an integer, leave portnumber at 80 
    102         String oldNum = portNumber_spinner.getValue().toString(); 
    103         oldUrl = oldUrl.replaceFirst(oldNum, "80"); 
    104         portNumber_spinner.setValue(new Integer(80)); 
     147    boolean toggle = !allowConnections.isSelected(); 
     148    if(e.getSource() == allowConnections) { 
     149        for(int i = 0; i < hostRadioButtons.length; i++) { 
     150        hostRadioButtons[i].setEnabled(toggle); 
    105151        } 
    106     } else { // no port number 
    107         oldUrl = oldUrl.replaceFirst(url, url+":80"); 
    108         portNumber_spinner.setValue(new Integer(80)); 
    109152    } 
    110153    } 
  • greenstone3/trunk/src/java/org/greenstone/server/Server3Settings.java

    r18868 r20604  
    7474    } 
    7575 
    76     public String onSave()  
     76    public boolean[] onSave() 
    7777    { 
    78     String result = ""; 
     78    boolean hasChanged = false; 
     79    boolean requireRestart = false; 
    7980    if (!servletDefault.equals((String)url_mappings.get(servlet_combobox.getSelectedItem()))) { 
    80         result += "changed"; 
    81         result += "restart"; 
     81        hasChanged = true; 
     82        requireRestart = true; 
    8283    } 
    83     return result; 
     84    boolean[] returnValues = { hasChanged, requireRestart }; 
     85    return returnValues; 
    8486    } 
    8587