return (Page)load(pc, child,rawPath, searchLocal, searchRoot,null,true);
}
private static Object load(PageContext pc,PageSource child,String rawPath, Boolean searchLocal, Boolean searchRoot, Map interfaceUDFs, boolean returnPage) throws PageException {
ConfigImpl config=(ConfigImpl) pc.getConfig();
boolean doCache=config.useComponentPathCache();
//print.o(rawPath);
//app-String appName=pc.getApplicationContext().getName();
rawPath=rawPath.trim().replace('\\','/');
String path=(rawPath.indexOf("./")==-1)?rawPath.replace('.','/'):rawPath;
String pathWithCFC=path.concat(".cfc");
boolean isRealPath=!StringUtil.startsWith(pathWithCFC,'/');
PageSource currPS = pc.getCurrentPageSource();
Page currP=((PageSourceImpl)currPS).loadPage(pc,(Page)null);
PageSource ps=null;
Page page=null;
if(searchLocal==null)
searchLocal=Caster.toBoolean(config.getComponentLocalSearch());
if(searchRoot==null)
searchRoot=Caster.toBoolean(config.getComponentRootSearch());
//boolean searchLocal=config.getComponentLocalSearch();
// CACHE
// check local in cache
String localCacheName=null;
if(searchLocal && isRealPath){
localCacheName=currPS.getDisplayPath().replace('\\', '/');
localCacheName=localCacheName.substring(0,localCacheName.lastIndexOf('/')+1).concat(pathWithCFC);
if(doCache){
page=config.getCachedPage(pc, localCacheName);
if(page!=null) return returnPage?page:load(pc,page,page.getPageSource(),trim(path.replace('/', '.')),isRealPath,interfaceUDFs);
}
}
// check import cache
if(doCache && isRealPath){
ImportDefintion impDef = config.getComponentDefaultImport();
ImportDefintion[] impDefs=currP==null?new ImportDefintion[0]:currP.getImportDefintions();
int i=-1;
do{
if(impDef.isWildcard() || impDef.getName().equalsIgnoreCase(path)){
page=config.getCachedPage(pc, "import:"+impDef.getPackageAsPath()+pathWithCFC);
if(page!=null) return returnPage?page:load(pc,page,page.getPageSource(),trim(path.replace('/', '.')),isRealPath,interfaceUDFs);
//app-page=config.getCachedPage(pc, "import:"+appName+":"+impDef.getPackageAsPath()+pathWithCFC);
//app-if(page!=null) return load(pc,page,page.getPageSource(),trim(path.replace('/', '.')),isRealPath,interfaceUDFs);
}
impDef=++i<impDefs.length?impDefs[i]:null;
}
while(impDef!=null);
}
if(doCache) {
// check global in cache
page=config.getCachedPage(pc, pathWithCFC);
if(page!=null) return returnPage?page:load(pc,page,page.getPageSource(),trim(path.replace('/', '.')),isRealPath,interfaceUDFs);
// get pages from application mappings
//app-page=config.getCachedPage(pc, ":"+appName+":"+pathWithCFC);
//app-if(page!=null) return load(pc,page,page.getPageSource(),trim(path.replace('/', '.')),isRealPath,interfaceUDFs);
}
// SEARCH
// search from local
if(searchLocal && isRealPath) {
// check realpath
PageSource[] arr = ((PageContextImpl)pc).getRelativePageSources(pathWithCFC);
page=PageSourceImpl.loadPage(pc, arr,null);
if(page!=null){
if(doCache)config.putCachedPageSource(localCacheName, page.getPageSource());
return returnPage?page:load(pc,page,page.getPageSource(),trim(path.replace('/', '.')),isRealPath,interfaceUDFs);
}
}
// search with imports
Mapping[] cMappings = config.getComponentMappings();
if(isRealPath){
ImportDefintion impDef = config.getComponentDefaultImport();
ImportDefintion[] impDefs=currP==null?new ImportDefintion[0]:currP.getImportDefintions();
PageSource[] arr;
int i=-1;
do{
if(impDef.isWildcard() || impDef.getName().equalsIgnoreCase(path)){
// search from local first
if(searchLocal){
arr = ((PageContextImpl)pc).getRelativePageSources(impDef.getPackageAsPath()+pathWithCFC);
page=PageSourceImpl.loadPage(pc, arr,null);
if(page!=null) {
if(doCache)config.putCachedPageSource("import:"+impDef.getPackageAsPath()+pathWithCFC, page.getPageSource());
return returnPage?page:load(pc,page,page.getPageSource(),trim(path.replace('/', '.')),isRealPath,interfaceUDFs);
}
}
// search local component mappings
/*app-if(lcMappings!=null) {
Mapping m;
for(int y=0;y<lcMappings.length;y++){
m=lcMappings[y];
String key=appName+":"+impDef.getPackageAsPath()+pathWithCFC;
ps=m.getPageSource(impDef.getPackageAsPath()+pathWithCFC);
page=((PageSourceImpl)ps).loadPage(pc,pc.getConfig(),null);
if(page!=null) {
if(doCache)config.putCachedPageSource("import:"+key, page.getPageSource());
return load(pc,page,page.getPageSource(),trim(path.replace('/', '.')),isRealPath,interfaceUDFs);
}
}
}*/
// search mappings and webroot
page=PageSourceImpl.loadPage(pc, ((PageContextImpl)pc).getPageSources("/"+impDef.getPackageAsPath()+pathWithCFC), null);
if(page!=null){
String key=impDef.getPackageAsPath()+pathWithCFC;
if(doCache && !((MappingImpl)page.getPageSource().getMapping()).isAppMapping())
config.putCachedPageSource("import:"+key, page.getPageSource());
return returnPage?page:load(pc,page,page.getPageSource(),trim(path.replace('/', '.')),isRealPath,interfaceUDFs);
}
// search component mappings
Mapping m;
for(int y=0;y<cMappings.length;y++){
m=cMappings[y];
ps=m.getPageSource(impDef.getPackageAsPath()+pathWithCFC);
page=((PageSourceImpl)ps).loadPage(pc,(Page)null);
if(page!=null) {
if(doCache)config.putCachedPageSource("import:"+impDef.getPackageAsPath()+pathWithCFC, page.getPageSource());
return returnPage?page:load(pc,page,page.getPageSource(),trim(path.replace('/', '.')),isRealPath,interfaceUDFs);
}
}
}
impDef=++i<impDefs.length?impDefs[i]:null;
}
while(impDef!=null);
}
String p;
if(isRealPath) p='/'+pathWithCFC;
else p=pathWithCFC;
// search local component mappings
/* app-if(lcMappings!=null) {
Mapping m;
for(int i=0;i<lcMappings.length;i++){
m=lcMappings[i];
ps=m.getPageSource(p);
page=((PageSourceImpl)ps).loadPage(pc,pc.getConfig(),null);
String key=":"+appName+":"+pathWithCFC;
if(page!=null){
if(doCache)config.putCachedPageSource(key, page.getPageSource());
return load(pc,page,page.getPageSource(),trim(path.replace('/', '.')),isRealPath,interfaceUDFs);
}
}
}*/
// search mappings and webroot
page=PageSourceImpl.loadPage(pc,((PageContextImpl)pc).getPageSources(p),null);
if(page!=null){
String key=pathWithCFC;
if(doCache && !((MappingImpl)page.getPageSource().getMapping()).isAppMapping())
config.putCachedPageSource(key, page.getPageSource());
return returnPage?page:load(pc,page,page.getPageSource(),trim(path.replace('/', '.')),isRealPath,interfaceUDFs);
}
// search component mappings
Mapping m;
for(int i=0;i<cMappings.length;i++){
m=cMappings[i];
ps=m.getPageSource(p);
page=((PageSourceImpl)ps).loadPage(pc,(Page)null);
// recursive search
if(page==null && config.doComponentDeepSearch() && m.hasPhysical() && path.indexOf('/')==-1) {
String _path=getPagePath(pc, m.getPhysical(), null,pathWithCFC,DirectoryResourceFilter.FILTER);
if(_path!=null) {
ps=m.getPageSource(_path);
page=((PageSourceImpl)ps).loadPage(pc,(Page)null);
doCache=false;// do not cache this, it could be ambigous
}
}
if(page!=null){
if(doCache)config.putCachedPageSource(pathWithCFC, page.getPageSource());
return returnPage?page:load(pc,page,page.getPageSource(),trim(path.replace('/', '.')),isRealPath,interfaceUDFs);
}
}