1 16 17 package org.springframework.beans.factory.xml; 18 19 import java.io.IOException ; 20 21 import org.xml.sax.EntityResolver ; 22 import org.xml.sax.InputSource ; 23 import org.xml.sax.SAXException ; 24 25 import org.springframework.util.Assert; 26 27 38 public class DelegatingEntityResolver implements EntityResolver { 39 40 41 public static final String DTD_SUFFIX = ".dtd"; 42 43 44 public static final String XSD_SUFFIX = ".xsd"; 45 46 47 private final EntityResolver dtdResolver; 48 49 private final EntityResolver schemaResolver; 50 51 52 60 public DelegatingEntityResolver(ClassLoader classLoader) { 61 this.dtdResolver = new BeansDtdResolver(); 62 this.schemaResolver = new PluggableSchemaResolver(classLoader); 63 } 64 65 72 public DelegatingEntityResolver(EntityResolver dtdResolver, EntityResolver schemaResolver) { 73 Assert.notNull(dtdResolver); 74 Assert.notNull(schemaResolver); 75 this.dtdResolver = dtdResolver; 76 this.schemaResolver = schemaResolver; 77 } 78 79 80 public InputSource resolveEntity(String publicId, String systemId) throws SAXException , IOException { 81 if (systemId != null) { 82 if (systemId.endsWith(DTD_SUFFIX)) { 83 return this.dtdResolver.resolveEntity(publicId, systemId); 84 } 85 else if (systemId.endsWith(XSD_SUFFIX)) { 86 return this.schemaResolver.resolveEntity(publicId, systemId); 87 } 88 } 89 return null; 90 } 91 92 } 93 | Popular Tags |