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

Last change on this file since 7624 was 7326, checked in by kjdon, 20 years ago

the intial stage of making gli work with gs3 - still uses gs2 building, but uses colls in gs3 setup

  • 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.msm.MSMUtils;
47import org.greenstone.gatherer.util.ArrayTools;
48import org.greenstone.gatherer.util.StaticStrings;
49import org.greenstone.gatherer.util.Utility;
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
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 + File.separator + "web" + File.separator + "WEB-INF"+ File.separator + "web.xml");
70
71 if (!web_xml.exists()) {
72 Gatherer.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 File col_dir = new File(possible_sites[i], Utility.COL_DIR);
84 if (site_config.exists() && col_dir.exists()) {
85 this.sites.add(possible_sites[i].getName());
86 }
87 }
88
89 this.mappings = new HashMap();
90 Document web_config = Utility.parse(web_xml.getAbsolutePath(), false);
91
92 NodeList servlet_mappings = web_config.getElementsByTagName("servlet-mapping");
93 // make a little map class
94 HashMap url_mappings = new HashMap();
95 for (int i=0; i<servlet_mappings.getLength(); i++) {
96 Element map = (Element)servlet_mappings.item(i);
97 String name = MSMUtils.getValue(MSMUtils.getNodeFromNamed(map, "servlet-name"));
98 String pattern = MSMUtils.getValue(MSMUtils.getNodeFromNamed(map, "url-pattern"));
99 url_mappings.put(name, pattern);
100
101 }
102
103 NodeList servlets = web_config.getElementsByTagName("servlet");
104 for (int i=0; i<servlets.getLength(); i++) {
105 Element servlet = (Element)servlets.item(i);
106 String name = MSMUtils.getValue(MSMUtils.getNodeFromNamed(servlet, "servlet-name"));
107 String description = MSMUtils.getValue(MSMUtils.getNodeFromNamed(servlet, "description"));
108 String site = getServletSite(servlet);
109
110 if (site != null) {
111 ArrayList this_site = (ArrayList)mappings.get(site);
112 if (this_site == null) {
113 this_site = new ArrayList();
114 }
115 String url = (String)url_mappings.get(name);
116 this_site.add(url);
117 mappings.put(site, this_site);
118 }
119
120 }
121
122 web_config = null;
123 url_mappings = null;
124 }
125
126 public ArrayList getSites() {
127 return this.sites;
128 }
129
130 public ArrayList getServletsForSite(String site) {
131 return (ArrayList)this.mappings.get(site);
132 }
133 public String getServletPath(String site) {
134
135 // for now, get the first one
136 ArrayList servlets = (ArrayList)mappings.get(site);
137 if(servlets == null) {
138 return null;
139 }
140 return (String)servlets.get(0);
141 }
142
143 private String getServletSite(Element servlet) {
144
145 NodeList params = servlet.getElementsByTagName("init-param");
146 if ( params == null || params.getLength() == 0) {
147 return null;
148 }
149 String site = null;
150 for (int i=0; i<params.getLength()&& site == null; i++) {
151 String p_name = MSMUtils.getValue(MSMUtils.getNodeFromNamed(params.item(i), "param-name"));
152 if (p_name.equals("site_name")) {
153 site = MSMUtils.getValue(MSMUtils.getNodeFromNamed(params.item(i), "param-value"));
154 }
155 }
156 return site;
157 }
158}
Note: See TracBrowser for help on using the repository browser.