if(ps==null) return null;
return ps.getPhyscalFile();*/
}
public PageSource toPageSource(Mapping[] mappings, Resource res,PageSource defaultValue) {
Mapping mapping;
String path;
// app-cfc mappings
if(mappings!=null){
for(int i=0;i<mappings.length;i++) {
mapping = mappings[i];
// Physical
if(mapping.hasPhysical()) {
path=ResourceUtil.getPathToChild(res, mapping.getPhysical());
if(path!=null) {
return mapping.getPageSource(path);
}
}
// Archive
if(mapping.hasArchive() && res.getResourceProvider() instanceof CompressResourceProvider) {
Resource archive = mapping.getArchive();
CompressResource cr = ((CompressResource) res);
if(archive.equals(cr.getCompressResource())) {
return mapping.getPageSource(cr.getCompressPath());
}
}
}
}
// config mappings
for(int i=0;i<this.mappings.length;i++) {
mapping = this.mappings[i];
// Physical
if(mapping.hasPhysical()) {
path=ResourceUtil.getPathToChild(res, mapping.getPhysical());
if(path!=null) {
return mapping.getPageSource(path);
}
}
// Archive
if(mapping.hasArchive() && res.getResourceProvider() instanceof CompressResourceProvider) {
Resource archive = mapping.getArchive();
CompressResource cr = ((CompressResource) res);
if(archive.equals(cr.getCompressResource())) {
return mapping.getPageSource(cr.getCompressPath());
}
}
}
// map resource to root mapping when same filesystem
Mapping rootMapping = this.mappings[this.mappings.length-1];
Resource root;
if(rootMapping.hasPhysical() &&
res.getResourceProvider().getScheme().equals((root=rootMapping.getPhysical()).getResourceProvider().getScheme())) {
String realpath="";
while(root!=null && !ResourceUtil.isChildOf(res, root)){
root=root.getParentResource();
realpath+="../";
}
String p2c=ResourceUtil.getPathToChild(res,root);
if(StringUtil.startsWith(p2c, '/') || StringUtil.startsWith(p2c, '\\') )
p2c=p2c.substring(1);
realpath+=p2c;
return rootMapping.getPageSource(realpath);
}
// MUST better impl than this
if(this instanceof ConfigWebImpl) {
Resource parent = res.getParentResource();
if(parent!=null && !parent.equals(res)) {
Mapping m = ((ConfigWebImpl)this).getApplicationMapping("/", parent.getAbsolutePath());
return m.getPageSource(res.getName());
}
}
// Archive