fixed component scanning for JBoss 5 VFS; applied revised vfs-fixes-3.patch; added ResourceHandlingUtils (SPR-5120)

This commit is contained in:
Thomas Risberg 2009-09-10 10:35:04 +00:00
parent 377359b924
commit 184f63f689
12 changed files with 656 additions and 212 deletions

View File

@ -1,202 +1,211 @@
<?xml version="1.0" encoding="UTF-8"?>
<module relativePaths="true" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="inheritedJdk" />
<orderEntry type="library" name="AspectJ" level="project" />
<orderEntry type="library" name="Commons Logging" level="project" />
<orderEntry type="library" name="EasyMock" level="project" />
<orderEntry type="library" name="JUnit" level="project" />
<orderEntry type="library" name="Log4j" level="project" />
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://$MODULE_DIR$/../org.springframework.asm/target/artifacts/org.springframework.asm.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://$IVY_CACHE$/org.custommonkey.xmlunit/com.springsource.org.custommonkey.xmlunit/1.2.0/com.springsource.org.custommonkey.xmlunit-1.2.0.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$IVY_CACHE$/org.custommonkey.xmlunit/com.springsource.org.custommonkey.xmlunit/1.2.0/com.springsource.org.custommonkey.xmlunit-sources-1.2.0.jar!/" />
</SOURCES>
</library>
</orderEntry>
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://$IVY_CACHE$/org.codehaus.woodstox/com.springsource.com.ctc.wstx/3.2.7/com.springsource.com.ctc.wstx-3.2.7.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
</component>
<component name="copyright">
<Base>
<setting name="state" value="1" />
</Base>
<LanguageOptions name="HTML">
<option name="templateOptions">
<value>
<option name="block" value="true" />
<option name="separateBefore" value="false" />
<option name="separateAfter" value="false" />
<option name="prefixLines" value="true" />
<option name="lenBefore" value="80" />
<option name="lenAfter" value="80" />
<option name="box" value="false" />
<option name="filler" value=" " />
</value>
</option>
<option name="notice" value="Copyright (c) &amp;#36;today.year, Your Corporation. All Rights Reserved." />
<option name="keyword" value="Copyright" />
<option name="fileTypeOverride" value="2" />
<option name="relativeBefore" value="true" />
<option name="addBlankAfter" value="true" />
<option name="fileLocation" value="1" />
<option name="useAlternate" value="false" />
</LanguageOptions>
<LanguageOptions name="JAVA">
<option name="templateOptions">
<value>
<option name="block" value="true" />
<option name="separateBefore" value="false" />
<option name="separateAfter" value="false" />
<option name="prefixLines" value="true" />
<option name="lenBefore" value="80" />
<option name="lenAfter" value="80" />
<option name="box" value="false" />
<option name="filler" value=" " />
</value>
</option>
<option name="notice" value="Copyright (c) &amp;#36;today.year, Your Corporation. All Rights Reserved." />
<option name="keyword" value="Copyright" />
<option name="fileTypeOverride" value="2" />
<option name="relativeBefore" value="true" />
<option name="addBlankAfter" value="true" />
<option name="fileLocation" value="1" />
<option name="useAlternate" value="false" />
</LanguageOptions>
<LanguageOptions name="JSP">
<option name="templateOptions">
<value>
<option name="block" value="true" />
<option name="separateBefore" value="false" />
<option name="separateAfter" value="false" />
<option name="prefixLines" value="true" />
<option name="lenBefore" value="80" />
<option name="lenAfter" value="80" />
<option name="box" value="false" />
<option name="filler" value=" " />
</value>
</option>
<option name="notice" value="Copyright (c) &amp;#36;today.year, Your Corporation. All Rights Reserved." />
<option name="keyword" value="Copyright" />
<option name="fileTypeOverride" value="2" />
<option name="relativeBefore" value="true" />
<option name="addBlankAfter" value="true" />
<option name="fileLocation" value="1" />
<option name="useAlternate" value="false" />
</LanguageOptions>
<LanguageOptions name="JavaScript">
<option name="templateOptions">
<value>
<option name="block" value="true" />
<option name="separateBefore" value="false" />
<option name="separateAfter" value="false" />
<option name="prefixLines" value="true" />
<option name="lenBefore" value="80" />
<option name="lenAfter" value="80" />
<option name="box" value="false" />
<option name="filler" value=" " />
</value>
</option>
<option name="notice" value="Copyright (c) &amp;#36;today.year, Your Corporation. All Rights Reserved." />
<option name="keyword" value="Copyright" />
<option name="fileTypeOverride" value="2" />
<option name="relativeBefore" value="true" />
<option name="addBlankAfter" value="true" />
<option name="fileLocation" value="1" />
<option name="useAlternate" value="false" />
</LanguageOptions>
<LanguageOptions name="Properties">
<option name="templateOptions">
<value>
<option name="block" value="true" />
<option name="separateBefore" value="false" />
<option name="separateAfter" value="false" />
<option name="prefixLines" value="true" />
<option name="lenBefore" value="80" />
<option name="lenAfter" value="80" />
<option name="box" value="false" />
<option name="filler" value=" " />
</value>
</option>
<option name="notice" value="Copyright (c) &amp;#36;today.year, Your Corporation. All Rights Reserved." />
<option name="keyword" value="Copyright" />
<option name="fileTypeOverride" value="2" />
<option name="relativeBefore" value="true" />
<option name="addBlankAfter" value="true" />
<option name="fileLocation" value="1" />
<option name="useAlternate" value="false" />
</LanguageOptions>
<LanguageOptions name="XML">
<option name="templateOptions">
<value>
<option name="block" value="true" />
<option name="separateBefore" value="false" />
<option name="separateAfter" value="false" />
<option name="prefixLines" value="true" />
<option name="lenBefore" value="80" />
<option name="lenAfter" value="80" />
<option name="box" value="false" />
<option name="filler" value=" " />
</value>
</option>
<option name="notice" value="Copyright (c) &amp;#36;today.year, Your Corporation. All Rights Reserved." />
<option name="keyword" value="Copyright" />
<option name="fileTypeOverride" value="2" />
<option name="relativeBefore" value="true" />
<option name="addBlankAfter" value="true" />
<option name="fileLocation" value="1" />
<option name="useAlternate" value="false" />
</LanguageOptions>
<LanguageOptions name="__TEMPLATE__">
<option name="templateOptions">
<value>
<option name="block" value="true" />
<option name="separateBefore" value="false" />
<option name="separateAfter" value="false" />
<option name="prefixLines" value="true" />
<option name="lenBefore" value="80" />
<option name="lenAfter" value="80" />
<option name="box" value="false" />
<option name="filler" value=" " />
</value>
</option>
<option name="notice" value="Copyright (c) &amp;#36;today.year, Your Corporation. All Rights Reserved." />
<option name="keyword" value="Copyright" />
<option name="fileTypeOverride" value="4" />
<option name="relativeBefore" value="true" />
<option name="addBlankAfter" value="true" />
<option name="fileLocation" value="1" />
<option name="useAlternate" value="false" />
</LanguageOptions>
</component>
</module>
<?xml version="1.0" encoding="UTF-8"?>
<module relativePaths="true" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="inheritedJdk" />
<orderEntry type="library" name="AspectJ" level="project" />
<orderEntry type="library" name="Commons Logging" level="project" />
<orderEntry type="library" name="EasyMock" level="project" />
<orderEntry type="library" name="JUnit" level="project" />
<orderEntry type="library" name="Log4j" level="project" />
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://$MODULE_DIR$/../org.springframework.asm/target/artifacts/org.springframework.asm.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://$IVY_CACHE$/org.custommonkey.xmlunit/com.springsource.org.custommonkey.xmlunit/1.2.0/com.springsource.org.custommonkey.xmlunit-1.2.0.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$IVY_CACHE$/org.custommonkey.xmlunit/com.springsource.org.custommonkey.xmlunit/1.2.0/com.springsource.org.custommonkey.xmlunit-sources-1.2.0.jar!/" />
</SOURCES>
</library>
</orderEntry>
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://$IVY_CACHE$/org.codehaus.woodstox/com.springsource.com.ctc.wstx/3.2.7/com.springsource.com.ctc.wstx-3.2.7.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://$IVY_CACHE$/org.jboss.vfs/com.springsource.org.jboss.virtual/2.1.0.GA/com.springsource.org.jboss.virtual-2.1.0.GA.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
</component>
<component name="copyright">
<Base>
<setting name="state" value="1" />
</Base>
<LanguageOptions name="HTML">
<option name="templateOptions">
<value>
<option name="block" value="true" />
<option name="separateBefore" value="false" />
<option name="separateAfter" value="false" />
<option name="prefixLines" value="true" />
<option name="lenBefore" value="80" />
<option name="lenAfter" value="80" />
<option name="box" value="false" />
<option name="filler" value=" " />
</value>
</option>
<option name="notice" value="Copyright (c) &amp;#36;today.year, Your Corporation. All Rights Reserved." />
<option name="keyword" value="Copyright" />
<option name="fileTypeOverride" value="2" />
<option name="relativeBefore" value="true" />
<option name="addBlankAfter" value="true" />
<option name="fileLocation" value="1" />
<option name="useAlternate" value="false" />
</LanguageOptions>
<LanguageOptions name="JAVA">
<option name="templateOptions">
<value>
<option name="block" value="true" />
<option name="separateBefore" value="false" />
<option name="separateAfter" value="false" />
<option name="prefixLines" value="true" />
<option name="lenBefore" value="80" />
<option name="lenAfter" value="80" />
<option name="box" value="false" />
<option name="filler" value=" " />
</value>
</option>
<option name="notice" value="Copyright (c) &amp;#36;today.year, Your Corporation. All Rights Reserved." />
<option name="keyword" value="Copyright" />
<option name="fileTypeOverride" value="2" />
<option name="relativeBefore" value="true" />
<option name="addBlankAfter" value="true" />
<option name="fileLocation" value="1" />
<option name="useAlternate" value="false" />
</LanguageOptions>
<LanguageOptions name="JSP">
<option name="templateOptions">
<value>
<option name="block" value="true" />
<option name="separateBefore" value="false" />
<option name="separateAfter" value="false" />
<option name="prefixLines" value="true" />
<option name="lenBefore" value="80" />
<option name="lenAfter" value="80" />
<option name="box" value="false" />
<option name="filler" value=" " />
</value>
</option>
<option name="notice" value="Copyright (c) &amp;#36;today.year, Your Corporation. All Rights Reserved." />
<option name="keyword" value="Copyright" />
<option name="fileTypeOverride" value="2" />
<option name="relativeBefore" value="true" />
<option name="addBlankAfter" value="true" />
<option name="fileLocation" value="1" />
<option name="useAlternate" value="false" />
</LanguageOptions>
<LanguageOptions name="JavaScript">
<option name="templateOptions">
<value>
<option name="block" value="true" />
<option name="separateBefore" value="false" />
<option name="separateAfter" value="false" />
<option name="prefixLines" value="true" />
<option name="lenBefore" value="80" />
<option name="lenAfter" value="80" />
<option name="box" value="false" />
<option name="filler" value=" " />
</value>
</option>
<option name="notice" value="Copyright (c) &amp;#36;today.year, Your Corporation. All Rights Reserved." />
<option name="keyword" value="Copyright" />
<option name="fileTypeOverride" value="2" />
<option name="relativeBefore" value="true" />
<option name="addBlankAfter" value="true" />
<option name="fileLocation" value="1" />
<option name="useAlternate" value="false" />
</LanguageOptions>
<LanguageOptions name="Properties">
<option name="templateOptions">
<value>
<option name="block" value="true" />
<option name="separateBefore" value="false" />
<option name="separateAfter" value="false" />
<option name="prefixLines" value="true" />
<option name="lenBefore" value="80" />
<option name="lenAfter" value="80" />
<option name="box" value="false" />
<option name="filler" value=" " />
</value>
</option>
<option name="notice" value="Copyright (c) &amp;#36;today.year, Your Corporation. All Rights Reserved." />
<option name="keyword" value="Copyright" />
<option name="fileTypeOverride" value="2" />
<option name="relativeBefore" value="true" />
<option name="addBlankAfter" value="true" />
<option name="fileLocation" value="1" />
<option name="useAlternate" value="false" />
</LanguageOptions>
<LanguageOptions name="XML">
<option name="templateOptions">
<value>
<option name="block" value="true" />
<option name="separateBefore" value="false" />
<option name="separateAfter" value="false" />
<option name="prefixLines" value="true" />
<option name="lenBefore" value="80" />
<option name="lenAfter" value="80" />
<option name="box" value="false" />
<option name="filler" value=" " />
</value>
</option>
<option name="notice" value="Copyright (c) &amp;#36;today.year, Your Corporation. All Rights Reserved." />
<option name="keyword" value="Copyright" />
<option name="fileTypeOverride" value="2" />
<option name="relativeBefore" value="true" />
<option name="addBlankAfter" value="true" />
<option name="fileLocation" value="1" />
<option name="useAlternate" value="false" />
</LanguageOptions>
<LanguageOptions name="__TEMPLATE__">
<option name="templateOptions">
<value>
<option name="block" value="true" />
<option name="separateBefore" value="false" />
<option name="separateAfter" value="false" />
<option name="prefixLines" value="true" />
<option name="lenBefore" value="80" />
<option name="lenAfter" value="80" />
<option name="box" value="false" />
<option name="filler" value=" " />
</value>
</option>
<option name="notice" value="Copyright (c) &amp;#36;today.year, Your Corporation. All Rights Reserved." />
<option name="keyword" value="Copyright" />
<option name="fileTypeOverride" value="4" />
<option name="relativeBefore" value="true" />
<option name="addBlankAfter" value="true" />
<option name="fileLocation" value="1" />
<option name="useAlternate" value="false" />
</LanguageOptions>
</component>
</module>

