01: /**
02: *
03: */package org.araneaframework.http.support;
04:
05: import java.io.InputStream;
06: import org.apache.commons.logging.Log;
07: import org.apache.commons.logging.LogFactory;
08: import org.araneaframework.http.core.Constants;
09: import org.xml.sax.EntityResolver;
10: import org.xml.sax.InputSource;
11: import org.xml.sax.SAXException;
12:
13: public class CachingEntityResolver implements EntityResolver {
14: public static final CachingEntityResolver INSTANCE = new CachingEntityResolver();
15:
16: private CachingEntityResolver() {
17: }
18:
19: // Logger
20: private static final Log log = LogFactory
21: .getLog(CachingEntityResolver.class);
22:
23: public InputSource resolveEntity(String publicId, String systemId)
24: throws SAXException {
25: for (int i = 0; i < Constants.CACHED_DTD_PUBLIC_IDS.length; i++) {
26: String cachedDtdPublicId = Constants.CACHED_DTD_PUBLIC_IDS[i];
27: if (cachedDtdPublicId.equals(publicId)) {
28: String resourcePath = Constants.CACHED_DTD_RESOURCE_PATHS[i];
29: InputStream input = this .getClass()
30: .getResourceAsStream(resourcePath);
31: if (input == null) {
32: throw new SAXException("Resource not found: '"
33: + resourcePath + "'!");
34: }
35: InputSource isrc = new InputSource(input);
36: return isrc;
37: }
38: }
39: if (log.isDebugEnabled())
40: log.debug("Entity resolving failed '" + publicId + " "
41: + systemId + "'.");
42: return null;
43: }
44:
45: public static CachingEntityResolver getInstance() {
46: return INSTANCE;
47: }
48: }
|