1 17 package org.apache.catalina.util; 18 19 20 import java.util.HashMap ; 21 22 import org.apache.tomcat.util.digester.Digester; 23 import org.xml.sax.InputSource ; 24 import org.xml.sax.EntityResolver ; 25 import org.xml.sax.SAXException ; 26 27 34 public class SchemaResolver implements EntityResolver { 35 36 39 protected Digester digester; 40 41 42 46 protected HashMap entityValidator = new HashMap (); 47 48 49 53 protected String publicId = null; 54 55 56 59 protected String schemaExtension = "xsd"; 60 61 62 67 public SchemaResolver(Digester digester) { 68 this.digester = digester; 69 } 70 71 72 84 public void register(String publicId, String entityURL) { 85 String key = publicId; 86 if (publicId.indexOf(schemaExtension) != -1) 87 key = publicId.substring(publicId.lastIndexOf('/')+1); 88 entityValidator.put(key, entityURL); 89 } 90 91 92 101 public InputSource resolveEntity(String publicId, String systemId) 102 throws SAXException { 103 104 if (publicId != null) { 105 this.publicId = publicId; 106 digester.setPublicId(publicId); 107 } 108 109 String entityURL = null; 111 if (publicId != null) { 112 entityURL = (String ) entityValidator.get(publicId); 113 } 114 115 String key = null; 117 if (entityURL == null && systemId != null) { 118 key = systemId.substring(systemId.lastIndexOf('/')+1); 119 entityURL = (String )entityValidator.get(key); 120 } 121 122 if (entityURL == null) { 123 return (null); 124 } 125 126 try { 127 return (new InputSource (entityURL)); 128 } catch (Exception e) { 129 throw new SAXException (e); 130 } 131 132 } 133 134 } 135 | Popular Tags |