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: daigle $'
|
7
|
* '$Date: 2009-08-24 14:34:17 -0700 (Mon, 24 Aug 2009) $'
|
8
|
* '$Revision: 5030 $'
|
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 edu.ucsb.nceas.metacat.AuthLdap;
|
28
|
import edu.ucsb.nceas.metacat.properties.PropertyService;
|
29
|
import edu.ucsb.nceas.utilities.PropertyNotFoundException;
|
30
|
|
31
|
import javax.servlet.ServletContext;
|
32
|
import javax.servlet.http.HttpServletRequest;
|
33
|
import javax.servlet.http.HttpSession;
|
34
|
|
35
|
import org.apache.log4j.Logger;
|
36
|
|
37
|
|
38
|
/**
|
39
|
* @author dcosta
|
40
|
*
|
41
|
* MetacatHelper provides auxiliary methods for helping the advanced search
|
42
|
* classes interact with Metacat.
|
43
|
*/
|
44
|
public class MetacatHelper {
|
45
|
|
46
|
private static Logger logMetacat = Logger.getLogger(AuthLdap.class);
|
47
|
|
48
|
/**
|
49
|
* Constructs a DN (Distinguished Name) string for the ecoinformatics.org
|
50
|
* LDAP.
|
51
|
*
|
52
|
* @param username
|
53
|
* The LDAP uid, e.g. "dcosta"
|
54
|
* @param organization
|
55
|
* The LDAP organization, e.g. "LTER"
|
56
|
* @return DN The distinguished name string.
|
57
|
*/
|
58
|
public String constructDN(final String username, final String organization) {
|
59
|
String DC;
|
60
|
try {
|
61
|
DC = PropertyService.getProperty("auth.base");
|
62
|
} catch (PropertyNotFoundException pnfe) {
|
63
|
DC = "dc=ecoinformatics,dc=org";
|
64
|
logMetacat.error("Could not find property: auth.base. Setting to: " +
|
65
|
"dc=ecoinformatics,dc=org : " + pnfe.getMessage());
|
66
|
}
|
67
|
final String DN = "uid=" + username + ",o=" + organization
|
68
|
+ "," + DC;
|
69
|
|
70
|
return DN;
|
71
|
}
|
72
|
|
73
|
|
74
|
/**
|
75
|
* Constructs a URL to the metacat servlet.
|
76
|
*
|
77
|
* @param serverName
|
78
|
* A server name, e.g. "prairie.lternet.edu"
|
79
|
* @param serverPort
|
80
|
* A server port, e.g. 8080. If no port is required in the URL,
|
81
|
* pass a 0 and the argument will be ignored.
|
82
|
* @param contextString
|
83
|
* The context under which metacat is running, e.g. "knb".
|
84
|
* @return metacatURL The URL to the metacat servlet.
|
85
|
*/
|
86
|
public String constructMetacatURL(final String serverName,
|
87
|
final int serverPort,
|
88
|
final String contextString) {
|
89
|
String metacatURL = "http://" + serverName;
|
90
|
|
91
|
if (serverPort > 0) {
|
92
|
final Integer serverPortInteger = new Integer(serverPort);
|
93
|
final String serverPortString = serverPortInteger.toString();
|
94
|
metacatURL += ":" + serverPortString;
|
95
|
}
|
96
|
|
97
|
metacatURL += "/" + contextString + "/metacat";
|
98
|
|
99
|
return metacatURL;
|
100
|
}
|
101
|
|
102
|
|
103
|
/**
|
104
|
* Gets the relative path to the advancedsearchresults.jsp file.
|
105
|
*
|
106
|
* @return resultsJSP The relative path to the advanced search results JSP.
|
107
|
*/
|
108
|
public String getResultsJSP() {
|
109
|
String resultsJSP = "style/skins/default/advancedsearchresults.jsp";
|
110
|
|
111
|
return resultsJSP;
|
112
|
}
|
113
|
|
114
|
|
115
|
/**
|
116
|
* Gets the path to the resultset XSL file.
|
117
|
*
|
118
|
* @param request The HttpServletRequest object.
|
119
|
* @return xslPath The real path to the resultset XSL file.
|
120
|
*/
|
121
|
public String getResultsetXSL(HttpServletRequest request) {
|
122
|
HttpSession httpSession = request.getSession();
|
123
|
ServletContext servletContext = httpSession.getServletContext();
|
124
|
String xslPath = servletContext.getRealPath("style/common/resultset.xsl");
|
125
|
|
126
|
return xslPath;
|
127
|
}
|
128
|
|
129
|
}
|