1 package net.sf.logdistiller.xml;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 import java.io.InputStream;
18 import java.util.HashSet;
19 import java.util.Set;
20 import org.xml.sax.EntityResolver;
21 import org.xml.sax.InputSource;
22
23 public class LogDistillerEntityResolver
24 implements EntityResolver
25 {
26 public final static String LATEST_DTD = "logdistiller-1_4.dtd";
27
28 public final static String LATEST_DTD_URL = "http://logdistiller.sourceforge.net/dtd/" + LATEST_DTD;
29
30 private final static Set<String> DTDS = new HashSet<String>()
31 {
32 private static final long serialVersionUID = -7218559731707450072L;
33
34 {
35 add( "logdistiller-1_0.dtd" );
36 add( "logdistiller-1_1.dtd" );
37 add( "logdistiller-1_2.dtd" );
38 add( "logdistiller-1_3.dtd" );
39 add( "logdistiller-1_4.dtd" );
40 }
41 };
42
43 private final static int LEN = 20;
44
45 private String currentDtd;
46
47 public InputSource resolveEntity( String publicId, String systemId )
48 {
49 if ( systemId.length() < LEN )
50 {
51 return null;
52 }
53 String dtd = systemId.substring( systemId.length() - LEN );
54 if ( DTDS.contains( dtd ) )
55 {
56 currentDtd = dtd;
57 InputStream in = LogDistillerEntityResolver.class.getResourceAsStream( dtd );
58 if ( in == null )
59 {
60 throw new RuntimeException( "unable to load DTD " + dtd );
61 }
62 else
63 {
64 return new InputSource( in );
65 }
66 }
67 else
68 {
69 return null;
70 }
71 }
72
73 public String getCurrentDtd()
74 {
75 return currentDtd;
76 }
77 }