1 34 35 package com.bull.eclipse.jonas.utils.xml; 36 37 38 import java.io.IOException ; 39 import java.util.HashMap ; 40 import java.util.Iterator ; 41 import java.util.List ; 42 import java.util.Map ; 43 44 import org.xml.sax.EntityResolver ; 45 import org.xml.sax.InputSource ; 46 import org.xml.sax.SAXException ; 47 48 import com.bull.eclipse.jonas.utils.xml.desc.DTDs; 49 import com.bull.eclipse.jonas.utils.xml.desc.Schemas; 50 51 56 public class JEntityResolver implements EntityResolver { 57 58 61 private HashMap entries = new HashMap (); 62 63 66 private JDigester jDigester = null; 67 68 69 72 public JEntityResolver(JDigester jd) { 73 super(); 74 jDigester = jd; 75 } 76 77 80 public JEntityResolver() { 81 super(); 82 } 83 84 88 private void addSchema(String path) { 89 String id = path.substring(path.lastIndexOf('/') + 1); 90 entries.put(id, path); 91 } 92 93 94 95 107 public InputSource resolveEntity(String publicId, String systemId) 108 throws IOException , SAXException { 109 110 if (jDigester != null) { 112 jDigester.setPublicId(publicId); 113 } 114 115 String localPath = null; 117 if (publicId != null) { 118 localPath = (String ) entries.get(publicId); 119 } else if (systemId != null) { 120 if (systemId.toLowerCase().endsWith(".xsd")) { 122 String baseName = systemId.substring(systemId.lastIndexOf('/') + 1); 124 125 localPath = (String ) entries.get(baseName); 127 } 128 } 129 130 if (localPath == null) { 131 return null; 133 } 134 135 return (new InputSource (localPath)); 137 } 138 139 140 144 public void addDtds(DTDs dtds) { 145 if (dtds != null) { 146 Map dtdsMapping = dtds.getMapping(); 147 if (dtdsMapping != null) { 148 for (Iterator it = dtdsMapping.entrySet().iterator(); it.hasNext(); ) { 149 Map.Entry entry = (Map.Entry ) it.next(); 150 String publicId = (String ) entry.getKey(); 151 String localURL = (String ) entry.getValue(); 152 entries.put(publicId, localURL); 153 } 154 } 155 } 156 } 157 158 159 163 public void addSchemas(Schemas schemas) { 164 if (schemas == null) { 166 return; 167 } 168 169 List localSchemas = schemas.getlocalSchemas(); 170 171 if (localSchemas != null) { 173 for (Iterator it = localSchemas.iterator(); it.hasNext(); ) { 174 String schema = (String ) it.next(); 175 addSchema(schema); 176 } 177 } 178 } 179 180 181 182 } 183 184 | Popular Tags |