source: trunk/gli/src/org/greenstone/gatherer/ServletConfiguration.java@ 10330

Last change on this file since 10330 was 10330, checked in by kjdon, 19 years ago

gsdl3 mode now has two args: -gsdl3 which is gsdl3home (the web dir) and -gsdl3src, which is the gsdl3 directory. so Configuration has an extra param to the constructor, etc

  • Property svn:keywords set to Author Date Id Revision
File size: 5.1 KB
Line 
1/**
2 *#########################################################################
3 *
4 * A component of the Gatherer application, part of the Greenstone digital
5 * library suite from the New Zealand Digital Library Project at the
6 * University of Waikato, New Zealand.
7 *
8 * <BR><BR>
9 *
10 * Author: John Thompson, Greenstone Digital Library, University of Waikato
11 *
12 * <BR><BR>
13 *
14 * Copyright (C) 1999 New Zealand Digital Library Project
15 *
16 * <BR><BR>
17 *
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2 of the License, or
21 * (at your option) any later version.
22 *
23 * <BR><BR>
24 *
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
29 *
30 * <BR><BR>
31 *
32 * You should have received a copy of the GNU General Public License
33 * along with this program; if not, write to the Free Software
34 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
35 *########################################################################
36 */
37package org.greenstone.gatherer;
38
39import java.awt.*;
40import java.io.*;
41import java.lang.ref.*;
42import java.net.*;
43import java.util.*;
44import javax.swing.*;
45import javax.swing.plaf.*;
46import org.greenstone.gatherer.util.ArrayTools;
47import org.greenstone.gatherer.util.StaticStrings;
48import org.greenstone.gatherer.util.Utility;
49import org.greenstone.gatherer.util.XMLTools;
50import org.w3c.dom.*;
51
52/** This class stores the mapping between sites and servlets available for them. The info is read in from the web.xml file.
53 * @author Katherine Don, New Zealand Digital Library, University of Waikato
54 * @version
55 */
56public class ServletConfiguration {
57
58 static public String ADD_COMMAND = "?a=s&sa=a&st=collection&sn=";
59 static public String DEACTIVATE_COMMAND = "?a=s&sa=d&st=collection&sn=";
60 private String gsdl3_path = "";
61 private ArrayList sites = null;
62 private HashMap mappings = null;
63
64 public ServletConfiguration(String gsdl3_path) {
65
66 this.gsdl3_path = gsdl3_path;
67
68 //String web_xml_path = gsdl3_path + File.separator + "web" + File.separator + "WEB-INF"+ File.separator + "web.xml";
69 File web_xml = new File(gsdl3_path + "WEB-INF"+ File.separator + "web.xml");
70
71 if (!web_xml.exists()) {
72 DebugStream.println("Error: no web.xml found at "+web_xml.toString());
73 return;
74 }
75
76 this.sites = new ArrayList();
77 // find the sites
78 File start = new File(Utility.getSitesDir(gsdl3_path));
79 File possible_sites[] = start.listFiles();
80 ArrayTools.sort(possible_sites);
81 for (int i=0; possible_sites != null && i < possible_sites.length; i++) {
82 File site_config = new File(possible_sites[i], "siteConfig.xml");
83 if (site_config.exists()) {
84 this.sites.add(possible_sites[i].getName());
85 }
86 }
87
88 this.mappings = new HashMap();
89 Document web_config = XMLTools.parseXMLFile(web_xml.getAbsolutePath(), false);
90
91 NodeList servlet_mappings = web_config.getElementsByTagName("servlet-mapping");
92 // make a little map class
93 HashMap url_mappings = new HashMap();
94 for (int i=0; i<servlet_mappings.getLength(); i++) {
95 Element map = (Element)servlet_mappings.item(i);
96 String name = XMLTools.getValue(XMLTools.getNodeFromNamed(map, "servlet-name"));
97 String pattern = XMLTools.getValue(XMLTools.getNodeFromNamed(map, "url-pattern"));
98 url_mappings.put(name, pattern);
99
100 }
101
102 NodeList servlets = web_config.getElementsByTagName("servlet");
103 for (int i=0; i<servlets.getLength(); i++) {
104 Element servlet = (Element)servlets.item(i);
105 String name = XMLTools.getValue(XMLTools.getNodeFromNamed(servlet, "servlet-name"));
106 String description = XMLTools.getValue(XMLTools.getNodeFromNamed(servlet, "description"));
107 String site = getServletSite(servlet);
108
109 if (site != null) {
110 ArrayList this_site = (ArrayList)mappings.get(site);
111 if (this_site == null) {
112 this_site = new ArrayList();
113 }
114 String url = (String)url_mappings.get(name);
115 this_site.add(url);
116 mappings.put(site, this_site);
117 }
118
119 }
120
121 web_config = null;
122 url_mappings = null;
123 }
124
125 public ArrayList getSites() {
126 return this.sites;
127 }
128
129 public ArrayList getServletsForSite(String site) {
130 return (ArrayList)this.mappings.get(site);
131 }
132 public String getServletPath(String site) {
133
134 // for now, get the first one
135 ArrayList servlets = (ArrayList)mappings.get(site);
136 if(servlets == null) {
137 return null;
138 }
139 return (String)servlets.get(0);
140 }
141
142 private String getServletSite(Element servlet) {
143
144 NodeList params = servlet.getElementsByTagName("init-param");
145 if ( params == null || params.getLength() == 0) {
146 return null;
147 }
148 String site = null;
149 for (int i=0; i<params.getLength()&& site == null; i++) {
150 String p_name = XMLTools.getValue(XMLTools.getNodeFromNamed(params.item(i), "param-name"));
151 if (p_name.equals("site_name")) {
152 site = XMLTools.getValue(XMLTools.getNodeFromNamed(params.item(i), "param-value"));
153 }
154 }
155 return site;
156 }
157}
Note: See TracBrowser for help on using the repository browser.