View File

@ -37,6 +37,7 @@
<dependency org="org.custommonkey.xmlunit" name="com.springsource.org.custommonkey.xmlunit" rev="1.2.0"
conf="test->compile"/>
<dependency org="org.codehaus.woodstox" name="com.springsource.com.ctc.wstx" rev="3.2.7" conf="test->compile"/>
<dependency org="org.jboss.vfs" name="com.springsource.org.jboss.virtual" rev="2.1.0.GA" />
</dependencies>

View File

@ -43,6 +43,12 @@
<version>1.6.2</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.jboss.vfs</groupId>
<artifactId>com.springsource.org.jboss.virtual</artifactId>
<version>2.1.0.GA</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>

View File

@ -27,6 +27,7 @@ import org.springframework.util.ClassUtils;
import org.springframework.util.ObjectUtils;
import org.springframework.util.ResourceUtils;
import org.springframework.util.StringUtils;
import org.springframework.core.io.support.ResourceHandlingUtils;
/**
* {@link Resource} implementation for class path resources.
@ -49,7 +50,6 @@ public class ClassPathResource extends AbstractResource {
private Class clazz;
/**
* Create a new ClassPathResource for ClassLoader usage.
* A leading slash will be removed, as the ClassLoader
@ -174,7 +174,7 @@ public class ClassPathResource extends AbstractResource {
*/
@Override
public File getFile() throws IOException {
return ResourceUtils.getFile(getURL(), getDescription());
return ResourceHandlingUtils.getFile(getURL(), getDescription());
}
/**
@ -186,10 +186,10 @@ public class ClassPathResource extends AbstractResource {
URL url = getURL();
if (ResourceUtils.isJarURL(url)) {
URL actualUrl = ResourceUtils.extractJarFileURL(url);
return ResourceUtils.getFile(actualUrl);
return ResourceHandlingUtils.getFile(actualUrl);
}
else {
return ResourceUtils.getFile(url, getDescription());
return ResourceHandlingUtils.getFile(url, getDescription());
}
}

View File

@ -28,6 +28,7 @@ import java.net.URLConnection;
import org.springframework.util.Assert;
import org.springframework.util.ResourceUtils;
import org.springframework.util.StringUtils;
import org.springframework.core.io.support.ResourceHandlingUtils;
/**
* {@link Resource} implementation for <code>java.net.URL</code> locators.
@ -163,10 +164,10 @@ public class UrlResource extends AbstractResource {
@Override
public File getFile() throws IOException {
if (this.uri != null) {
return ResourceUtils.getFile(this.uri, getDescription());
return ResourceHandlingUtils.getFile(this.uri, getDescription());
}
else {
return ResourceUtils.getFile(this.url, getDescription());
return ResourceHandlingUtils.getFile(this.url, getDescription());
}
}
@ -178,7 +179,7 @@ public class UrlResource extends AbstractResource {
protected File getFileForLastModifiedCheck() throws IOException {
if (ResourceUtils.isJarURL(this.url)) {
URL actualUrl = ResourceUtils.extractJarFileURL(this.url);
return ResourceUtils.getFile(actualUrl);
return ResourceHandlingUtils.getFile(actualUrl);
}
else {
return getFile();

View File

@ -154,6 +154,7 @@ import org.springframework.util.StringUtils;
*
* @author Juergen Hoeller
* @author Colin Sampaleanu
* @author Marius Bogoevici
* @since 1.0.2
* @see #CLASSPATH_ALL_URL_PREFIX
* @see org.springframework.util.AntPathMatcher
@ -334,8 +335,9 @@ public class PathMatchingResourcePatternResolver implements ResourcePatternResol
Resource[] rootDirResources = getResources(rootDirPath);
Set<Resource> result = new LinkedHashSet<Resource>(16);
for (Resource rootDirResource : rootDirResources) {
rootDirResource = resolveRootDirResource(rootDirResource);
if (isJarResource(rootDirResource)) {
if (ResourceHandlingUtils.useResourceHandlingDelegate(rootDirResource.getURL())) {
result.addAll(ResourceHandlingUtils.findMatchingResourcesByDelegate(rootDirResource, subPattern, getPathMatcher()));
} else if (isJarResource(rootDirResource)) {
result.addAll(doFindPathMatchingJarResources(rootDirResource, subPattern));
}
else {

View File

@ -0,0 +1,48 @@
/*
* Copyright 2002-2009 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.core.io.support;
import java.io.IOException;
import java.net.URL;
import java.net.URI;
import java.util.Set;
import org.springframework.core.io.Resource;
import org.springframework.util.PathMatcher;
/**
* Abstraction for a path matching strategy, for customizing the way in which a resource can be
* scanned for finding underlying resources that match a given pattern.
* Used for implementing application-server specific resource scanning strategies (e.g. for JBoss AS)
*
* @author Marius Bogoevici
*
*/
public interface ResourceHandlingDelegate {
boolean canHandleResource(URL url);
boolean canHandleResource(URI uri);
Set<Resource> findMatchingResources(Resource rootResource, String subPattern, PathMatcher pathMatcher) throws
IOException;
Resource loadResource(URL url) throws IOException;
Resource loadResource(URI uri) throws IOException;
}

