江陵 读取配置文件property

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * 
 * ProjectName:cms-common-util ClassName:PropertiesReader Description:
 * 
 * @author fanghuaichang Copyright © Oct 23, 2014,8:09:55 PM, The Hikvision
 *         Company. All Rights Reserved
 */
public class PropertiesReader {

    private static final String COMMON_PROPERTIES_FILE_NAME = "common-constants.properties";
    private static final String WEB_PROPERTIES_FILE_NAME = "constants.properties";

    private static Properties commonConfig = null;
    private static Properties webConfig = null;

    static {
        commonConfig = readProperties(COMMON_PROPERTIES_FILE_NAME);
        webConfig = readProperties(WEB_PROPERTIES_FILE_NAME);
    }

    public static String getProperty(String key) {
        return commonConfig.getProperty(key);
    }

    public static String getWebProperty(String key) {
        return webConfig.getProperty(key);
    }

    private static Properties readProperties(String fileName) {
        InputStream inputStream = PropertiesReader.class.getClassLoader().getResourceAsStream(fileName);

        Properties config = new Properties();
        try {
            config.load(inputStream);
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (inputStream != null) {
                try {
                    inputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

        return config;
    }
}
/**
* 地图相关参数
*/
public static String GIS_PLATFORM_IP = PropertiesReader.getWebProperty("gisplatform.ip");
public static Integer GIS_PLATFORM_PORT = Integer.valueOf(PropertiesReader.getWebProperty("gisplatform.port"));
public static String GIS_PLATFORM_SERVICE = PropertiesReader.getWebProperty("gisplatform.service");
public static String GIS_PLATFORM_NAME = PropertiesReader.getWebProperty("gisplatform.name");
public static String GIS_PLATFORM_PASSWORD = PropertiesReader.getWebProperty("gisplatform.password");
public static String GIS_PLATFORM_REFER = PropertiesReader.getWebProperty("gisplatform.refer");
public static String GIS_MAX_EXTENT_LEFT = PropertiesReader.getWebProperty("maxExtent.left");
public static String GIS_MAX_EXTENT_BOTTOM = PropertiesReader.getWebProperty("maxExtent.bottom");
public static String GIS_MAX_EXTENT_RIGHT = PropertiesReader.getWebProperty("maxExtent.right");
public static String GIS_MAX_EXTENT_TOP = PropertiesReader.getWebProperty("maxExtent.top");
public static String GIS_LAYER_SPATIAL_REFER = PropertiesReader.getWebProperty("layer.spatialRefer");
public static String GIS_LAYER_TYPE = PropertiesReader.getWebProperty("layer.type");
public static String GIS_INIT_CENTER_LON = PropertiesReader.getWebProperty("initCenter.lon");
public static String GIS_INIT_CENTER_LAT = PropertiesReader.getWebProperty("initCenter.lat");
public static Integer GIS_INIT_MAP_LEVEL = Integer.valueOf(PropertiesReader.getWebProperty("map.initLevel"));
public static Integer GIS_MIN_MAP_LEVEL = Integer.valueOf(PropertiesReader.getWebProperty("map.minLevel"));
public static Integer GIS_JS_RENDER_MAX_COUNT = 1000;
public static String EMS_VERSION = PropertiesReader.getWebProperty("version");

猜你喜欢

转载自www.cnblogs.com/xjatj/p/9712027.html
今日推荐