2 package org
.de
.metux
.util
;
5 import java
.io
.IOException
;
6 import java
.util
.Hashtable
;
8 import java
.io
.FileNotFoundException
;
10 public class CachedDatasource
12 private Hashtable cache
= new Hashtable();
13 public boolean enabled
= true;
15 public String
loadContent(URL url
, boolean strip_comments
)
17 String filename
= url
.toString();
22 return LoadFile
.load(url
,strip_comments
);
30 String key
= "::URL::CONTENT::"+(strip_comments?
"STRIP::":"")+url
;
35 content
= (String
)cache
.get(key
);
37 catch (ClassCastException e
)
39 /* we've got an cached NOT-FOUND */
48 content
= LoadFile
.load(url
,strip_comments
);
49 cache
.put(key
,content
);
54 /* put the error into the cache */
60 public String
loadContent(File filename
, boolean strip_comments
)
65 return LoadFile
.load(filename
,strip_comments
);
73 String key
= "::FILENAME::CONTENT::"+(strip_comments?
"STRIP::":"")+filename
;
78 content
= (String
)cache
.get(key
);
80 catch (ClassCastException e
)
82 /* we've got an cached NOT-FOUND */
91 content
= LoadFile
.load(filename
,strip_comments
);
93 throw new RuntimeException("Could not load file: "+filename
);
94 cache
.put(key
,content
);
99 /* put the error into the cache */
105 public Hashtable
loadTextTable(String fn
, String pkey
)
108 String key
= "::FILENAME::TEXTDB::["+pkey
+"]"+fn
;
111 return TextTable
.Load(fn
,pkey
);
115 ht
= (Hashtable
)cache
.get(key
);
119 catch (ClassCastException e
)
124 ht
= TextTable
.Load(fn
,pkey
);
127 cache
.put(key
,new FileNotFoundException(fn
));