View Javadoc
1   /**
2    * Logback: the reliable, generic, fast and flexible logging framework.
3    * Copyright (C) 1999-2015, QOS.ch. All rights reserved.
4    *
5    * This program and the accompanying materials are dual-licensed under
6    * either the terms of the Eclipse Public License v1.0 as published by
7    * the Eclipse Foundation
8    *
9    *   or (per the licensee's choosing)
10   *
11   * under the terms of the GNU Lesser General Public License version 2.1
12   * as published by the Free Software Foundation.
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      // key: public id, value: relative path to DTD file
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          // System.out.println(publicId);
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  }