All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.wesleyhome.johksoftware.resource.VFS2ResourceEvaluator Maven / Gradle / Ivy

Go to download

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.

There is a newer version: 2.0.0
Show newest version
/**
 * 
 */
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);
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy