/**
 * ConversionPropertyReader.java
 * Created on Aug 7, 2008
 * (C) Copyright TANDBERG Television Ltd.
 */
package com.tandbergtv.watchpoint.pmm.util.schedule.ingest;

import java.util.Enumeration;
import java.util.ResourceBundle;

/**
 * This is a helper class to read the properties from conversion.properties file
 * 
 * @author spuranik
 * 
 */
public class ConversionPropertyReader {

	// property which inidcates which providers have complete metadata in the incoming planner /
	// program list
	public static String PARTNERS_WITH_METADATA = "providerIds.with.metadata";

	// property which indicates the value for default encoding.
	public static String DEFAULT_ENCODING = "default.encoding";

	// suffix for the each provider's encoding property.
	// e.g. DTV.com.encoding=UTF-8 where DTV.com is set as the provider Id for the partner.
	public static final String ENCODING_KEY_SUFFIX = ".encoding";

	private static final String BUNDLE_NAME = "template-actions.conversion";
	private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME);

	/**
	 * Gets the value for the key specified in the conversion.properties
	 * 
	 * @param key
	 *            property name for which the value is expected
	 * @return string value of the property if present in conversion.properties
	 */
	public static String getProperty(String key) {
		return RESOURCE_BUNDLE.getString(key);
	}

	/**
	 * Generates the encodign key for the given providerId
	 * 
	 * @param providerId
	 * @return
	 */
	public static String getEncodingKey(String providerId) {
		return providerId + ENCODING_KEY_SUFFIX;
	}
	
	/**
	 * Goes thru all the keys in the bundle and checks if the name matches
	 * the reuqested key.
	 * 
	 * @param key
	 * 	Key to search for in the resource bundle
	 * @return
	 * 	True if the key is found else false. 
	 */
	public static boolean hasProperty(String key) {
		for (Enumeration<String> keys = RESOURCE_BUNDLE.getKeys(); keys.hasMoreElements();) {
			if (keys.nextElement().equalsIgnoreCase(key)) {
				return true;
			}
		}
		return false;
	}
}
