Search in sources :

Example 1 with MappingImpl

use of lucee.runtime.MappingImpl in project Lucee by lucee.

the class Admin method doGetCustomTagMappings.

/**
 * @throws PageException
 */
private void doGetCustomTagMappings() throws PageException {
    Mapping[] mappings = config.getCustomTagMappings();
    lucee.runtime.type.Query qry = new QueryImpl(new String[] { "archive", "strarchive", "physical", "strphysical", "virtual", "hidden", "physicalFirst", "readonly", "inspect" }, mappings.length, "query");
    for (int i = 0; i < mappings.length; i++) {
        MappingImpl m = (MappingImpl) mappings[i];
        int row = i + 1;
        qry.setAt("archive", row, m.getArchive());
        qry.setAt("strarchive", row, m.getStrArchive());
        qry.setAt("physical", row, m.getPhysical());
        qry.setAt("strphysical", row, m.getStrPhysical());
        qry.setAt("virtual", row, m.getVirtual());
        qry.setAt("hidden", row, Caster.toBoolean(m.isHidden()));
        qry.setAt("physicalFirst", row, Caster.toBoolean(m.isPhysicalFirst()));
        qry.setAt("readonly", row, Caster.toBoolean(m.isReadonly()));
        qry.setAt("inspect", row, ConfigWebUtil.inspectTemplate(m.getInspectTemplateRaw(), ""));
    }
    pageContext.setVariable(getString("admin", action, "returnVariable"), qry);
}
Also used : QueryImpl(lucee.runtime.type.QueryImpl) Mapping(lucee.runtime.Mapping) MappingImpl(lucee.runtime.MappingImpl) Query(lucee.runtime.type.Query)

Example 2 with MappingImpl

use of lucee.runtime.MappingImpl in project Lucee by lucee.

the class Admin method doGetMapping.

/**
 * @throws PageException
 */
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 + "]");
}
Also used : StructImpl(lucee.runtime.type.StructImpl) ApplicationException(lucee.runtime.exp.ApplicationException) Mapping(lucee.runtime.Mapping) MappingImpl(lucee.runtime.MappingImpl) Struct(lucee.runtime.type.Struct)

Example 3 with MappingImpl

use of lucee.runtime.MappingImpl in project Lucee by lucee.

the class ComponentLoader method _search.

