Project

General

Profile

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 4729 daigle
import edu.ucsb.nceas.metacat.AuthLdap;
28
import edu.ucsb.nceas.metacat.service.PropertyService;
29
import edu.ucsb.nceas.utilities.PropertyNotFoundException;
30
31 3009 costa
import javax.servlet.ServletContext;
32
import javax.servlet.http.HttpServletRequest;
33
import javax.servlet.http.HttpSession;
34 2741 costa
35 4729 daigle
import org.apache.log4j.Logger;
36 3009 costa
37 4729 daigle
38 2741 costa
/**
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 4729 daigle
46
	private static Logger logMetacat = Logger.getLogger(AuthLdap.class);
47
48 2741 costa
  /**
49 4729 daigle
	 * 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 2741 costa
73
74
  /**
75 4729 daigle
	 * 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 2741 costa
  public String constructMetacatURL(final String serverName,
87 2822 costa
                                    final int serverPort,
88
                                    final String contextString) {
89 2741 costa
    String metacatURL = "http://" + serverName;
90
91
    if (serverPort > 0) {
92
      final Integer serverPortInteger = new Integer(serverPort);
93
      final String serverPortString = serverPortInteger.toString();
94 2822 costa
      metacatURL += ":" + serverPortString;
95 2741 costa
    }
96
97 2822 costa
    metacatURL += "/" + contextString + "/metacat";
98
99 2741 costa
    return metacatURL;
100
  }
101 3009 costa
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 2741 costa
114 3009 costa
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 2741 costa
}