View File

@ -0,0 +1,107 @@
/*
* Copyright 2002-2007 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.core.io.support;
import java.net.URL;
import java.net.URI;
import java.util.Set;
import java.io.IOException;
import java.io.FileNotFoundException;
import java.io.File;
import org.springframework.util.ReflectionUtils;
import org.springframework.util.PathMatcher;
import org.springframework.util.ResourceUtils;
import org.springframework.util.Assert;
import org.springframework.core.io.support.jboss.VfsResourceHandlingDelegate;
import org.springframework.core.io.Resource;
/**
* Utility class for determining whether a given URL is a resource
* location that should receive special treatmen, such as looking up a
* resource in JBoss VFS.
*
* @author Thomas Risberg
* @author Marius Bogoevici
* @since 3.0
*/
public abstract class ResourceHandlingUtils {
private static ResourceHandlingDelegate resourceHandlingDelegate;
static {
try {
Class jBossVersionClass = PathMatchingResourcePatternResolver.class.getClassLoader().loadClass("org.jboss.Version");
Object versionObject = ReflectionUtils.invokeMethod(ReflectionUtils.findMethod(jBossVersionClass, "getInstance"), null);
Integer majorVersion = (Integer) ReflectionUtils.invokeMethod(ReflectionUtils.findMethod(jBossVersionClass, "getMajor"), versionObject);
// For JBoss AS versions 5 and higher
if (majorVersion >= 5) {
resourceHandlingDelegate = new VfsResourceHandlingDelegate();
}
}
catch (Throwable ex) {
// do nothing
}
}
public static File getFile(URL resourceUrl) throws FileNotFoundException {
return getFile(resourceUrl, "URL");
}
public static File getFile(URL resourceUrl, String description) throws FileNotFoundException {
Assert.notNull(resourceUrl, "Resource URL must not be null");
if (useResourceHandlingDelegate(resourceUrl)) {
try {
return resourceHandlingDelegate.loadResource(resourceUrl).getFile();
}
catch (IOException e) {
throw new FileNotFoundException(description + " cannot be resolved as a file resource");
}
}
return ResourceUtils.getFile(resourceUrl, description);
}
public static File getFile(URI resourceUri) throws FileNotFoundException {
return getFile(resourceUri, "URI");
}
public static File getFile(URI resourceUri, String description) throws FileNotFoundException {
Assert.notNull(resourceUri, "Resource URI must not be null");
if (useResourceHandlingDelegate(resourceUri)) {
try {
return resourceHandlingDelegate.loadResource(resourceUri).getFile();
}
catch (IOException e) {
throw new FileNotFoundException(description + " cannot be resolved as a file resource");
}
}
return ResourceUtils.getFile(resourceUri, description);
}
public static boolean useResourceHandlingDelegate(URL url) {
return resourceHandlingDelegate != null && resourceHandlingDelegate.canHandleResource(url);
}
public static boolean useResourceHandlingDelegate(URI uri) {
return resourceHandlingDelegate != null && resourceHandlingDelegate.canHandleResource(uri);
}
public static Set<Resource> findMatchingResourcesByDelegate(Resource resource, String pattern, PathMatcher matcher) throws
IOException {
return resourceHandlingDelegate.findMatchingResources(resource, pattern, matcher);
}
}

