Search in sources :

Example 1 with CompressResource

use of lucee.commons.io.res.type.compress.CompressResource in project Lucee by lucee.

the class ConfigImpl method toPageSource.

public PageSource toPageSource(Mapping[] mappings, Resource res, PageSource defaultValue) {
    Mapping mapping;
    String path;
    // app 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("application", "/", parent.getAbsolutePath(), null, true, false);
            return m.getPageSource(res.getName());
        }
    }
    // MUST check archive
    return defaultValue;
}
Also used : Resource(lucee.commons.io.res.Resource) CompressResource(lucee.commons.io.res.type.compress.CompressResource) CompressResource(lucee.commons.io.res.type.compress.CompressResource) Mapping(lucee.runtime.Mapping) CompressResourceProvider(lucee.commons.io.res.type.compress.CompressResourceProvider)

Aggregations

Resource (lucee.commons.io.res.Resource)1 CompressResource (lucee.commons.io.res.type.compress.CompressResource)1 CompressResourceProvider (lucee.commons.io.res.type.compress.CompressResourceProvider)1 Mapping (lucee.runtime.Mapping)1