return cf session scope

@param pc PageContext
@param isNew
@return cf session matching the context
@throws PageException
19303
private Session getCFSessionScope(PageContext pc, RefBoolean isNew) throws PageException {

	ApplicationContext appContext = pc.getApplicationContext();
	// get Context
	Map<String, Scope> context = getSubMap(cfSessionContexts, appContext.getName());

	// get Session
	boolean isMemory = false;
	String storage = appContext.getSessionstorage();
	if (StringUtil.isEmpty(storage, true)) {
	    storage = ConfigImpl.DEFAULT_STORAGE_SESSION;
	    isMemory = true;
	}
	else if ("ram".equalsIgnoreCase(storage)) {
	    storage = "memory";
	    isMemory = true;
	}
	else if ("registry".equalsIgnoreCase(storage)) {
	    storage = "file";
	}
	else {
	    storage = storage.toLowerCase();
	    if ("memory".equals(storage)) isMemory = true;
	}

	Session existing = (Session) context.get(pc.getCFID());
	if (existing != null && (existing.isExpired() || !(existing instanceof StorageScope))) existing = null; // second should not happen

	Session session = appContext.getSessionCluster() ? null : existing;

	if (session == null || !(session instanceof StorageScope) || !((StorageScope) session).getStorage().equalsIgnoreCase(storage)) {
	    // not necessary to check session in the same way, because it is overwritten anyway
	    if (isMemory) {
		if (existing != null) session = existing;
		else session = SessionMemory.getInstance(pc, isNew, getLog());
	    }
	    else if ("file".equals(storage)) {
		session = SessionFile.getInstance(appContext.getName(), pc, getLog());
	    }
	    else if ("cookie".equals(storage)) session = SessionCookie.getInstance(appContext.getName(), pc, getLog());
	    else {
		DataSource ds = pc.getDataSource(storage, null);
		if (ds != null && ds.isStorage()) {
		    if (INVIDUAL_STORAGE_KEYS) {
			try {
			    session = (Session) IKStorageScopeSupport.getInstance(Scope.SCOPE_SESSION, new IKHandlerDatasource(), appContext.getName(), storage, pc, existing,
				    getLog());
			}
			catch (PageException pe) {
			    session = SessionDatasource.getInstance(storage, pc, getLog(), null);
			}
		    }
		    else session = SessionDatasource.getInstance(storage, pc, getLog(), null);
		}
		else {
		    if (INVIDUAL_STORAGE_KEYS) {
			try {
			    session = (Session) IKStorageScopeSupport.getInstance(Scope.SCOPE_SESSION, new IKHandlerCache(), appContext.getName(), storage, pc, existing, getLog());
			}
			catch (PageException pe) {
			    session = SessionCache.getInstance(storage, appContext.getName(), pc, existing, getLog(), null);
			}
		    }
		    else session = SessionCache.getInstance(storage, appContext.getName(), pc, existing, getLog(), null);
		}

		if (session == null) {
		    // datasource not enabled for storage
		    if (ds != null) {
			if (!ds.isStorage()) throw new ApplicationException("datasource [" + storage + "] is not enabled to be used as session storage, "
				+ "you have to enable it in the Lucee administrator or define key \"storage=true\" for datasources defined in the application event handler.");
			throw new ApplicationException("datasource [" + storage
				+ "] could not be reached for session storage. Please make sure the datasource settings are correct, and the datasource is available.");
		    }
		    CacheConnection cc = CacheUtil.getCacheConnection(pc, storage, null);
		    if (cc != null) throw new ApplicationException(
			    "cache [" + storage + "] is not enabled to be used  as a session/client storage, you have to enable it in the Lucee administrator.");

		    throw new ApplicationException("there is no cache or datasource with name [" + storage + "] defined.");
		}
	    }
	    if (session instanceof StorageScope) ((StorageScope) session).setStorage(storage);
	    context.put(pc.getCFID(), session);
	    isNew.setValue(true);
	}
	else {
	    getLog().log(Log.LEVEL_INFO, "scope-context", "use existing session scope for " + appContext.getName() + "/" + pc.getCFID() + " from storage " + storage);
	}
	session.touchBeforeRequest(pc);
	return session;
    }
