Search in sources :

Example 6 with TimeSpan

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);
    }
}
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 7 with TimeSpan

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;
}
Also used : ArrayList(java.util.ArrayList) DateTime(lucee.runtime.type.dt.DateTime) TimeSpan(lucee.runtime.type.dt.TimeSpan) ArrayList(java.util.ArrayList) List(java.util.List)

Example 8 with TimeSpan

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);
}
Also used : TimeSpan(lucee.runtime.type.dt.TimeSpan) ServerImpl(lucee.runtime.net.mail.ServerImpl)

Example 9 with TimeSpan

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);
}
Also used : TimeSpan(lucee.runtime.type.dt.TimeSpan)

Example 10 with TimeSpan

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;
}
Also used : TimeSpan(lucee.runtime.type.dt.TimeSpan) ApplicationContextSupport(lucee.runtime.listener.ApplicationContextSupport) ApplicationContext(lucee.runtime.listener.ApplicationContext) CredentialImpl(lucee.runtime.security.CredentialImpl) CookieImpl(lucee.runtime.type.scope.CookieImpl) Resource(lucee.commons.io.res.Resource) Tag(javax.servlet.jsp.tagext.Tag) AuthCookieData(lucee.runtime.listener.AuthCookieData)

Aggregations

TimeSpan (lucee.runtime.type.dt.TimeSpan)14 ApplicationException (lucee.runtime.exp.ApplicationException)4 Date (java.util.Date)3 ApplicationContext (lucee.runtime.listener.ApplicationContext)3 Struct (lucee.runtime.type.Struct)3 List (java.util.List)2 Resource (lucee.commons.io.res.Resource)2 PageContextImpl (lucee.runtime.PageContextImpl)2 PageException (lucee.runtime.exp.PageException)2 ApplicationContextSupport (lucee.runtime.listener.ApplicationContextSupport)2 StructImpl (lucee.runtime.type.StructImpl)2 DateTime (lucee.runtime.type.dt.DateTime)2 TimeSpanImpl (lucee.runtime.type.dt.TimeSpanImpl)2 File (java.io.File)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 MalformedURLException (java.net.MalformedURLException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1