2 package org
.de
.metux
.util
;
4 import java
.util
.Hashtable
;
5 import java
.util
.Properties
;
7 import java
.util
.Enumeration
;
11 public static Hashtable
Load(String filename
,String pkey
)
13 Hashtable h
= new Hashtable ();
14 if (LoadIntoHashtable(filename
,h
, pkey
))
20 public static boolean LoadIntoHashtable(String filename
, Hashtable table
, String pkey
)
26 in
= new BufferedReader(new FileReader(filename
));
28 catch (FileNotFoundException e
)
36 Hashtable record
= new Properties();
39 while ((line
=in
.readLine())!=null)
44 /* strip off comments */
45 if ((x
=line
.indexOf('#'))>=0)
46 line
= line
.substring(0,x
);
49 if ((len
=line
.length())>0)
51 /* -- split into key and value -- */
52 if ((x
= line
.indexOf(':'))>0)
58 key
= (line
.substring(0,x
)).trim();
59 value
= (line
.substring(x
+1)).trim();
61 if (record
.containsKey(key
))
62 record
.put(key
,record
.get(key
)+"\n"+value
);
64 record
.put(key
,value
);
66 else if ((line
.indexOf("--")==0)&&(!record
.isEmpty()))
68 String k
= (String
)record
.get(pkey
);
72 table
.put(record
,record
);
74 record
= new Hashtable();
79 filename
+":"+linecnt
+"): "+line
);
87 System
.err
.println("File input error");
92 public static String
DumpTable ( Hashtable table
)
98 for (Enumeration e
= table
.keys(); e
.hasMoreElements(); )
100 String key
= (String
)e
.nextElement();
101 res
+= "#PKEY: "+key
+"\n";
102 Hashtable record
= (Hashtable
)table
.get(key
);
103 for (Enumeration re
= record
.keys(); re
.hasMoreElements(); )
105 String rk
= (String
)re
.nextElement();
106 res
+= rk
+": "+record
.get(rk
)+"\n";