648810
public static Session getInstance(String name, PageContext pc, Log log) {
	if (!StringUtil.isEmpty(name)) name = StringUtil.toUpperCase(StringUtil.toVariableName(name));
	String cookieName = "CF_" + TYPE + "_" + name;
	return new SessionCookie(pc, cookieName, _loadData(pc, cookieName, SCOPE_SESSION, "session", log));
    }
1132022
private void doGetMapping() throws PageException {

	Mapping[] mappings = config.getMappings();
	Struct sct = new StructImpl();
	String virtual = getString("admin", action, "virtual");

	for (int i = 0; i < mappings.length; i++) {
	    MappingImpl m = (MappingImpl) mappings[i];
	    if (!m.getVirtual().equals(virtual)) continue;

	    sct.set("archive", m.getArchive());
	    sct.set("strarchive", m.getStrArchive());
	    sct.set("physical", m.getPhysical());
	    sct.set("strphysical", m.getStrPhysical());
	    sct.set("virtual", m.getVirtual());
	    sct.set(KeyConstants._hidden, Caster.toBoolean(m.isHidden()));
	    sct.set("physicalFirst", Caster.toBoolean(m.isPhysicalFirst()));
	    sct.set("readonly", Caster.toBoolean(m.isReadonly()));
	    sct.set("inspect", ConfigWebUtil.inspectTemplate(m.getInspectTemplateRaw(), ""));
	    sct.set("toplevel", Caster.toBoolean(m.isTopLevel()));

	    pageContext.setVariable(getString("admin", action, "returnVariable"), sct);
	    return;
	}
	throw new ApplicationException("there is no mapping with virtual [" + virtual + "]");
    }
1279750
public static Object invokeBIF(PageContext pc, Object[] args, String className, String bundleName, String bundleVersion) throws PageException {
	try {
	    Class<?> clazz = ClassUtil.loadClassByBundle(className, bundleName, bundleVersion, pc.getConfig().getIdentification());
	    BIF bif;
	    if (Reflector.isInstaneOf(clazz, BIF.class)) bif = (BIF) clazz.newInstance();
	    else bif = new BIFProxy(clazz);

	    return bif.invoke(pc, args);

	}
	catch (Exception e) {
	    throw Caster.toPageException(e);
	}
    }
456497
public static Object[] getValue(PageContext pc, Ref[] refs) throws PageException {
	Object[] objs = new Object[refs.length];
	for (int i = 0; i < refs.length; i++) {
	    objs[i] = refs[i].getValue(pc);
	}
	return objs;
    }
454069
public static double call(PageContext pc, String strFilter) throws PageException {
	return _call(pc, strFilter, null);
    }
859252
protected PageContext getPageContext()
    {
        JspContext ctxt = getJspContext();
        if (ctxt instanceof PageContext)
            return (PageContext) ctxt;

        // assert the page context and log an error in production
        assert(false) : "The JspContext was not a PageContext";
        logger.error("The JspContext was not a PageContext");
        return null;
    }
1308108
public static Object getVariableEL(PageContext pc, String var, Object defaultValue) {
	StringList list = parse(pc, new ParserString(var), false);
	if (list == null) return defaultValue;

	int scope = scopeString2Int(pc.ignoreScopes(), list.next());
	Object coll = null;
	if (scope == Scope.SCOPE_UNDEFINED) {
	    coll = pc.undefinedScope().get(KeyImpl.init(list.current()), NullSupportHelper.NULL());
	    if (coll == NullSupportHelper.NULL()) return defaultValue;
	}
	else {
	    try {
		coll = VariableInterpreter.scope(pc, scope, list.hasNext());
		// coll=pc.scope(scope);
	    }
	    catch (PageException e) {
		return defaultValue;
	    }
	}

	while (list.hasNext()) {
	    coll = pc.getVariableUtil().get(pc, coll, KeyImpl.init(list.next()), NullSupportHelper.NULL());
	    if (coll == NullSupportHelper.NULL()) return defaultValue;
	}
	return coll;
    }
