use of lucee.runtime.type.dt.TimeSpan 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.TimeSpan in project Lucee by lucee.
the class TagLibTagAttr method getValues.
public Object[] getValues() {
if (valueList == null)
return null;
if (values != null)
return values;
String[] res = ListUtil.trimItems(ListUtil.listToStringArray(valueList, delimiter));
short type = CFTypes.toShort(getType(), false, CFTypes.TYPE_ANY);
// String
if (type == CFTypes.TYPE_STRING || type == CFTypes.TYPE_ANY) {
values = res;
} else // Numeric
if (type == CFTypes.TYPE_NUMERIC) {
List<Double> list = new ArrayList<Double>();
Double d;
for (int i = 0; i < res.length; i++) {
d = Caster.toDouble(res[i], null);
if (d != null)
list.add(d);
}
values = list.toArray(new Double[list.size()]);
} else // Boolean
if (type == CFTypes.TYPE_BOOLEAN) {
List<Boolean> list = new ArrayList<Boolean>();
Boolean b;
for (int i = 0; i < res.length; i++) {
b = Caster.toBoolean(res[i], null);
if (b != null)
list.add(b);
}
values = list.toArray(new Boolean[list.size()]);
} else // DateTime
if (type == CFTypes.TYPE_DATETIME) {
List<DateTime> list = new ArrayList<DateTime>();
DateTime dt;
for (int i = 0; i < res.length; i++) {
dt = Caster.toDate(res[i], true, null, null);
if (dt != null)
list.add(dt);
}
values = list.toArray(new DateTime[list.size()]);
} else // Timespan
if (type == CFTypes.TYPE_TIMESPAN) {
List<TimeSpan> list = new ArrayList<TimeSpan>();
TimeSpan ts;
for (int i = 0; i < res.length; i++) {
ts = Caster.toTimespan(res[i], null);
if (ts != null)
list.add(ts);
}
values = list.toArray(new TimeSpan[list.size()]);
} else // TODO add support for other types ?
{
valueList = null;
}
return values;
}
use of lucee.runtime.type.dt.TimeSpan in project Lucee by lucee.
the class AppListenerUtil method toMailServer.
public static Server toMailServer(Config config, Struct data, Server defaultValue) {
String hostName = Caster.toString(data.get(KeyConstants._host, null), null);
if (StringUtil.isEmpty(hostName, true))
hostName = Caster.toString(data.get(KeyConstants._server, null), null);
if (StringUtil.isEmpty(hostName, true))
return defaultValue;
int port = Caster.toIntValue(data.get(KeyConstants._port, null), 25);
String username = Caster.toString(data.get(KeyConstants._username, null), null);
if (StringUtil.isEmpty(username, true))
username = Caster.toString(data.get(KeyConstants._user, null), null);
String password = ConfigWebUtil.decrypt(Caster.toString(data.get(KeyConstants._password, null), null));
TimeSpan lifeTimespan = Caster.toTimespan(data.get("lifeTimespan", null), null);
if (lifeTimespan == null)
lifeTimespan = Caster.toTimespan(data.get("life", null), FIVE_MINUTES);
TimeSpan idleTimespan = Caster.toTimespan(data.get("idleTimespan", null), null);
if (idleTimespan == null)
idleTimespan = Caster.toTimespan(data.get("idle", null), ONE_MINUTE);
boolean tls = Caster.toBooleanValue(data.get("tls", null), false);
boolean ssl = Caster.toBooleanValue(data.get("ssl", null), false);
// MUST improve store connection somehow
return new ServerImpl(-1, hostName, port, username, password, lifeTimespan.getMillis(), idleTimespan.getMillis(), tls, ssl, false, ServerImpl.TYPE_LOCAL);
}
use of lucee.runtime.type.dt.TimeSpan in project Lucee by lucee.
the class Cache method doPut.
private void doPut() throws PageException {
required("cache", "id", id);
required("cache", "value", value);
TimeSpan ts = timespan;
TimeSpan it = idletime;
if (ts == TIMESPAN_FAR_AWAY)
ts = TIMESPAN_0;
if (it == TIMESPAN_FAR_AWAY)
it = TIMESPAN_0;
CachePut.call(pageContext, Caster.toString(id), value, ts, it, cachename);
}
use of lucee.runtime.type.dt.TimeSpan in project Lucee by lucee.
the class Loginuser method doStartTag.
@Override
public int doStartTag() throws PageException {
Resource rolesDir = pageContext.getConfig().getConfigDir().getRealResource("roles");
CredentialImpl login = new CredentialImpl(name, password, roles, rolesDir);
pageContext.setRemoteUser(login);
Tag parent = getParent();
while (parent != null && !(parent instanceof Login)) {
parent = parent.getParent();
}
ApplicationContext appContext = pageContext.getApplicationContext();
if (parent != null) {
int loginStorage = appContext.getLoginStorage();
String name = Login.getApplicationName(appContext);
if (loginStorage == Scope.SCOPE_SESSION && pageContext.getApplicationContext().isSetSessionManagement())
pageContext.sessionScope().set(KeyImpl.init(name), login.encode());
else {
ApplicationContext ac = pageContext.getApplicationContext();
TimeSpan tsExpires = AuthCookieDataImpl.DEFAULT.getTimeout();
if (ac instanceof ApplicationContextSupport) {
ApplicationContextSupport acs = (ApplicationContextSupport) ac;
AuthCookieData data = acs.getAuthCookie();
if (data != null) {
TimeSpan tmp = data.getTimeout();
if (tmp != null)
tsExpires = tmp;
}
}
int expires;
long tmp = tsExpires.getSeconds();
if (Integer.MAX_VALUE < tmp)
expires = Integer.MAX_VALUE;
else
expires = (int) tmp;
((CookieImpl) pageContext.cookieScope()).setCookie(KeyImpl.init(name), login.encode(), expires, false, "/", Login.getCookieDomain(appContext));
}
}
return SKIP_BODY;
}
Aggregations