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: 2006-06-14 08:41:09 -0700 (Wed, 14 Jun 2006) $'
|
8
|
* '$Revision: 3009 $'
|
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 javax.servlet.ServletContext;
|
28
|
import javax.servlet.http.HttpServletRequest;
|
29
|
import javax.servlet.http.HttpSession;
|
30
|
|
31
|
|
32
|
/**
|
33
|
* @author dcosta
|
34
|
*
|
35
|
* MetacatHelper provides auxiliary methods for helping the advanced search
|
36
|
* classes interact with Metacat.
|
37
|
*/
|
38
|
public class MetacatHelper {
|
39
|
|
40
|
/**
|
41
|
* Constructs a DN (Distinguished Name) string for the ecoinformatics.org
|
42
|
* LDAP.
|
43
|
*
|
44
|
* @param username The LDAP uid, e.g. "dcosta"
|
45
|
* @param organization The LDAP organization, e.g. "LTER"
|
46
|
* @return DN The distinguished name string.
|
47
|
*/
|
48
|
public String constructDN(final String username, final String organization) {
|
49
|
final String DN = "uid=" + username +
|
50
|
",o=" + organization +
|
51
|
",dc=ecoinformatics,dc=org";
|
52
|
|
53
|
return DN;
|
54
|
}
|
55
|
|
56
|
|
57
|
/**
|
58
|
* Constructs a URL to the metacat servlet.
|
59
|
*
|
60
|
* @param serverName A server name, e.g. "prairie.lternet.edu"
|
61
|
* @param serverPort A server port, e.g. 8080. If no port is required in
|
62
|
* the URL, pass a 0 and the argument will be ignored.
|
63
|
* @param contextString The context under which metacat is running, e.g. "knb".
|
64
|
* @return metacatURL The URL to the metacat servlet.
|
65
|
*/
|
66
|
public String constructMetacatURL(final String serverName,
|
67
|
final int serverPort,
|
68
|
final String contextString) {
|
69
|
String metacatURL = "http://" + serverName;
|
70
|
|
71
|
if (serverPort > 0) {
|
72
|
final Integer serverPortInteger = new Integer(serverPort);
|
73
|
final String serverPortString = serverPortInteger.toString();
|
74
|
metacatURL += ":" + serverPortString;
|
75
|
}
|
76
|
|
77
|
metacatURL += "/" + contextString + "/metacat";
|
78
|
|
79
|
return metacatURL;
|
80
|
}
|
81
|
|
82
|
|
83
|
/**
|
84
|
* Gets the relative path to the advancedsearchresults.jsp file.
|
85
|
*
|
86
|
* @return resultsJSP The relative path to the advanced search results JSP.
|
87
|
*/
|
88
|
public String getResultsJSP() {
|
89
|
String resultsJSP = "style/skins/default/advancedsearchresults.jsp";
|
90
|
|
91
|
return resultsJSP;
|
92
|
}
|
93
|
|
94
|
|
95
|
/**
|
96
|
* Gets the path to the resultset XSL file.
|
97
|
*
|
98
|
* @param request The HttpServletRequest object.
|
99
|
* @return xslPath The real path to the resultset XSL file.
|
100
|
*/
|
101
|
public String getResultsetXSL(HttpServletRequest request) {
|
102
|
HttpSession httpSession = request.getSession();
|
103
|
ServletContext servletContext = httpSession.getServletContext();
|
104
|
String xslPath = servletContext.getRealPath("style/common/resultset.xsl");
|
105
|
|
106
|
return xslPath;
|
107
|
}
|
108
|
|
109
|
}
|