1 package org.lcsim.util.cache;
2
3 import java.io.File;
4 import java.io.FileInputStream;
5 import java.io.IOException;
6 import java.net.URL;
7 import org.xml.sax.EntityResolver;
8 import org.xml.sax.InputSource;
9 import org.xml.sax.SAXException;
10
11
12
13
14
15
16
17
18
19 public class CachingEntityResolver implements EntityResolver {
20 private FileCache fileCache;
21
22 public CachingEntityResolver() throws IOException {
23 fileCache = new FileCache();
24 }
25
26 public CachingEntityResolver(File cacheDirectory) throws IOException {
27 fileCache = new FileCache(cacheDirectory);
28 }
29
30 public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
31 File file = fileCache.getCachedFile(new URL(systemId));
32 InputSource result = new InputSource(new FileInputStream(file));
33 result.setSystemId(systemId);
34 return result;
35 }
36 }