/**
 * 
 * <DL>
 * <DT><B>系统配置文件读取类</B></DT>
 * </DL>
 * 处理具有类似下面内容的文件:
[System Define]
SYSID=006
SYSNAME=支票影像交换系统
Authenticated MODE=1
Server Access MODE= CLIENT
IPADD=
URL=
CLIENT= PATH
AB=[System Define]
SYSID=007
SYSNAME=电子验印系统-联机
Authenticated MODE=1
Server Access MODE= CLIENT
IPADD=
URL=
CLIENT= PATH
AB= * @author
 * @author
 * @version $Revision: 1.00 $ $Date: 2011/10/22 $
 */
public class ConfigFileUtil{
private static String instanceDir;
private static final String FILE_NAME = "/resources/para/uccb.dat";
private static final String FILE_NAME2 = "/resources/para/UCCB_field.hlp";
/***
 * 读取系统配置文件
 * @param trade
 * @return
 */
public static Map<String, String> readConfigFile(Trade trade, String sysId){
Map<String, String> m = new HashMap<String, String>();
m.put("sign", "");
String instanceDir = getInstanceDir();// /home/abs/workspace
String projectDir = trade.getResourceManager().getProjectName(
trade.getClass().getName());
String fileName = instanceDir + "/" + projectDir + FILE_NAME;
try {
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(fileName)));
String line = "";
String  = "0";
while ((line = br.readLine().trim()) != null) {
if (line.length() == 0){
continue;
}
read(line, m);
String[] str = line.split("=");
if ("SYSID".equals(str[0])){
if (str[1].equals(sysId)){
 = "1";
continue;
}
}
if ("[System Define]".equals(line)){
if (!"1".equals()){
m.clear();
continue;
} else {
 = "0";
break;
}
}
}
br.close();
} catch (FileNotFoundException e) {
trade.showInfo("单点登录系统配置文件不存在:" + FILE_NAME);
} catch (IOException e) {
trade.showInfo("读取单点登录系统配置文件[ " + FILE_NAME + " ]失败!");
} catch (NullPointerException e){
m.put("sign", "over");
} catch (Exception e){
}
return m;
}
         
         
/***
 * 分割键值
 * @param line
 * @return
 */
private static void read(String line, Map<String, String> map) throws IOException{
if ("".equals(line.trim())){
return ;
}
int index = line.indexOf("=");
if (index < 0){
return ;
}
String key = line.substring(0, index);
if (index + 1 == line.length()){
map.put(key, "");
} else {
String value = line.substring(index+1);
map.put(key, value);
}
return ;
}}