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 DTDS = new HashSet()
31 {
32 {
33 add( "logdistiller-1_0.dtd" );
34 add( "logdistiller-1_1.dtd" );
35 add( "logdistiller-1_2.dtd" );
36 add( "logdistiller-1_3.dtd" );
37 add( "logdistiller-1_4.dtd" );
38 }
39 };
40
41 private final static int LEN = 20;
42
43 private String currentDtd;
44
45 public InputSource resolveEntity( String publicId, String systemId )
46 {
47 if ( systemId.length() < LEN )
48 {
49 return null;
50 }
51 String dtd = systemId.substring( systemId.length() - LEN );
52 if ( DTDS.contains( dtd ) )
53 {
54 currentDtd = dtd;
55 InputStream in = LogDistillerEntityResolver.class.getResourceAsStream( dtd );
56 if ( in == null )
57 {
58 throw new RuntimeException( "unable to load DTD " + dtd );
59 }
60 else
61 {
62 return new InputSource( in );
63 }
64 }
65 else
66 {
67 return null;
68 }
69 }
70
71 public String getCurrentDtd()
72 {
73 return currentDtd;
74 }
75 }