1 |
2741
|
costa
|
/**
|
2 |
|
|
* '$RCSfile$'
|
3 |
|
|
* Copyright: 2005 University of New Mexico and the
|
4 |
|
|
* Regents of the University of California and the
|
5 |
|
|
* National Center for Ecological Analysis and Synthesis
|
6 |
|
|
* '$Author$'
|
7 |
|
|
* '$Date$'
|
8 |
|
|
* '$Revision$'
|
9 |
|
|
*
|
10 |
|
|
* This program is free software; you can redistribute it and/or modify
|
11 |
|
|
* it under the terms of the GNU General Public License as published by
|
12 |
|
|
* the Free Software Foundation; either version 2 of the License, or
|
13 |
|
|
* (at your option) any later version.
|
14 |
|
|
*
|
15 |
|
|
* This program is distributed in the hope that it will be useful,
|
16 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
17 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
18 |
|
|
* GNU General Public License for more details.
|
19 |
|
|
*
|
20 |
|
|
* You should have received a copy of the GNU General Public License
|
21 |
|
|
* along with this program; if not, write to the Free Software
|
22 |
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
23 |
|
|
*/
|
24 |
|
|
|
25 |
|
|
package edu.ucsb.nceas.metacat.advancedsearch;
|
26 |
|
|
|
27 |
2822
|
costa
|
import java.io.File;
|
28 |
2741
|
costa
|
import java.io.IOException;
|
29 |
|
|
|
30 |
|
|
import javax.servlet.RequestDispatcher;
|
31 |
2822
|
costa
|
import javax.servlet.ServletConfig;
|
32 |
2741
|
costa
|
import javax.servlet.ServletContext;
|
33 |
|
|
import javax.servlet.ServletException;
|
34 |
|
|
import javax.servlet.http.HttpServlet;
|
35 |
|
|
import javax.servlet.http.HttpServletRequest;
|
36 |
|
|
import javax.servlet.http.HttpServletResponse;
|
37 |
|
|
import javax.servlet.http.HttpSession;
|
38 |
|
|
|
39 |
|
|
import edu.ucsb.nceas.metacat.client.*;
|
40 |
5030
|
daigle
|
import edu.ucsb.nceas.metacat.properties.PropertyService;
|
41 |
5015
|
daigle
|
import edu.ucsb.nceas.metacat.shared.ServiceException;
|
42 |
4080
|
daigle
|
import edu.ucsb.nceas.metacat.util.SystemUtil;
|
43 |
|
|
import edu.ucsb.nceas.utilities.PropertyNotFoundException;
|
44 |
2741
|
costa
|
|
45 |
|
|
/**
|
46 |
|
|
* @author dcosta
|
47 |
|
|
*
|
48 |
|
|
* The BrowseServlet class executes a browse action. This is equivalent to
|
49 |
|
|
* a simple search, but the user clicks on a link to determine the search term.
|
50 |
|
|
*/
|
51 |
|
|
public class BrowseServlet extends HttpServlet {
|
52 |
|
|
|
53 |
2822
|
costa
|
/*
|
54 |
|
|
* Class fields
|
55 |
|
|
*/
|
56 |
|
|
private static final String CONFIG_DIR = "WEB-INF";
|
57 |
|
|
private static final String CONFIG_NAME = "metacat.properties";
|
58 |
3011
|
costa
|
static final long serialVersionUID = 0; // Needed for Eclipse warning.
|
59 |
2822
|
costa
|
|
60 |
|
|
// Instance Variables
|
61 |
|
|
private String contextString = "";
|
62 |
2741
|
costa
|
|
63 |
|
|
// Methods
|
64 |
|
|
|
65 |
|
|
/**
|
66 |
|
|
* Executes a browse-based simple search.
|
67 |
|
|
*/
|
68 |
|
|
public void doPost(HttpServletRequest request, HttpServletResponse response)
|
69 |
|
|
throws IOException, ServletException {
|
70 |
|
|
AdvancedSearch advancedSearch;
|
71 |
|
|
String browseValue;
|
72 |
|
|
RequestDispatcher dispatcher;
|
73 |
|
|
HttpSession httpSession = request.getSession();
|
74 |
|
|
Metacat metacat = (Metacat) httpSession.getAttribute("metacat");
|
75 |
3011
|
costa
|
MetacatHelper metacatHelper = new MetacatHelper();
|
76 |
2741
|
costa
|
String metacatURL;
|
77 |
3011
|
costa
|
String qformat = (String) httpSession.getAttribute("qformat");
|
78 |
2741
|
costa
|
String result = "";
|
79 |
3011
|
costa
|
final String resultsJSP = metacatHelper.getResultsJSP();
|
80 |
2741
|
costa
|
ServletContext servletContext = httpSession.getServletContext();
|
81 |
3011
|
costa
|
String xslPath = metacatHelper.getResultsetXSL(request);
|
82 |
2741
|
costa
|
|
83 |
|
|
// First check whether the metacat URL was set as a context-param.
|
84 |
|
|
metacatURL = servletContext.getInitParameter("metacatURL");
|
85 |
|
|
|
86 |
|
|
// If no metacat URL was configured, then derive the metacat URL from the
|
87 |
|
|
// server name and server port.
|
88 |
|
|
if (metacatURL == null || metacatURL.equals("")) {
|
89 |
|
|
String serverName = request.getServerName();
|
90 |
|
|
int serverPort = request.getServerPort();
|
91 |
2822
|
costa
|
metacatURL =
|
92 |
3011
|
costa
|
metacatHelper.constructMetacatURL(serverName, serverPort, contextString);
|
93 |
2741
|
costa
|
}
|
94 |
|
|
|
95 |
|
|
// Tell the web server that the response is HTML
|
96 |
|
|
response.setContentType("text/html");
|
97 |
|
|
|
98 |
|
|
// Fetch the browseValue parameter from the request and execute a search
|
99 |
|
|
advancedSearch = new AdvancedSearch(null);
|
100 |
|
|
browseValue = request.getParameter("browseValue");
|
101 |
3011
|
costa
|
result = advancedSearch.executeSearch(metacatURL, metacat, qformat,
|
102 |
|
|
xslPath, browseValue);
|
103 |
2741
|
costa
|
|
104 |
|
|
// Store the result HTML string in the request for retrieval by
|
105 |
|
|
// the metacatpathqueryresults.jsp form.
|
106 |
|
|
request.setAttribute("result", result);
|
107 |
|
|
|
108 |
|
|
dispatcher = request.getRequestDispatcher(resultsJSP);
|
109 |
|
|
dispatcher.forward(request, response);
|
110 |
|
|
}
|
111 |
|
|
|
112 |
2822
|
costa
|
/**
|
113 |
4080
|
daigle
|
* Initializes the servlet. Reads properties and initializes object fields.
|
114 |
|
|
*
|
115 |
|
|
* @throws ServletException
|
116 |
|
|
*/
|
117 |
|
|
public void init(ServletConfig config) throws ServletException {
|
118 |
|
|
ServletContext context = null;
|
119 |
|
|
String dirPath;
|
120 |
2822
|
costa
|
|
121 |
4080
|
daigle
|
super.init(config);
|
122 |
|
|
context = config.getServletContext();
|
123 |
|
|
dirPath = context.getRealPath(CONFIG_DIR);
|
124 |
2822
|
costa
|
|
125 |
4080
|
daigle
|
try {
|
126 |
4708
|
daigle
|
PropertyService.getInstance();
|
127 |
4080
|
daigle
|
this.contextString = PropertyService.getProperty("application.context");
|
128 |
4124
|
daigle
|
} catch (ServiceException se) {
|
129 |
|
|
System.err.println("Error in loading properties: " + se.getMessage());
|
130 |
4080
|
daigle
|
} catch (PropertyNotFoundException pnfe) {
|
131 |
|
|
System.err.println("couldn't read property during initialization: "
|
132 |
|
|
+ pnfe.getMessage());
|
133 |
|
|
}
|
134 |
|
|
}
|
135 |
2741
|
costa
|
}
|