View File

@ -0,0 +1,153 @@
/*
* Copyright 2002-2009 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.core.io.support.jboss;
import java.io.IOException;
import java.io.File;
import java.io.InputStream;
import java.net.URL;
import java.net.URISyntaxException;
import java.net.URI;
import org.jboss.virtual.VirtualFile;
import org.jboss.virtual.VFSUtils;
import org.springframework.core.io.Resource;
import org.springframework.core.io.AbstractResource;
import org.springframework.util.Assert;
/**
* VFS based Resource.
*
* @author Ales Justin
*/
class VfsResource extends AbstractResource {
private VirtualFile file;
public VfsResource(VirtualFile file) {
Assert.notNull(file, "The file cannot be null.");
this.file = file;
}
public boolean exists() {
try {
return file.exists();
}
catch (IOException e) {
throw new RuntimeException(e);
}
}
public boolean isOpen() {
return false;
}
public boolean isReadable() {
try {
return file.getSize() > 0;
}
catch (IOException e) {
throw new RuntimeException(e);
}
}
public long lastModified() {
try {
return file.getLastModified();
}
catch (IOException e) {
throw new RuntimeException(e);
}
}
public URL getURL() throws IOException {
try {
return file.toURL();
}
catch (URISyntaxException e) {
IOException ioe = new IOException(e.getMessage());
ioe.initCause(e);
throw ioe;
}
}
public URI getURI() throws IOException {
try {
return file.toURI();
}
catch (URISyntaxException e) {
IOException ioe = new IOException(e.getMessage());
ioe.initCause(e);
throw ioe;
}
}
public File getFile() throws IOException {
if (VFSUtils.isNestedFile(file)) {
throw new IOException("This resource is a nested resource: " + file);
}
try {
return new File(VFSUtils.getCompatibleURI(file));
}
catch (IOException e) {
throw e;
}
catch (Exception e) {
IOException ioe = new IOException(e.getMessage());
ioe.initCause(e);
throw ioe;
}
}
@SuppressWarnings("deprecation")
public Resource createRelative(String relativePath) throws IOException {
return new VfsResource(file.findChild(relativePath));
}
public String getFilename() {
return file.getName();
}
public String getDescription() {
return file.toString();
}
public InputStream getInputStream() throws IOException {
return file.openStream();
}
public String toString() {
return getDescription();
}
@Override
public boolean equals(Object obj) {
if (obj instanceof VfsResource) {
return file.equals(((VfsResource)obj).file);
}
else {
return false;
}
}
@Override
public int hashCode() {
return this.file.hashCode();
}
}

