|
From: <tr...@us...> - 2003-08-06 03:23:53
|
Update of /cvsroot/babeldoc/babeldoc/modules/core/src/com/babeldoc/core
In directory sc8-pr-cvs1:/tmp/cvs-serv29205/src/com/babeldoc/core
Modified Files:
TieredConfigurationHelper.java
Log Message:
Changed the ad-hoc configuration scanning code with the csv reader code.
Index: TieredConfigurationHelper.java
===================================================================
RCS file: /cvsroot/babeldoc/babeldoc/modules/core/src/com/babeldoc/core/TieredConfigurationHelper.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** TieredConfigurationHelper.java 19 Jul 2003 15:32:27 -0000 1.5
--- TieredConfigurationHelper.java 6 Aug 2003 03:23:41 -0000 1.6
***************
*** 68,73 ****
--- 68,76 ----
import com.babeldoc.core.config.IConfig;
import com.babeldoc.core.config.ConfigService;
+ import com.mindprod.csv.CSVReader;
import java.util.*;
+ import java.io.StringReader;
+ import java.io.IOException;
/**
***************
*** 121,142 ****
String value = config.getString(key);
! StringTokenizer st = new StringTokenizer(key, ".");
! int numTokens = st.countTokens();
! Map working = configs;
! int tokenCount = 1;
! while (st.hasMoreTokens()) {
! String token = st.nextToken();
! if(tokenCount < numTokens) {
! if (working.get(token) == null) {
! working.put(token, new HashMap());
! }
! working = (Map)working.get(token);
! } else {
! working.put(token, value);
}
! ++tokenCount;
}
}
--- 124,148 ----
String value = config.getString(key);
! try {
! CSVReader csvReader = new CSVReader(new StringReader(key), '.', '"', false, true);
! String [] tokens = csvReader.getAllFieldsInLine();
! int numTokens = tokens.length;
! Map working = configs;
! for(int tokenCount = 0; tokenCount < numTokens; ++tokenCount) {
! String token = tokens[tokenCount];
! if(tokenCount < numTokens-1) {
! if (working.get(token) == null) {
! working.put(token, new HashMap());
! }
! working = (Map)working.get(token);
! } else {
! working.put(token, value);
! }
}
! } catch (IOException e) {
! // This should never happen
}
}
***************
*** 179,197 ****
cfg.setString("mike.four", "4");
cfg.setString("mike.five", "5");
! cfg.setString("peter.four.alpha", "4");
! cfg.setString("peter.five.beta", "5");
! cfg.setString(".info.broken", "aaa");
Map map = new TieredConfigurationHelper(cfg).getNamedConfigs();
for (Iterator iterator = map.keySet().iterator(); iterator.hasNext();) {
String name = (String) iterator.next();
! System.out.println("Map name: "+name);
! Map inner = (Map)map.get(name);
! for (Iterator iterator1 = inner.keySet().iterator(); iterator1.hasNext();) {
! String s = (String) iterator1.next();
! String v = (String)inner.get(s);
! System.out.println(" "+s+"="+v);
}
}
--- 185,211 ----
cfg.setString("mike.four", "4");
cfg.setString("mike.five", "5");
! cfg.setString("peter.\"four.alpha\"", "4");
! cfg.setString("peter.\"five.beta\"", "5");
! cfg.setString("\".info.broken\"", "aaa");
Map map = new TieredConfigurationHelper(cfg).getNamedConfigs();
+ printMap(map, 0);
+ }
+
+ private static void printMap(Map map, int i) {
for (Iterator iterator = map.keySet().iterator(); iterator.hasNext();) {
String name = (String) iterator.next();
+ Object o = map.get(name);
! for(int j = 0; j < i; ++j) {
! System.out.print(" ");
! }
! System.out.print(name);
! if(o instanceof Map) {
! System.out.println("");
! printMap((Map)o, i+1);
! } else {
! System.out.println("="+o);
}
}
|