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