Search in sources :

Example 76 with Resource

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

the class FileMove method call.

public static String call(PageContext pc, Object oSrc, Object oDst) throws PageException {
    Resource src = Caster.toResource(pc, oSrc, false);
    if (!src.exists())
        throw new FunctionException(pc, "FileMove", 1, "source", "source file [" + src + "] does not exist");
    FileTag.actionMove(pc, pc.getConfig().getSecurityManager(), src, Caster.toString(oDst), FileUtil.NAMECONFLICT_UNDEFINED, null, null, -1, null);
    return null;
}
Also used : Resource(lucee.commons.io.res.Resource) FunctionException(lucee.runtime.exp.FunctionException)

Example 77 with Resource

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

the class FileRead method call.

public static Object call(PageContext pc, Object obj, Object charsetOrSize) throws PageException {
    if (charsetOrSize == null)
        return call(pc, obj);
    if (obj instanceof FileStreamWrapper) {
        return _call((FileStreamWrapper) obj, Caster.toIntValue(charsetOrSize));
    }
    Resource res = Caster.toResource(pc, obj, true);
    String charset = Caster.toString(charsetOrSize);
    if (Decision.isInteger(charset)) {
        charset = ((PageContextImpl) pc).getResourceCharset().name();
        return _call(pc, res, charset, Caster.toIntValue(charset));
    }
    return _call(pc, res, charset);
}
Also used : Resource(lucee.commons.io.res.Resource) PageContextImpl(lucee.runtime.PageContextImpl)

Example 78 with Resource

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

the class FileReadBinary method call.

public static Object call(PageContext pc, Object oSrc) throws PageException {
    Resource src = Caster.toResource(pc, oSrc, false);
    pc.getConfig().getSecurityManager().checkFileLocation(src);
    try {
        return IOUtil.toBytes(src);
    } catch (IOException e) {
        throw Caster.toPageException(e);
    }
}
Also used : Resource(lucee.commons.io.res.Resource) IOException(java.io.IOException)

Example 79 with Resource

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

the class FileSetLastModified method call.

public static String call(PageContext pc, Object oSrc, DateTime date) throws PageException {
    Resource src = Caster.toResource(pc, oSrc, false);
    pc.getConfig().getSecurityManager().checkFileLocation(src);
    if (!src.exists() || !src.isFile())
        throw Caster.toPageException(new FileNotFoundException(src.getAbsolutePath()));
    src.setLastModified(date.getTime());
    return null;
}
Also used : Resource(lucee.commons.io.res.Resource) FileNotFoundException(java.io.FileNotFoundException)

Example 80 with Resource

use of lucee.commons.io.res.Resource 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)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