[18558] | 1 | package org.greenstone.server;
|
---|
| 2 |
|
---|
[18710] | 3 | import java.awt.BorderLayout;
|
---|
[20604] | 4 | import java.awt.FlowLayout;
|
---|
| 5 | import java.awt.GridLayout;
|
---|
[18710] | 6 | import java.awt.event.*;
|
---|
[20604] | 7 | import java.net.InetAddress;
|
---|
| 8 | import java.net.UnknownHostException;
|
---|
[18868] | 9 | import java.util.ArrayList;
|
---|
[18558] | 10 | import javax.swing.*;
|
---|
[18710] | 11 | import javax.swing.event.*;
|
---|
[18558] | 12 |
|
---|
| 13 | import org.greenstone.server.BaseServerSettings;
|
---|
[22085] | 14 | import org.greenstone.util.ScriptReadWrite;
|
---|
[18558] | 15 |
|
---|
[20618] | 16 | public class Server2Settings extends BaseServerSettings
|
---|
[18558] | 17 | {
|
---|
[18710] | 18 | protected JComboBox prefix_combobox;
|
---|
[20604] | 19 | protected JRadioButton[] hostRadioButtons = new JRadioButton[4];
|
---|
[18710] | 20 |
|
---|
[23251] | 21 | // 0 to 3: 0 is resolved (hostname) from local IP, 1 is local IP address, 2 is localhost, 3 is 127.0.0.1
|
---|
[20604] | 22 | protected int address_resolution_method = 2;
|
---|
| 23 |
|
---|
[18558] | 24 | public Server2Settings(BaseServer server)
|
---|
| 25 | {
|
---|
[20604] | 26 | super(server);
|
---|
[18558] | 27 | }
|
---|
| 28 |
|
---|
| 29 | protected JPanel createServletPanel()
|
---|
| 30 | {
|
---|
[20604] | 31 | JPanel server2panel = new JPanel();
|
---|
| 32 | server2panel.setLayout(new BorderLayout());
|
---|
| 33 |
|
---|
| 34 | JPanel connect_panel = new JPanel(new GridLayout(4, 1));
|
---|
| 35 | connect_panel.setBackground(bg_color);
|
---|
[20618] | 36 | connect_panel.setBorder(BorderFactory.createTitledBorder(server.dictionary.get(BaseServer.Property.SERVER_SETTINGS+".AddressResolutionMethod")));
|
---|
[18668] | 37 |
|
---|
[20604] | 38 | hostRadioButtons = new JRadioButton[4];
|
---|
| 39 | hostRadioButtons[0] = new JRadioButton(server.dictionary.get(BaseServer.Property.SERVER_SETTINGS+".ResolveIP"));
|
---|
| 40 | hostRadioButtons[1] = new JRadioButton(server.dictionary.get(BaseServer.Property.SERVER_SETTINGS+".LocalIP"));
|
---|
| 41 | hostRadioButtons[2] = new JRadioButton(server.dictionary.get(BaseServer.Property.SERVER_SETTINGS+".AlwaysUse")+" localhost");
|
---|
| 42 | hostRadioButtons[3] = new JRadioButton(server.dictionary.get(BaseServer.Property.SERVER_SETTINGS+".AlwaysUse")+" 127.0.0.1");
|
---|
[18668] | 43 |
|
---|
[20604] | 44 | ButtonGroup hostGroup = new ButtonGroup();
|
---|
| 45 | for(int i = 0; i < hostRadioButtons.length; i ++) {
|
---|
| 46 | connect_panel.add(hostRadioButtons[i]);
|
---|
| 47 | hostGroup.add(hostRadioButtons[i]);
|
---|
| 48 | hostRadioButtons[i].setBackground(bg_color);
|
---|
[20618] | 49 | }
|
---|
[20604] | 50 |
|
---|
[29843] | 51 | String addressResolutionMethod = server.config_properties.getProperty("address_resolution_method", "").trim();
|
---|
| 52 | if(!addressResolutionMethod.equals("")) {
|
---|
[20604] | 53 | this.address_resolution_method = Integer.parseInt(addressResolutionMethod);
|
---|
| 54 | }
|
---|
| 55 | hostRadioButtons[address_resolution_method].setSelected(true);
|
---|
| 56 |
|
---|
| 57 | JPanel comb_panel = new JPanel(new BorderLayout());
|
---|
| 58 | comb_panel.add(connect_panel, BorderLayout.CENTER);
|
---|
[18668] | 59 | return comb_panel;
|
---|
[18558] | 60 | }
|
---|
[18710] | 61 |
|
---|
[20604] | 62 | public boolean[] onSave()
|
---|
[18710] | 63 | {
|
---|
[20604] | 64 | // superclass detects changes to port and autoenter
|
---|
[29845] | 65 | // handle changes to address_resolution_method here
|
---|
[20604] | 66 |
|
---|
| 67 | boolean hasChanged = false;
|
---|
| 68 | boolean requireRestart = false;
|
---|
| 69 |
|
---|
| 70 | for(int i = 0; i < hostRadioButtons.length; i++) {
|
---|
| 71 | if(hostRadioButtons[i].isSelected() && address_resolution_method != i) {
|
---|
| 72 | address_resolution_method = i;
|
---|
| 73 | hasChanged = true;
|
---|
| 74 | requireRestart = true;
|
---|
[20945] | 75 | server.reconfigRequired();
|
---|
[20604] | 76 | }
|
---|
[18969] | 77 | }
|
---|
[20604] | 78 |
|
---|
| 79 | boolean[] returnValues = { hasChanged, requireRestart };
|
---|
| 80 | return returnValues;
|
---|
[18710] | 81 | }
|
---|
| 82 |
|
---|
[25635] | 83 | public void save(ScriptReadWrite scriptReadWrite, ArrayList<String> newFileLines)
|
---|
[18868] | 84 | {
|
---|
[20604] | 85 | // write only 1 or 0 (and not true or false) for Server2
|
---|
[18969] | 86 | boolean auto_enter = autoEnter.isSelected();
|
---|
| 87 | if(autoStart != auto_enter) {
|
---|
| 88 | String newAutoEnter = auto_enter ? "1" : "0";
|
---|
| 89 | newFileLines = scriptReadWrite.queryReplace(newFileLines, BaseServer.Property.AUTOSTART, newAutoEnter);
|
---|
| 90 | }
|
---|
[24207] | 91 | boolean keep_port = keepPortToggle.isSelected();
|
---|
| 92 | if(keepPort != keep_port) {
|
---|
| 93 | String newKeepPort = keep_port ? "1" : "0";
|
---|
| 94 | newFileLines = scriptReadWrite.queryReplace(newFileLines, BaseServer.Property.KEEPPORT, newKeepPort);
|
---|
| 95 | }
|
---|
[18868] | 96 |
|
---|
[20604] | 97 | // external access - onSave() would have updated this value
|
---|
[29845] | 98 | // Its possible values are specific to the version of Greenstone: 0 or 1 for GS2 (true or false for GS3)
|
---|
| 99 | newFileLines = scriptReadWrite.queryReplace(newFileLines, BaseServer.Property.ALLOW_EXTERNAL_ACCESS, externalaccess ? "1" : "0");
|
---|
[20604] | 100 |
|
---|
| 101 | // work out the host (default is address_resolution_method 2: localhost)
|
---|
[20623] | 102 | String hostIP = "127.0.0.1";
|
---|
[23251] | 103 | String hosts = "";
|
---|
[20604] | 104 | InetAddress inetAddress = null;
|
---|
| 105 | try {
|
---|
| 106 | inetAddress = InetAddress.getLocalHost();
|
---|
[23251] | 107 | hosts = inetAddress.getHostName();
|
---|
[20623] | 108 | hostIP = inetAddress.getHostAddress(); // used for all cases unless an Exception is thrown here
|
---|
[20604] | 109 | } catch(UnknownHostException e) {
|
---|
| 110 | logger.error(e);
|
---|
[20623] | 111 | logger.info("Server2.java reload(): Defaulting host URL to localhost");
|
---|
| 112 | hostIP = "127.0.0.1";
|
---|
[23251] | 113 | hosts = "";
|
---|
[20623] | 114 | address_resolution_method = 2;
|
---|
[18710] | 115 | }
|
---|
| 116 |
|
---|
[20940] | 117 | newFileLines = scriptReadWrite.replaceOrAddLine(newFileLines, "hostIP", hostIP, true);
|
---|
[23251] | 118 | newFileLines = scriptReadWrite.replaceOrAddLine(newFileLines, "hosts", hosts, true);
|
---|
[20618] | 119 |
|
---|
[20604] | 120 | // address resolution method - onSave() would have updated
|
---|
| 121 | // this value (or the UnknownHostException above might have)
|
---|
| 122 | newFileLines = scriptReadWrite.queryReplace(newFileLines, "address_resolution_method", Integer.toString(address_resolution_method));
|
---|
[18710] | 123 |
|
---|
[20618] | 124 | }
|
---|
[18558] | 125 | }
|
---|