From 490b23518bca643445ec126f4021ed8bf559c836 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Tue, 26 Feb 2019 17:42:49 +0100 Subject: [PATCH] Polishing --- .../beans/factory/xml/BeansDtdResolver.java | 7 +++--- .../factory/xml/PluggableSchemaResolver.java | 23 +++++++++++-------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/xml/BeansDtdResolver.java b/spring-beans/src/main/java/org/springframework/beans/factory/xml/BeansDtdResolver.java index b77b31700a..dce36a05e4 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/xml/BeansDtdResolver.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/xml/BeansDtdResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 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. @@ -28,7 +28,7 @@ import org.springframework.core.io.Resource; import org.springframework.lang.Nullable; /** - * EntityResolver implementation for the Spring beans DTD, + * {@link EntityResolver} implementation for the Spring beans DTD, * to load the DTD from the Spring class path (or JAR file). * *

Fetches "spring-beans.dtd" from the class path resource @@ -57,6 +57,7 @@ public class BeansDtdResolver implements EntityResolver { logger.trace("Trying to resolve XML entity with public ID [" + publicId + "] and system ID [" + systemId + "]"); } + if (systemId != null && systemId.endsWith(DTD_EXTENSION)) { int lastPathSeparator = systemId.lastIndexOf('/'); int dtdNameStart = systemId.indexOf(DTD_NAME, lastPathSeparator); @@ -83,7 +84,7 @@ public class BeansDtdResolver implements EntityResolver { } } - // Use the default behavior -> download from website or wherever. + // Fall back to the parser's default behavior. return null; } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/xml/PluggableSchemaResolver.java b/spring-beans/src/main/java/org/springframework/beans/factory/xml/PluggableSchemaResolver.java index 96ac31fda4..696a849801 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/xml/PluggableSchemaResolver.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/xml/PluggableSchemaResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2019 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. @@ -38,15 +38,15 @@ import org.springframework.util.CollectionUtils; * {@link EntityResolver} implementation that attempts to resolve schema URLs into * local {@link ClassPathResource classpath resources} using a set of mappings files. * - *

By default, this class will look for mapping files in the classpath using the pattern: - * {@code META-INF/spring.schemas} allowing for multiple files to exist on the - * classpath at any one time. + *

By default, this class will look for mapping files in the classpath using the + * pattern: {@code META-INF/spring.schemas} allowing for multiple files to exist on + * the classpath at any one time. * - * The format of {@code META-INF/spring.schemas} is a properties - * file where each line should be of the form {@code systemId=schema-location} - * where {@code schema-location} should also be a schema file in the classpath. - * Since systemId is commonly a URL, one must be careful to escape any ':' characters - * which are treated as delimiters in properties files. + *

The format of {@code META-INF/spring.schemas} is a properties file where each line + * should be of the form {@code systemId=schema-location} where {@code schema-location} + * should also be a schema file in the classpath. Since systemId is commonly a URL, + * one must be careful to escape any ':' characters which are treated as delimiters + * in properties files. * *

The pattern for the mapping files can be overidden using the * {@link #PluggableSchemaResolver(ClassLoader, String)} constructor @@ -103,6 +103,7 @@ public class PluggableSchemaResolver implements EntityResolver { this.schemaMappingsLocation = schemaMappingsLocation; } + @Override @Nullable public InputSource resolveEntity(String publicId, @Nullable String systemId) throws IOException { @@ -131,6 +132,8 @@ public class PluggableSchemaResolver implements EntityResolver { } } } + + // Fall back to the parser's default behavior. return null; } @@ -169,7 +172,7 @@ public class PluggableSchemaResolver implements EntityResolver { @Override public String toString() { - return "EntityResolver using mappings " + getSchemaMappings(); + return "EntityResolver using schema mappings " + getSchemaMappings(); } }