Search in sources :

Example 1 with DateTimeImpl

use of lucee.runtime.type.dt.DateTimeImpl in project Lucee by lucee.

the class Admin method translateTime.

private Array translateTime(Array exp) {
    exp = (Array) Duplicator.duplicate(exp, true);
    Iterator<Object> it = exp.valueIterator();
    Struct sct;
    while (it.hasNext()) {
        sct = (Struct) it.next();
        sct.setEL("time", new DateTimeImpl(pageContext, Caster.toLongValue(sct.get("time", null), 0), true));
    }
    return exp;
}
Also used : DateTimeImpl(lucee.runtime.type.dt.DateTimeImpl) Struct(lucee.runtime.type.Struct)

Example 2 with DateTimeImpl

use of lucee.runtime.type.dt.DateTimeImpl in project Lucee by lucee.

the class FileTag method _actionUpload.

private static Struct _actionUpload(PageContext pageContext, lucee.runtime.security.SecurityManager securityManager, FormItem formItem, String strDestination, int nameconflict, String accept, boolean strict, int mode, String attributes, Object acl, String serverPassword) throws PageException {
    if (nameconflict == NAMECONFLICT_UNDEFINED)
        nameconflict = NAMECONFLICT_ERROR;
    boolean fileWasRenamed = false;
    boolean fileWasAppended = false;
    boolean fileExisted = false;
    boolean fileWasOverwritten = false;
    String contentType = ResourceUtil.getMimeType(formItem.getResource(), formItem.getContentType());
    // set cffile struct
    Struct cffile = new StructImpl();
    long length = formItem.getResource().length();
    cffile.set("timecreated", new DateTimeImpl(pageContext.getConfig()));
    cffile.set("timelastmodified", new DateTimeImpl(pageContext.getConfig()));
    cffile.set("datelastaccessed", new DateImpl(pageContext));
    cffile.set("oldfilesize", Long.valueOf(length));
    cffile.set("filesize", Long.valueOf(length));
    cffile.set("contenttype", ListFirst.call(pageContext, contentType, "/"));
    cffile.set("contentsubtype", ListLast.call(pageContext, contentType, "/"));
    // client file
    String strClientFile = formItem.getName();
    while (strClientFile.indexOf('\\') != -1) strClientFile = strClientFile.replace('\\', '/');
    Resource clientFile = pageContext.getConfig().getResource(strClientFile);
    String clientFileName = clientFile.getName();
    // check file type
    checkContentType(contentType, accept, getFileExtension(clientFile), strict);
    cffile.set("clientdirectory", getParent(clientFile));
    cffile.set("clientfile", clientFile.getName());
    cffile.set("clientfileext", getFileExtension(clientFile));
    cffile.set("clientfilename", getFileName(clientFile));
    // check destination
    if (StringUtil.isEmpty(strDestination))
        throw new ApplicationException("attribute destination is not defined in tag file");
    Resource destination = toDestination(pageContext, strDestination, null);
    securityManager.checkFileLocation(pageContext.getConfig(), destination, serverPassword);
    if (destination.isDirectory())
        destination = destination.getRealResource(clientFileName);
    else if (!destination.exists() && (strDestination.endsWith("/") || strDestination.endsWith("\\")))
        destination = destination.getRealResource(clientFileName);
    else if (!clientFileName.equalsIgnoreCase(destination.getName())) {
        if (ResourceUtil.getExtension(destination, null) == null)
            destination = destination.getRealResource(clientFileName);
        else
            fileWasRenamed = true;
    }
    // check parent destination -> directory of the desinatrion
    Resource parentDestination = destination.getParentResource();
    if (!parentDestination.exists()) {
        Resource pp = parentDestination.getParentResource();
        if (pp == null || !pp.exists())
            throw new ApplicationException("attribute destination has an invalid value [" + destination + "], directory [" + parentDestination + "] doesn't exist");
        try {
            parentDestination.createDirectory(true);
        } catch (IOException e) {
            throw Caster.toPageException(e);
        }
    } else if (!parentDestination.canWrite())
        throw new ApplicationException("can't write to destination directory [" + parentDestination + "], no access to write");
    // set server variables
    cffile.set("serverdirectory", getParent(destination));
    cffile.set("serverfile", destination.getName());
    cffile.set("serverfileext", getFileExtension(destination));
    cffile.set("serverfilename", getFileName(destination));
    cffile.set("attemptedserverfile", destination.getName());
    // check nameconflict
    if (destination.exists()) {
        fileExisted = true;
        if (nameconflict == NAMECONFLICT_ERROR) {
            throw new ApplicationException("destination file [" + destination + "] already exist");
        } else if (nameconflict == NAMECONFLICT_SKIP) {
            cffile.set("fileexisted", Caster.toBoolean(fileExisted));
            cffile.set("filewasappended", Boolean.FALSE);
            cffile.set("filewasoverwritten", Boolean.FALSE);
            cffile.set("filewasrenamed", Boolean.FALSE);
            cffile.set("filewassaved", Boolean.FALSE);
            return cffile;
        } else if (nameconflict == NAMECONFLICT_MAKEUNIQUE) {
            destination = makeUnique(destination);
            fileWasRenamed = true;
            // if(fileWasRenamed) {
            cffile.set("serverdirectory", getParent(destination));
            cffile.set("serverfile", destination.getName());
            cffile.set("serverfileext", getFileExtension(destination));
            cffile.set("serverfilename", getFileName(destination));
            cffile.set("attemptedserverfile", destination.getName());
        // }
        } else if (nameconflict == NAMECONFLICT_OVERWRITE) {
            // fileWasAppended=true;
            fileWasOverwritten = true;
            if (!destination.delete())
                if (// hier hatte ich concurrent problem das damit ausgeraeumt ist
                destination.exists())
                    throw new ApplicationException("can't delete destination file [" + destination + "]");
        }
    // for "overwrite" no action is neded
    }
    setACL(pageContext, destination, acl);
    try {
        destination.createNewFile();
        IOUtil.copy(formItem.getResource(), destination);
    } catch (Throwable t) {
        ExceptionUtil.rethrowIfNecessary(t);
        throw Caster.toPageException(t);
    }
    // Set cffile/file struct
    cffile.set("fileexisted", Caster.toBoolean(fileExisted));
    cffile.set("filewasappended", Caster.toBoolean(fileWasAppended));
    cffile.set("filewasoverwritten", Caster.toBoolean(fileWasOverwritten));
    cffile.set("filewasrenamed", Caster.toBoolean(fileWasRenamed));
    cffile.set("filewassaved", Boolean.TRUE);
    setMode(destination, mode);
    setAttributes(destination, attributes);
    return cffile;
}
Also used : StructImpl(lucee.runtime.type.StructImpl) ApplicationException(lucee.runtime.exp.ApplicationException) Resource(lucee.commons.io.res.Resource) DateTimeImpl(lucee.runtime.type.dt.DateTimeImpl) IOException(java.io.IOException) DateImpl(lucee.runtime.type.dt.DateImpl) Struct(lucee.runtime.type.Struct)

