add master

package cn.richinfo.cmail.plugs.task.bill.common;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Map;
import cn.richinfo.cmail.common.config.PropertiesUtil;
import richinfo.rmapi.common.ApiConfig;

public class InitLoad {
    
    private static ApiConfig apiConfig = ApiConfig.getInstance();
    
    //mail 模板
    static String sendMailMaste=null;
    
    //星期
    static Map<String, String> weekDay = new HashMap<String, String>();
    
    static Map<String, String> visitType = new HashMap<String, String>();
    
    public static String getMailMaste()
    {
        if(null!=sendMailMaste)
        {
            return sendMailMaste;
        }
        String path=apiConfig.loadLocalProps()+"/mail.eml";
        StringBuffer content=new StringBuffer();
        content.append("");
        InputStreamReader read;
        try {
            read = new InputStreamReader(new FileInputStream(new File(path)),"UTF-8");
            BufferedReader reader=new BufferedReader(read);
                String tempString = null;
                while ((tempString = reader.readLine()) != null) {
                    content.append(tempString);
                }
                reader.close();
        } catch (UnsupportedEncodingException e2) {
            e2.printStackTrace();
        } catch (FileNotFoundException e2) {
            e2.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        sendMailMaste=content.toString();
        return sendMailMaste;
    }
    
    
    
    public static String getWeekDay(String key) {
        String res = null;
        if (weekDay.size() > 0) {
            res = weekDay.get(key);
        } else {
            String weekDayStr = PropertiesUtil
                    .getProperty("admin.user.bill.Week" );
            String[] weekDays = weekDayStr.split(";");
            if (weekDays != null) {
                for (int i = 0; i < weekDays.length; i++) {
                    String[] ch = weekDays[i].split(":");

                    if (ch.length == 2) {
                        weekDay.put(ch[0], ch[1]);
                    }
                }
            }
            res = weekDay.get(key);
        }
        if (res != null) {
            return res;
        } else {
            return key;
        }
    }
    
    public static String getVisitType(String key) {
        String res = null;
        if (visitType.size() > 0) {
            res = visitType.get(key);
        } else {
            String visitTypeStr = PropertiesUtil
                    .getProperty("admin.user.bill.channel.type" );
            String[] visitTypeDays = visitTypeStr.split(";");
            if (visitTypeDays != null) {
                for (int i = 0; i < visitTypeDays.length; i++) {
                    String[] ch = visitTypeDays[i].split(":");

                    if (ch.length == 2) {
                        visitType.put(ch[0], ch[1]);
                    }
                }
            }
            res = visitType.get(key);
        }
        if (res != null) {
            return res;
        } else {
            return "";
        }
    }
}



package cn.richinfo.cmail.plugs.task.bill.common;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import cn.richinfo.cmail.common.log.AdminLogger;
import cn.richinfo.cmail.common.log.Log;

public class LoadMaster {
    
    private final static Log log = AdminLogger.getInstance();
    //mail 模板
    static String sendMailMaste=null;
    
     private static volatile LoadMaster conf;
    
       public static LoadMaster getInstance()
        {
            if (conf == null)
            {
                synchronized (LoadMaster.class)
                {
                    if (conf == null)
                    {
                        conf = new LoadMaster();
                    }
                }
            }
            return conf;
        }
       
       public  String getLoadMailMaste()
        {
            if(null!=sendMailMaste)
            {
                return sendMailMaste;
            }
            InputStream is = null;
            StringBuffer content=new StringBuffer();
            content.append("");
            InputStreamReader read;
            try {
                    is = getClass().getResourceAsStream(
                        "../masterfile/mail.html");
                    if (is == null)
                    {
                        is = getClass().getResourceAsStream(
                            "/" + "masterfile/mail.html");
                    }

                    if (is != null)
                    {
                        log.info("load mail master Success end ========================================");
                    }
                    else
                    {
                        log.info("load mail master Error end ========================================");
                    }

                    read = new InputStreamReader(is, "UTF-8");
                BufferedReader reader=new BufferedReader(read);
                    String tempString = null;
                    while ((tempString = reader.readLine()) != null) {
                        content.append(tempString);
                    }
                    reader.close();
            } catch (UnsupportedEncodingException e2) {
                e2.printStackTrace();
            } catch (FileNotFoundException e2) {
                e2.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
            sendMailMaste=content.toString();
            return sendMailMaste;
        }

}


package richinfo.rmapi.common;

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

import org.apache.log4j.Logger;

import richinfo.tools.Tools;

/**
 * @Description :读取配置文件类
 * @date(创建日期):2010-11-10 下午03:34:28
 * @company(公司):深圳市彩讯科技有限公司
 *
 * @History(修改历史):
 */
public class ApiConfig
{