private static Object _search(PageContext pc, PageSource loadingLocation, String rawPath, Boolean searchLocal, Boolean searchRoot, boolean executeConstr, short returnType, PageSource currPS, ImportDefintion[] importDefintions, int dialect, final boolean isExtendedComponent) throws PageException {
    ConfigImpl config = (ConfigImpl) pc.getConfig();
    if (dialect == CFMLEngine.DIALECT_LUCEE && !config.allowLuceeDialect())
        PageContextImpl.notSupported();
    boolean doCache = config.useComponentPathCache();
    String sub = null;
    if (returnType != RETURN_TYPE_PAGE && rawPath.indexOf(':') != -1) {
        int d = rawPath.indexOf(':');
        int s = rawPath.indexOf('.');
        if (d > s) {
            sub = rawPath.substring(d + 1);
            rawPath = rawPath.substring(0, d);
        }
    }
    // app-String appName=pc.getApplicationContext().getName();
    rawPath = rawPath.trim().replace('\\', '/');
    String path = (rawPath.indexOf("./") == -1) ? rawPath.replace('.', '/') : rawPath;
    boolean isRealPath = !StringUtil.startsWith(path, '/');
    // PageSource currPS = pc.getCurrentPageSource();
    // Page currP=currPS.loadPage(pc,false);
    PageSource ps = null;
    CIPage page = null;
    // MUSTMUST improve to handle different extensions
    String pathWithCFC = path.concat("." + (dialect == CFMLEngine.DIALECT_CFML ? Constants.getCFMLComponentExtension() : Constants.getLuceeComponentExtension()));
    // no cache for per application pathes
    Mapping[] acm = pc.getApplicationContext().getComponentMappings();
    if (!ArrayUtil.isEmpty(acm)) {
        Mapping m;
        for (int y = 0; y < acm.length; y++) {
            m = acm[y];
            ps = m.getPageSource(pathWithCFC);
            page = toCIPage(ps.loadPageThrowTemplateException(pc, false, (Page) null));
            if (page != null) {
                return returnType == RETURN_TYPE_PAGE ? page : load(pc, page, trim(path.replace('/', '.')), sub, isRealPath, returnType, isExtendedComponent, executeConstr);
            }
        }
    }
    if (searchLocal == null)
        searchLocal = Caster.toBoolean(rawPath.indexOf('.') == -1 ? true : config.getComponentLocalSearch());
    if (searchRoot == null)
        searchRoot = Caster.toBoolean(config.getComponentRootSearch());
    // CACHE
    // check local in cache
    String localCacheName = null;
    if (searchLocal && isRealPath && currPS != null) {
        localCacheName = currPS.getDisplayPath().replace('\\', '/');
        localCacheName = localCacheName.substring(0, localCacheName.lastIndexOf('/') + 1).concat(pathWithCFC);
        if (doCache) {
            page = config.getCachedPage(pc, localCacheName);
            if (page != null)
                return returnType == RETURN_TYPE_PAGE ? page : load(pc, page, trim(path.replace('/', '.')), sub, isRealPath, returnType, isExtendedComponent, executeConstr);
        }
    }
    // check import cache
    if (doCache && isRealPath) {
        ImportDefintion impDef = config.getComponentDefaultImport();
        ImportDefintion[] impDefs = importDefintions == null ? EMPTY_ID : importDefintions;
        int i = -1;
        do {
            if (impDef.isWildcard() || impDef.getName().equalsIgnoreCase(path)) {
                page = config.getCachedPage(pc, "import:" + impDef.getPackageAsPath() + pathWithCFC);
                if (page != null)
                    return returnType == RETURN_TYPE_PAGE ? page : load(pc, page, trim(path.replace('/', '.')), sub, isRealPath, returnType, isExtendedComponent, executeConstr);
            }
            impDef = ++i < impDefs.length ? impDefs[i] : null;
        } while (impDef != null);
    }
    if (doCache) {
        // check global in cache
        page = config.getCachedPage(pc, pathWithCFC);
        if (page != null)
            return returnType == RETURN_TYPE_PAGE ? page : load(pc, page, trim(path.replace('/', '.')), sub, isRealPath, returnType, isExtendedComponent, executeConstr);
    }
    // search from local
    if (searchLocal && isRealPath) {
        // check realpath
        PageSource[] arr = ((PageContextImpl) pc).getRelativePageSources(pathWithCFC);
        page = toCIPage(PageSourceImpl.loadPage(pc, arr, null));
        if (page != null) {
            if (doCache)
                config.putCachedPageSource(localCacheName, page.getPageSource());
            return returnType == RETURN_TYPE_PAGE ? page : load(pc, page, trim(path.replace('/', '.')), sub, isRealPath, returnType, isExtendedComponent, executeConstr);
        }
    }
    // search with imports
    Mapping[] cMappings = config.getComponentMappings();
    if (isRealPath) {
        ImportDefintion impDef = config.getComponentDefaultImport();
        ImportDefintion[] impDefs = importDefintions == null ? EMPTY_ID : importDefintions;
        PageSource[] arr;
        int i = -1;
        do {
            if (impDef.isWildcard() || impDef.getName().equalsIgnoreCase(path)) {
                // search from local first
                if (searchLocal) {
                    arr = ((PageContextImpl) pc).getRelativePageSources(impDef.getPackageAsPath() + pathWithCFC);
                    page = toCIPage(PageSourceImpl.loadPage(pc, arr, null));
                    if (page != null) {
                        if (doCache)
                            config.putCachedPageSource("import:" + impDef.getPackageAsPath() + pathWithCFC, page.getPageSource());
                        return returnType == RETURN_TYPE_PAGE ? page : load(pc, page, trim(path.replace('/', '.')), sub, isRealPath, returnType, isExtendedComponent, executeConstr);
                    }
                }
                // search mappings and webroot
                page = toCIPage(PageSourceImpl.loadPage(pc, ((PageContextImpl) pc).getPageSources("/" + impDef.getPackageAsPath() + pathWithCFC), null));
                if (page != null) {
                    String key = impDef.getPackageAsPath() + pathWithCFC;
                    if (doCache && !((MappingImpl) page.getPageSource().getMapping()).isAppMapping())
                        config.putCachedPageSource("import:" + key, page.getPageSource());
                    return returnType == RETURN_TYPE_PAGE ? page : load(pc, page, trim(path.replace('/', '.')), sub, isRealPath, returnType, isExtendedComponent, executeConstr);
                }
                // search component mappings
                Mapping m;
                for (int y = 0; y < cMappings.length; y++) {
                    m = cMappings[y];
                    ps = m.getPageSource(impDef.getPackageAsPath() + pathWithCFC);
                    page = toCIPage(ps.loadPageThrowTemplateException(pc, false, (Page) null));
                    if (page != null) {
                        if (doCache)
                            config.putCachedPageSource("import:" + impDef.getPackageAsPath() + pathWithCFC, page.getPageSource());
                        return returnType == RETURN_TYPE_PAGE ? page : load(pc, page, trim(path.replace('/', '.')), sub, isRealPath, returnType, isExtendedComponent, executeConstr);
                    }
                }
            }
            impDef = ++i < impDefs.length ? impDefs[i] : null;
        } while (impDef != null);
    }
    String p;
    if (isRealPath)
        p = '/' + pathWithCFC;
    else
        p = pathWithCFC;
    // search mappings and webroot
    page = toCIPage(PageSourceImpl.loadPage(pc, ((PageContextImpl) pc).getPageSources(p), null));
    if (page != null) {
        String key = pathWithCFC;
        if (doCache && !((MappingImpl) page.getPageSource().getMapping()).isAppMapping())
            config.putCachedPageSource(key, page.getPageSource());
        return returnType == RETURN_TYPE_PAGE ? page : load(pc, page, trim(path.replace('/', '.')), sub, isRealPath, returnType, isExtendedComponent, executeConstr);
    }
    // search component mappings
    Mapping m;
    for (int i = 0; i < cMappings.length; i++) {
        m = cMappings[i];
        ps = m.getPageSource(p);
        page = toCIPage(ps.loadPageThrowTemplateException(pc, false, (Page) null));
        // recursive search
        if (page == null && config.doComponentDeepSearch() && path.indexOf('/') == -1) {
            ps = MappingUtil.searchMappingRecursive(m, pathWithCFC, true);
            if (ps != null) {
                page = toCIPage(ps.loadPageThrowTemplateException(pc, false, (Page) null));
                // do not cache this, it could be ambigous
                if (page != null)
                    doCache = false;
            }
        }
        if (page != null) {
            if (doCache)
                config.putCachedPageSource(pathWithCFC, page.getPageSource());
            return returnType == RETURN_TYPE_PAGE ? page : load(pc, page, trim(path.replace('/', '.')), sub, isRealPath, returnType, isExtendedComponent, executeConstr);
        }
    }
    // search relative to active component (this get not cached because the cache get ambigous if we do)
    if (searchLocal && isRealPath) {
        if (loadingLocation == null) {
            Component c = pc.getActiveComponent();
            if (c != null)
                loadingLocation = c.getPageSource();
        }
        if (loadingLocation != null) {
            ps = loadingLocation.getRealPage(pathWithCFC);
            if (ps != null) {
                page = toCIPage(ps.loadPageThrowTemplateException(pc, false, (Page) null));
                if (page != null) {
                    return returnType == RETURN_TYPE_PAGE ? page : load(pc, page, trim(path.replace('/', '.')), sub, isRealPath, returnType, isExtendedComponent, executeConstr);
                }
            }
        }
    }
    // translate cfide. to org.lucee.cfml
    if (StringUtil.startsWithIgnoreCase(rawPath, "cfide.")) {
        String rpm = Constants.DEFAULT_PACKAGE + "." + rawPath.substring(6);
        try {
            return _search(pc, loadingLocation, rpm, searchLocal, searchRoot, executeConstr, returnType, currPS, importDefintions, dialect, false);
        } catch (ExpressionException ee) {
            return null;
        // throw new ExpressionException("invalid "+toStringType(returnType)+" definition, can't find "+rawPath+" or "+rpm);
        }
    }
    return null;
// throw new ExpressionException("invalid "+toStringType(returnType)+" definition, can't find "+toStringType(returnType)+" ["+rawPath+"]");
}
Also used : CIPage(lucee.runtime.CIPage) Mapping(lucee.runtime.Mapping) PageContextImpl(lucee.runtime.PageContextImpl) MappingImpl(lucee.runtime.MappingImpl) ExpressionException(lucee.runtime.exp.ExpressionException) PageSource(lucee.runtime.PageSource) Component(lucee.runtime.Component) ConfigImpl(lucee.runtime.config.ConfigImpl)

