diff --git a/org.springframework.core/src/main/java/org/springframework/core/io/VfsResource.java b/org.springframework.core/src/main/java/org/springframework/core/io/VfsResource.java
index 5e487cd36c..e5450de45b 100644
--- a/org.springframework.core/src/main/java/org/springframework/core/io/VfsResource.java
+++ b/org.springframework.core/src/main/java/org/springframework/core/io/VfsResource.java
@@ -27,6 +27,7 @@ import org.springframework.util.Assert;
/**
* VFS based {@link Resource} implementation.
+ * Supports the corresponding VFS API versions on JBoss AS 5.x as well as 6.x.
*
* @author Ales Justin
* @author Juergen Hoeller
@@ -39,53 +40,58 @@ public class VfsResource extends AbstractResource {
private final Object resource;
+
public VfsResource(Object resources) {
Assert.notNull(resources, "VirtualFile must not be null");
this.resource = resources;
}
+
public boolean exists() {
- return VfsUtils.exists(resource);
+ return VfsUtils.exists(this.resource);
}
public boolean isReadable() {
- return VfsUtils.isReadable(resource);
+ return VfsUtils.isReadable(this.resource);
}
public long lastModified() throws IOException {
- return VfsUtils.getLastModified(resource);
+ return VfsUtils.getLastModified(this.resource);
}
public InputStream getInputStream() throws IOException {
- return VfsUtils.getInputStream(resource);
+ return VfsUtils.getInputStream(this.resource);
}
public URL getURL() throws IOException {
try {
- return VfsUtils.getURL(resource);
- } catch (Exception ex) {
+ return VfsUtils.getURL(this.resource);
+ }
+ catch (Exception ex) {
throw new NestedIOException("Failed to obtain URL for file " + this.resource, ex);
}
}
public URI getURI() throws IOException {
try {
- return VfsUtils.getURI(resource);
- } catch (Exception ex) {
+ return VfsUtils.getURI(this.resource);
+ }
+ catch (Exception ex) {
throw new NestedIOException("Failed to obtain URI for " + this.resource, ex);
}
}
public File getFile() throws IOException {
- return VfsUtils.getFile(resource);
+ return VfsUtils.getFile(this.resource);
}
public Resource createRelative(String relativePath) throws IOException {
if (!relativePath.startsWith(".") && relativePath.contains("/")) {
try {
- return new VfsResource(VfsUtils.getChild(resource, relativePath));
- } catch (IOException ex) {
- // fall back to #getRelative
+ return new VfsResource(VfsUtils.getChild(this.resource, relativePath));
+ }
+ catch (IOException ex) {
+ // fall back to getRelative
}
}
@@ -93,7 +99,7 @@ public class VfsResource extends AbstractResource {
}
public String getFilename() {
- return VfsUtils.getName(resource);
+ return VfsUtils.getName(this.resource);
}
public String getDescription() {
@@ -109,4 +115,5 @@ public class VfsResource extends AbstractResource {
public int hashCode() {
return this.resource.hashCode();
}
-}
\ No newline at end of file
+
+}
diff --git a/org.springframework.core/src/main/java/org/springframework/core/io/VfsUtils.java b/org.springframework.core/src/main/java/org/springframework/core/io/VfsUtils.java
index a9014540ba..5596803b51 100644
--- a/org.springframework.core/src/main/java/org/springframework/core/io/VfsUtils.java
+++ b/org.springframework.core/src/main/java/org/springframework/core/io/VfsUtils.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2010 the original author or authors.
+ * Copyright 2002-2010 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.
@@ -32,29 +32,27 @@ import org.springframework.util.ReflectionUtils;
/**
* Utility for detecting the JBoss VFS version available in the classpath.
- * JBoss AS 5+ uses VFS 2.x (package org.jboss.virtual
) while JBoss AS 6+ uses
- * VFS 3.x (package org.jboss.vfs
).
- *
- *
org.jboss.virtual
) while
+ * JBoss AS 6+ uses VFS 3.x (package org.jboss.vfs
).
+ *
+ * Thanks go to Marius Bogoevici for the initial patch.
*
* Note: This is an internal class and should not be used outside the framework.
- *
+ *
* @author Costin Leau
+ * @since 3.0.3
*/
public abstract class VfsUtils {
- private static final Log log = LogFactory.getLog(VfsUtils.class);
+ private static final Log logger = LogFactory.getLog(VfsUtils.class);
private static final String VFS2_PKG = "org.jboss.virtual.";
private static final String VFS3_PKG = "org.jboss.vfs.";
private static final String VFS_NAME = "VFS";
- private static enum VFS_VER {
- V2, V3
- }
+ private static enum VFS_VER { V2, V3 }
- private static VFS_VER version = null;
+ private static VFS_VER version;
private static Method VFS_METHOD_GET_ROOT_URL = null;
private static Method VFS_METHOD_GET_ROOT_URI = null;
@@ -71,7 +69,6 @@ public abstract class VfsUtils {
protected static Class> VIRTUAL_FILE_VISITOR_INTERFACE;
protected static Method VIRTUAL_FILE_METHOD_VISIT;
-
private static Method VFS_UTILS_METHOD_IS_NESTED_FILE = null;
private static Method VFS_UTILS_METHOD_GET_COMPATIBLE_URI = null;
private static Field VISITOR_ATTRIBUTES_FIELD_RECURSE = null;
@@ -79,33 +76,33 @@ public abstract class VfsUtils {
static {
ClassLoader loader = VfsUtils.class.getClassLoader();
+ String pkg;
+ Class> vfsClass;
- String pkg = "";
-
- Class> vfsClass = null;
-
- // check JBoss 6
+ // check for JBoss 6
try {
vfsClass = loader.loadClass(VFS3_PKG + VFS_NAME);
version = VFS_VER.V3;
pkg = VFS3_PKG;
- if (log.isDebugEnabled())
- log.debug("JBoss VFS packages for JBoss AS 6 found");
- } catch (ClassNotFoundException ex) {
+ if (logger.isDebugEnabled()) {
+ logger.debug("JBoss VFS packages for JBoss AS 6 found");
+ }
+ }
+ catch (ClassNotFoundException ex) {
// fallback to JBoss 5
- if (log.isDebugEnabled())
- log.debug("JBoss VFS packages for JBoss AS 6 not found; falling back to JBoss AS 5 packages");
+ if (logger.isDebugEnabled())
+ logger.debug("JBoss VFS packages for JBoss AS 6 not found; falling back to JBoss AS 5 packages");
try {
vfsClass = loader.loadClass(VFS2_PKG + VFS_NAME);
version = VFS_VER.V2;
pkg = VFS2_PKG;
- if (log.isDebugEnabled())
- log.debug("JBoss VFS packages for JBoss AS 5 found");
+ if (logger.isDebugEnabled())
+ logger.debug("JBoss VFS packages for JBoss AS 5 found");
} catch (ClassNotFoundException ex1) {
- log.error("JBoss VFS packages (for both JBoss AS 5 and 6) were not found - JBoss VFS support disabled");
+ logger.error("JBoss VFS packages (for both JBoss AS 5 and 6) were not found - JBoss VFS support disabled");
throw new IllegalStateException("Cannot detect JBoss VFS packages", ex1);
}
}
@@ -144,8 +141,8 @@ public abstract class VfsUtils {
Class> visitorAttributesClass = loader.loadClass(pkg + "VisitorAttributes");
VISITOR_ATTRIBUTES_FIELD_RECURSE = ReflectionUtils.findField(visitorAttributesClass, "RECURSE");
-
- } catch (ClassNotFoundException ex) {
+ }
+ catch (ClassNotFoundException ex) {
throw new IllegalStateException("Could not detect the JBoss VFS infrastructure", ex);
}
}
@@ -153,13 +150,15 @@ public abstract class VfsUtils {
protected static Object invokeVfsMethod(Method method, Object target, Object... args) throws IOException {
try {
return method.invoke(target, args);
- } catch (InvocationTargetException ex) {
+ }
+ catch (InvocationTargetException ex) {
Throwable targetEx = ex.getTargetException();
if (targetEx instanceof IOException) {
throw (IOException) targetEx;
}
ReflectionUtils.handleInvocationTargetException(ex);
- } catch (Exception ex) {
+ }
+ catch (Exception ex) {
ReflectionUtils.handleReflectionException(ex);
}
@@ -169,7 +168,8 @@ public abstract class VfsUtils {
static boolean exists(Object vfsResource) {
try {
return (Boolean) invokeVfsMethod(VIRTUAL_FILE_METHOD_EXISTS, vfsResource);
- } catch (IOException ex) {
+ }
+ catch (IOException ex) {
return false;
}
}
@@ -177,7 +177,8 @@ public abstract class VfsUtils {
static boolean isReadable(Object vfsResource) {
try {
return ((Long) invokeVfsMethod(VIRTUAL_FILE_METHOD_GET_SIZE, vfsResource) > 0);
- } catch (IOException ex) {
+ }
+ catch (IOException ex) {
return false;
}
}
@@ -201,7 +202,8 @@ public abstract class VfsUtils {
static String getName(Object vfsResource) {
try {
return (String) invokeVfsMethod(VIRTUAL_FILE_METHOD_GET_NAME, vfsResource);
- } catch (IOException ex) {
+ }
+ catch (IOException ex) {
throw new IllegalStateException("Cannot get resource name", ex);
}
}
@@ -221,7 +223,8 @@ public abstract class VfsUtils {
}
try {
return new File((URI) invokeVfsMethod(VFS_UTILS_METHOD_GET_COMPATIBLE_URI, null, vfsResource));
- } catch (Exception ex) {
+ }
+ catch (Exception ex) {
throw new NestedIOException("Failed to obtain File reference for " + vfsResource, ex);
}
}
diff --git a/org.springframework.core/src/main/java/org/springframework/core/io/support/PathMatchingResourcePatternResolver.java b/org.springframework.core/src/main/java/org/springframework/core/io/support/PathMatchingResourcePatternResolver.java
index aaad408872..8ed5a1b54f 100644
--- a/org.springframework.core/src/main/java/org/springframework/core/io/support/PathMatchingResourcePatternResolver.java
+++ b/org.springframework.core/src/main/java/org/springframework/core/io/support/PathMatchingResourcePatternResolver.java
@@ -33,6 +33,7 @@ import java.util.jar.JarFile;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+
import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.Resource;
@@ -645,10 +646,11 @@ public class PathMatchingResourcePatternResolver implements ResourcePatternResol
*/
private static class VfsResourceMatchingDelegate {
- public static Set