Search in sources :

Example 86 with StructImpl

use of lucee.runtime.type.StructImpl in project Lucee by lucee.

the class CGIImplReadOnly method get.

@Override
public Object get(Collection.Key key, Object defaultValue) {
    if (https == null) {
        https = new StructImpl();
        headers = new StructImpl();
        String k, v;
        try {
            Enumeration e = req.getHeaderNames();
            while (e.hasMoreElements()) {
                k = (String) e.nextElement();
                v = req.getHeader(k);
                // print.err(k.length()+":"+k);
                headers.setEL(KeyImpl.init(k), v);
                headers.setEL(KeyImpl.init(k = k.replace('-', '_')), v);
                https.setEL(KeyImpl.init("http_" + k), v);
            }
        } catch (Throwable t) {
            ExceptionUtil.rethrowIfNecessary(t);
        }
    }
    String lkey = key.getLowerString();
    if (lkey.length() > 7) {
        char first = lkey.charAt(0);
        if (first == 'a') {
            if (key.equals(KeyConstants._auth_type))
                return toString(req.getAuthType());
        } else if (first == 'c') {
            if (key.equals(KeyConstants._context_path))
                return toString(req.getContextPath());
            if (key.equals(KeyConstants._cf_template_path))
                return getPathTranslated();
        } else if (first == 'h') {
            if (lkey.startsWith("http_")) {
                Object o = https.get(key, NullSupportHelper.NULL());
                if (o == NullSupportHelper.NULL() && key.equals(KeyConstants._http_if_modified_since))
                    o = https.get(KeyConstants._last_modified, NullSupportHelper.NULL());
                if (o != NullSupportHelper.NULL())
                    return doScriptProtect((String) o);
            }
        } else if (first == 'r') {
            if (key.equals(KeyConstants._remote_user))
                return toString(req.getRemoteUser());
            if (key.equals(KeyConstants._remote_addr)) {
                return toString(req.getRemoteAddr());
            }
            if (key.equals(KeyConstants._remote_host))
                return toString(req.getRemoteHost());
            if (key.equals(KeyConstants._request_method))
                return req.getMethod();
            if (key.equals(KeyConstants._request_url))
                return ReqRspUtil.getRequestURL(req, true);
            if (key.equals(KeyConstants._request_uri))
                return toString(req.getAttribute("javax.servlet.include.request_uri"));
            if (key.getUpperString().startsWith("REDIRECT_")) {
                // from attributes (key sensitive)
                Object value = req.getAttribute(key.getString());
                if (!StringUtil.isEmpty(value))
                    return toString(value);
                // from attributes (key insensitive)
                Enumeration<String> names = req.getAttributeNames();
                String k;
                while (names.hasMoreElements()) {
                    k = names.nextElement();
                    if (k.equalsIgnoreCase(key.getString())) {
                        return toString(req.getAttribute(k));
                    }
                }
            }
        } else if (first == 'l') {
            if (key.equals(KeyConstants._local_addr))
                return toString(localAddress);
            if (key.equals(KeyConstants._local_host))
                return toString(localHost);
        } else if (first == 's') {
            if (key.equals(KeyConstants._script_name))
                return ReqRspUtil.getScriptName(null, req);
            // return StringUtil.emptyIfNull(req.getContextPath())+StringUtil.emptyIfNull(req.getServletPath());
            if (key.equals(KeyConstants._server_name))
                return toString(req.getServerName());
            if (key.equals(KeyConstants._server_protocol))
                return toString(req.getProtocol());
            if (key.equals(KeyConstants._server_port))
                return Caster.toString(req.getServerPort());
            if (key.equals(KeyConstants._server_port_secure))
                return req.isSecure() ? "1" : "0";
        } else if (first == 'p') {
            if (key.equals(KeyConstants._path_info)) {
                String pathInfo = Caster.toString(req.getAttribute("javax.servlet.include.path_info"), null);
                if (StringUtil.isEmpty(pathInfo))
                    pathInfo = Caster.toString(req.getHeader("xajp-path-info"), null);
                if (StringUtil.isEmpty(pathInfo))
                    pathInfo = req.getPathInfo();
                if (StringUtil.isEmpty(pathInfo)) {
                    pathInfo = Caster.toString(req.getAttribute("requestedPath"), null);
                    if (!StringUtil.isEmpty(pathInfo, true)) {
                        String scriptName = ReqRspUtil.getScriptName(null, req);
                        if (pathInfo.startsWith(scriptName))
                            pathInfo = pathInfo.substring(scriptName.length());
                    }
                }
                if (!StringUtil.isEmpty(pathInfo, true))
                    return pathInfo;
                return "";
            }
            if (key.equals(KeyConstants._path_translated))
                return getPathTranslated();
        } else if (first == 'q') {
            if (key.equals(KeyConstants._query_string))
                return doScriptProtect(toString(ReqRspUtil.getQueryString(req)));
        }
    }
    // check header
    // req.getHeader(key.getString());
    String headerValue = (String) headers.get(key, null);
    if (headerValue != null)
        return doScriptProtect(headerValue);
    return other(key, defaultValue);
}
Also used : StructImpl(lucee.runtime.type.StructImpl) Enumeration(java.util.Enumeration)