Example 4 with MappingImpl

use of lucee.runtime.MappingImpl in project Lucee by lucee.

the class ConfigImpl method setFunctionDirectory.

protected void setFunctionDirectory(Resource functionDirectory) {
    this.functionMapping = new MappingImpl(this, "/mapping-function/", functionDirectory.getAbsolutePath(), null, ConfigImpl.INSPECT_NEVER, true, true, true, true, false, true, null, -1, -1);
    FunctionLib flc = cfmlFlds[cfmlFlds.length - 1];
    FunctionLib fll = luceeFlds[luceeFlds.length - 1];
    // now overwrite with new data
    if (functionDirectory.isDirectory()) {
        String[] files = functionDirectory.list(new ExtensionResourceFilter(Constants.getTemplateExtensions()));
        for (int i = 0; i < files.length; i++) {
            if (flc != null)
                createFunction(flc, files[i]);
            if (fll != null)
                createFunction(fll, files[i]);
        }
        combinedCFMLFLDs = null;
        combinedLuceeFLDs = null;
    }
}
Also used : FunctionLib(lucee.transformer.library.function.FunctionLib) ExtensionResourceFilter(lucee.commons.io.res.filter.ExtensionResourceFilter) MappingImpl(lucee.runtime.MappingImpl)

Example 5 with MappingImpl

