Search in sources :

Example 96 with Resource

use of lucee.commons.io.res.Resource in project Lucee by lucee.

the class ResourceUtil method toResourceExisting.

public static Resource toResourceExisting(Config config, String path) throws ExpressionException {
    path = path.replace('\\', '/');
    Resource res = config.getResource(path);
    if (res.exists())
        return res;
    throw new ExpressionException("file or directory " + path + " not exist");
}
Also used : HTTPResource(lucee.commons.io.res.type.http.HTTPResource) Resource(lucee.commons.io.res.Resource) ExpressionException(lucee.runtime.exp.ExpressionException)

Example 97 with Resource

use of lucee.commons.io.res.Resource in project Lucee by lucee.

the class ResourceUtil method toResourceExisting.

public static Resource toResourceExisting(PageContext pc, String path, boolean allowRealpath) throws ExpressionException {
    path = path.replace('\\', '/');
    Resource res = pc.getConfig().getResource(path);
    if (res.exists())
        return res;
    else if (!allowRealpath)
        throw new ExpressionException("file or directory " + path + " not exist");
    if (res.isAbsolute() && res.exists()) {
        return res;
    }
    if (StringUtil.startsWith(path, '/')) {
        PageContextImpl pci = (PageContextImpl) pc;
        ConfigWebImpl cwi = (ConfigWebImpl) pc.getConfig();
        PageSource[] sources = cwi.getPageSources(pci, pc.getApplicationContext().getMappings(), path, false, pci.useSpecialMappings(), true);
        if (!ArrayUtil.isEmpty(sources)) {
            for (int i = 0; i < sources.length; i++) {
                if (sources[i].exists())
                    return sources[i].getResource();
            }
        }
    }
    res = getRealResource(pc, path, res);
    if (res.exists())
        return res;
    throw new ExpressionException("file or directory " + path + " not exist");
}
Also used : ConfigWebImpl(lucee.runtime.config.ConfigWebImpl) HTTPResource(lucee.commons.io.res.type.http.HTTPResource) Resource(lucee.commons.io.res.Resource) PageContextImpl(lucee.runtime.PageContextImpl) ExpressionException(lucee.runtime.exp.ExpressionException) PageSource(lucee.runtime.PageSource)

Example 98 with Resource

use of lucee.commons.io.res.Resource in project Lucee by lucee.

the class ResourceUtil method toResourceNotExisting.

public static Resource toResourceNotExisting(PageContext pc, String destination, boolean allowRealpath, boolean checkComponentMappings) {
    destination = destination.replace('\\', '/');
    Resource res = pc.getConfig().getResource(destination);
    if (!allowRealpath || res.exists()) {
        return res;
    }
    boolean isUNC;
    if (!(isUNC = isUNCPath(destination)) && StringUtil.startsWith(destination, '/')) {
        PageContextImpl pci = (PageContextImpl) pc;
        ConfigWebImpl cwi = (ConfigWebImpl) pc.getConfig();
        PageSource[] sources = cwi.getPageSources(pci, pc.getApplicationContext().getMappings(), destination, false, pci.useSpecialMappings(), SystemUtil.isWindows(), checkComponentMappings);
        if (!ArrayUtil.isEmpty(sources)) {
            for (int i = 0; i < sources.length; i++) {
                res = sources[i].getResource();
                if (res != null)
                    return res;
            }
        }
    // Resource res2 = pc.getPhysical(destination,SystemUtil.isWindows());
    // if(res2!=null) return res2;
    }
    if (isUNC) {
        res = pc.getConfig().getResource(destination.replace('/', '\\'));
    } else if (!destination.startsWith(".."))
        res = pc.getConfig().getResource(destination);
    if (res != null && res.isAbsolute())
        return res;
    return getRealResource(pc, destination, res);
}
Also used : ConfigWebImpl(lucee.runtime.config.ConfigWebImpl) HTTPResource(lucee.commons.io.res.type.http.HTTPResource) Resource(lucee.commons.io.res.Resource) PageContextImpl(lucee.runtime.PageContextImpl) PageSource(lucee.runtime.PageSource)

Example 99 with Resource

