Project

General

Profile

« Previous | Next » 

Revision 82

Added by Matt Jones over 24 years ago

created options file for MetaCatServlet

View differences:

src/edu/ucsb/nceas/metacat/MetaCatUtil.java
19 19
 */
20 20
public class MetaCatUtil {
21 21

  
22
  static  String 	user = "jones";
23
  static  String 	password = "your-pw-goes-here";
24
  static  String 	defaultDB = "jdbc:oracle:thin:@localhost:1521:test";
25

  
26 22
  /** 
27 23
   * Utility method to establish a JDBC database connection 
28 24
   *
src/edu/ucsb/nceas/metacat/MetaCatServlet.java
17 17
import java.io.BufferedReader;
18 18
import java.util.Enumeration;
19 19
import java.util.Hashtable;
20
import java.util.ResourceBundle;
21
import java.util.PropertyResourceBundle;
20 22
import java.net.URL;
21 23
import java.net.MalformedURLException;
22 24
import java.sql.Connection;
......
61 63
  Connection 		conn = null;
62 64
  DBSimpleQuery		queryobj = null;
63 65
  DBReader		docreader = null;
64
  static  String 	user = MetaCatUtil.user;
65
  static  String 	password = MetaCatUtil.password;
66
  static  String 	defaultDB = MetaCatUtil.defaultDB;
67
  static  String 	resultStyleURL = "file:///home/httpd/html/xmltodb/resultset.xsl";
66
  String 	user = null;
67
  String 	password = null;
68
  String 	defaultDB = null;
69
  String 	resultStyleURL = null;
70
  //String 	resultStyleURL = "file:///home/httpd/html/xmltodb/resultset.xsl";
71
  PropertyResourceBundle options = null;
68 72

  
69 73
  /**
70 74
   * Initialize the servlet by creating appropriate database connections
......
74 78
      super.init( config );
75 79
      this.config = config;
76 80
      this.context = config.getServletContext();
77
    System.out.println("Servlet Initialize");
81
      System.out.println("Servlet Initialize");
82

  
83
      // Get the configuration file
84
      options = (PropertyResourceBundle)PropertyResourceBundle.getBundle("edu.ucsb.nceas.metacat.metacat");
85
      user = (String)options.handleGetObject("user");
86
      password = (String)options.handleGetObject("password");
87
      defaultDB = (String)options.handleGetObject("defaultDB");
88
      resultStyleURL = (String)options.handleGetObject("resultStyleURL");
89

  
78 90
      try {
79 91
        // Open a connection to the database
80 92
        conn = MetaCatUtil.openDBConnection(
......
152 164
  private void handleQueryAction(PrintWriter out, Hashtable params, 
153 165
               HttpServletResponse response) {
154 166
      // Run the query
167
      Hashtable nodelist = null;
155 168
      String query = ((String[])params.get("query"))[0]; 
156
      Hashtable nodelist = queryobj.findRootNodes(query);
169
      if (queryobj != null) {
170
        nodelist = queryobj.findRootNodes(query);
171
      } else {
172
        out.println("Query Object Init failed.");
173
        out.println(user);
174
        out.println(defaultDB);
175
      }
157 176
 
158 177
      // Create a buffer to hold the xml result
159 178
      StringBuffer resultset = new StringBuffer();
MetaCatUtil.java
19 19
 */
20 20
public class MetaCatUtil {
21 21

  
22
  static  String 	user = "jones";
23
  static  String 	password = "your-pw-goes-here";
24
  static  String 	defaultDB = "jdbc:oracle:thin:@localhost:1521:test";
25

  
26 22
  /** 
27 23
   * Utility method to establish a JDBC database connection 
28 24
   *
MetaCatServlet.java
17 17
import java.io.BufferedReader;
18 18
import java.util.Enumeration;
19 19
import java.util.Hashtable;
20
import java.util.ResourceBundle;
21
import java.util.PropertyResourceBundle;
20 22
import java.net.URL;
21 23
import java.net.MalformedURLException;
22 24
import java.sql.Connection;
......
61 63
  Connection 		conn = null;
62 64
  DBSimpleQuery		queryobj = null;
63 65
  DBReader		docreader = null;
64
  static  String 	user = MetaCatUtil.user;
65
  static  String 	password = MetaCatUtil.password;
66
  static  String 	defaultDB = MetaCatUtil.defaultDB;
67
  static  String 	resultStyleURL = "file:///home/httpd/html/xmltodb/resultset.xsl";
66
  String 	user = null;
67
  String 	password = null;
68
  String 	defaultDB = null;
69
  String 	resultStyleURL = null;
70
  //String 	resultStyleURL = "file:///home/httpd/html/xmltodb/resultset.xsl";
71
  PropertyResourceBundle options = null;
68 72

  
69 73
  /**
70 74
   * Initialize the servlet by creating appropriate database connections
......
74 78
      super.init( config );
75 79
      this.config = config;
76 80
      this.context = config.getServletContext();
77
    System.out.println("Servlet Initialize");
81
      System.out.println("Servlet Initialize");
82

  
83
      // Get the configuration file
84
      options = (PropertyResourceBundle)PropertyResourceBundle.getBundle("edu.ucsb.nceas.metacat.metacat");
85
      user = (String)options.handleGetObject("user");
86
      password = (String)options.handleGetObject("password");
87
      defaultDB = (String)options.handleGetObject("defaultDB");
88
      resultStyleURL = (String)options.handleGetObject("resultStyleURL");
89

  
78 90
      try {
79 91
        // Open a connection to the database
80 92
        conn = MetaCatUtil.openDBConnection(
......
152 164
  private void handleQueryAction(PrintWriter out, Hashtable params, 
153 165
               HttpServletResponse response) {
154 166
      // Run the query
167
      Hashtable nodelist = null;
155 168
      String query = ((String[])params.get("query"))[0]; 
156
      Hashtable nodelist = queryobj.findRootNodes(query);
169
      if (queryobj != null) {
170
        nodelist = queryobj.findRootNodes(query);
171
      } else {
172
        out.println("Query Object Init failed.");
173
        out.println(user);
174
        out.println(defaultDB);
175
      }
157 176
 
158 177
      // Create a buffer to hold the xml result
159 178
      StringBuffer resultset = new StringBuffer();
lib/metacat.properties
1
#
2
# Properties file defining options for the MetaCatServlet.java servlet
3
# Matt Jones
4
# '$Id$'
5
#
6
user=jones
7
password=your-pw-goes-here
8
defaultDB=jdbc:oracle:thin:@localhost:1521:test
9
dbDriver=oracle.jdbc.driver.OracleDriver
10
resultStyleURL=file:///home/httpd/html/xmltodb/resultset.xsl
0 11

  
Makefile
45 45
servlet: query reader orasax xvalid
46 46
	$(JAVAC) -classpath "$(CPATH)" MetaCatServlet.java
47 47
	cp -r classes/edu /home/httpd/servlets/
48
	cp metacat.properties /home/httpd/servlets/edu/ucsb/nceas/metacat/
48 49

  
49 50
util: 
50 51
	$(JAVAC) -classpath "$(CPATH)" \
metacat.properties
1
#
2
# Properties file defining options for the MetaCatServlet.java servlet
3
# Matt Jones
4
# '$Id$'
5
#
6
user=jones
7
password=your-pw-goes-here
8
defaultDB=jdbc:oracle:thin:@localhost:1521:test
9
dbDriver=oracle.jdbc.driver.OracleDriver
10
resultStyleURL=file:///home/httpd/html/xmltodb/resultset.xsl
0 11

  

Also available in: Unified diff