1 /**
2 * .
3 * Copyright � 1999 Erich P G.
4 *
5 */
6
7 package creator.compiler;
8
9 //import org.xml.sax.EntityResolver;
10 import org.xml.sax.InputSource;
11 import org.xml.sax.SAXException;
12 import java.io.StringReader;
13 import java.util.Vector;
14 import com.sun.xml.parser.Resolver;
15
16 /**
17 * Implement our own resolver to handle XML activities.
18 * For the most part, this is used to provide DTDs.
19 *
20 * Do NOT use the default constructor!
21 *
22 * @author Erich P. Gatejen
23 * @version 1.0
24 * <i>Version History</i>
25 * <code>EPG - Initial - 12Jan99</code>
26 *
27 */
28 public class XmlCompilerResolver extends Resolver {
29
30 // --- FINAL FIELDS ------------------------------------------------------
31
32 // --- FIELDS ------------------------------------------------------------
33
34 /**
35 * The DTD to use when parsing the Sim text.
36 */
37 private String myDTD;
38
39 /**
40 * The entity to trap.
41 */
42 private String myURI;
43
44 // --- PUBLIC METHODS ----------------------------------------------------
45
46 /**
47 * Constructor. Set up the input source. We will pass to this
48 * a string containing the DTD.
49 *
50 * @param uri A string containing the textual entity to trap and resolve.
51 * @param dtdText A string containing the DTD.
52 */
53 XmlCompilerResolver(String uri, String dtdText) {
54
55 super();
56
57 myDTD = dtdText;
58 myURI = uri;
59 }
60
61 /**
62 * overrides the resolver.
63 *
64 * @param name not implimented.
65 * @param uri Passed to this from the parser. We will trap
66 * the uri.
67 * @return an input source to be used by the XML parser.
68 */
69 public InputSource resolveEntity (java.lang.String name,
70 java.lang.String uri)
71 throws SAXException, java.io.IOException {
72
73 //DEBUG
74 //System.out.println("Resolve Entity: public=[" + name + "] system=[" + uri + "]");
75
76
77 // Is it asking for the SIM.DTD?
78 if (uri.equals(myURI)) {
79
80 // return a reader for the dtdText
81 return new InputSource(new StringReader(myDTD));
82
83 } else {
84
85 // use the default behaviour
86 return new InputSource(new StringReader(myDTD));
87
88 }
89
90 }
91
92
93
94 // --- PRIVATE METHODS ---------------------------------------------------
95 }
|