Example 3 with DateTimeImpl

use of lucee.runtime.type.dt.DateTimeImpl in project Lucee by lucee.

the class Ftp method toQuery.

public static lucee.runtime.type.Query toQuery(FTPFile[] files, String prefix, String directory, String hostName) throws PageException {
    String[] cols = new String[] { "name", "isdirectory", "lastmodified", "length", "mode", "path", "url", "type", "raw", "attributes" };
    String[] types = new String[] { "VARCHAR", "BOOLEAN", "DATE", "DOUBLE", "VARCHAR", "VARCHAR", "VARCHAR", "VARCHAR", "VARCHAR", "VARCHAR" };
    lucee.runtime.type.Query query = new QueryImpl(cols, types, 0, "query");
    // translate directory path for display
    if (directory.length() == 0)
        directory = "/";
    else if (directory.startsWith("./"))
        directory = directory.substring(1);
    else if (directory.charAt(0) != '/')
        directory = '/' + directory;
    if (directory.charAt(directory.length() - 1) != '/')
        directory = directory + '/';
    int row;
    for (int i = 0; i < files.length; i++) {
        FTPFile file = files[i];
        if (file.getName().equals(".") || file.getName().equals(".."))
            continue;
        row = query.addRow();
        query.setAt("attributes", row, "");
        query.setAt("isdirectory", row, Caster.toBoolean(file.isDirectory()));
        query.setAt("lastmodified", row, new DateTimeImpl(file.getTimestamp()));
        query.setAt("length", row, Caster.toDouble(file.getSize()));
        query.setAt("mode", row, FTPConstant.getPermissionASInteger(file));
        query.setAt("type", row, FTPConstant.getTypeAsString(file.getType()));
        // query.setAt("permission",row,FTPConstant.getPermissionASInteger(file));
        query.setAt("raw", row, file.getRawListing());
        query.setAt("name", row, file.getName());
        query.setAt("path", row, directory + file.getName());
        query.setAt("url", row, prefix + "://" + hostName + "" + directory + file.getName());
    }
    return query;
}
Also used : QueryImpl(lucee.runtime.type.QueryImpl) DateTimeImpl(lucee.runtime.type.dt.DateTimeImpl) FTPFile(org.apache.commons.net.ftp.FTPFile)

