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
28
/**
29
 * @author dcosta
30
 *
31
 * MetacatHelper provides auxiliary methods for helping the advanced search
32
 * classes interact with Metacat.
33
 */
34
public class MetacatHelper {
35
36
  /**
37
   * Constructs a DN (Distinguished Name) string for the ecoinformatics.org
38
   * LDAP.
39
   *
40
   * @param username       The LDAP uid, e.g. "dcosta"
41
   * @param organization   The LDAP organization, e.g. "LTER"
42
   * @return DN            The distinguished name string.
43
   */
44
  public String constructDN(final String username, final String organization) {
45
    final String DN = "uid=" + username +
46
                      ",o=" + organization +
47
                      ",dc=ecoinformatics,dc=org";
48
49
    return DN;
50
  }
51
52
53
  /**
54 2822 costa
   * Constructs a URL to the metacat servlet.
55 2741 costa
   *
56
   * @param serverName   A server name, e.g. "prairie.lternet.edu"
57
   * @param serverPort   A server port, e.g. 8080. If no port is required in
58
   *                     the URL, pass a 0 and the argument will be ignored.
59 2822 costa
   * @param contextString The context under which metacat is running, e.g. "knb".
60 2741 costa
   * @return metacatURL  The URL to the metacat servlet.
61
   */
62
  public String constructMetacatURL(final String serverName,
63 2822 costa
                                    final int serverPort,
64
                                    final String contextString) {
65 2741 costa
    String metacatURL = "http://" + serverName;
66
67
    if (serverPort > 0) {
68
      final Integer serverPortInteger = new Integer(serverPort);
69
      final String serverPortString = serverPortInteger.toString();
70 2822 costa
      metacatURL += ":" + serverPortString;
71 2741 costa
    }
72
73 2822 costa
    metacatURL += "/" + contextString + "/metacat";
74
75 2741 costa
    return metacatURL;
76
  }
77
78
}