source: greenstone3/trunk/src/java/org/greenstone/server/Server3Settings.java@ 18868

Last change on this file since 18868 was 18868, checked in by ak19, 15 years ago

Updated Server files for Linux GS2 Local Library Server to work the same way as the Windows GS2 LLS. Basically the major difference is that build.properties is no longer used but glisite.cfg or llssite.cfg depending on whether or not gs2-server.sh is launched from gli. There are a few additional changes required for this to keep it consistent with the way the Windows GS2 LLS works: storing the preview URL in glisite.cfg/llssite.cfg while the server is running and removing it when the server has stopped, Server2.java's main method taking the configfile as an additional parameter (and corresponding adjustments in the gsicontrol.sh script of GS2).

File size: 3.0 KB
Line 
1package org.greenstone.server;
2
3import java.awt.*;
4import java.awt.event.*;
5import java.io.File;
6import java.util.ArrayList;
7import java.util.HashMap;
8import javax.swing.*;
9
10import org.w3c.dom.*;
11
12import org.greenstone.gsdl3.util.GSXML;
13import org.greenstone.gsdl3.util.GlobalProperties;
14import org.greenstone.gsdl3.util.XMLConverter;
15
16import org.greenstone.server.BaseServerSettings;
17
18public class Server3Settings extends BaseServerSettings
19{
20 protected String servletDefault = null;
21 protected JComboBox servlet_combobox;
22 protected HashMap url_mappings = null;
23
24 public Server3Settings(BaseServer server)
25 {
26 super(server);
27 }
28
29 protected JPanel createServletPanel()
30 {
31 JLabel servlet_label = new JLabel(server.dictionary.get(BaseServer.Property.SERVER_SETTINGS+".URL"));
32
33 this.servletDefault = server.config_properties.getProperty(BaseServer.Property.DEFAULT_SERVLET).replaceAll("/","");
34
35 servlet_combobox = new JComboBox();
36 servlet_combobox.setMaximumRowCount(5);
37 servlet_combobox.setBackground(bg_color);
38
39 File web_xml = new File(GlobalProperties.getProperty(BaseServer.Property.GSDL_HOME) + File.separator + "WEB-INF" + File.separator + "web.xml");
40 XMLConverter converter = new XMLConverter();
41 Document web_config = converter.getDOM(web_xml);
42 if (web_config == null) {
43 logger.error("web.xml is null! "+web_xml.getAbsolutePath());
44 return null;
45 }
46
47 NodeList servlet_mappings = web_config.getElementsByTagName("servlet-mapping");
48 // make a little map class
49 url_mappings = new HashMap();
50 for (int i = 0; i < servlet_mappings.getLength(); i++) {
51 Element map = (Element) servlet_mappings.item(i);
52 Element servlet_name_elem = (Element) GSXML.getChildByTagName(map, "servlet-name");
53 String name = GSXML.getNodeText(servlet_name_elem);
54 Element url_pattern_elem = (Element) GSXML.getChildByTagName(map, "url-pattern");
55 String pattern = GSXML.getNodeText(url_pattern_elem);
56 // Ignore the Axis servlets
57 if (!(name.equals("AxisServlet"))) {
58 servlet_combobox.addItem(name.trim());
59 url_mappings.put(name, pattern);
60 }
61
62 if (pattern.replaceAll("/","").equals(servletDefault)) {
63 servlet_combobox.setSelectedItem(name);
64 }
65 }
66
67
68 JPanel comb_panel = new JPanel();
69 comb_panel.setLayout(new FlowLayout(FlowLayout.LEFT));
70 comb_panel.add(servlet_label);
71 comb_panel.add(servlet_combobox);
72
73 return comb_panel;
74 }
75
76 public String onSave()
77 {
78 String result = "";
79 if (!servletDefault.equals((String)url_mappings.get(servlet_combobox.getSelectedItem()))) {
80 result += "changed";
81 result += "restart";
82 }
83 return result;
84 }
85
86 public void save(ScriptReadWrite scriptReadWrite, ArrayList newFileLines)
87 {
88 String newAutoEnter = (new Boolean(autoEnter.isSelected())).toString();
89 newFileLines = scriptReadWrite.queryReplace(newFileLines, BaseServer.Property.AUTOSTART, newAutoEnter);
90
91 String newServletDef = (String) servlet_combobox.getSelectedItem();
92 newFileLines = scriptReadWrite.queryReplace(newFileLines,BaseServer.Property.DEFAULT_SERVLET, (String) url_mappings.get(newServletDef));
93 }
94
95}
Note: See TracBrowser for help on using the repository browser.