Example 87 with StructImpl

use of lucee.runtime.type.StructImpl in project Lucee by lucee.

the class RequestImpl method duplicate.

@Override
public Collection duplicate(boolean deepCopy) {
    Struct trg = new StructImpl();
    StructImpl.copy(this, trg, deepCopy);
    return trg;
}
Also used : StructImpl(lucee.runtime.type.StructImpl) Struct(lucee.runtime.type.Struct)

Example 88 with StructImpl

use of lucee.runtime.type.StructImpl in project Lucee by lucee.

the class ScopeContext method getAllSessionScopes.

private Struct getAllSessionScopes(Map<String, Scope> context, String appName) {
    Iterator<Entry<String, Scope>> it = context.entrySet().iterator();
    Entry<String, Scope> entry;
    Struct sct = new StructImpl();
    Session s;
    while (it.hasNext()) {
        entry = it.next();
        s = (Session) entry.getValue();
        if (!s.isExpired())
            sct.setEL(KeyImpl.init(appName + "_" + entry.getKey() + "_0"), s);
    }
    return sct;
}
Also used : Entry(java.util.Map.Entry) StructImpl(lucee.runtime.type.StructImpl) StorageScope(lucee.runtime.type.scope.storage.StorageScope) MemoryScope(lucee.runtime.type.scope.storage.MemoryScope) MapAsStruct(lucee.runtime.type.wrap.MapAsStruct) Struct(lucee.runtime.type.Struct) HttpSession(javax.servlet.http.HttpSession)

Example 89 with StructImpl

use of lucee.runtime.type.StructImpl in project Lucee by lucee.

the class ScopeContext method getAllCFSessionScopes.

public Struct getAllCFSessionScopes() {
    Struct trg = new StructImpl();
    StructImpl.copy(MapAsStruct.toStruct(this.cfSessionContexts, true), trg, false);
    return trg;
}
Also used : StructImpl(lucee.runtime.type.StructImpl) MapAsStruct(lucee.runtime.type.wrap.MapAsStruct) Struct(lucee.runtime.type.Struct)

Example 90 with StructImpl

use of lucee.runtime.type.StructImpl 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)

Aggregations

StructImpl (lucee.runtime.type.StructImpl)251 Struct (lucee.runtime.type.Struct)216 PageException (lucee.runtime.exp.PageException)40 Entry (java.util.Map.Entry)34 Key (lucee.runtime.type.Collection.Key)28 Array (lucee.runtime.type.Array)25 ArrayImpl (lucee.runtime.type.ArrayImpl)24 ApplicationException (lucee.runtime.exp.ApplicationException)21 IOException (java.io.IOException)19 Map (java.util.Map)19 Resource (lucee.commons.io.res.Resource)18 Iterator (java.util.Iterator)17 PageContextImpl (lucee.runtime.PageContextImpl)14 QueryImpl (lucee.runtime.type.QueryImpl)13 Collection (lucee.runtime.type.Collection)11 Query (lucee.runtime.type.Query)11 DateTimeImpl (lucee.runtime.type.dt.DateTimeImpl)11 HashMap (java.util.HashMap)9 PageSource (lucee.runtime.PageSource)8 Element (org.w3c.dom.Element)8