| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.dozer.loader.xml; |
| 17 | |
|
| 18 | |
import org.dozer.config.BeanContainer; |
| 19 | |
import org.dozer.util.DozerClassLoader; |
| 20 | |
import org.dozer.util.DozerConstants; |
| 21 | |
import org.slf4j.Logger; |
| 22 | |
import org.slf4j.LoggerFactory; |
| 23 | |
import org.xml.sax.EntityResolver; |
| 24 | |
import org.xml.sax.InputSource; |
| 25 | |
|
| 26 | |
import java.io.InputStream; |
| 27 | |
import java.net.URL; |
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | 707 | public class DozerResolver implements EntityResolver { |
| 39 | |
|
| 40 | 707 | private final Logger log = LoggerFactory.getLogger(DozerResolver.class); |
| 41 | |
|
| 42 | |
public InputSource resolveEntity(String publicId, String systemId) { |
| 43 | 608 | log.debug("Trying to resolve XML entity with public ID [{}] and system ID [{}]", publicId, systemId); |
| 44 | 608 | if (systemId != null && systemId.indexOf(DozerConstants.XSD_NAME) > systemId.lastIndexOf("/")) { |
| 45 | 608 | String fileName = systemId.substring(systemId.indexOf(DozerConstants.XSD_NAME)); |
| 46 | 608 | log.debug("Trying to locate [{}] in classpath", fileName); |
| 47 | |
try { |
| 48 | 608 | DozerClassLoader classLoader = BeanContainer.getInstance().getClassLoader(); |
| 49 | 608 | URL url = classLoader.loadResource(fileName); |
| 50 | 608 | InputStream stream = url.openStream(); |
| 51 | 608 | InputSource source = new InputSource(stream); |
| 52 | 608 | source.setPublicId(publicId); |
| 53 | 608 | source.setSystemId(systemId); |
| 54 | 608 | log.debug("Found beanmapping XML Schema [{}] in classpath", systemId); |
| 55 | 608 | return source; |
| 56 | 0 | } catch (Exception ex) { |
| 57 | 0 | log.error("Could not resolve beanmapping XML Schema [" + systemId + "]: not found in classpath", ex); |
| 58 | |
} |
| 59 | |
} |
| 60 | |
|
| 61 | 0 | return null; |
| 62 | |
} |
| 63 | |
} |