    001package org.vishia.guiBzr;
    002
    003import java.io.BufferedReader;
    004import java.io.File;
    005import java.io.FileReader;
    006import java.io.IOException;
    007import java.util.LinkedList;
    008import java.util.List;
    009import java.util.Map;
    010import java.util.TreeMap;
    011
    012
    013public class DataConfig
    014{
    015
    016        final List<String> listSwPrjs = new LinkedList<String>();
    017
    018        final Map<String, String> indexCmds = new TreeMap<String, String>();
    019
    020        DataConfig()
    021        {
    022
    023        }
    024
    025
    026        String readConfig(File fileCfg)
    027        { String sError = null;
    028          FileReader fileReader = null;
    029          String sDivision;
    030          try{
    031                fileReader = new FileReader(fileCfg);
    032                        BufferedReader reader = new BufferedReader(fileReader);
    033                        String sLine;
    034                        while(sError == null && (sLine = reader.readLine())!=null){
    035                                sLine = sLine.trim();
    036                                if(sLine.length()>0){
    037                                        if(sLine.startsWith("==")){
    038                                                sDivision = sLine.trim();
    039                                        } else if(sLine.startsWith("cmd ")){
    040                            int posSep = sLine.indexOf('=');
    041            if(posSep < 0){
    042                sError = "missing \"=\" in line:" + sLine;
    043            }
    044            String sCmdIdent = sLine.substring(4, posSep).trim();
    045            String sCmdString = sLine.substring(posSep+1).trim();
    046            indexCmds.put(sCmdIdent, sCmdString);
    047                                        } else {
    048                                                listSwPrjs.add(sLine.trim());
    049                                        }
    050                                }
    051                        }
    052                        reader.close();
    053                } catch(IOException exc){
    054                        sError = "File error: " + fileCfg.getAbsolutePath();
    055                }
    056                try{ if(fileReader !=null){ fileReader.close();}} catch(IOException exc){
    057                        if(sError == null){ sError = "close error"; }
    058                }
    059                return sError;
    060        }
    061
    062}