public PageSource getPageSourceExisting(PageContext pc,Mapping[] mappings, String realPath,boolean onlyTopLevel,boolean useSpecialMappings, boolean useDefaultMapping, boolean onlyPhysicalExisting) {
realPath=realPath.replace('\\','/');
String lcRealPath = StringUtil.toLowerCase(realPath)+'/';
Mapping mapping;
PageSource ps;
if(mappings!=null){
for(int i=0;i<mappings.length;i++) {
mapping = mappings[i];
//print.err(lcRealPath+".startsWith"+(mapping.getStrPhysical()));
if(lcRealPath.startsWith(mapping.getVirtualLowerCaseWithSlash(),0)) {
ps= mapping.getPageSource(realPath.substring(mapping.getVirtual().length()));
if(onlyPhysicalExisting) {
if(ps.physcalExists())return ps;
}
else if(ps.exists()) return ps;
}
}
}
/// special mappings
if(useSpecialMappings && lcRealPath.startsWith("/mapping-",0)){
String virtual="/mapping-tag";
// tag mappings
Mapping[] tagMappings=(this instanceof ConfigWebImpl)?new Mapping[]{((ConfigWebImpl)this).getServerTagMapping(),getTagMapping()}:new Mapping[]{getTagMapping()};
if(lcRealPath.startsWith(virtual,0)){
for(int i=0;i<tagMappings.length;i++) {
mapping = tagMappings[i];
//if(lcRealPath.startsWith(mapping.getVirtualLowerCaseWithSlash(),0)) {
ps = mapping.getPageSource(realPath.substring(virtual.length()));
if(onlyPhysicalExisting) {
if(ps.physcalExists())return ps;
}
else if(ps.exists()) return ps;
//}
}
}
// customtag mappings
tagMappings=getCustomTagMappings();
virtual="/mapping-customtag";
if(lcRealPath.startsWith(virtual,0)){
for(int i=0;i<tagMappings.length;i++) {
mapping = tagMappings[i];
//if(lcRealPath.startsWith(mapping.getVirtualLowerCaseWithSlash(),0)) {
ps = mapping.getPageSource(realPath.substring(virtual.length()));
if(onlyPhysicalExisting) {
if(ps.physcalExists())return ps;
}
else if(ps.exists()) return ps;
//}
}
}
}
// component mappings (only used for gateway)
if(pc!=null && ((PageContextImpl)pc).isGatewayContext()) {
boolean isCFC=getCFCExtension().equalsIgnoreCase(ResourceUtil.getExtension(realPath, null));
if(isCFC) {
Mapping[] cmappings = getComponentMappings();
for(int i=0;i<cmappings.length;i++) {
ps = cmappings[i].getPageSource(realPath);
if(onlyPhysicalExisting) {
if(ps.physcalExists())return ps;
}
else if(ps.exists()) return ps;
}
}
}
// config mappings
for(int i=0;i<this.mappings.length-1;i++) {
mapping = this.mappings[i];
if((!onlyTopLevel || mapping.isTopLevel()) && lcRealPath.startsWith(mapping.getVirtualLowerCaseWithSlash(),0)) {
ps= mapping.getPageSource(realPath.substring(mapping.getVirtual().length()));
if(onlyPhysicalExisting) {
if(ps.physcalExists())return ps;
}
else if(ps.exists()) return ps;
}
}
if(useDefaultMapping){
ps= this.mappings[this.mappings.length-1].getPageSource(realPath);
if(onlyPhysicalExisting) {
if(ps.physcalExists())return ps;
}
else if(ps.exists()) return ps;
}
return null;
}