Search in sources :

Example 11 with ConfigWebImpl

use of lucee.runtime.config.ConfigWebImpl in project Lucee by lucee.

the class DatasourceStorageScopeCleaner method clean.

private void clean(ConfigWeb config, DataSource dataSource) throws PageException, SQLException {
    ConfigWebImpl cwi = (ConfigWebImpl) config;
    DatasourceConnection dc = null;
    DatasourceConnectionPool pool = cwi.getDatasourceConnectionPool();
    try {
        dc = pool.getDatasourceConnection(null, dataSource, null, null);
        Log log = ((ConfigImpl) config).getLog("scope");
        SQLExecutor executor = SQLExecutionFactory.getInstance(dc);
        executor.clean(config, dc, type, engine, this, listener, log);
    } finally {
        if (dc != null)
            pool.releaseDatasourceConnection(dc);
    }
}
Also used : ConfigWebImpl(lucee.runtime.config.ConfigWebImpl) DatasourceConnection(lucee.runtime.db.DatasourceConnection) DatasourceConnectionPool(lucee.runtime.db.DatasourceConnectionPool) Log(lucee.commons.io.log.Log) SQLExecutor(lucee.runtime.type.scope.storage.db.SQLExecutor) ConfigImpl(lucee.runtime.config.ConfigImpl)

Example 12 with ConfigWebImpl

use of lucee.runtime.config.ConfigWebImpl in project Lucee by lucee.

the class FileStorageScopeCleaner method _clean.

@Override
protected void _clean() {
    ConfigWebImpl cwi = (ConfigWebImpl) engine.getFactory().getConfig();
    Resource dir = type == Scope.SCOPE_CLIENT ? cwi.getClientScopeDir() : cwi.getSessionScopeDir();
    // for old files only the defintion from admin can be used
    long timeout = type == Scope.SCOPE_CLIENT ? cwi.getClientTimeout().getMillis() : cwi.getSessionTimeout().getMillis();
    long time = new DateTimeImpl(cwi).getTime() - timeout;
    try {
        // delete files that has expired
        AndResourceFilter andFilter = new AndResourceFilter(new ResourceFilter[] { EXT_FILTER, new ExpiresFilter(time, true) });
        String appName, cfid2, cfid;
        Resource[] apps = dir.listResources(DIR_FILTER), cfidDir, files;
        if (apps != null)
            for (int a = 0; a < apps.length; a++) {
                appName = StorageScopeImpl.decode(apps[a].getName());
                cfidDir = apps[a].listResources(DIR_FILTER);
                if (cfidDir != null)
                    for (int b = 0; b < cfidDir.length; b++) {
                        cfid2 = cfidDir[b].getName();
                        files = cfidDir[b].listResources(andFilter);
                        if (files != null) {
                            for (int c = 0; c < files.length; c++) {
                                cfid = files[c].getName();
                                cfid = cfid2 + cfid.substring(0, cfid.length() - 5);
                                if (listener != null)
                                    listener.doEnd(engine, this, appName, cfid);
                                // info("remove from memory "+appName+"/"+cfid);
                                engine.remove(type, appName, cfid);
                                info("remove file " + files[c]);
                                files[c].delete();
                            }
                        }
                    }
            }
        ResourceUtil.deleteEmptyFolders(dir);
    } catch (Throwable t) {
        ExceptionUtil.rethrowIfNecessary(t);
        error(t);
    }
// long maxSize = type==Scope.SCOPE_CLIENT?cwi.getClientScopeDirSize():cwi.getSessionScopeDirSize();
// checkSize(config,dir,maxSize,extfilter);
}
Also used : ConfigWebImpl(lucee.runtime.config.ConfigWebImpl) AndResourceFilter(lucee.commons.io.res.filter.AndResourceFilter) Resource(lucee.commons.io.res.Resource) DateTimeImpl(lucee.runtime.type.dt.DateTimeImpl)

Example 13 with ConfigWebImpl