Example 4 with DateTimeImpl

use of lucee.runtime.type.dt.DateTimeImpl in project Lucee by lucee.

the class Trace method _doEndTag.

public void _doEndTag() throws IOException, PageException {
    PageSource ps = pageContext.getCurrentTemplatePageSource();
    // var
    String varValue = null;
    Object value = null, traceValue = null;
    if (!StringUtil.isEmpty(var)) {
        try {
            if (caller instanceof Scope)
                value = VariableInterpreter.getVariable(pageContext, var, (Scope) caller);
            else
                value = pageContext.getVariable(var);
        } catch (PageException e) {
            varValue = "(undefined)";
            follow = false;
        }
        if (follow) {
            // print.o(1);
            if (StringUtil.isEmpty(text, true))
                text = var;
            // print.o(2);
            traceValue = TraceObjectSupport.toTraceObject(pageContext.getDebugger(), value, type, category, text);
            if (caller instanceof Scope)
                VariableInterpreter.setVariable(pageContext, var, traceValue, (Scope) caller);
            else
                pageContext.setVariable(var, traceValue);
        }
        try {
            varValue = new ScriptConverter().serialize(value);
        } catch (ConverterException e) {
            if (value != null)
                varValue = "(" + Caster.toTypeName(value) + ")";
        }
    }
    DebugTrace trace = ((DebuggerImpl) pageContext.getDebugger()).addTrace(type, category, text, ps, var, varValue);
    DebugTrace[] traces = pageContext.getDebugger().getTraces(pageContext);
    String total = "(1st trace)";
    if (traces.length > 1) {
        long t = 0;
        for (int i = 0; i < traces.length; i++) {
            t += traces[i].getTime();
        }
        total = "(" + t + ")";
    }
    boolean hasCat = !StringUtil.isEmpty(trace.getCategory());
    boolean hasText = !StringUtil.isEmpty(trace.getText());
    boolean hasVar = !StringUtil.isEmpty(var);
    // inline
    if (inline) {
        lucee.runtime.format.TimeFormat tf = new lucee.runtime.format.TimeFormat(pageContext.getConfig().getLocale());
        StringBuffer sb = new StringBuffer();
        sb.append("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" bgcolor=\"white\">");
        sb.append("<tr>");
        // sb.append("<td><img src=\"/CFIDE/debug/images/Error_16x16.gif\" alt=\"Error type\">");
        sb.append("<td>");
        sb.append("<font color=\"orange\">");
        sb.append("<b>");
        sb.append(DebugTraceImpl.toType(trace.getType(), "INFO") + " - ");
        sb.append("[CFTRACE " + tf.format(new DateTimeImpl(pageContext.getConfig()), "hh:mm:ss:l") + "]");
        sb.append("[" + trace.getTime() + " ms " + total + "]");
        sb.append("[" + trace.getTemplate() + " @ line: " + trace.getLine() + "]");
        if (hasCat || hasText)
            sb.append(" -");
        if (hasCat)
            sb.append("  [" + trace.getCategory() + "]");
        if (hasText)
            sb.append(" <i>" + trace.getText() + "&nbsp;</i>");
        sb.append("</b>");
        sb.append("</font>");
        sb.append("</td>");
        sb.append("</tr>");
        sb.append("</table>");
        pageContext.forceWrite(sb.toString());
        if (hasVar)
            Dump.call(pageContext, value, var);
    }
    // log
    Log log = ((ConfigImpl) pageContext.getConfig()).getLog("trace");
    StringBuffer msg = new StringBuffer();
    msg.append("[" + trace.getTime() + " ms " + total + "] ");
    msg.append("[" + trace.getTemplate() + " @ line: " + trace.getLine() + "]");
    if (hasCat || hasText || hasVar)
        msg.append("- ");
    if (hasCat)
        msg.append("[" + trace.getCategory() + "] ");
    if (hasVar)
        msg.append("[" + var + "=" + varValue + "] ");
    if (hasText)
        msg.append(" " + trace.getText() + " ");
    log.log(trace.getType(), "cftrace", msg.toString());
    // abort
    if (abort)
        throw new Abort(Abort.SCOPE_REQUEST);
}
Also used : PageException(lucee.runtime.exp.PageException) ConverterException(lucee.runtime.converter.ConverterException) Log(lucee.commons.io.log.Log) DebuggerImpl(lucee.runtime.debug.DebuggerImpl) PageSource(lucee.runtime.PageSource) Abort(lucee.runtime.exp.Abort) Scope(lucee.runtime.type.scope.Scope) DebugTrace(lucee.runtime.debug.DebugTrace) ScriptConverter(lucee.runtime.converter.ScriptConverter) DateTimeImpl(lucee.runtime.type.dt.DateTimeImpl) ConfigImpl(lucee.runtime.config.ConfigImpl)

