Project

General

Profile

1
/**
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: costa $'
7
 *     '$Date: 2005-11-16 09:57:33 -0800 (Wed, 16 Nov 2005) $'
8
 * '$Revision: 2741 $'
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
import java.io.IOException;
28
import java.util.Enumeration;
29

    
30
import javax.servlet.RequestDispatcher;
31
import javax.servlet.ServletContext;
32
import javax.servlet.ServletException;
33
import javax.servlet.http.HttpServlet;
34
import javax.servlet.http.HttpServletRequest;
35
import javax.servlet.http.HttpServletResponse;
36
import javax.servlet.http.HttpSession;
37

    
38
import edu.ucsb.nceas.metacat.client.*;
39

    
40
/** 
41
 * @author dcosta
42
 * 
43
 * The AdvancedSearchServlet executes an advanced search.
44
 */
45
public class AdvancedSearchServlet extends HttpServlet {
46

    
47
  // Instance Variables -- (Not used because they are not thread-safe.)
48

    
49
  // Methods
50
  
51
  /**
52
   * Executes an advanced search.
53
   */
54
  public void doPost(HttpServletRequest request, HttpServletResponse response)
55
          throws IOException, ServletException {
56
    AdvancedSearch advancedSearch;
57
    AdvancedSearchBean advancedSearchBean;
58
    RequestDispatcher dispatcher;
59
    HttpSession httpSession = request.getSession();
60
    Metacat metacat = (Metacat) httpSession.getAttribute("metacat");
61
    String metacatURL;
62
    String result;
63
    final String resultsJSP = "style/skins/default/advancedsearchresults.jsp";
64
    final String resultsXSL = "style/common/resultset.xsl";
65
    ServletContext servletContext = httpSession.getServletContext();
66
    String xslPath = servletContext.getRealPath(resultsXSL);
67

    
68
    // First check whether the metacat URL was set as a context-param.
69
    metacatURL = servletContext.getInitParameter("metacatURL");
70
 
71
    // If no metacat URL was configured, then derive the metacat URL from the
72
    // server name and server port.
73
    if (metacatURL == null || metacatURL.equals("")) {
74
      MetacatHelper metacatHelper = new MetacatHelper();
75
      String serverName = request.getServerName();
76
      int serverPort = request.getServerPort();
77
      metacatURL = metacatHelper.constructMetacatURL(serverName, serverPort);
78
    }
79

    
80
    // Get the advancedSearchBean object that has been loaded up with user
81
    // input. Pass the bean to the advancedSearch object, execute the query,
82
    // and return the search result HTML string.
83
    advancedSearchBean = 
84
                (AdvancedSearchBean) request.getAttribute("advancedSearchBean");
85
    advancedSearch = new AdvancedSearch(advancedSearchBean);
86
    result = advancedSearch.executeAdvancedSearch(metacatURL, metacat, xslPath);
87
    
88
    // Store the result HTML string in the request for retrieval by
89
    // the metacatpathqueryresults.jsp form.
90
    request.setAttribute("result", result);
91
		
92
    dispatcher = request.getRequestDispatcher(resultsJSP);
93
    dispatcher.forward(request, response);
94
  }
95
  
96
}
(6-6/14)