use of lucee.commons.io.res.Resource in project Lucee by lucee.

the class ResourceUtil method toResourceExistingParent.

public static Resource toResourceExistingParent(PageContext pc, String destination, boolean allowRealpath) throws ExpressionException {
    destination = destination.replace('\\', '/');
    Resource res = pc.getConfig().getResource(destination);
    // not allow realpath
    if (!allowRealpath) {
        if (res.exists() || parentExists(res))
            return res;
        throw new ExpressionException("parent directory " + res.getParent() + "  for file " + destination + " doesn't exist");
    }
    // allow realpath
    if (res.isAbsolute() && (res.exists() || parentExists(res))) {
        return res;
    }
    if (StringUtil.startsWith(destination, '/')) {
        PageContextImpl pci = (PageContextImpl) pc;
        ConfigWebImpl cwi = (ConfigWebImpl) pc.getConfig();
        PageSource[] sources = cwi.getPageSources(pci, pc.getApplicationContext().getMappings(), destination, false, pci.useSpecialMappings(), true);
        // Resource[] reses = cwi.getPhysicalResourcesX(pc,pc.getApplicationContext().getMappings(),destination,false,pci.useSpecialMappings(),true);
        if (!ArrayUtil.isEmpty(sources)) {
            for (int i = 0; i < sources.length; i++) {
                if (sources[i].exists() || parentExists(sources[i])) {
                    res = sources[i].getResource();
                    if (res != null)
                        return res;
                }
            }
        }
    }
    res = getRealResource(pc, destination, res);
    if (res != null && (res.exists() || parentExists(res)))
        return res;
    throw new ExpressionException("parent directory " + res.getParent() + "  for file " + destination + " doesn't exist");
}
Also used : ConfigWebImpl(lucee.runtime.config.ConfigWebImpl) HTTPResource(lucee.commons.io.res.type.http.HTTPResource) Resource(lucee.commons.io.res.Resource) PageContextImpl(lucee.runtime.PageContextImpl) ExpressionException(lucee.runtime.exp.ExpressionException) PageSource(lucee.runtime.PageSource)

Example 100 with Resource

use of lucee.commons.io.res.Resource in project Lucee by lucee.

the class ResourceUtil method _check.

private static Resource _check(Resource file) {
    // todo cascade durch while ersetzten
    Resource parent = file.getParentResource();
    if (parent == null)
        return file;
    if (!parent.exists()) {
        Resource op = parent;
        parent = _check(parent);
        if (op == parent)
            return file;
        if ((file = parent.getRealResource(file.getName())).exists())
            return file;
    }
    String[] files = parent.list();
    if (files == null)
        return file;
    String name = file.getName();
    for (int i = 0; i < files.length; i++) {
        if (name.equalsIgnoreCase(files[i]))
            return parent.getRealResource(files[i]);
    }
    return file;
}
Also used : HTTPResource(lucee.commons.io.res.type.http.HTTPResource) Resource(lucee.commons.io.res.Resource)

Aggregations

Resource (lucee.commons.io.res.Resource)309 IOException (java.io.IOException)100 ApplicationException (lucee.runtime.exp.ApplicationException)54 PageException (lucee.runtime.exp.PageException)40 ArrayList (java.util.ArrayList)31 Struct (lucee.runtime.type.Struct)28 ByteArrayInputStream (java.io.ByteArrayInputStream)21 InputStream (java.io.InputStream)21 ExpressionException (lucee.runtime.exp.ExpressionException)19 StructImpl (lucee.runtime.type.StructImpl)18 MalformedURLException (java.net.MalformedURLException)17 PageContextImpl (lucee.runtime.PageContextImpl)17 PageSource (lucee.runtime.PageSource)16 FileResource (lucee.commons.io.res.type.file.FileResource)15 SecurityException (lucee.runtime.exp.SecurityException)15 BundleException (org.osgi.framework.BundleException)15 ZipEntry (java.util.zip.ZipEntry)13 ExtensionResourceFilter (lucee.commons.io.res.filter.ExtensionResourceFilter)13 Array (lucee.runtime.type.Array)13 File (java.io.File)12