Project

General

Profile

« Previous | Next » 

Revision 2822

Added by Duane Costa over 18 years ago

Eliminate hard-coding of the knb context from the advanced search code. Advanced search servlet determines the metacat context name by reading the metacat.properties file at servlet initialization.

View differences:

LoginServlet.java
24 24

  
25 25
package edu.ucsb.nceas.metacat.advancedsearch;
26 26

  
27
import java.io.File;
27 28
import java.io.IOException;
28 29

  
29 30
import javax.servlet.RequestDispatcher;
31
import javax.servlet.ServletConfig;
30 32
import javax.servlet.ServletContext;
31 33
import javax.servlet.ServletException;
32 34
import javax.servlet.http.HttpServlet;
......
35 37
import javax.servlet.http.HttpSession;
36 38

  
37 39
import edu.ucsb.nceas.metacat.client.*;
40
import edu.ucsb.nceas.utilities.Options;
38 41

  
39 42
/** 
40 43
 * @author dcosta
......
43 46
 */
44 47
public class LoginServlet extends HttpServlet {
45 48

  
46
  // Instance Variables -- (Not used because they are not thread-safe.)
49
  /*
50
   * Class fields
51
   */
52
  private static final String CONFIG_DIR = "WEB-INF";
53
  private static final String CONFIG_NAME = "metacat.properties";
54
				   
55
  // Instance Variables
56
  private String contextString = "";
47 57

  
48 58
  // Methods
49 59
  
......
74 84
      MetacatHelper metacatHelper = new MetacatHelper();
75 85
      String serverName = request.getServerName();
76 86
      int serverPort = request.getServerPort();
77
      metacatURL = metacatHelper.constructMetacatURL(serverName, serverPort);
87
      metacatURL = metacatHelper.constructMetacatURL(serverName, serverPort, "knb");
78 88
    }
79 89
    
80 90
    if (metacat == null) {
......
107 117
    dispatcher.forward(request, response);
108 118
  }
109 119

  
120

  
121
  /**
122
   * Initializes the servlet. Reads properties and initializes object fields.
123
   * 
124
   * @throws ServletException
125
   */
126
  public void init(ServletConfig config) throws ServletException {
127
	ServletContext context = null;
128
    String dirPath;
129
    Options options = null;
130

  
131
    super.init(config);
132
    context = config.getServletContext();
133
    dirPath = context.getRealPath(CONFIG_DIR);
134
    File propertyFile = new File(dirPath, CONFIG_NAME);
135
    
136
    try {
137
      options = Options.initialize(propertyFile);
138
    }
139
    catch (IOException e) {
140
      System.err.println("Error in loading options: " + e.getMessage());
141
    }
142
    
143
    this.contextString = options.getOption("context");
144
  }
145

  
110 146
}

Also available in: Unified diff