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();
}
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);
}
}
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);
}
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);
}
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);
}
}
Aggregations