1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.mirae.j2me.xml;
18
19 import java.util.Hashtable;
20
21 /***
22 * This entity resolver is mainly used by NonValidatingParser
23 * @author Ias (iasandcb@tmax.co.kr)
24 *
25 */
26 public class EntityResolver {
27 /***
28 * The registered entities.
29 */
30 private Hashtable entities;
31
32 /***
33 * Initializes the resolver.
34 */
35 public EntityResolver() {
36 this.entities = new Hashtable();
37 this.entities.put("amp", "&");
38 this.entities.put("quot", """);
39 this.entities.put("apos", "'");
40 this.entities.put("lt", "<");
41 this.entities.put("gt", ">");
42 }
43
44 /***
45 * Adds an internal entity.
46 *
47 * @param name - the name of the entity.
48 * @param value - the value of the entity.
49 */
50 public void addInternalEntity(String name, String value) {
51 if (!this.entities.containsKey(name)) {
52 this.entities.put(name, value);
53 }
54 }
55
56 /***
57 * Adds an external entity.
58 *
59 * @param name - the name of the entity.
60 * @param publicID - the public ID of the entity, which may be null.
61 * @param systemID - the system ID of the entity.
62 */
63 public void addExternalEntity(String name, String publicID, String systemID) {
64 if (!this.entities.containsKey(name)) {
65 this.entities.put(name, new String[] { publicID, systemID });
66 }
67 }
68
69 /***
70 * Returns a Java reader containing the value of an entity.
71 *
72 * @param xmlReader
73 * the current XML reader
74 * @param name
75 * the name of the entity.
76 *
77 * @return the reader, or null if the entity could not be resolved.
78 */
79 public Object getEntity(String name) {
80 Object obj = this.entities.get(name);
81
82 if (obj == null) {
83 return null;
84 }
85 else if (obj instanceof java.lang.String) {
86 return (String) obj;
87 }
88 else {
89 String[] id = (String[]) obj;
90 return id;
91 }
92 }
93
94 /***
95 * Returns true if an entity is external.
96 *
97 * @param name
98 * the name of the entity.
99 */
100 public boolean isExternalEntity(String name) {
101 Object obj = this.entities.get(name);
102 return !(obj instanceof java.lang.String);
103 }
104
105 }