从.property文件中取值:并处理之

该文介绍了一个从特定文件中加载代理信息的过程,包括读取配置文件确定文件路径、解析代理信息并将其存储到哈希表中等步骤。文章还涉及了对代理是否活跃的检查以及邮件地址缺失情况的处理。

private Hashtable loadAgentReference(int cond) throws Exception{

        if (agentFeedPath == null || agentFeedPath.length() == 0){

            Properties pathProperties = new Properties();

            pathProperties.load(new FileInputStream("deliveryxxx.properties"));

            for (Enumeration upProp = pathProperties.keys() ; upProp.hasMoreElements() ;){

                String ketStr = (String)upProp.nextElement();

                //System.out.println(getLogMessage(ketStr+"="+pathProperties.getProperty(ketStr)));

            }

 

            agentFeedPath = pathProperties.getProperty("ftpFilePath")

                    + pathProperties.getProperty("agentFeedFile");

        }

 

        Hashtable agentTable = new Hashtable();

        BufferedReader br = new BufferedReader(new FileReader(agentFeedPath));

        String line = "";

        String agentCode = "";

        AgentIdentification agent;

        AgentIdentification branch;

        ArrayList missEmailBranchHead = new ArrayList();

        

        //200904 add for Checking agent

        boolean isActiveAgent = true;

        CSMSUserInterface csmsUserDAO = (CSMSUserInterface) new CSMSUserImpl();

        CSMSUserVO csmsUser = null;

        ArrayList csmsUserList = new ArrayList();

        csmsUserList = csmsUserDAO.searchCSMSUserList(null, null);

        if (csmsUserList != null) {

            csmsUser = (CSMSUserVO)csmsUserList.get(0);

            if (csmsUser != null) {

                if (!csmsUser.checkUser()) {

                    csmsUser = null;

                    System.out.println("CSMS is not available");

                }

            }

        }

        //200904<--

        

        while ((line = br.readLine()) != null){

            /** Feed Layout AGT_TRACK.DAT

             AgentCode   X(6)

             AgentName   X(30)

             UnitCode    X(5)

             BranchCode  X(5)

             BranchHead  X(30)

             BranchName  X(30)

             AgentEmail  X(60)

             */

            if (line.startsWith("HEADER") || line.startsWith("TRAILER"))

                continue;

            agentCode = line.substring(0, 6).trim();

            agent = new AgentIdentification();

            agent.setAgentCode(agentCode);

            agent.setAgentName(line.substring(6, 36).trim());

            agent.setUnitCode(line.substring(36, 41).trim());

            agent.setBranchCode(line.substring(41, 46).trim());

            agent.setBranchHead(line.substring(46, 76).trim());

            agent.setBranchName(line.substring(76, 106).trim());

            agent.setAgentEmail(line.substring(106, 166).trim());

            if (cond == BY_AGENT){

                agentTable.put(agentCode, agent);

            } else if (cond == BY_BRANCH_HEAD){

                if (agent.getAgentName().equalsIgnoreCase(agent.getBranchHead())){

                    if (agent.getAgentEmail().equals("")){

                        missEmailBranchHead.add(agent);

                        if (!agentTable.containsKey(agent.getBranchCode())){

                            agentTable.put(agent.getBranchCode(), agent);

                        }

                        

                    } else{

                    //----------------------

                    // Check Hashtable

                    // Assumption: latest agent code value should be the larger

                    // Keith 2006-02-07

                        if (agentTable.containsKey(agent.getBranchCode())){

                            branch = (AgentIdentification)agentTable.get(agent.getBranchCode());

                            

                            //200904 check if agent active

                            if (csmsUser != null) {

                                isActiveAgent = true;

                                if (csmsUser.searchAgent(agent.getAgentCode())) {

                                    if (!csmsUser.getIsActiveAgent()) {

                                        isActiveAgent = false;

                                    }

                                } else {

                                    isActiveAgent = false;

                                }

                            }

                            if (isActiveAgent) {

//                                System.out.println("update branch head: [" + agent.getBranchCode() + "] "

//                                                   +  branch.getAgentCode() + " >> " + agent.getAgentCode());

                                agentTable.put(agent.getBranchCode(),  agent);

                            }

//                            if (Integer.parseInt(agentCode)  > Integer.parseInt(branch.getAgentCode())) 

//                            {

//                                agentTable.put(agent.getBranchCode(),  agent);

//                            } else  {

//                              //Skip record

//                            }

                        } else 

                        {

                            agentTable.put(agent.getBranchCode(),  agent);

                        }

                      //----------------------

                      //agentTable.put(agent.getBranchCode(),  agent);

                    }

                }

            }

        }

        if (cond == BY_BRANCH_HEAD){

            for (int i = 0 ; i < missEmailBranchHead.size() ; i++){

                agent = (AgentIdentification)missEmailBranchHead.get(i);

                for (Enumeration n = agentTable.keys() ; n.hasMoreElements() ;){

                    branch = (AgentIdentification)agentTable.get((String)n.nextElement());

                    if (agent.getBranchHead().equalsIgnoreCase(branch.getBranchHead()) && !branch.getAgentEmail().equals("")){

                        agent.setAgentEmail(branch.getAgentEmail());

                        

                        //-----KW060207

                        if (Integer.parseInt(agent.getAgentCode())  > Integer.parseInt(branch.getAgentCode())) 

                        {

                            //200904 check if agent active

                            if (csmsUser != null) {

                                isActiveAgent = true;

                                if (csmsUser.searchAgent(agent.getAgentCode())) {

                                    if (!csmsUser.getIsActiveAgent()) {

                                        isActiveAgent = false;

                                    }

                                } else {

                                    isActiveAgent = false;

                                }

                            }

                            if (isActiveAgent) {

                                agentTable.put(agent.getBranchCode(),  agent);

                            }

                        }

                        //-----

                        //agentTable.put(agent.getBranchCode(), agent);

                        break;

                    }

                }

            }

        }

        return agentTable;

    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值