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:

BrowseServlet.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
......
44 47
 */
45 48
public class BrowseServlet extends HttpServlet {
46 49

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

  
49 59
  // Methods
50 60
  
......
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 = 
88
    	  metacatHelper.constructMetacatURL(serverName, serverPort, contextString);
78 89
    }
79 90

  
80 91
    // Tell the web server that the response is HTML
......
94 105
    dispatcher.forward(request, response);
95 106
  }
96 107
  
108
  /**
109
   * Initializes the servlet. Reads properties and initializes object fields.
110
   * 
111
   * @throws ServletException
112
   */
113
  public void init(ServletConfig config) throws ServletException {
114
	ServletContext context = null;
115
    String dirPath;
116
    Options options = null;
117

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

  
97 133
}

Also available in: Unified diff