Search in sources :

Example 11 with TimeSpan

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

the class Query method setTimeout.

/**
 * set the value timeout The maximum number of milliseconds for the query to execute before returning an error indicating that the query has timed-out. This
 * attribute is not supported by most ODBC drivers. timeout is supported by the SQL Server 6.x or above driver. The minimum and maximum allowable values
 * vary, depending on the driver.
 *
 * @param timeout
 *            value to set
 * @throws PageException
 */
public void setTimeout(Object timeout) throws PageException {
    if (timeout instanceof TimeSpan)
        this.timeout = (TimeSpan) timeout;
    else // seconds
    {
        int i = Caster.toIntValue(timeout);
        if (i < 0)
            throw new ApplicationException("invalid value [" + i + "] for attribute timeout, value must be a positive integer greater or equal than 0");
        this.timeout = new TimeSpanImpl(0, 0, 0, i);
    }
}
Also used : TimeSpan(lucee.runtime.type.dt.TimeSpan) ApplicationException(lucee.runtime.exp.ApplicationException) TimeSpanImpl(lucee.runtime.type.dt.TimeSpanImpl)

Example 12 with TimeSpan

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

the class Admin method doGetScope.

/**
 * @throws PageException
 */
private void doGetScope() throws PageException {
    String sessionType = AppListenerUtil.toSessionType(config.getSessionType(), "application");
    String localMode = AppListenerUtil.toLocalMode(config.getLocalMode(), "classic");
    Struct sct = new StructImpl();
    pageContext.setVariable(getString("admin", action, "returnVariable"), sct);
    sct.set("allowImplicidQueryCall", Caster.toBoolean(config.allowImplicidQueryCall()));
    sct.set("mergeFormAndUrl", Caster.toBoolean(config.mergeFormAndURL()));
    sct.set("sessiontype", sessionType);
    sct.set("localmode", localMode);
    sct.set("sessionManagement", Caster.toBoolean(config.isSessionManagement()));
    sct.set("clientManagement", Caster.toBoolean(config.isClientManagement()));
    sct.set("domainCookies", Caster.toBoolean(config.isDomainCookies()));
    sct.set("clientCookies", Caster.toBoolean(config.isClientCookies()));
    sct.set("clientStorage", config.getClientStorage());
    sct.set("sessionStorage", config.getSessionStorage());
    sct.set("cgiReadonly", config.getCGIScopeReadonly());
    TimeSpan ts = config.getSessionTimeout();
    sct.set("sessionTimeout", ts);
    sct.set("sessionTimeout_day", Caster.toInteger(ts.getDay()));
    sct.set("sessionTimeout_hour", Caster.toInteger(ts.getHour()));
    sct.set("sessionTimeout_minute", Caster.toInteger(ts.getMinute()));
    sct.set("sessionTimeout_second", Caster.toInteger(ts.getSecond()));
    ts = config.getApplicationTimeout();
    sct.set("applicationTimeout", ts);
    sct.set("applicationTimeout_day", Caster.toInteger(ts.getDay()));
    sct.set("applicationTimeout_hour", Caster.toInteger(ts.getHour()));
    sct.set("applicationTimeout_minute", Caster.toInteger(ts.getMinute()));
    sct.set("applicationTimeout_second", Caster.toInteger(ts.getSecond()));
    ts = config.getClientTimeout();
    sct.set("clientTimeout", ts);
    sct.set("clientTimeout_day", Caster.toInteger(ts.getDay()));
    sct.set("clientTimeout_hour", Caster.toInteger(ts.getHour()));
    sct.set("clientTimeout_minute", Caster.toInteger(ts.getMinute()));
    sct.set("clientTimeout_second", Caster.toInteger(ts.getSecond()));
    // scope cascading type
    if (config.getScopeCascadingType() == Config.SCOPE_STRICT)
        sct.set("scopeCascadingType", "strict");
    else if (config.getScopeCascadingType() == Config.SCOPE_SMALL)
        sct.set("scopeCascadingType", "small");
    else if (config.getScopeCascadingType() == Config.SCOPE_STANDARD)
        sct.set("scopeCascadingType", "standard");
}
Also used : TimeSpan(lucee.runtime.type.dt.TimeSpan) StructImpl(lucee.runtime.type.StructImpl) Struct(lucee.runtime.type.Struct)

Example 13 with TimeSpan

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

the class PageContextImpl method setClientCookies.

private void setClientCookies() {
    TimeSpan tsExpires = SessionCookieDataImpl.DEFAULT.getTimeout();
    String domain = PageContextUtil.getCookieDomain(this);
    boolean httpOnly = SessionCookieDataImpl.DEFAULT.isHttpOnly();
    boolean secure = SessionCookieDataImpl.DEFAULT.isSecure();
    ApplicationContext ac = getApplicationContext();
    if (ac instanceof ApplicationContextSupport) {
        ApplicationContextSupport acs = (ApplicationContextSupport) ac;
        SessionCookieData data = acs.getSessionCookie();
        if (data != null) {
            // expires
            TimeSpan ts = data.getTimeout();
            if (ts != null)
                tsExpires = ts;
            // httpOnly
            httpOnly = data.isHttpOnly();
            // secure
            secure = data.isSecure();
            // domain
            String tmp = data.getDomain();
            if (!StringUtil.isEmpty(tmp, true))
                domain = tmp.trim();
        }
    }
    int expires;
    long tmp = tsExpires.getSeconds();
    if (Integer.MAX_VALUE < tmp)
        expires = Integer.MAX_VALUE;
    else
        expires = (int) tmp;
    cookieScope().setCookieEL(KeyConstants._cfid, cfid, expires, secure, "/", domain, httpOnly, true, false);
    cookieScope().setCookieEL(KeyConstants._cftoken, cftoken, expires, secure, "/", domain, httpOnly, true, false);
}
Also used : TimeSpan(lucee.runtime.type.dt.TimeSpan) ApplicationContextSupport(lucee.runtime.listener.ApplicationContextSupport) ClassicApplicationContext(lucee.runtime.listener.ClassicApplicationContext) ApplicationContext(lucee.runtime.listener.ApplicationContext) SessionCookieData(lucee.runtime.listener.SessionCookieData)

