1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.ken.util;
17
18 import java.io.IOException;
19 import java.util.ArrayList;
20 import java.util.List;
21
22 import org.apache.log4j.Logger;
23 import org.xml.sax.EntityResolver;
24 import org.xml.sax.InputSource;
25 import org.xml.sax.SAXException;
26
27
28
29
30
31
32 public class CompoundEntityResolver implements EntityResolver {
33 private static final Logger LOG = Logger.getLogger(CompoundEntityResolver.class);
34
35 private final List<EntityResolver> resolvers;
36
37
38
39
40
41
42 public CompoundEntityResolver(EntityResolver first, EntityResolver second) {
43 this.resolvers = new ArrayList<EntityResolver>(2);
44 this.resolvers.add(first);
45 this.resolvers.add(second);
46 }
47
48
49
50
51
52 public CompoundEntityResolver(List<EntityResolver> resolvers) {
53 this.resolvers = resolvers;
54 }
55
56
57
58
59 public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
60 LOG.debug("resolveEntity: " + publicId + " " + systemId);
61 for (EntityResolver resolver: resolvers) {
62 LOG.debug("Invoking entity resolver: " + resolver);
63 InputSource source = resolver.resolveEntity(publicId, systemId);
64 if (source != null) {
65 LOG.debug("source != null: " + source);
66 return source;
67 }
68 }
69 return null;
70 }
71 }