Search in sources :

Example 26 with PageContextImpl

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

the class DebugEntryTemplatePartComparator method getEntry.

@Override
public DebugEntryTemplatePart getEntry(PageContext pc, PageSource source, int startPos, int endPos) {
    String src = DebugEntryTemplatePartImpl.getSrc(source == null ? "" : source.getDisplayPath(), startPos, endPos);
    DebugEntryTemplatePartImpl de = null;
    if (partEntries != null) {
        de = partEntries.get(src);
        if (de != null) {
            de.countPP();
            return de;
        }
    } else {
        partEntries = new HashMap<String, DebugEntryTemplatePartImpl>();
    }
    ResourceSnippet snippet = snippetsMap.getSnippet(source, startPos, endPos, ((PageContextImpl) pc).getResourceCharset().name());
    de = new DebugEntryTemplatePartImpl(source, startPos, endPos, snippet.getStartLine(), snippet.getEndLine(), snippet.getContent());
    partEntries.put(src, de);
    return de;
}
Also used : ResourceSnippet(lucee.commons.io.res.util.ResourceSnippet) PageContextImpl(lucee.runtime.PageContextImpl)

Example 27 with PageContextImpl

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

the class DebugEntryTemplatePartComparator method writeOut.

@Override
public void writeOut(PageContext pc) throws IOException {
    // stop();
    if (!output)
        return;
    String addr = pc.getHttpServletRequest().getRemoteAddr();
    lucee.runtime.config.DebugEntry debugEntry = ((ConfigImpl) pc.getConfig()).getDebugEntry(addr, null);
    if (debugEntry == null) {
        // pc.forceWrite(pc.getConfig().getDefaultDumpWriter().toString(pc,toDumpData(pc, 9999,DumpUtil.toDumpProperties()),true));
        return;
    }
    Struct args = new StructImpl();
    args.setEL(KeyConstants._custom, debugEntry.getCustom());
    try {
        args.setEL(KeyConstants._debugging, pc.getDebugger().getDebuggingData(pc));
    } catch (PageException e1) {
    }
    try {
        String path = debugEntry.getPath();
        PageSource[] arr = ((PageContextImpl) pc).getPageSources(path);
        Page p = PageSourceImpl.loadPage(pc, arr, null);
        // patch for old path
        String fullname = debugEntry.getFullname();
        if (p == null) {
            if (path != null) {
                boolean changed = false;
                if (path.endsWith("/Modern.cfc") || path.endsWith("\\Modern.cfc")) {
                    path = "/lucee-server-context/admin/debug/Modern.cfc";
                    fullname = "lucee-server-context.admin.debug.Modern";
                    changed = true;
                } else if (path.endsWith("/Classic.cfc") || path.endsWith("\\Classic.cfc")) {
                    path = "/lucee-server-context/admin/debug/Classic.cfc";
                    fullname = "lucee-server-context.admin.debug.Classic";
                    changed = true;
                } else if (path.endsWith("/Comment.cfc") || path.endsWith("\\Comment.cfc")) {
                    path = "/lucee-server-context/admin/debug/Comment.cfc";
                    fullname = "lucee-server-context.admin.debug.Comment";
                    changed = true;
                }
                if (changed)
                    pc.write("<span style='color:red'>Please update your debug template defintions in the Lucee admin by going into the detail view and hit the \"update\" button.</span>");
            }
            arr = ((PageContextImpl) pc).getPageSources(path);
            p = PageSourceImpl.loadPage(pc, arr);
        }
        pc.addPageSource(p.getPageSource(), true);
        try {
            Component c = pc.loadComponent(fullname);
            c.callWithNamedValues(pc, "output", args);
        } finally {
            pc.removeLastPageSource(true);
        }
    } catch (PageException e) {
        pc.handlePageException(e);
    }
}
Also used : PageException(lucee.runtime.exp.PageException) Page(lucee.runtime.Page) PageContextImpl(lucee.runtime.PageContextImpl) Struct(lucee.runtime.type.Struct) PageSource(lucee.runtime.PageSource) StructImpl(lucee.runtime.type.StructImpl) Component(lucee.runtime.Component) ConfigImpl(lucee.runtime.config.ConfigImpl)

Example 28 with PageContextImpl

use of lucee.runtime.PageContextImpl 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 29 with PageContextImpl

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

the class ComponentListPackage method _call.

