2 package org
.de
.metux
.util
;
4 import java
.util
.Properties
;
5 import java
.util
.Hashtable
;
6 import java
.io
.FileNotFoundException
;
7 import java
.io
.BufferedReader
;
8 import java
.io
.FileReader
;
9 import java
.net
.URLDecoder
;
12 Note: URLDecoder.decode(String text) is deprecated.
13 Instead .decode(String text, String enc) should be used.
14 Have to think about it carefully.
19 Properties hash
= new Properties();
21 public Hashtable
getHashtable ()
26 public Hashtable
Load(String filename
)
28 Hashtable h
= new Hashtable ();
29 if (LoadIntoHashtable(filename
,h
))
35 public static boolean LoadIntoHashtable(String filename
, Hashtable table
)
41 in
= new BufferedReader(new FileReader(filename
));
43 catch (FileNotFoundException e
)
51 while ((line
=in
.readLine())!=null)
56 /* strip off comments */
57 if ((x
=line
.indexOf('#'))>=0)
58 line
= line
.substring(0,x
);
61 if ((len
=line
.length())>0)
63 /* -- split into key and value -- */
64 if ((x
= line
.indexOf(':'))>0)
70 key
= (line
.substring(0,x
)).trim();
71 value
= (line
.substring(x
+1)).trim();
72 value
= URLDecoder
.decode(value
);
74 if (table
.containsKey(key
))
75 table
.put(key
,table
.get(key
)+"\n"+value
);
80 System
.err
.println ( "CORRUPT LINE "+line
);
87 System
.err
.println("File input error");
92 public TextDB ( String filename
) throws FileNotFoundException
95 this.hash
= new Properties();
97 LoadIntoHashtable(filename
,this.hash
);