package com.seeyon.apps.src_ordinary.kit;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 读取参数
 */

public class PropKit {
	
	private static long lastModify;
	
	private static ConcurrentHashMap<String, String> props;
    
    public static final String PROFILE = "profile";
    
    public static final String DELIVERYURL = "deliveryUrl";
    
    public static final String PROD_DELIVERYURL = "prod.deliveryUrl";
    
    /**
     * @return
     * @throws IOException 
     * @throws FileNotFoundException 
     */
    public static String getProp(String key) throws FileNotFoundException, IOException {
		File f = new File(A8FolderKit.getPropFile());
		if(null == props) {
			props = new ConcurrentHashMap<String, String>();
		}
		if(f.lastModified() != lastModify) {
			/**
			 * huangzhengguo 
			 * 2022-10-18
			 */
			Properties prop = new Properties();
			prop.load(new FileInputStream(f));
//			Properties prop = PropertiesUtil.getFromFile((CtpLocalFile) f);
			/**
			 * end
			 */
			String profile = prop.getProperty(PROFILE);
			if("prod".equals(profile)) {
				props.put(DELIVERYURL, prop.getProperty(PROD_DELIVERYURL));
			} else {
				props.put(DELIVERYURL, prop.getProperty(PROD_DELIVERYURL));
			}
		}
		return props.get(key);
    }
  
}