979915
public static Server getServerScope(PageContext pc, boolean jsr223) {
	if (server == null) {
	    server = new ServerImpl(pc, jsr223);
	}
	return server;
    }
452210
public static String call(PageContext pc, Object object) throws PageException {
	return call(pc, object, null, true, 9999, null, null, null, null, 9999, true, true);
    }
216113
public static boolean operate(PageContext pc, double scope, Collection.Key[] varNames) {
	return _operate(pc, scope, varNames, 0);
    }
411287
public static Object currentrow(PageContext pc, Object obj) throws PageException {
	if (obj instanceof Query) return Caster.toDouble(((Query) obj).getCurrentrow(pc.getId()));
	return pc.getCollection(obj, KeyConstants._CURRENTROW);
    }
102804
public static Object call(PageContext pc, Object udf, double timeout) throws PageException {
	return Future._then(pc, Caster.toFunction(udf), (long) timeout);
    }
925944
public static Client getInstance(String cacheName, String appName, PageContext pc, Client existing, Log log) throws PageException {
	if (appName != null && appName.startsWith("no-in-memory-cache-")) existing = null;
	synchronized (token) {
	    StorageValue sv = _loadData(pc, cacheName, appName, "client", log);
	    if (sv != null) {
		long time = sv.lastModified();

		if (existing instanceof StorageScopeCache) {
		    if (((StorageScopeCache) existing).lastModified() >= time) return existing;
		}
		return new ClientCache(pc, cacheName, appName, sv.getValue(), time);
	    }
	    else if (existing != null) return existing;

	    ClientCache cc = new ClientCache(pc, cacheName, appName, new StructImpl(), 0);
	    cc.store(pc);
	    return cc;
	}
    }
18418
public static Object get(PageContext pc, Object coll, int[] types, Key[] keys, Object[][] args, Object defaultValue) throws PageException {
	if (coll == null) return defaultValue;
	int to = keys.length - 1;
	VariableUtilImpl vu = (VariableUtilImpl) pc.getVariableUtil();
	for (int i = 0; i <= to; i++) {
	    switch (types[i]) {
	    case TYPE_DATA:
		coll = vu.getCollection(pc, coll, keys[i], Null.NULL);
		break;
	    case TYPE_UDF_ARGS:
		coll = vu.callFunctionWithoutNamedValues(pc, coll, keys[i], args[i], false, Null.NULL);
		break;
	    case TYPE_UDF_NAMED_ARGS:
		coll = vu.callFunctionWithNamedValues(pc, coll, keys[i], args[i], false, Null.NULL);
		break;
	    case TYPE_BIF:
		coll = null;// TODO
		break;
	    }

	    if (coll == Null.NULL || (coll == null && i < to)) return defaultValue;
	}
	return coll;
    }
423271
@Override
    public int doEndTag() throws JspException {
        if (!scopeSpecified) {
            pageContext.removeAttribute(var);
        } else {
            pageContext.removeAttribute(var, scope);
        }
        return EVAL_PAGE;
    }
714181
public static Query toQuery(Object o) throws PageException {
	if (o instanceof Query) return (Query) o;
	if (o instanceof ObjectWrap) {
	    return toQuery(((ObjectWrap) o).getEmbededObject());
	}
	if (o instanceof ResultSet) return new QueryImpl((ResultSet) o, "query", ThreadLocalPageContext.getTimeZone());
	if (o instanceof Component) {
	    Member member = ((Component) o).getMember(Component.ACCESS_PRIVATE, KeyConstants.__toQuery, false, false);
	    if (member instanceof UDFPlus) {
		UDFPlus udf = (UDFPlus) member;
		if (udf.getReturnType() == CFTypes.TYPE_QUERY && udf.getFunctionArguments().length == 0) {
		    return Caster.toQuery(((Component) o).call(ThreadLocalPageContext.get(), KeyConstants.__toQuery, new Object[] {}));
		}
	    }
	}

	throw new CasterException(o, "query");
    }