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

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

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

    
39
/** 
40
 * @author dcosta
41
 * 
42
 * The BrowseServlet class executes a browse action. This is equivalent to
43
 * a simple search, but the user clicks on a link to determine the search term.
44
 */
45
public class BrowseServlet extends HttpServlet {
46

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

    
49
  // Methods
50
  
51
  /**
52
   * Executes a browse-based simple search.
53
   */
54
  public void doPost(HttpServletRequest request, HttpServletResponse response)
55
      throws IOException, ServletException {
56
    AdvancedSearch advancedSearch;
57
    String browseValue;
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
    ServletContext servletContext = httpSession.getServletContext();
65
    String stylesheet = (String) httpSession.getAttribute("stylesheet");
66
    String xslPath = servletContext.getRealPath("style/common/resultset.xsl");
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
    // Tell the web server that the response is HTML
81
    response.setContentType("text/html");
82

    
83
    // Fetch the browseValue parameter from the request and execute a search
84
    advancedSearch = new AdvancedSearch(null);
85
    browseValue = request.getParameter("browseValue");
86
    result = advancedSearch.executeSearch(metacatURL, metacat, xslPath, 
87
                                          browseValue);
88

    
89
    // Store the result HTML string in the request for retrieval by
90
    // the metacatpathqueryresults.jsp form.
91
    request.setAttribute("result", result);
92

    
93
    dispatcher = request.getRequestDispatcher(resultsJSP);
94
    dispatcher.forward(request, response);
95
  }
96
  
97
}
(7-7/14)