1 26 27 package org.objectweb.jonas_lib.deployment.digester; 28 29 30 import java.io.IOException ; 31 import java.util.HashMap ; 32 import java.util.Iterator ; 33 import java.util.List ; 34 import java.util.Map ; 35 36 import org.xml.sax.EntityResolver ; 37 import org.xml.sax.InputSource ; 38 import org.xml.sax.SAXException ; 39 40 import org.objectweb.jonas_lib.deployment.api.DTDs; 41 import org.objectweb.jonas_lib.deployment.api.Schemas; 42 43 48 public class JEntityResolver implements EntityResolver { 49 50 53 private HashMap entries = new HashMap (); 54 55 58 private JDigester jDigester = null; 59 60 61 66 public JEntityResolver(JDigester jd) { 67 super(); 68 jDigester = jd; 69 } 70 71 74 public JEntityResolver() { 75 super(); 76 } 77 78 82 private void addSchema(String path) { 83 String id = path.substring(path.lastIndexOf('/') + 1); 84 entries.put(id, path); 85 } 86 87 88 89 101 public InputSource resolveEntity(String publicId, String systemId) 102 throws IOException , SAXException { 103 104 if (jDigester != null) { 106 jDigester.setPublicId(publicId); 107 } 108 109 String localPath = null; 111 if (publicId != null) { 112 localPath = (String ) entries.get(publicId); 113 } else if (systemId != null) { 114 if (systemId.toLowerCase().endsWith(".xsd")) { 116 String baseName = systemId.substring(systemId.lastIndexOf('/') + 1); 118 119 localPath = (String ) entries.get(baseName); 121 } 122 } 123 124 if (localPath == null) { 125 return null; 127 } 128 129 return (new InputSource (localPath)); 131 } 132 133 134 138 public void addDtds(DTDs dtds) { 139 if (dtds != null) { 140 Map dtdsMapping = dtds.getMapping(); 141 if (dtdsMapping != null) { 142 for (Iterator it = dtdsMapping.entrySet().iterator(); it.hasNext();) { 143 Map.Entry entry = (Map.Entry ) it.next(); 144 String publicId = (String ) entry.getKey(); 145 String localURL = (String ) entry.getValue(); 146 entries.put(publicId, localURL); 147 } 148 } 149 } 150 } 151 152 153 157 public void addSchemas(Schemas schemas) { 158 if (schemas == null) { 160 return; 161 } 162 163 List localSchemas = schemas.getlocalSchemas(); 164 165 if (localSchemas != null) { 167 for (Iterator it = localSchemas.iterator(); it.hasNext();) { 168 String schema = (String ) it.next(); 169 addSchema(schema); 170 } 171 } 172 } 173 174 175 176 } 177 178 | Popular Tags |