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:

AdvancedSearchServlet.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
import java.util.Enumeration;
29 29

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

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

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

  
47
  // 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 = "";
48 57

  
49 58
  // Methods
50 59
  
......
74 83
      MetacatHelper metacatHelper = new MetacatHelper();
75 84
      String serverName = request.getServerName();
76 85
      int serverPort = request.getServerPort();
77
      metacatURL = metacatHelper.constructMetacatURL(serverName, serverPort);
86
      metacatURL = 
87
    	  metacatHelper.constructMetacatURL(serverName, serverPort, contextString);
78 88
    }
79 89

  
80 90
    // Get the advancedSearchBean object that has been loaded up with user
......
93 103
    dispatcher.forward(request, response);
94 104
  }
95 105
  
106
  /**
107
   * Initializes the servlet. Reads properties and initializes object fields.
108
   * 
109
   * @throws ServletException
110
   */
111
  public void init(ServletConfig config) throws ServletException {
112
	ServletContext context = null;
113
    String dirPath;
114
    Options options = null;
115

  
116
    super.init(config);
117
    context = config.getServletContext();
118
    dirPath = context.getRealPath(CONFIG_DIR);
119
    File propertyFile = new File(dirPath, CONFIG_NAME);
120
    
121
    try {
122
      options = Options.initialize(propertyFile);
123
    }
124
    catch (IOException e) {
125
      System.err.println("Error in loading options: " + e.getMessage());
126
    }
127
    
128
    this.contextString = options.getOption("context");
129
  }
130

  
96 131
}

Also available in: Unified diff