[utilities COMMIT] in /spring-extensions/trunk/src/main/java/net/shibboleth/ext/spring: context/FileSystemXmlWebAppli...

noreply at shibboleth.net noreply at shibboleth.net
Wed May 20 13:43:27 EDT 2015


Author: tzeller
Date: Wed May 20 13:43:27 2015
New Revision: 793

URL: http://svn.shibboleth.net/view/utilities?rev=793&view=rev
Log:
JSE-13 Support classpath*: resources.

Modified:
    spring-extensions/trunk/src/main/java/net/shibboleth/ext/spring/context/FileSystemXmlWebApplicationContext.java
    spring-extensions/trunk/src/main/java/net/shibboleth/ext/spring/resource/PreferFileSystemResourceLoader.java
    spring-extensions/trunk/src/main/java/net/shibboleth/ext/spring/util/SpringSupport.java

Modified: spring-extensions/trunk/src/main/java/net/shibboleth/ext/spring/context/FileSystemXmlWebApplicationContext.java
URL: http://svn.shibboleth.net/view/utilities/spring-extensions/trunk/src/main/java/net/shibboleth/ext/spring/context/FileSystemXmlWebApplicationContext.java?rev=793&r1=792&r2=793&view=diff
==============================================================================
--- spring-extensions/trunk/src/main/java/net/shibboleth/ext/spring/context/FileSystemXmlWebApplicationContext.java	(original)
+++ spring-extensions/trunk/src/main/java/net/shibboleth/ext/spring/context/FileSystemXmlWebApplicationContext.java	Wed May 20 13:43:27 2015
@@ -17,22 +17,19 @@
 
 package net.shibboleth.ext.spring.context;
 
-import javax.annotation.Nonnull;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import org.springframework.core.io.ClassPathResource;
 import org.springframework.core.io.FileSystemResource;
 import org.springframework.core.io.Resource;
+import org.springframework.core.io.support.ResourcePatternResolver;
+import org.springframework.util.Assert;
 import org.springframework.web.context.support.XmlWebApplicationContext;
 
 /**
- * An extension of {@link XmlWebApplicationContext} that is biased in favor of the filesystem such that bare resource
- * paths are assumed to be files rather than classpath resources.
+ * An extension of {@link XmlWebApplicationContext} that (1) is biased in favor of the filesystem such that bare
+ * resource paths are assumed to be files rather than classpath resources and (2) supports loading "classpath*:"
+ * resources.
  */
 public class FileSystemXmlWebApplicationContext extends XmlWebApplicationContext {
-
-    /** Class logger. */
-    @Nonnull private final Logger log = LoggerFactory.getLogger(FileSystemXmlWebApplicationContext.class);
 
     /** Constructor. */
     public FileSystemXmlWebApplicationContext() {
@@ -55,4 +52,20 @@
         return super.getResourceByPath(path);
     }
 
+    /**
+     * {@inheritDoc}
+     * 
+     * <p>
+     * Supports wildcard classpath locations prefixed with {@link ResourcePatternResolver#CLASSPATH_ALL_URL_PREFIX}.
+     * </p>
+     */
+    @Override public Resource getResource(String location) {
+        Assert.notNull(location, "Location must not be null");
+        if (location.startsWith(ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX)) {
+            return new ClassPathResource(location.substring(ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX.length()),
+                    getClassLoader());
+        }
+        return super.getResource(location);
+    }
+
 }

Modified: spring-extensions/trunk/src/main/java/net/shibboleth/ext/spring/resource/PreferFileSystemResourceLoader.java
URL: http://svn.shibboleth.net/view/utilities/spring-extensions/trunk/src/main/java/net/shibboleth/ext/spring/resource/PreferFileSystemResourceLoader.java?rev=793&r1=792&r2=793&view=diff
==============================================================================
--- spring-extensions/trunk/src/main/java/net/shibboleth/ext/spring/resource/PreferFileSystemResourceLoader.java	(original)
+++ spring-extensions/trunk/src/main/java/net/shibboleth/ext/spring/resource/PreferFileSystemResourceLoader.java	Wed May 20 13:43:27 2015
@@ -17,13 +17,16 @@
 
 package net.shibboleth.ext.spring.resource;
 
+import org.springframework.core.io.ClassPathResource;
 import org.springframework.core.io.DefaultResourceLoader;
 import org.springframework.core.io.FileSystemResource;
 import org.springframework.core.io.Resource;
+import org.springframework.core.io.support.ResourcePatternResolver;
+import org.springframework.util.Assert;
 
 /**
- * An extension of {@link DefaultResourceLoader} that is biased in favor of the filesystem such that bare resource paths
- * are assumed to be files rather than classpath resources.
+ * An extension of {@link DefaultResourceLoader} that (1) is biased in favor of the filesystem such that bare resource
+ * paths are assumed to be files rather than classpath resources and (2) supports loading "classpath*:" resources.
  */
 public class PreferFileSystemResourceLoader extends DefaultResourceLoader {
 
@@ -45,4 +48,20 @@
         return super.getResourceByPath(path);
     }
 
+    /**
+     * {@inheritDoc}
+     * 
+     * <p>
+     * Supports wildcard classpath locations prefixed with {@link ResourcePatternResolver#CLASSPATH_ALL_URL_PREFIX}.
+     * </p>
+     */
+    @Override public Resource getResource(String location) {
+        Assert.notNull(location, "Location must not be null");

[... 32 lines stripped ...]


More information about the commits mailing list