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;
    }