    /** 属性列表值. */
    private Properties props = null;
    /** 全局配置文件 */
    private Properties localProps = null;
    /**
     * 本地配置:配置文件所在文件夹
     */
    private String configDir;
    private static Logger log = Logger.getLogger(ApiConfig.class);

    private static volatile ApiConfig conf;

    private ApiConfig()
    {
        props = new Properties();
        localProps = new Properties();
        loadLocalProps();
        loadProps();
    }

    public static ApiConfig getInstance()
    {
        if (conf == null)
        {
            synchronized (ApiConfig.class)
            {
                if (conf == null)
                {
                    conf = new ApiConfig();
                }
            }
        }
        return conf;
    }

    public String getProperty(String key)
    {
        return props.getProperty(key);
    }

    public String getProperty(String key, String defaultValue)
    {
        return props.getProperty(key, defaultValue);
    }

    public int getPropertyInt(String key)
    {
        String tmpstr = props.getProperty(key);
        int result = 0;
        try
        {
            result = Integer.parseInt(tmpstr);
        }
        catch (Exception e)
        {}
        tmpstr = null;
        return result;
    }

    public int getPropertyInt(String key, int defaultValue)
    {
        String tmpstr = props.getProperty(key);
        int result = defaultValue;
        try
        {
            result = Integer.parseInt(tmpstr);
        }
        catch (Exception e)
        {}
        tmpstr = null;
        return result;
    }

    public long getPropertyLong(String key, long defaultValue)
    {
        String tmpstr = props.getProperty(key);
        long result = defaultValue;
        try
        {
            result = Tools.String2Long(tmpstr);
        }
        catch (Exception e)
        {}
        tmpstr = null;
        return result;
    }

    public Boolean getPropertyBoolean(String key, boolean defaultValue)
    {
        String tmpstr = props.getProperty(key);
        Boolean result = defaultValue;
        try
        {
            result = Boolean.parseBoolean(tmpstr);
        }
        catch (Exception e)
        {}
        tmpstr = null;
        return result;
    }

    /**
     * 加载本服务器配置文件
     */
    public String loadLocalProps()
    {
        InputStream is = null;
        InputStreamReader reader = null;
        try
        {
            log.info("load LocalProperties Start========================================");
            is = getClass().getResourceAsStream(
                "/WEB-INF/classes/" + ApiConsts.LOCALPROPERTIES);
            if (is == null)
            {
                is = getClass().getResourceAsStream(
                    "/" + ApiConsts.LOCALPROPERTIES);
            }

            if (is != null)
            {
                log.info("load LocalProperties Success end ========================================");
            }
            else
            {
                log.info("load LocalProperties Error end ========================================");
            }

            reader = new InputStreamReader(is, "UTF-8");
            localProps.load(reader);

            this.configDir = localProps.getProperty("configdir");
            return this.configDir;
        }
        catch (Exception e)
        {
            log.error("Exception", e);
            return "";
        }
        finally
        {
            if (is != null)
            {
                try
                {
                    is.close();
                    is = null;
                }
                catch (Exception e)
                {
                    log.error("Exception", e);
                }
            }
            if (reader != null)
            {
                try
                {
                    reader.close();
                    reader = null;
                }
                catch (Exception e)
                {
                    log.error("Exception", e);
                }
            }
        }
    }

    /**
     * 提供给系统配置使用,当配置变化后可以通过一个servlet管理页面调用这个函数来重新加载配置
     */
    @SuppressWarnings("unused")
    public void loadProps()
    {
        props.clear();
        InputStream is = null;
        InputStreamReader reader = null;

        try
        {
            log.info("load ApiConfig Start========================================");

            if (!Tools.isEmpty(this.configDir))
            {
                is = new FileInputStream(this.configDir + "/"
                    + ApiConsts.RMAPIPROPERTIES);
            }

            if (is == null)
            {
                is = getClass().getResourceAsStream(
                    "/" + ApiConsts.RMAPIPROPERTIES);
            }

            if (is == null)
            {
                log.info("first load ApiConfig error");
                is = getClass().getResourceAsStream(
                    "/WEB-INF/classes/" + ApiConsts.RMAPIPROPERTIES);

            }
            if (is != null)
            {
                log.info("load ApiConfig Success end ========================================");
            }
            else
            {
                log.info("load ApiConfig Error end ========================================");
            }

            reader = new InputStreamReader(is, "UTF-8");
            props.load(reader);
        }
        catch (IOException e)
        {
            log.error("Exception", e);
        }
        finally
        {
            if (is != null)
            {
                try
                {
                    is.close();
                    is = null;
                }
                catch (Exception e)
                {
                    log.error("Exception", e);
                }
            }
            if (reader != null)
            {
                try
                {
                    reader.close();
                    reader = null;
                }
                catch (Exception e)
                {
                    log.error("Exception", e);
                }
            }
        }
    }

}




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值