private static Set<String> _call(PageContext pc, String packageName) throws IOException, ApplicationException {
    PageContextImpl pci = (PageContextImpl) pc;
    ConfigWebImpl config = (ConfigWebImpl) pc.getConfig();
    Set<String> rtn = null;
    // var SEP=server.separator.file;
    // get enviroment configuration
    boolean searchLocal = packageName.indexOf('.') == -1 ? true : config.getComponentLocalSearch();
    boolean searchRoot = config.getComponentRootSearch();
    String path = StringUtil.replace(packageName, ".", File.separator, false);
    // search local
    if (searchLocal) {
        PageSource ps = pci.getRelativePageSourceExisting(path);
        if (ps != null) {
            Mapping mapping = ps.getMapping();
            String _path = ps.getRealpath();
            _path = ListUtil.trim(_path, "\\/");
            String[] list = _listMapping(pc, mapping, _path);
            if (!ArrayUtil.isEmpty(list))
                rtn = add(rtn, list);
        }
    }
    // check mappings (this includes the webroot)
    if (searchRoot) {
        String virtual = "/" + StringUtil.replace(packageName, ".", "/", false);
        Mapping[] mappings = config.getMappings();
        Mapping mapping;
        String _path;
        String[] list;
        for (int i = 0; i < mappings.length; i++) {
            mapping = mappings[i];
            if (StringUtil.startsWithIgnoreCase(virtual, mapping.getVirtual())) {
                _path = ListUtil.trim(virtual.substring(mapping.getVirtual().length()), "\\/").trim();
                _path = StringUtil.replace(_path, "/", File.separator, false);
                list = _listMapping(pc, mapping, _path);
                if (!ArrayUtil.isEmpty(list))
                    rtn = add(rtn, list);
            }
        }
    }
    // check component mappings
    Mapping[] mappings = config.getComponentMappings();
    Mapping mapping;
    String[] list;
    for (int i = 0; i < mappings.length; i++) {
        mapping = mappings[i];
        list = _listMapping(pc, mapping, path);
        if (!ArrayUtil.isEmpty(list))
            rtn = add(rtn, list);
    }
    if (rtn == null)
        throw new ApplicationException("no package with name [" + packageName + "] found");
    return rtn;
}
Also used : ConfigWebImpl(lucee.runtime.config.ConfigWebImpl) ApplicationException(lucee.runtime.exp.ApplicationException) Mapping(lucee.runtime.Mapping) PageContextImpl(lucee.runtime.PageContextImpl) PageSource(lucee.runtime.PageSource)

Example 30 with PageContextImpl

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

the class Evaluate method call.

public static Object call(PageContext pc, Object[] objs, boolean preciseMath) throws PageException {
    // define a ohter enviroment for the function
    if (objs.length > 1 && objs[objs.length - 1] instanceof Scope) {
        // Variables Scope
        Variables var = null;
        Local lcl = null, cLcl = null;
        Argument arg = null, cArg = null;
        if (objs[objs.length - 1] instanceof Variables) {
            var = (Variables) objs[objs.length - 1];
        } else if (objs[objs.length - 1] instanceof CallerImpl) {
            CallerImpl ci = ((CallerImpl) objs[objs.length - 1]);
            var = ci.getVariablesScope();
            lcl = ci.getLocalScope();
            arg = ci.getArgumentsScope();
        }
        if (var != null) {
            Variables cVar = pc.variablesScope();
            pc.setVariablesScope(var);
            if (lcl != null && !(lcl instanceof LocalNotSupportedScope)) {
                cLcl = pc.localScope();
                cArg = pc.argumentsScope();
                pc.setFunctionScopes(lcl, arg);
            }
            try {
                return _call(pc, objs, objs.length - 1, preciseMath);
            } finally {
                pc.setVariablesScope(cVar);
                if (cLcl != null)
                    pc.setFunctionScopes(cLcl, cArg);
            }
        } else // Undefined Scope
        if (objs[objs.length - 1] instanceof Undefined) {
            PageContextImpl pci = (PageContextImpl) pc;
            Undefined undefined = (Undefined) objs[objs.length - 1];
            boolean check = undefined.getCheckArguments();
            Variables orgVar = pc.variablesScope();
            Argument orgArgs = pc.argumentsScope();
            Local orgLocal = pc.localScope();
            pci.setVariablesScope(undefined.variablesScope());
            if (check)
                pci.setFunctionScopes(undefined.localScope(), undefined.argumentsScope());
            try {
                return _call(pc, objs, objs.length - 1, preciseMath);
            } finally {
                pc.setVariablesScope(orgVar);
                if (check)
                    pci.setFunctionScopes(orgLocal, orgArgs);
            }
        }
    }
    return _call(pc, objs, objs.length, preciseMath);
}
Also used : Variables(lucee.runtime.type.scope.Variables) Undefined(lucee.runtime.type.scope.Undefined) CallerImpl(lucee.runtime.type.scope.CallerImpl) Scope(lucee.runtime.type.scope.Scope) LocalNotSupportedScope(lucee.runtime.type.scope.LocalNotSupportedScope) Argument(lucee.runtime.type.scope.Argument) LocalNotSupportedScope(lucee.runtime.type.scope.LocalNotSupportedScope) Local(lucee.runtime.type.scope.Local) PageContextImpl(lucee.runtime.PageContextImpl)

Aggregations

PageContextImpl (lucee.runtime.PageContextImpl)84 PageSource (lucee.runtime.PageSource)19 Resource (lucee.commons.io.res.Resource)17 Key (lucee.runtime.type.Collection.Key)15 Struct (lucee.runtime.type.Struct)15 StructImpl (lucee.runtime.type.StructImpl)14 IOException (java.io.IOException)12 ApplicationException (lucee.runtime.exp.ApplicationException)10 PageException (lucee.runtime.exp.PageException)10 Component (lucee.runtime.Component)9 ConfigWeb (lucee.runtime.config.ConfigWeb)9 ConfigWebImpl (lucee.runtime.config.ConfigWebImpl)9 CFMLFactoryImpl (lucee.runtime.CFMLFactoryImpl)7 ByteArrayInputStream (java.io.ByteArrayInputStream)6 ArrayList (java.util.ArrayList)6 Mapping (lucee.runtime.Mapping)6 PageContext (lucee.runtime.PageContext)6 ConfigImpl (lucee.runtime.config.ConfigImpl)6 ExpressionException (lucee.runtime.exp.ExpressionException)6 HttpServletResponse (javax.servlet.http.HttpServletResponse)5