use of lucee.runtime.config.ConfigWebImpl in project Lucee by lucee.

the class MemberUtil method getMembers.

public static Map<Collection.Key, FunctionLibFunction> getMembers(PageContext pc, short type) {
    Map<Short, Map<Key, FunctionLibFunction>> matches = pc.getCurrentTemplateDialect() == CFMLEngine.DIALECT_LUCEE ? matchesLucee : matchesCFML;
    Map<Key, FunctionLibFunction> match = matches.get(type);
    if (match != null)
        return match;
    FunctionLib[] flds = ((ConfigWebImpl) pc.getConfig()).getFLDs(pc.getCurrentTemplateDialect());
    Iterator<FunctionLibFunction> it;
    FunctionLibFunction f;
    match = new HashMap<Collection.Key, FunctionLibFunction>();
    String[] names;
    for (int i = 0; i < flds.length; i++) {
        it = flds[i].getFunctions().values().iterator();
        while (it.hasNext()) {
            f = it.next();
            names = f.getMemberNames();
            if (!ArrayUtil.isEmpty(names) && f.getMemberType() == type && f.getArgType() == FunctionLibFunction.ARG_FIX) {
                for (int y = 0; y < names.length; y++) match.put(KeyImpl.getInstance(names[y]), f);
            }
        }
    }
    matches.put(type, match);
    return match;
}
Also used : FunctionLib(lucee.transformer.library.function.FunctionLib) LString(lucee.runtime.interpreter.ref.literal.LString) ConfigWebImpl(lucee.runtime.config.ConfigWebImpl) FunctionLibFunction(lucee.transformer.library.function.FunctionLibFunction) HashMap(java.util.HashMap) Map(java.util.Map) Key(lucee.runtime.type.Collection.Key)

Example 14 with ConfigWebImpl

use of lucee.runtime.config.ConfigWebImpl in project Lucee by lucee.

the class CFFunction method loadUDF.

public static UDF loadUDF(PageContext pc, String filename, Collection.Key name, boolean isweb) throws PageException {
    ConfigWebImpl config = (ConfigWebImpl) pc.getConfig();
    String key = isweb ? name.getString() + config.getIdentification().getId() : name.getString();
    UDF udf = config.getFromFunctionCache(key);
    if (udf != null)
        return udf;
    Mapping mapping = isweb ? config.getFunctionMapping() : config.getServerFunctionMapping();
    Page p = mapping.getPageSource(filename).loadPage(pc, false);
    // execute page
    Variables old = pc.variablesScope();
    pc.setVariablesScope(VAR);
    boolean wasSilent = pc.setSilent();
    try {
        p.call(pc);
        Object o = pc.variablesScope().get(name, null);
        if (o instanceof UDF) {
            udf = (UDF) o;
            config.putToFunctionCache(key, udf);
            return udf;
        }
        throw new ExpressionException("there is no Function defined with name [" + name + "] in template [" + mapping.getStrPhysical() + File.separator + filename + "]");
    } catch (Throwable t) {
        ExceptionUtil.rethrowIfNecessary(t);
        throw Caster.toPageException(t);
    } finally {
        pc.setVariablesScope(old);
        if (!wasSilent)
            pc.unsetSilent();
    }
}
Also used : Variables(lucee.runtime.type.scope.Variables) ConfigWebImpl(lucee.runtime.config.ConfigWebImpl) UDF(lucee.runtime.type.UDF) Mapping(lucee.runtime.Mapping) Page(lucee.runtime.Page) ExpressionException(lucee.runtime.exp.ExpressionException)

Example 15 with ConfigWebImpl

use of lucee.runtime.config.ConfigWebImpl in project Lucee by lucee.

the class ExpandPath method call.

