1
2
3
4
5
6
7
8
9
10
11
12
13
14 package ch.qos.logback.classic.html;
15
16 import java.io.InputStream;
17 import java.util.HashMap;
18 import java.util.Map;
19
20 import org.xml.sax.EntityResolver;
21 import org.xml.sax.InputSource;
22
23 public class XHTMLEntityResolver implements EntityResolver {
24
25
26 static Map<String, String> entityMap = new HashMap<String, String>();
27
28 static {
29 entityMap.put("-//W3C//DTD XHTML 1.0 Strict//EN", "/dtd/xhtml1-strict.dtd");
30 entityMap.put("-//W3C//ENTITIES Latin 1 for XHTML//EN", "/dtd/xhtml-lat1.ent");
31 entityMap.put("-//W3C//ENTITIES Symbols for XHTML//EN", "/dtd/xhtml-symbol.ent");
32 entityMap.put("-//W3C//ENTITIES Special for XHTML//EN", "/dtd/xhtml-special.ent");
33 }
34
35 public InputSource resolveEntity(String publicId, String systemId) {
36
37 final String relativePath = (String) entityMap.get(publicId);
38
39 if (relativePath != null) {
40 Class<?> clazz = getClass();
41 InputStream in = clazz.getResourceAsStream(relativePath);
42 if (in == null) {
43 return null;
44 } else {
45 return new InputSource(in);
46 }
47 } else {
48 return null;
49 }
50 }
51 }