private static Resource toResourceExisting(Config config, ApplicationContext ac,Object obj, boolean onlyDir) {
//Resource root = config.getRootDirectory();
String path = Caster.toString(obj,null);
if(StringUtil.isEmpty(path,true)) return null;
path=path.trim();
Resource res;
PageContext pc = ThreadLocalPageContext.get();
// first check relative to application.cfc
if(pc!=null) {
if(ac==null) ac= pc.getApplicationContext();
// abs path
if(path.startsWith("/")){
ConfigWebImpl cwi=(ConfigWebImpl) config;
PageSource ps = cwi.getPageSourceExisting(
pc, ac==null?null:ac.getMappings(), path, false, false, true, false);
//res=cwi.getPhysicalResourceExistingX(
// pc,
// ac==null?null:ac.getMappings(), path,
// false, false, true);
if(ps!=null){
res=ps.getResource();
if(res!=null && (!onlyDir || res.isDirectory())) return res;
}
}
// real path
else {
Resource src= ac!=null?ac.getSource():null;
if(src!=null) {
res=src.getParentResource().getRealResource(path);
if(res!=null && (!onlyDir || res.isDirectory())) return res;
}
// happens when this is called from within the application.cfc (init)
else {
res=ResourceUtil.toResourceNotExisting(pc, path);