Configuration.java 2.5 KB
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.airport.util;

import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
import org.springframework.core.io.Resource;
import org.springframework.util.DefaultPropertiesPersister;
import org.springframework.util.PropertiesPersister;

public class Configuration extends PropertyPlaceholderConfigurer {
    private static final Logger logger = Logger.getLogger(Configuration.class);
    private static final Map<String, String> parameterMap = new HashMap();
    private Resource location;

    public void setLocation(Resource location) {
        this.location = location;
    }

    public void loadProperties(Properties props) throws IOException {
        PropertiesPersister propertiesPersister = new DefaultPropertiesPersister();
        InputStream is = null;

        try {
            Resource location = this.location;
            is = location.getInputStream();
            propertiesPersister.load(props, is);
            Iterator var6 = props.keySet().iterator();

            while(var6.hasNext()) {
                Object key = var6.next();
                String code = props.getProperty((String)key).trim();
                parameterMap.put((String)key, code);
            }
        } catch (Exception var11) {
            logger.error("initialization error", var11);
            var11.printStackTrace();
        } finally {
            if (is != null) {
                is.close();
            }

        }

    }

    public Configuration() {
        logger.setLevel(Level.INFO);
    }

    public String getProperty(String name) throws LteException {
        String str = (String)parameterMap.get(name);
        if (str == null) {
            String errMsg = String.format("config.properties key Error, can not find key [%s]", name);
            logger.error(errMsg);
            throw new LteException(errMsg);
        } else {
            return str.trim();
        }
    }

    public String getPropertyMaybeNull(String name) throws LteException {
        String str = (String)parameterMap.get(name);
        if (StringUtils.isBlank(str)) {
            str = "";
        }

        return str.trim();
    }
}