Search in sources :

Example 16 with DateTimeImpl

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

the class StorageScopeCookie method _loadData.

protected static Struct _loadData(PageContext pc, String cookieName, int type, String strType, Log log) {
    String data = (String) pc.cookieScope().get(cookieName, null);
    if (data != null) {
        try {
            Struct sct = (Struct) evaluator.interpret(pc, data);
            long l;
            String str;
            // last visit
            str = (String) pc.cookieScope().get(cookieName + "_LV", null);
            if (!StringUtil.isEmpty(str)) {
                l = Caster.toLongValue(str, 0);
                if (l > 0)
                    sct.setEL(LASTVISIT, new DateTimeImpl(pc, l, true));
            }
            if (type == SCOPE_CLIENT) {
                // hit count
                str = (String) pc.cookieScope().get(cookieName + "_HC", null);
                if (!StringUtil.isEmpty(str))
                    sct.setEL(HITCOUNT, Caster.toDouble(str, null));
                // time created
                str = (String) pc.cookieScope().get(cookieName + "_TC", null);
                if (!StringUtil.isEmpty(str)) {
                    l = Caster.toLongValue(str, 0);
                    if (l > 0)
                        sct.setEL(TIMECREATED, new DateTimeImpl(pc, l, true));
                }
            }
            ScopeContext.info(log, "load data from cookie for " + strType + " scope for " + pc.getApplicationContext().getName() + "/" + pc.getCFID());
            return sct;
        } catch (Exception e) {
        }
    }
    ScopeContext.info(log, "create new " + strType + " scope for " + pc.getApplicationContext().getName() + "/" + pc.getCFID());
    return new StructImpl();
}
Also used : StructImpl(lucee.runtime.type.StructImpl) DateTimeImpl(lucee.runtime.type.dt.DateTimeImpl) Struct(lucee.runtime.type.Struct)

Example 17 with DateTimeImpl

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

the class StorageScopeCookie method touchAfterRequest.

@Override
public void touchAfterRequest(PageContext pc) {
    boolean _isInit = isinit;
    super.touchAfterRequest(pc);
    if (!_isInit)
        return;
    ApplicationContext ac = pc.getApplicationContext();
    TimeSpan timespan = (getType() == SCOPE_CLIENT) ? ac.getClientTimeout() : ac.getSessionTimeout();
    Cookie cookie = pc.cookieScope();
    Date exp = new DateTimeImpl(pc, System.currentTimeMillis() + timespan.getMillis(), true);
    try {
        String ser = serializer.serializeStruct(sct, ignoreSet);
        if (hasChanges()) {
            cookie.setCookie(KeyImpl.init(cookieName), ser, exp, false, "/", null);
        }
        cookie.setCookie(KeyImpl.init(cookieName + "_LV"), Caster.toString(_lastvisit.getTime()), exp, false, "/", null);
        if (getType() == SCOPE_CLIENT) {
            cookie.setCookie(KeyImpl.init(cookieName + "_TC"), Caster.toString(timecreated.getTime()), exp, false, "/", null);
            cookie.setCookie(KeyImpl.init(cookieName + "_HC"), Caster.toString(sct.get(HITCOUNT, "")), exp, false, "/", null);
        }
    } catch (Throwable t) {
        ExceptionUtil.rethrowIfNecessary(t);
    }
}
Also used : TimeSpan(lucee.runtime.type.dt.TimeSpan) Cookie(lucee.runtime.type.scope.Cookie) ApplicationContext(lucee.runtime.listener.ApplicationContext) DateTimeImpl(lucee.runtime.type.dt.DateTimeImpl) Date(java.util.Date)

Example 18 with DateTimeImpl

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

the class StorageScopeImpl method resetEnv.

public void resetEnv(PageContext pc) {
    _lastvisit = new DateTimeImpl(pc.getConfig());
    timecreated = new DateTimeImpl(pc.getConfig());
    touchBeforeRequest(pc);
}
Also used : DateTimeImpl(lucee.runtime.type.dt.DateTimeImpl)

Example 19 with DateTimeImpl

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

the class FileStorageScopeCleaner method _clean.

@Override
protected void _clean() {
    ConfigWebImpl cwi = (ConfigWebImpl) engine.getFactory().getConfig();
    Resource dir = type == Scope.SCOPE_CLIENT ? cwi.getClientScopeDir() : cwi.getSessionScopeDir();
    // for old files only the defintion from admin can be used
    long timeout = type == Scope.SCOPE_CLIENT ? cwi.getClientTimeout().getMillis() : cwi.getSessionTimeout().getMillis();
    long time = new DateTimeImpl(cwi).getTime() - timeout;
    try {
        // delete files that has expired
        AndResourceFilter andFilter = new AndResourceFilter(new ResourceFilter[] { EXT_FILTER, new ExpiresFilter(time, true) });
        String appName, cfid2, cfid;
        Resource[] apps = dir.listResources(DIR_FILTER), cfidDir, files;
        if (apps != null)
            for (int a = 0; a < apps.length; a++) {
                appName = StorageScopeImpl.decode(apps[a].getName());
                cfidDir = apps[a].listResources(DIR_FILTER);
                if (cfidDir != null)
                    for (int b = 0; b < cfidDir.length; b++) {
                        cfid2 = cfidDir[b].getName();
                        files = cfidDir[b].listResources(andFilter);
                        if (files != null) {
                            for (int c = 0; c < files.length; c++) {
                                cfid = files[c].getName();
                                cfid = cfid2 + cfid.substring(0, cfid.length() - 5);
                                if (listener != null)
                                    listener.doEnd(engine, this, appName, cfid);
                                // info("remove from memory "+appName+"/"+cfid);
                                engine.remove(type, appName, cfid);
                                info("remove file " + files[c]);
                                files[c].delete();
                            }
                        }
                    }
            }
        ResourceUtil.deleteEmptyFolders(dir);
    } catch (Throwable t) {
        ExceptionUtil.rethrowIfNecessary(t);
        error(t);
    }
// long maxSize = type==Scope.SCOPE_CLIENT?cwi.getClientScopeDirSize():cwi.getSessionScopeDirSize();
// checkSize(config,dir,maxSize,extfilter);
}
Also used : ConfigWebImpl(lucee.runtime.config.ConfigWebImpl) AndResourceFilter(lucee.commons.io.res.filter.AndResourceFilter) Resource(lucee.commons.io.res.Resource) DateTimeImpl(lucee.runtime.type.dt.DateTimeImpl)

Example 20 with DateTimeImpl

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

the class LSParseDateTime method _call.

private static lucee.runtime.type.dt.DateTime _call(PageContext pc, Object oDate, Locale locale, TimeZone tz, String format) throws PageException {
    if (oDate instanceof Date)
        return Caster.toDate(oDate, tz);
    String strDate = Caster.toString(oDate);
    // regular parse date time
    if (StringUtil.isEmpty(format, true))
        return DateCaster.toDateTime(locale, strDate, tz, locale.equals(Locale.US));
    // with java based format
    tz = ThreadLocalPageContext.getTimeZone(tz);
    if (locale == null)
        locale = pc.getLocale();
    SimpleDateFormat df = new SimpleDateFormat(format, locale);
    df.setTimeZone(tz);
    try {
        return new DateTimeImpl(df.parse(strDate));
    } catch (ParseException e) {
        throw Caster.toPageException(e);
    }
}
Also used : DateTimeImpl(lucee.runtime.type.dt.DateTimeImpl) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

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