加载模板

来源:互联网 发布:c语言中double和float 编辑:程序博客网 时间:2024/04/29 17:40
package cn.richinfo.cmail.plugs.task.bill.common;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
import org.springframework.context.MessageSource;
import org.springframework.context.MessageSourceAware;
import org.springframework.context.support.MessageSourceAccessor;

import cn.richinfo.cmail.common.log.AdminLogger;
import cn.richinfo.cmail.common.log.Log;
import richinfo.rmapi.common.ApiConfig;

public class InitLoad implements MessageSourceAware{
    
    private final static Log log = AdminLogger.getInstance();
    
    private static MessageSourceAccessor  messageSourceAccessor;
    
    private static ApiConfig apiConfig = ApiConfig.getInstance();
    
    //mail 模板
    static String sendMailMaste=null;
    
    static String loginSituation=null;
    
    static String bosomSendByNumSituation=null;
    
    //星期
    static Map<String, String> weekDay = new HashMap<String, String>();
    
    static Map<String, String> visitType = new HashMap<String, String>();
    
    static Map<String,String> activeUnits=new HashMap<String,String>();
    
    public static String getMailMaste()
    {
        if(null!=sendMailMaste)
        {
            return sendMailMaste;
        }
        String path=apiConfig.loadLocalProps()+"/mail_bill.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 (Exception e) {
            log.error("load bill master mail_bill.eml is error",e);
        }
        sendMailMaste=content.toString();
        return sendMailMaste;
    }
    
    public static String getLoginSituationMaste()
    {
        if(null!=loginSituation)
        {
            return loginSituation;
        }
        String path=apiConfig.loadLocalProps()+"/loginStatution.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 (Exception e) {
            log.error("load bill master loginStatution.eml is error",e);
        }
        loginSituation=content.toString();
        return loginSituation;
    }
    
    public static String getBosomSendByNumSituationMaste()
    {
        if(null!=bosomSendByNumSituation)
        {
            return bosomSendByNumSituation;
        }
        String path=apiConfig.loadLocalProps()+"/bosomSendByNumSituation.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 (IOException e) {
            log.error("load bill master bosomSendByNumSituation.eml is error",e);
        }
        bosomSendByNumSituation=content.toString();
        return bosomSendByNumSituation;
    }
    
    public static String getWeekDay(String key) {
        String res = null;
        if (weekDay.size() > 0) {
            res = weekDay.get(key);
        } else {
            String weekDayStr = messageSourceAccessor.getMessage("log.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 =messageSourceAccessor.getMessage("log.user.bill.login_channel");
            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 "";
        }
    }
    
    public static String getUnit(String key,MessageSourceAccessor  messageSourceAccessor) {
        String res = null;
        if (activeUnits.size() > 0) {
            res = activeUnits.get(key);
        } else {
            String unitStr = messageSourceAccessor.getMessage("log.user.bill.active_units");
            String[] units = unitStr.split(";");
            if (units != null) {
                for (int i = 0; i < units.length; i++) {
                    String[] ch = units[i].split("@");
                    if (ch.length == 2) {
                        activeUnits.put(ch[0], ch[1]);
                    }
                }
            }
            res = weekDay.get(key);
        }
        if (res != null) {
            return res;
        } else {
            return key;
        }
    }

    @Override
    public void setMessageSource(MessageSource messageSource) {
        // TODO Auto-generated method stub
        messageSourceAccessor=new MessageSourceAccessor(messageSource);
    }
    
    
}

0 0
原创粉丝点击