Example 5 with DateTimeImpl

use of lucee.runtime.type.dt.DateTimeImpl in project Lucee by lucee.

the class Zip method actionList.

private void actionList() throws PageException, IOException {
    required("file", file, true);
    required("name", name);
    lucee.runtime.type.Query query = new QueryImpl(new String[] { "name", "size", "type", "dateLastModified", "directory", "crc", "compressedSize", "comment" }, 0, "query");
    pageContext.setVariable(name, query);
    ZipFile zip = getZip(file);
    Enumeration entries = zip.entries();
    try {
        String path, name, dir;
        ZipEntry ze;
        int row = 0, index;
        while (entries.hasMoreElements()) {
            ze = (ZipEntry) entries.nextElement();
            if (!showDirectory && ze.isDirectory())
                continue;
            path = ze.getName().replace('\\', '/');
            index = path.lastIndexOf('/');
            if (!recurse && index > 0)
                continue;
            dir = index == -1 ? "" : path.substring(0, index);
            name = path.substring(index + 1);
            if (filter != null && !filter.accept(file.getRealResource(name)))
                continue;
            if (!entryPathMatch(dir))
                continue;
            // if(entryPath!=null && !(dir.equalsIgnoreCase(entryPath) || StringUtil.startsWithIgnoreCase(dir,entryPath+"/"))) ;///continue;
            row++;
            query.addRow();
            query.setAt("name", row, path);
            query.setAt("size", row, Caster.toDouble(ze.getSize()));
            query.setAt("type", row, ze.isDirectory() ? "Directory" : "File");
            query.setAt("dateLastModified", row, new DateTimeImpl(pageContext, ze.getTime(), false));
            query.setAt("crc", row, Caster.toDouble(ze.getCrc()));
            query.setAt("compressedSize", row, Caster.toDouble(ze.getCompressedSize()));
            query.setAt("comment", row, ze.getComment());
            query.setAt("directory", row, dir);
        // zis.closeEntry();
        }
    } finally {
        IOUtil.closeEL(zip);
    }
}
Also used : QueryImpl(lucee.runtime.type.QueryImpl) Enumeration(java.util.Enumeration) ZipFile(java.util.zip.ZipFile) ZipEntry(java.util.zip.ZipEntry) DateTimeImpl(lucee.runtime.type.dt.DateTimeImpl)

Aggregations

DateTimeImpl (lucee.runtime.type.dt.DateTimeImpl)41 Struct (lucee.runtime.type.Struct)12 StructImpl (lucee.runtime.type.StructImpl)11 Date (java.util.Date)7 PageException (lucee.runtime.exp.PageException)6 Calendar (java.util.Calendar)5 Resource (lucee.commons.io.res.Resource)5 Collection (lucee.runtime.type.Collection)5 QueryImpl (lucee.runtime.type.QueryImpl)5 IOException (java.io.IOException)4 ConfigWebImpl (lucee.runtime.config.ConfigWebImpl)4 TimeZone (java.util.TimeZone)3 PageContextImpl (lucee.runtime.PageContextImpl)3 ExpressionException (lucee.runtime.exp.ExpressionException)3 Array (lucee.runtime.type.Array)3 ArrayImpl (lucee.runtime.type.ArrayImpl)3 DateTime (lucee.runtime.type.dt.DateTime)3 File (java.io.File)2 Method (java.lang.reflect.Method)2 DateFormat (java.text.DateFormat)2