BeansDtdResolver resolves spring-beans.dtd declarations to spring-beans-2.0.dtd file
Issue: SPR-12836
This commit is contained in:
parent
898c24fcdd
commit
8e4bfa9cc1
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -17,7 +17,6 @@
|
|||
package org.springframework.beans.factory.xml;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
@ -45,7 +44,9 @@ public class BeansDtdResolver implements EntityResolver {
|
|||
|
||||
private static final String DTD_EXTENSION = ".dtd";
|
||||
|
||||
private static final String[] DTD_NAMES = {"spring-beans-2.0", "spring-beans"};
|
||||
private static final String DTD_FILENAME = "spring-beans-2.0";
|
||||
|
||||
private static final String DTD_NAME = "spring-beans";
|
||||
|
||||
private static final Log logger = LogFactory.getLog(BeansDtdResolver.class);
|
||||
|
||||
|
@ -58,30 +59,28 @@ public class BeansDtdResolver implements EntityResolver {
|
|||
}
|
||||
if (systemId != null && systemId.endsWith(DTD_EXTENSION)) {
|
||||
int lastPathSeparator = systemId.lastIndexOf("/");
|
||||
for (String DTD_NAME : DTD_NAMES) {
|
||||
int dtdNameStart = systemId.indexOf(DTD_NAME);
|
||||
if (dtdNameStart > lastPathSeparator) {
|
||||
String dtdFile = systemId.substring(dtdNameStart);
|
||||
if (logger.isTraceEnabled()) {
|
||||
logger.trace("Trying to locate [" + dtdFile + "] in Spring jar");
|
||||
}
|
||||
try {
|
||||
Resource resource = new ClassPathResource(dtdFile, getClass());
|
||||
InputSource source = new InputSource(resource.getInputStream());
|
||||
source.setPublicId(publicId);
|
||||
source.setSystemId(systemId);
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Found beans DTD [" + systemId + "] in classpath: " + dtdFile);
|
||||
}
|
||||
return source;
|
||||
}
|
||||
catch (IOException ex) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Could not resolve beans DTD [" + systemId + "]: not found in class path", ex);
|
||||
}
|
||||
}
|
||||
|
||||
int dtdNameStart = systemId.indexOf(DTD_NAME);
|
||||
if (dtdNameStart > lastPathSeparator) {
|
||||
String dtdFile = DTD_FILENAME + DTD_EXTENSION;
|
||||
if (logger.isTraceEnabled()) {
|
||||
logger.trace("Trying to locate [" + dtdFile + "] in Spring jar on classpath");
|
||||
}
|
||||
try {
|
||||
Resource resource = new ClassPathResource(dtdFile, getClass());
|
||||
InputSource source = new InputSource(resource.getInputStream());
|
||||
source.setPublicId(publicId);
|
||||
source.setSystemId(systemId);
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Found beans DTD [" + systemId + "] in classpath: " + dtdFile);
|
||||
}
|
||||
return source;
|
||||
}
|
||||
catch (IOException ex) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Could not resolve beans DTD [" + systemId + "]: not found in classpath", ex);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -92,7 +91,7 @@ public class BeansDtdResolver implements EntityResolver {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "EntityResolver for DTDs " + Arrays.toString(DTD_NAMES);
|
||||
return "EntityResolver for spring-beans DTD";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
|
||||
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
|
||||
|
||||
<beans>
|
||||
|
||||
|
|
Loading…
Reference in New Issue