/**
 * JobProperties.java
 * Created on Jul 18, 2008
 * (C) Copyright TANDBERG Television Ltd.
 */
package com.tandbergtv.watchpoint.pmm.job.conf;

import static java.io.File.separator;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

import org.apache.log4j.Logger;

/**
 * This class reads the job.properties file and provides a way to get the value for that property.
 * 
 * @author spuranik
 * 
 */
public class JobProperties {

	public static String RECOVER_ALL_JOBS = "recoverAllJobs";
	private static final Logger logger = Logger.getLogger(JobProperties.class);
	private static String CONFIG_FILE = "job.properties";
	private static final String PRODUCT_DIR = "com.tandbergtv.cms.product.dir";
	private static final String PMM_CONFIG_DIR = "pmm";

	/**
	 * @param propertyName
	 *            property name whose value needs to be retrieved
	 * @return string value of the property which should exist in the properties file OR null if
	 *         there was a problem accessing the properties file
	 */
	public static String getProperty(String propertyName) {
		try {
			String dir = System.getProperty(PRODUCT_DIR) + separator + "conf";
			String filename = dir + separator + PMM_CONFIG_DIR + separator + CONFIG_FILE;
			
			Properties props = new Properties();
			props.load(new FileInputStream(new File(filename)));

			return props.getProperty(propertyName);
		} catch (IOException e) {
			String errorMsg = "Error while getting property: " + propertyName;
			logger.error(errorMsg, e);
			return null;
		}
	}
}