use of lucee.runtime.MappingImpl in project Lucee by lucee.

the class ConfigImpl method getScriptMapping.

/* *
	 * @return the tagDirectory
	
	public Resource getTagDirectory() {
		return tagDirectory;
	} */
/**
 * mapping used for script (JSR 223)
 * @return
 */
public Mapping getScriptMapping() {
    if (scriptMapping == null) {
        // Physical resource TODO make in RAM
        Resource physical = getConfigDir().getRealResource("jsr223");
        if (!physical.exists())
            physical.mkdirs();
        this.scriptMapping = new MappingImpl(this, "/mapping-script/", physical.getAbsolutePath(), null, ConfigImpl.INSPECT_NEVER, true, true, true, true, false, true, null, -1, -1);
    }
    return scriptMapping;
}
Also used : Resource(lucee.commons.io.res.Resource) CompressResource(lucee.commons.io.res.type.compress.CompressResource) MappingImpl(lucee.runtime.MappingImpl)

Aggregations

MappingImpl (lucee.runtime.MappingImpl)18 Mapping (lucee.runtime.Mapping)11 Iterator (java.util.Iterator)4 Resource (lucee.commons.io.res.Resource)4 Entry (java.util.Map.Entry)3 lucee.aprint (lucee.aprint)3 ExtensionResourceFilter (lucee.commons.io.res.filter.ExtensionResourceFilter)3 Query (lucee.runtime.type.Query)3 QueryImpl (lucee.runtime.type.QueryImpl)3 Element (org.w3c.dom.Element)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 DirectoryResourceFilter (lucee.commons.io.res.filter.DirectoryResourceFilter)2 OrResourceFilter (lucee.commons.io.res.filter.OrResourceFilter)2 ResourceFilter (lucee.commons.io.res.filter.ResourceFilter)2 ApplicationException (lucee.runtime.exp.ApplicationException)2 Struct (lucee.runtime.type.Struct)2 IOException (java.io.IOException)1