View File

@ -0,0 +1,117 @@
/*
* Copyright 2002-2009 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.core.io.support.jboss;
import java.io.IOException;
import java.io.File;
import java.util.Set;
import java.util.LinkedHashSet;
import java.net.URL;
import java.net.URI;
import org.jboss.virtual.VFS;
import org.jboss.virtual.VirtualFile;
import org.jboss.virtual.VirtualFileVisitor;
import org.jboss.virtual.VisitorAttributes;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.ResourceHandlingDelegate;
import org.springframework.util.PathMatcher;
/**
* {@link org.springframework.core.io.support.ResourceHandlingDelegate} implementation
* for JBoss' Virtual File System.
*
* @author Marius Bogoevici
* @author Ales Justin
*
* Note: Thanks to David Ward from Alfresco for indicating a fix for path matching.
*/
public class VfsResourceHandlingDelegate implements ResourceHandlingDelegate {
public boolean canHandleResource(URL url) {
return url.getProtocol().startsWith("vfs");
}
public boolean canHandleResource(URI uri) {
return uri.getScheme().startsWith("vfs");
}
public Set<Resource> findMatchingResources(Resource rootResource, String locationPattern, PathMatcher pathMatcher) throws IOException {
VirtualFile root = VFS.getRoot(rootResource.getURL());
PatternVirtualFileVisitor visitor = new PatternVirtualFileVisitor(root.getPathName(), locationPattern, pathMatcher);
root.visit(visitor);
return visitor.getResources();
}
public Resource loadResource(URL url) throws IOException{
return new VfsResource(VFS.getRoot(url));
}
public Resource loadResource(URI uri) throws IOException {
return new VfsResource(VFS.getRoot(uri));
}
protected static class PatternVirtualFileVisitor implements VirtualFileVisitor
{
private final String subPattern;
private final Set<Resource> resources = new LinkedHashSet<Resource>();
private final PathMatcher pathMatcher;
private final String rootPath;
private PatternVirtualFileVisitor(String rootPath, String subPattern, PathMatcher pathMatcher)
{
this.subPattern = subPattern;
this.pathMatcher = pathMatcher;
this.rootPath = rootPath.length() == 0 || rootPath.endsWith("/") ? rootPath : rootPath + "/";
}
public VisitorAttributes getAttributes()
{
return VisitorAttributes.RECURSE;
}
public void visit(VirtualFile vf)
{
if (pathMatcher.match(subPattern, vf.getPathName().substring(rootPath.length())))
resources.add(new VfsResource(vf));
}
public Set<Resource> getResources()
{
return resources;
}
public int size()
{
return resources.size();
}
public String toString()
{
StringBuffer buffer = new StringBuffer();
buffer.append("sub-pattern: ").append(subPattern);
buffer.append(", resources: ").append(resources);
return buffer.toString();
}
}
}

View File

@ -256,7 +256,6 @@ public abstract class ResourceUtils {
String protocol = url.getProtocol();
return (URL_PROTOCOL_JAR.equals(protocol) ||
URL_PROTOCOL_ZIP.equals(protocol) ||
URL_PROTOCOL_VFSZIP.equals(protocol) ||
URL_PROTOCOL_WSJAR.equals(protocol) ||
(URL_PROTOCOL_CODE_SOURCE.equals(protocol) && url.getPath().indexOf(JAR_URL_SEPARATOR) != -1));
}

View File

@ -10,6 +10,7 @@ Import-Template:
org.springframework.asm.*;version="[3.0.0, 3.0.1)";resolution:=optional,
org.apache.log4j.*;version="[1.2.15, 2.0.0)";resolution:=optional,
org.aspectj.*;version="[1.5.4, 2.0.0)";resolution:=optional,
org.jboss.virtual.*;version="[2.1.0.GA,2.1.0.GA]";resolution:=optional,
org.xml.sax.*;version="0";resolution:=optional,
org.w3c.dom.*;version="0";resolution:=optional
Ignored-Existing-Headers: