1
1
/*
2
- * Copyright 2002-2012 the original author or authors.
2
+ * Copyright 2002-2015 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
17
17
package org .springframework .beans .factory .xml ;
18
18
19
19
import java .io .IOException ;
20
- import java .util .Arrays ;
21
20
22
21
import org .apache .commons .logging .Log ;
23
22
import org .apache .commons .logging .LogFactory ;
@@ -45,7 +44,9 @@ public class BeansDtdResolver implements EntityResolver {
45
44
46
45
private static final String DTD_EXTENSION = ".dtd" ;
47
46
48
- private static final String [] DTD_NAMES = {"spring-beans-2.0" , "spring-beans" };
47
+ private static final String DTD_FILENAME = "spring-beans-2.0" ;
48
+
49
+ private static final String DTD_NAME = "spring-beans" ;
49
50
50
51
private static final Log logger = LogFactory .getLog (BeansDtdResolver .class );
51
52
@@ -58,30 +59,28 @@ public InputSource resolveEntity(String publicId, String systemId) throws IOExce
58
59
}
59
60
if (systemId != null && systemId .endsWith (DTD_EXTENSION )) {
60
61
int lastPathSeparator = systemId .lastIndexOf ("/" );
61
- for (String DTD_NAME : DTD_NAMES ) {
62
- int dtdNameStart = systemId .indexOf (DTD_NAME );
63
- if (dtdNameStart > lastPathSeparator ) {
64
- String dtdFile = systemId .substring (dtdNameStart );
65
- if (logger .isTraceEnabled ()) {
66
- logger .trace ("Trying to locate [" + dtdFile + "] in Spring jar" );
67
- }
68
- try {
69
- Resource resource = new ClassPathResource (dtdFile , getClass ());
70
- InputSource source = new InputSource (resource .getInputStream ());
71
- source .setPublicId (publicId );
72
- source .setSystemId (systemId );
73
- if (logger .isDebugEnabled ()) {
74
- logger .debug ("Found beans DTD [" + systemId + "] in classpath: " + dtdFile );
75
- }
76
- return source ;
62
+ int dtdNameStart = systemId .indexOf (DTD_NAME );
63
+ if (dtdNameStart > lastPathSeparator ) {
64
+ String dtdFile = DTD_FILENAME + DTD_EXTENSION ;
65
+ if (logger .isTraceEnabled ()) {
66
+ logger .trace ("Trying to locate [" + dtdFile + "] in Spring jar on classpath" );
67
+ }
68
+ try {
69
+ Resource resource = new ClassPathResource (dtdFile , getClass ());
70
+ InputSource source = new InputSource (resource .getInputStream ());
71
+ source .setPublicId (publicId );
72
+ source .setSystemId (systemId );
73
+ if (logger .isDebugEnabled ()) {
74
+ logger .debug ("Found beans DTD [" + systemId + "] in classpath: " + dtdFile );
77
75
}
78
- catch (IOException ex ) {
79
- if (logger .isDebugEnabled ()) {
80
- logger .debug ("Could not resolve beans DTD [" + systemId + "]: not found in class path" , ex );
81
- }
76
+ return source ;
77
+ }
78
+ catch (IOException ex ) {
79
+ if (logger .isDebugEnabled ()) {
80
+ logger .debug ("Could not resolve beans DTD [" + systemId + "]: not found in classpath" , ex );
82
81
}
83
-
84
82
}
83
+
85
84
}
86
85
}
87
86
@@ -92,7 +91,7 @@ public InputSource resolveEntity(String publicId, String systemId) throws IOExce
92
91
93
92
@ Override
94
93
public String toString () {
95
- return "EntityResolver for DTDs " + Arrays . toString ( DTD_NAMES ) ;
94
+ return "EntityResolver for spring-beans DTD" ;
96
95
}
97
96
98
97
}
0 commit comments