public static String call(PageContext pc, String relPath) throws PageException {
    ConfigWeb config = pc.getConfig();
    relPath = prettifyPath(pc, relPath);
    String contextPath = pc.getHttpServletRequest().getContextPath();
    if (!StringUtil.isEmpty(contextPath) && relPath.startsWith(contextPath + "/")) {
        boolean sws = StringUtil.startsWith(relPath, '/');
        relPath = relPath.substring(contextPath.length());
        if (sws && !StringUtil.startsWith(relPath, '/'))
            relPath = "/" + relPath;
    }
    Resource res;
    if (StringUtil.startsWith(relPath, '/')) {
        PageContextImpl pci = (PageContextImpl) pc;
        ConfigWebImpl cwi = (ConfigWebImpl) config;
        PageSource[] sources = cwi.getPageSources(pci, pc.getApplicationContext().getMappings(), relPath, false, pci.useSpecialMappings(), true);
        if (!ArrayUtil.isEmpty(sources)) {
            // first check for existing
            for (int i = 0; i < sources.length; i++) {
                if (sources[i].exists()) {
                    return toReturnValue(relPath, sources[i].getResource());
                }
            }
            // no expand needed
            if (!SystemUtil.isWindows() && !sources[0].exists()) {
                res = pc.getConfig().getResource(relPath);
                if (res.exists()) {
                    return toReturnValue(relPath, res);
                }
            }
            for (int i = 0; i < sources.length; i++) {
                res = sources[i].getResource();
                if (res != null) {
                    return toReturnValue(relPath, res);
                }
            }
        } else // no expand needed
        if (!SystemUtil.isWindows()) {
            res = pc.getConfig().getResource(relPath);
            if (res.exists()) {
                return toReturnValue(relPath, res);
            }
        }
    // Resource[] reses = cwi.getPhysicalResources(pc,pc.getApplicationContext().getMappings(),realPath,false,pci.useSpecialMappings(),true);
    }
    relPath = ConfigWebUtil.replacePlaceholder(relPath, config);
    res = pc.getConfig().getResource(relPath);
    if (res.isAbsolute())
        return toReturnValue(relPath, res);
    PageSource ps = pc.getBasePageSource();
    res = ps == null ? ResourceUtil.getCanonicalResourceEL(ResourceUtil.toResourceExisting(pc.getConfig(), ReqRspUtil.getRootPath(pc.getServletContext()))) : ResourceUtil.getResource(pc, ps);
    if (!res.isDirectory())
        res = res.getParentResource();
    res = res.getRealResource(relPath);
    return toReturnValue(relPath, res);
}
Also used : ConfigWebImpl(lucee.runtime.config.ConfigWebImpl) Resource(lucee.commons.io.res.Resource) PageContextImpl(lucee.runtime.PageContextImpl) ConfigWeb(lucee.runtime.config.ConfigWeb) PageSource(lucee.runtime.PageSource)

Aggregations

ConfigWebImpl (lucee.runtime.config.ConfigWebImpl)42 Resource (lucee.commons.io.res.Resource)9 PageContextImpl (lucee.runtime.PageContextImpl)9 Struct (lucee.runtime.type.Struct)9 PageSource (lucee.runtime.PageSource)8 PageException (lucee.runtime.exp.PageException)8 Key (lucee.runtime.type.Collection.Key)8 CFMLFactoryImpl (lucee.runtime.CFMLFactoryImpl)7 Mapping (lucee.runtime.Mapping)7 ConfigServer (lucee.runtime.config.ConfigServer)6 ConfigWeb (lucee.runtime.config.ConfigWeb)5 ApplicationException (lucee.runtime.exp.ApplicationException)5 StructImpl (lucee.runtime.type.StructImpl)5 IOException (java.io.IOException)4 Entry (java.util.Map.Entry)4 ConfigImpl (lucee.runtime.config.ConfigImpl)4 HTTPResource (lucee.commons.io.res.type.http.HTTPResource)3 Page (lucee.runtime.Page)3 PageContext (lucee.runtime.PageContext)3 ExpressionException (lucee.runtime.exp.ExpressionException)3