com.wesleyhome.johksoftware.resource.VFS2ResourceEvaluator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jboss-vfs2-resource-loader Show documentation
Show all versions of jboss-vfs2-resource-loader Show documentation
This project will load resources from version 2 of the JBoss virtual file system. Version 2 is found in JBoss Community AS 6 and JBoss EAP 5.1.
/**
*
*/
package com.wesleyhome.johksoftware.resource;
import java.io.IOException;
import java.net.URL;
import org.jboss.virtual.VFS;
import org.jboss.virtual.VirtualFile;
import com.wesleyhome.johksoftware.resource.api.ClassResourceLoader;
import com.wesleyhome.johksoftware.resource.api.ResourceEvaluator;
/**
* @author Justin Wesley
* @since 1.0
*
*/
public class VFS2ResourceEvaluator implements ResourceEvaluator {
/* (non-Javadoc)
* @see com.wesleyhome.johksoftware.resource.api.ResourceEvaluator#canLoad(java.net.URL)
*/
@Override
public boolean canLoad(final URL systemResource) {
return VFS2ResourceLoader.VFS_PROTOCOL.equalsIgnoreCase(systemResource.getProtocol());
}
/* (non-Javadoc)
* @see com.wesleyhome.johksoftware.resource.api.ResourceEvaluator#getLoader(java.net.URL, java.lang.String)
*/
@Override
public ClassResourceLoader getLoader(final URL url, final String resourceName) {
try {
String file = url.getFile();
int resourceIndex = file.indexOf(resourceName);
file = file.substring(0, resourceIndex);
URL url2 = new URL(url.getProtocol(), url.getHost(), url.getPort(), file);
VirtualFile child = VFS.getRoot(url2);
return new VFS2ResourceLoader(child);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}