Skip to content

Instantly share code, notes, and snippets.

@rbackhouse
Created March 26, 2011 11:09
Show Gist options
  • Save rbackhouse/888206 to your computer and use it in GitHub Desktop.
Save rbackhouse/888206 to your computer and use it in GitHub Desktop.
A Multiple Rooted Resource Loader
import java.io.File;
import java.io.IOException;
import java.net.URL;
import org.dojotoolkit.compressor.JSCompressorFactory;
import org.dojotoolkit.compressor.JSCompressorResourceLoader;
public class MultiRootResourceLoader extends JSCompressorResourceLoader {
private File[] roots = null;
public MultiRootResourceLoader(File[] roots, JSCompressorFactory jsCompressorFactory) {
super(jsCompressorFactory);
this.roots = roots;
}
public MultiRootResourceLoader(File[] roots) {
super(null);
this.roots = roots;
}
protected URL _getResource(String path) throws IOException {
for (File root : roots) {
URL url = searchRoot(root, path);
if (url != null) {
return url;
}
}
return null;
}
private URL searchRoot(File root, String path) throws IOException {
File resourceFile = new File(root, path);
if (resourceFile.exists()) {
timestampLookup.put(path, resourceFile.toURI().toURL());
return resourceFile.toURI().toURL();
} else {
return null;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment