Search in sources :

Example 1 with ModeObjectWrap

use of lucee.commons.io.res.util.ModeObjectWrap in project Lucee by lucee.

the class Directory method _fillQueryAll.

private static int _fillQueryAll(Query query, Resource directory, ResourceFilter filter, int count, boolean hasMeta, boolean recurse) throws PageException, IOException {
    Resource[] list = directory.listResources();
    if (list == null || list.length == 0)
        return count;
    String dir = directory.getCanonicalPath();
    // fill data to query
    // query.addRow(list.length);
    boolean isDir;
    for (int i = 0; i < list.length; i++) {
        if (filter == null || filter.accept(list[i])) {
            query.addRow(1);
            count++;
            query.setAt(KeyConstants._name, count, list[i].getName());
            isDir = list[i].isDirectory();
            query.setAt(KeyConstants._size, count, new Double(isDir ? 0 : list[i].length()));
            query.setAt(KeyConstants._type, count, isDir ? "Dir" : "File");
            if (directory.getResourceProvider().isModeSupported()) {
                query.setAt(MODE, count, new ModeObjectWrap(list[i]));
            }
            query.setAt(DATE_LAST_MODIFIED, count, new Date(list[i].lastModified()));
            query.setAt(ATTRIBUTES, count, getFileAttribute(list[i], true));
            if (hasMeta) {
                query.setAt(META, count, ((ResourceMetaData) list[i]).getMetaData());
            }
            query.setAt(DIRECTORY, count, dir);
        }
        if (recurse && list[i].isDirectory())
            count = _fillQueryAll(query, list[i], filter, count, hasMeta, recurse);
    }
    return count;
}
Also used : ModeObjectWrap(lucee.commons.io.res.util.ModeObjectWrap) Resource(lucee.commons.io.res.Resource) FileResource(lucee.commons.io.res.type.file.FileResource) Date(java.util.Date)

Example 2 with ModeObjectWrap

use of lucee.commons.io.res.util.ModeObjectWrap in project Lucee by lucee.

the class FileTag method getInfo.

public static Struct getInfo(PageContext pc, Resource file, String serverPassword) throws PageException {
    SecurityManager sm = pc.getConfig().getSecurityManager();
    checkFile(pc, sm, file, serverPassword, false, false, false, false);
    Struct sct = new StructImpl();
    // fill data to query
    sct.setEL(KeyConstants._name, file.getName());
    sct.setEL(KeyConstants._size, Long.valueOf(file.length()));
    sct.setEL(KeyConstants._type, file.isDirectory() ? "Dir" : "File");
    sct.setEL("dateLastModified", new DateTimeImpl(pc, file.lastModified(), false));
    sct.setEL("attributes", getFileAttribute(file));
    if (SystemUtil.isUnix())
        sct.setEL(KeyConstants._mode, new ModeObjectWrap(file));
    try {
        sct.setEL(KeyConstants._checksum, Hash.md5(file));
    } catch (Throwable t) {
        ExceptionUtil.rethrowIfNecessary(t);
    }
    try {
        BufferedImage bi = ImageUtil.toBufferedImage(file, null);
        if (bi != null) {
            Struct img = new StructImpl();
            img.setEL(KeyConstants._width, new Double(bi.getWidth()));
            img.setEL(KeyConstants._height, new Double(bi.getHeight()));
            sct.setEL(KeyConstants._img, img);
        }
    } catch (Throwable t) {
        ExceptionUtil.rethrowIfNecessary(t);
    }
    return sct;
}
Also used : ModeObjectWrap(lucee.commons.io.res.util.ModeObjectWrap) StructImpl(lucee.runtime.type.StructImpl) SecurityManager(lucee.runtime.security.SecurityManager) DateTimeImpl(lucee.runtime.type.dt.DateTimeImpl) BufferedImage(java.awt.image.BufferedImage) Struct(lucee.runtime.type.Struct)

Aggregations

ModeObjectWrap (lucee.commons.io.res.util.ModeObjectWrap)2 BufferedImage (java.awt.image.BufferedImage)1 Date (java.util.Date)1 Resource (lucee.commons.io.res.Resource)1 FileResource (lucee.commons.io.res.type.file.FileResource)1 SecurityManager (lucee.runtime.security.SecurityManager)1 Struct (lucee.runtime.type.Struct)1 StructImpl (lucee.runtime.type.StructImpl)1 DateTimeImpl (lucee.runtime.type.dt.DateTimeImpl)1