Example 14 with TimeSpan

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

the class JSONConverter method _serialize.

/**
 * serialize a Object to his xml Format represenation
 * @param object Object to serialize
 * @param sb StringBuilder to write data
 * @param serializeQueryByColumns
 * @param done
 * @throws ConverterException
 */
private void _serialize(PageContext pc, Set test, Object object, StringBuilder sb, boolean serializeQueryByColumns, Set done) throws ConverterException {
    // NULL
    if (object == null || object == NULL) {
        sb.append(goIn());
        sb.append("null");
        return;
    }
    // String
    if (object instanceof String || object instanceof StringBuilder) {
        sb.append(goIn());
        sb.append(StringUtil.escapeJS(object.toString(), '"', charsetEncoder));
        return;
    }
    // Character
    if (object instanceof Character) {
        sb.append(goIn());
        sb.append(StringUtil.escapeJS(String.valueOf(((Character) object).charValue()), '"', charsetEncoder));
        return;
    }
    // Number
    if (object instanceof Number) {
        sb.append(goIn());
        sb.append(Caster.toString(((Number) object)));
        return;
    }
    // Boolean
    if (object instanceof Boolean) {
        sb.append(goIn());
        sb.append(Caster.toString(((Boolean) object).booleanValue()));
        return;
    }
    // DateTime
    if (object instanceof DateTime) {
        _serializeDateTime((DateTime) object, sb);
        return;
    }
    // Date
    if (object instanceof Date) {
        _serializeDate((Date) object, sb);
        return;
    }
    // XML
    if (object instanceof Node) {
        _serializeXML((Node) object, sb);
        return;
    }
    // Timespan
    if (object instanceof TimeSpan) {
        _serializeTimeSpan((TimeSpan) object, sb);
        return;
    }
    // File
    if (object instanceof File) {
        _serialize(pc, test, ((File) object).getAbsolutePath(), sb, serializeQueryByColumns, done);
        return;
    }
    // String Converter
    if (object instanceof ScriptConvertable) {
        sb.append(((ScriptConvertable) object).serialize());
        return;
    }
    // byte[]
    if (object instanceof byte[]) {
        sb.append("\"" + Base64Coder.encode((byte[]) object) + "\"");
        return;
    }
    Object raw = LazyConverter.toRaw(object);
    if (done.contains(raw)) {
        sb.append(goIn());
        sb.append("null");
        return;
    }
    done.add(raw);
    try {
        // Component
        if (object instanceof Component) {
            _serializeComponent(pc, test, (Component) object, sb, serializeQueryByColumns, done);
            return;
        }
        // UDF
        if (object instanceof UDF) {
            _serializeUDF(pc, test, (UDF) object, sb, serializeQueryByColumns, done);
            return;
        }
        // Struct
        if (object instanceof Struct) {
            _serializeStruct(pc, test, (Struct) object, sb, serializeQueryByColumns, true, done);
            return;
        }
        // Map
        if (object instanceof Map) {
            _serializeMap(pc, test, (Map) object, sb, serializeQueryByColumns, done);
            return;
        }
        // Array
        if (object instanceof Array) {
            _serializeArray(pc, test, (Array) object, sb, serializeQueryByColumns, done);
            return;
        }
        // List
        if (object instanceof List) {
            _serializeList(pc, test, (List) object, sb, serializeQueryByColumns, done);
            return;
        }
        // Query
        if (object instanceof Query) {
            _serializeQuery(pc, test, (Query) object, sb, serializeQueryByColumns, done);
            return;
        }
        // Native Array
        if (Decision.isNativeArray(object)) {
            if (object instanceof char[])
                _serialize(pc, test, new String((char[]) object), sb, serializeQueryByColumns, done);
            else {
                _serializeArray(pc, test, ArrayUtil.toReferenceType(object, ArrayUtil.OBJECT_EMPTY), sb, serializeQueryByColumns, done);
            }
            return;
        }
        // ObjectWrap
        if (object instanceof ObjectWrap) {
            try {
                _serialize(pc, test, ((ObjectWrap) object).getEmbededObject(), sb, serializeQueryByColumns, done);
            } catch (PageException e) {
                if (object instanceof JavaObject) {
                    _serializeClass(pc, test, ((JavaObject) object).getClazz(), null, sb, serializeQueryByColumns, done);
                } else
                    throw new ConverterException("can't serialize Object of type [ " + Caster.toClassName(object) + " ]");
            }
            return;
        }
        _serializeClass(pc, test, object.getClass(), object, sb, serializeQueryByColumns, done);
    } finally {
        done.remove(raw);
    }
}
Also used : PageException(lucee.runtime.exp.PageException) ObjectWrap(lucee.runtime.type.ObjectWrap) Query(lucee.runtime.type.Query) Node(org.w3c.dom.Node) DateTime(lucee.runtime.type.dt.DateTime) Date(java.util.Date) Struct(lucee.runtime.type.Struct) TimeSpan(lucee.runtime.type.dt.TimeSpan) Array(lucee.runtime.type.Array) JavaObject(lucee.runtime.java.JavaObject) UDF(lucee.runtime.type.UDF) JavaObject(lucee.runtime.java.JavaObject) List(java.util.List) Component(lucee.runtime.Component) File(java.io.File) Map(java.util.Map)

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