Project

General

Profile

« Previous | Next » 

Revision 4125

Added by daigle over 16 years ago

Replace Options class with PropertyService

View differences:

test/edu/ucsb/nceas/metacatnettest/MetaCatServletNetTest.java
28 28

  
29 29
import edu.ucsb.nceas.metacat.*;
30 30
import edu.ucsb.nceas.metacat.service.PropertyService;
31
import edu.ucsb.nceas.metacat.util.SystemUtil;
32
import edu.ucsb.nceas.utilities.Options;
33 31
import edu.ucsb.nceas.utilities.PropertyNotFoundException;
34 32
import edu.ucsb.nceas.morpho.framework.*;
35 33
import junit.framework.Test;
......
49 47
public class MetaCatServletNetTest extends TestCase {
50 48
	private static String metacatURL;
51 49
	static {
52
		try {
53
			metacatURL = SystemUtil.getServletURL();
54
			Options.initialize(new File("build/tests/metacat.properties"));
50
		try {		
51
			PropertyService.getInstance("build/tests");
52
			metacatURL = PropertyService.getProperty("test.metacat.url");
55 53
		} catch (PropertyNotFoundException pnfe) {
56 54
			System.err.println("could not find metacat URL in MetacatServletNetTest: "
57 55
					+ pnfe.getMessage());
......
125 123
		//insert invalid xml document
126 124
		number = Math.random() * 100000;
127 125
		serial = Integer.toString(((new Double(number)).intValue()));
128
		suite
129
				.addTest(new MetaCatServletNetTest("testInsertInvalidateXMLDocument",
126
		suite.addTest(new MetaCatServletNetTest("testInsertInvalidateXMLDocument",
130 127
						serial));
131 128
		//insert non well formed document
132 129
		number = Math.random() * 100000;
test/edu/ucsb/nceas/metacat/clientview/ClientViewHelperTest.java
7 7

  
8 8
package edu.ucsb.nceas.metacat.clientview;
9 9

  
10
import edu.ucsb.nceas.utilities.Options;
11 10
import java.io.ByteArrayOutputStream;
12 11
import java.io.File;
13 12
import junit.framework.*;
14 13
import com.oreilly.servlet.multipart.MultipartParser;
15
import edu.ucsb.nceas.metacat.client.MetacatClient;
16 14
import java.io.InputStream;
17 15
import java.util.HashMap;
18 16
import java.util.Stack;
......
24 22
import org.w3c.dom.Document;
25 23
import org.w3c.dom.Node;
26 24

  
25
import edu.ucsb.nceas.metacat.client.MetacatClient;
26
import edu.ucsb.nceas.metacat.service.PropertyService;
27

  
27 28
/**
28 29
 * ClientViewHelper JUnit tests
29 30
 * @author barteau
......
32 33
    ClientViewHelper            instance;
33 34
    ClientView                  clientViewBean;
34 35
    
35
    final static String         PATH_TO_PROPERTIES = "projects/metacat/build/war/WEB-INF/metacat.properties";
36
//    final static String         PATH_TO_PROPERTIES = "projects/metacat/build/war/WEB-INF/metacat.properties";
37
    final static String         PATH_TO_PROPERTIES = "projects/metacat/build/war/WEB-INF";
36 38
    final static String         USR = "";
37 39
    final static String         ORG = "NCEAS";
38 40
    final static String         PWD = "";
......
59 61
        if (DOWNLOAD_DATA_DOCID.equals("")) 
60 62
            fail("Please set the class property DOWNLOAD_DATA_DOCID before running this test.");
61 63
        
62
        Options.initialize(new File(PATH_TO_PROPERTIES));
64
        PropertyService.getInstance(PATH_TO_PROPERTIES);
63 65
        
64 66
        clientViewBean = new ClientView();
65 67
        clientViewBean.setUsername(USR);
src/edu/ucsb/nceas/metacat/harvesterClient/Harvester.java
25 25
package edu.ucsb.nceas.metacat.harvesterClient;
26 26

  
27 27
import com.oreilly.servlet.MailMessage;
28
import edu.ucsb.nceas.utilities.Options;
29
import java.io.File;
30 28
import java.io.IOException;
31 29
import java.io.PrintStream;
32 30
import java.sql.Connection;
......
43 41
import edu.ucsb.nceas.metacat.client.Metacat;
44 42
import edu.ucsb.nceas.metacat.client.MetacatFactory;
45 43
import edu.ucsb.nceas.metacat.client.MetacatInaccessibleException;
44
import edu.ucsb.nceas.metacat.service.PropertyService;
45
import edu.ucsb.nceas.metacat.service.ServiceException;
46 46
import edu.ucsb.nceas.metacat.util.SystemUtil;
47
import edu.ucsb.nceas.utilities.PropertyNotFoundException;
47 48

  
48 49
/**
49 50
 * Harvester is the main class for the Harvester application. The main
......
59 60
   */
60 61
  private static final String CONFIG_DIR = "../../build/war/WEB-INF";
61 62
  private static final String CONFIG_DIR_TEST = "./build/war/WEB-INF";
62
  private static final String CONFIG_NAME = "metacat.properties";
63
//  private static final String CONFIG_NAME = "metacat.properties";
63 64
  public static final String filler = "*";
64 65
  private static boolean keepRunning = true;
65 66
  public static final String marker =
66 67
"*****************************************************************************";
67
  public static Options options = null;
68
//  public static PropertyService propertyService = null;
68 69
  private static String schemaLocation = null;
69 70
   
70 71

  
......
83 84
  /**
84 85
   * Loads Harvester options from a configuration file.
85 86
   */
86
  public static void loadOptions(boolean test) {
87
  public static void loadProperties(boolean test) {
87 88
    String configDir = test ? CONFIG_DIR_TEST : CONFIG_DIR;    
88
    File propertyFile = new File(configDir, CONFIG_NAME);
89 89

  
90 90
    try {
91
      options = Options.initialize(propertyFile);
91
    	PropertyService.getInstance(configDir);
92 92
    } 
93
    catch (IOException e) {
94
      System.out.println("Error in loading options: " + e.getMessage());
93
    catch (ServiceException e) {
94
      System.out.println("Error in loading properties: " + e.getMessage());
95 95
    }
96 96
  }
97 97
  
98 98
  
99
  /**
100
    * Harvester main method.
101
    * 
102
    * @param args        the command line arguments
103
    * @throws SAXException
104
    * @throws IOException
105
    * @throws ParserConfigurationException
106
    */
107
  public static void main(String[] args) {
108
    Integer delayDefault = new Integer(0); // Default number of hours delay
109
    int delay = delayDefault.intValue();  // Delay in hours before first harvest
110
    Integer d;                            // Used for determining delay
111
    long delta;                           // endTime - startTime
112
    long endTime;                         // time that a harvest completes
113
    Harvester harvester;                  // object for a single harvest run
114
    Integer maxHarvestsDefault = new Integer(0);     // Default max harvests
115
    int maxHarvests = maxHarvestsDefault.intValue(); // Max number of harvests
116
    Integer mh;                              // used in determining max harvests
117
    int nHarvests = 0;                      // counts the number of harvest runs
118
    final long oneHour = (60 * 60 * 1000);   // milliseconds in one hour
119
    Integer periodDefault = new Integer(24); // Default hours between harvests
120
    int period = periodDefault.intValue();   // Hours between harvests
121
    Integer p;                               // Used in determining the period
122
    long startTime;                          // time that a harvest run starts
123
    boolean test = false;                    // Passed to loadOption()
124
    
125
    if (args.length > 0) {
126
      schemaLocation = args[0];
127
      System.err.println("schemaLocation: " + schemaLocation);
128
      
129
      try {
130
        Thread.sleep(10000);
131
      } 
132
      catch (InterruptedException e) {
133
        e.printStackTrace();
134
      }
135
    }
99
    /**
100
	 * Harvester main method.
101
	 * 
102
	 * @param args
103
	 *            the command line arguments
104
	 * @throws SAXException
105
	 * @throws IOException
106
	 * @throws ParserConfigurationException
107
	 */
108
	public static void main(String[] args) {
109
		Integer delayDefault = new Integer(0); // Default number of hours delay
110
		int delay = delayDefault.intValue(); // Delay in hours before first
111
												// harvest
112
		Integer d; // Used for determining delay
113
		long delta; // endTime - startTime
114
		long endTime; // time that a harvest completes
115
		Harvester harvester; // object for a single harvest run
116
		Integer maxHarvestsDefault = new Integer(0); // Default max harvests
117
		int maxHarvests = maxHarvestsDefault.intValue(); // Max number of
118
															// harvests
119
		Integer mh; // used in determining max harvests
120
		int nHarvests = 0; // counts the number of harvest runs
121
		final long oneHour = (60 * 60 * 1000); // milliseconds in one hour
122
		Integer periodDefault = new Integer(24); // Default hours between
123
													// harvests
124
		int period = periodDefault.intValue(); // Hours between harvests
125
		Integer p; // Used in determining the period
126
		long startTime; // time that a harvest run starts
127
		boolean test = false; // Passed to loadOption()
136 128

  
137
    System.out.println(marker);
138
    System.out.println("Starting Harvester");
139
    Harvester.loadOptions(test);
129
		if (args.length > 0) {
130
			schemaLocation = args[0];
131
			System.err.println("schemaLocation: " + schemaLocation);
140 132

  
141
    // Parse the delay property. Use default if necessary.    
142
    try {
143
      d = Integer.valueOf(options.getOption("delay"));
144
      delay = d.intValue();
145
    }
146
    catch (NumberFormatException e) {
147
      System.out.println("NumberFormatException: Error parsing delay: " +
148
                         e.getMessage());
149
      System.out.println("Defaulting to delay=" + delayDefault);
150
      delay = delayDefault.intValue();
151
    }
133
			try {
134
				Thread.sleep(10000);
135
			} catch (InterruptedException e) {
136
				e.printStackTrace();
137
			}
138
		}
152 139

  
153
    // Parse the maxHarvests property. Use default if necessary.    
154
    try {
155
      mh = Integer.valueOf(options.getOption("maxHarvests"));
156
      maxHarvests = mh.intValue();
157
    }
158
    catch (NumberFormatException e) {
159
      System.out.println("NumberFormatException: Error parsing maxHarvests: " +
160
                         e.getMessage());
161
      System.out.println("Defaulting to maxHarvests=" + maxHarvestsDefault);
162
      maxHarvests = maxHarvestsDefault.intValue();
163
    }
140
		System.out.println(marker);
141
		System.out.println("Starting Harvester");
142
		Harvester.loadProperties(test);
164 143

  
165
    // Parse the period property. Use default if necessary.    
166
    try {
167
      p = Integer.valueOf(options.getOption("period"));
168
      period = p.intValue();
169
    }
170
    catch (NumberFormatException e) {
171
      System.out.println("NumberFormatException: Error parsing period: " +
172
                         e.getMessage());
173
      System.out.println("Defaulting to period=" + periodDefault);
174
      period = periodDefault.intValue();
175
    }
176
    
177
    // Sleep for delay number of hours prior to starting first harvest
178
    if (delay > 0) {
179
      try {
180
        System.out.print("First harvest will begin in " + delay);
181
        if (delay == 1) {
182
          System.out.println(" hour.");
183
        }
184
        else {
185
          System.out.println(" hours.");
186
        }
187
        Thread.sleep(delay * oneHour);
188
      }
189
      catch (InterruptedException e) {
190
        System.err.println("InterruptedException: " + e.getMessage());
191
        System.exit(1);
192
      }
193
    }
144
		// Parse the delay property. Use default if necessary.
145
		try {
146
			d = Integer.valueOf(PropertyService.getProperty("delay"));
147
			delay = d.intValue();
148
		} catch (NumberFormatException e) {
149
			System.out.println("NumberFormatException: Error parsing delay: "
150
					+ e.getMessage());
151
			System.out.println("Defaulting to delay=" + delayDefault);
152
			delay = delayDefault.intValue();
153
		} catch (PropertyNotFoundException pnfe) {
154
			System.out.println("PropertyNotFoundException: Error finding delay: "
155
					+ pnfe.getMessage());
156
			System.out.println("Defaulting to delay=" + delayDefault);
157
			delay = delayDefault.intValue();
158
		}
194 159

  
160
		// Parse the maxHarvests property. Use default if necessary.
161
		try {
162
			mh = Integer.valueOf(PropertyService.getProperty("maxHarvests"));
163
			maxHarvests = mh.intValue();
164
		} catch (NumberFormatException e) {
165
			System.out.println("NumberFormatException: Error parsing maxHarvests: "
166
					+ e.getMessage());
167
			System.out.println("Defaulting to maxHarvests=" + maxHarvestsDefault);
168
			maxHarvests = maxHarvestsDefault.intValue();
169
		} catch (PropertyNotFoundException pnfe) {
170
			System.out.println("PropertyNotFoundException: Error finding maxHarvests: "
171
					+ pnfe.getMessage());
172
			System.out.println("Defaulting to maxHarvests=" + maxHarvestsDefault);
173
			maxHarvests = maxHarvestsDefault.intValue();
174
		}
175

  
176
		// Parse the period property. Use default if necessary.
177
		try {
178
			p = Integer.valueOf(PropertyService.getProperty("period"));
179
			period = p.intValue();
180
		} catch (NumberFormatException e) {
181
			System.out.println("NumberFormatException: Error parsing period: "
182
					+ e.getMessage());
183
			System.out.println("Defaulting to period=" + periodDefault);
184
			period = periodDefault.intValue();
185
		} catch (PropertyNotFoundException pnfe) {
186
			System.out.println("PropertyNotFoundException: Error finding period: "
187
					+ pnfe.getMessage());
188
			System.out.println("Defaulting to period=" + periodDefault);
189
			period = periodDefault.intValue();
190
		}
191

  
192
		// Sleep for delay number of hours prior to starting first harvest
193
		if (delay > 0) {
194
			try {
195
				System.out.print("First harvest will begin in " + delay);
196
				if (delay == 1) {
197
					System.out.println(" hour.");
198
				} else {
199
					System.out.println(" hours.");
200
				}
201
				Thread.sleep(delay * oneHour);
202
			} catch (InterruptedException e) {
203
				System.err.println("InterruptedException: " + e.getMessage());
204
				System.exit(1);
205
			}
206
		}
207

  
195 208
    // Repeat a new harvest once every period number of hours, until we reach
196 209
    // the maximum number of harvests, or indefinitely if maxHarvests <= 0.
197
    // Subtract delta from the time period so 
210
    // Subtract delta from the time period so
198 211
    // that each harvest will start at a fixed interval.
199 212
    //
200 213
    while (keepRunning && ((nHarvests < maxHarvests) || (maxHarvests <= 0))) {
201 214
      nHarvests++;
202 215
      startTime = System.currentTimeMillis();
203
      harvester = new Harvester();                // New object for this harvest
216
      harvester = new Harvester();                // New object for this
217
													// harvest
204 218
      harvester.startup(nHarvests, maxHarvests);  // Start up Harvester
205 219
      harvester.readHarvestSiteSchedule();        // Read the database table
206 220
      harvester.harvest();                        // Harvest the documents
......
395 409
   */
396 410
  public Connection getConnection() {
397 411
    String dbDriver = "";
398
    String defaultDB;
399
    String password;
400
    String user;
412
    String defaultDB = null;
413
    String password = null;
414
    String user = null;
401 415
    SQLWarning warn;
402 416
    
403 417
    if (conn == null) {
404
      dbDriver = options.getOption("database.driver");
405
      defaultDB = options.getOption("database.connectionURI");
406
      password = options.getOption("database.password");
407
      user = options.getOption("database.user");
418
    	try {
419
			dbDriver = PropertyService.getProperty("database.driver");
420
			defaultDB = PropertyService.getProperty("database.connectionURI");
421
			password = PropertyService.getProperty("database.password");
422
			user = PropertyService.getProperty("database.user");
423
		} catch (PropertyNotFoundException pnfe) {
424
			System.out.println("Can't find property " + pnfe);
425
	        System.exit(1);
426
		}
408 427

  
409 428
      // Load the jdbc driver
410 429
      try {
......
950 969
  }
951 970
    
952 971

  
953
  /**
954
   * Initializes Harvester at startup. Connects to the database and to Metacat.
955
   * 
956
   * @param nHarvests        the nth harvest
957
   * @param maxHarvests      the maximum number of harvests that this process
958
   *                         can run
959
   */
960
  private void startup(int nHarvests, int maxHarvests) {
961
    Boolean ctm;
962
    Integer lp;
963
    String metacatURL;
964
    Date now = new Date();
965
    
966
    timestamp = now.toString();
967
    System.out.println(Harvester.marker);
968
    System.out.print(timestamp + ": Starting Next Harvest");
969
    if (maxHarvests > 0) {
970
      System.out.print(" (" + nHarvests + "/" + maxHarvests + ")");
971
    }
972
    System.out.print("\n");
973
    ctm = Boolean.valueOf(options.getOption("connectToMetacat"));
974
    connectToMetacat = ctm.booleanValue();
975
    harvesterAdministrator = options.getOption("harvesterAdministrator");
976
    smtpServer = options.getOption("smtpServer");
972
    /**
973
	 * Initializes Harvester at startup. Connects to the database and to Metacat.
974
	 * 
975
	 * @param nHarvests        the nth harvest
976
	 * @param maxHarvests      the maximum number of harvests that this process
977
	 *                         can run
978
	 */
979
	private void startup(int nHarvests, int maxHarvests) {
980
		Boolean ctm;
981
		Integer lp;
982
		String metacatURL;
983
		Date now = new Date();
977 984

  
978
    try {
979
      lp = Integer.valueOf(options.getOption("logPeriod"));
980
      logPeriod = lp.intValue();
981
    }
982
    catch (NumberFormatException e) {
983
      System.err.println("NumberFormatException: Error parsing logPeriod " +
984
                         logPeriod + e.getMessage());
985
      System.err.println("Defaulting to logPeriod of 90 days");
986
      logPeriod = 90;
987
    }
985
		timestamp = now.toString();
986
		System.out.println(Harvester.marker);
987
		System.out.print(timestamp + ": Starting Next Harvest");
988
		if (maxHarvests > 0) {
989
			System.out.print(" (" + nHarvests + "/" + maxHarvests + ")");
990
		}
991
		System.out.print("\n");
992
		try {
993
			ctm = Boolean.valueOf(PropertyService.getProperty("connectToMetacat"));
994
			connectToMetacat = ctm.booleanValue();
995
			harvesterAdministrator = PropertyService
996
					.getProperty("harvesterAdministrator");
997
			smtpServer = PropertyService.getProperty("smtpServer");
988 998

  
989
    conn = getConnection();
990
    initLogIDs();
991
    setHarvestStartTime(now);
992
    // Log startup operation
993
    addLogEntry(0, "Starting Up Harvester", "HarvesterStartup", 0, null, "");
994
      
995
    if (connectToMetacat()) {      
996
      try {
997
        metacatURL = SystemUtil.getServletURL();
998
        System.out.println("Connecting to Metacat: " + metacatURL);
999
        metacat = MetacatFactory.createMetacatConnection(metacatURL);
1000
      } 
1001
      catch (MetacatInaccessibleException e) {
1002
        System.out.println("Metacat connection failed." + e.getMessage());
1003
      } 
1004
      catch (Exception e) {
1005
        System.out.println("Metacat connection failed." + e.getMessage());
1006
      }
1007
    }
1008
  }
999
			lp = Integer.valueOf(PropertyService.getProperty("logPeriod"));
1000
			logPeriod = lp.intValue();
1001
		} catch (NumberFormatException e) {
1002
			System.err.println("NumberFormatException: Error parsing logPeriod "
1003
					+ logPeriod + e.getMessage());
1004
			System.err.println("Defaulting to logPeriod of 90 days");
1005
			logPeriod = 90;
1006
		} catch (PropertyNotFoundException pnfe) {
1007
			System.out.println("PropertyNotFoundException: Error getting property: "
1008
					+ pnfe.getMessage());
1009
			return;
1010
		}
1009 1011

  
1012
		conn = getConnection();
1013
		initLogIDs();
1014
		setHarvestStartTime(now);
1015
		// Log startup operation
1016
		addLogEntry(0, "Starting Up Harvester", "HarvesterStartup", 0, null, "");
1017

  
1018
		if (connectToMetacat()) {
1019
			try {
1020
				metacatURL = SystemUtil.getServletURL();
1021
				System.out.println("Connecting to Metacat: " + metacatURL);
1022
				metacat = MetacatFactory.createMetacatConnection(metacatURL);
1023
			} catch (MetacatInaccessibleException e) {
1024
				System.out.println("Metacat connection failed." + e.getMessage());
1025
			} catch (Exception e) {
1026
				System.out.println("Metacat connection failed." + e.getMessage());
1027
			}
1028
		}
1029
	}
1030

  
1010 1031
}
src/edu/ucsb/nceas/metacat/harvesterClient/HarvesterServlet.java
24 24

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

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

  
30 27
import javax.servlet.*;
31 28
import javax.servlet.http.*;
32

  
33
import edu.ucsb.nceas.utilities.Options;
34

  
35 29
/**
36 30
 * HarvesterServlet class allows Harvester to be run as a background
37 31
 * process. This eliminates the need to run Harvester in a terminal window.
src/edu/ucsb/nceas/metacat/harvesterClient/HarvestLog.java
24 24

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

  
27
import edu.ucsb.nceas.utilities.Options;
28 27
import java.io.PrintStream;
29 28
import java.sql.Connection;
30 29
import java.sql.ResultSet;
......
35 34
import java.util.Date;
36 35
import java.util.StringTokenizer;
37 36

  
37
import edu.ucsb.nceas.metacat.service.PropertyService;
38
import edu.ucsb.nceas.utilities.PropertyNotFoundException;
38 39

  
39 40
/**
40 41
 * Manages log entries to be inserted to the HARVEST_LOG table.
......
252 253
  String getHarvestOperation(String fieldName, String harvestOperationCode) {
253 254
    String explanation = "No explanation available";
254 255
    String harvestOperationCodeLevel = "debug";
255
    Options options = Harvester.options;
256
    String propertyValue;
256
    String propertyValue = null;
257 257
    String returnString = "";
258 258
    StringTokenizer stringTokenizer;
259 259
    
260
    propertyValue = options.getOption(harvestOperationCode);
261
    stringTokenizer = new StringTokenizer(propertyValue, ",");
260
    try {
261
		propertyValue = PropertyService.getProperty(harvestOperationCode);
262
	} catch (PropertyNotFoundException pnfe) {
263
		System.out.println("Error trying to get property: " + harvestOperationCode
264
					+ " : " + pnfe.getMessage());
265
	}
266
	stringTokenizer = new StringTokenizer(propertyValue, ",");
262 267
    
263 268
    explanation = (String) stringTokenizer.nextElement();
264 269
    harvestOperationCodeLevel = (String) stringTokenizer.nextElement();
src/edu/ucsb/nceas/metacat/harvesterClient/HarvesterRegistration.java
25 25
package edu.ucsb.nceas.metacat.harvesterClient;
26 26

  
27 27
import com.oreilly.servlet.ParameterParser;
28
import edu.ucsb.nceas.utilities.Options;
29
import java.io.File;
30
import java.io.InputStream;
31 28
import java.io.IOException;
32 29
import java.io.PrintWriter;
33 30
import java.sql.Connection;
......
39 36
import java.text.ParseException;
40 37
import java.text.SimpleDateFormat;
41 38
import java.util.Date;
42
import java.util.Enumeration;
43 39
import javax.servlet.ServletConfig;
44 40
import javax.servlet.ServletContext;
45 41
import javax.servlet.ServletException;
......
48 44
import javax.servlet.http.HttpServletResponse;
49 45
import javax.servlet.http.HttpSession;
50 46

  
47
import edu.ucsb.nceas.metacat.service.PropertyService;
48
import edu.ucsb.nceas.metacat.service.ServiceException;
49
import edu.ucsb.nceas.utilities.PropertyNotFoundException;
50

  
51 51
/**
52 52
 * HarvesterRegistration is a servlet that implements harvester registration.
53 53
 * The servlet reads parameters that were entered in a harvester registration
......
64 64
   * Class fields
65 65
   */
66 66
  private static final String CONFIG_DIR = "WEB-INF";
67
  private static final String CONFIG_NAME = "metacat.properties";
68 67
   
68
  private static final long serialVersionUID = 7390084694699704362L;
69
	
69 70
  /*
70 71
   * Object fields
71 72
   */
......
726 727
  }
727 728
  
728 729

  
729
  /**
730
   * Initializes the servlet. Reads properties and initializes object fields.
731
   * 
732
   * @throws ServletException
733
   */
734
  public void init(ServletConfig config) throws ServletException {
735
    String database;
736
    String dbDriver = "";
737
    String dirPath;
738
    Options options = null;
730
    /**
731
	 * Initializes the servlet. Reads properties and initializes object fields.
732
	 * 
733
	 * @throws ServletException
734
	 */
735
	public void init(ServletConfig config) throws ServletException {
736
		String database;
737
		String dbDriver = "";
738
		String dirPath;
739 739

  
740
    super.init(config);
741
    this.config = config;
742
    this.context = config.getServletContext();
743
    dirPath = context.getRealPath(CONFIG_DIR);
744
    File propertyFile = new File(dirPath, CONFIG_NAME);
745
    
746
    try {
747
      options = Options.initialize(propertyFile);
748
    }
749
    catch (IOException e) {
750
      System.out.println("Error in loading options: " + e.getMessage());
751
    }
752
    
753
    dbDriver = options.getOption("database.driver");
754
    defaultDB = options.getOption("database.connectionURI");
755
    password = options.getOption("database.password");
756
    user = options.getOption("database.user");
740
		super.init(config);
741
		this.config = config;
742
		this.context = config.getServletContext();
743
		dirPath = context.getRealPath(CONFIG_DIR);
757 744

  
758
    // Load the jdbc driver
759
    try {
760
      Class.forName(dbDriver);
761
    }
762
    catch (ClassNotFoundException e) {
763
      System.out.println("Can't load driver " + e);
764
    } 
765
  }
745
		try {
746
			PropertyService.getInstance(dirPath);
766 747

  
748
			dbDriver = PropertyService.getProperty("database.driver");
749
			defaultDB = PropertyService.getProperty("database.connectionURI");
750
			password = PropertyService.getProperty("database.password");
751
			user = PropertyService.getProperty("database.user");
752
		} catch (ServiceException se) {
753
			System.out.println("Error initializing PropertyService: " + se.getMessage());
754
		} catch (PropertyNotFoundException pnfe) {
755
			System.out.println("Error reading property: " + pnfe.getMessage());
756
		}
767 757

  
758
		// Load the jdbc driver
759
		try {
760
			Class.forName(dbDriver);
761
		} catch (ClassNotFoundException e) {
762
			System.out.println("Can't load driver " + e);
763
		}
764
	}
765

  
766

  
768 767
  /**
769
   * Surrounds a string with single quotes.
770
   * @param str  the original string
771
   * @return     the quoted string
772
   */
768
	 * Surrounds a string with single quotes.
769
	 * 
770
	 * @param str
771
	 *            the original string
772
	 * @return the quoted string
773
	 */
773 774
  private String quoteString(String str) {
774 775
    return "'" + str + "'";
775 776
  }

Also available in: Unified diff