Search in sources :

Example 6 with ConfigWebImpl

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

the class PageSourceImpl method _compile.

private Page _compile(ConfigWeb config, Resource classRootDir, Page existing, boolean returnValue, boolean ignoreScopes) throws IOException, SecurityException, IllegalArgumentException, PageException {
    ConfigWebImpl cwi = (ConfigWebImpl) config;
    int dialect = getDialect();
    long now;
    if ((getPhyscalFile().lastModified() + 10000) > (now = System.currentTimeMillis()))
        // SystemUtil.get
        cwi.getCompiler().watch(this, now);
    Result result;
    result = cwi.getCompiler().compile(cwi, this, cwi.getTLDs(dialect), cwi.getFLDs(dialect), classRootDir, returnValue, ignoreScopes);
    try {
        Class<?> clazz = mapping.getPhysicalClass(getClassName(), result.barr);
        return newInstance(clazz);
    } catch (Throwable t) {
        ExceptionUtil.rethrowIfNecessary(t);
        PageException pe = Caster.toPageException(t);
        pe.setExtendedInfo("failed to load template " + getDisplayPath());
        throw pe;
    }
}
Also used : ConfigWebImpl(lucee.runtime.config.ConfigWebImpl) PageException(lucee.runtime.exp.PageException) Result(lucee.runtime.compiler.CFMLCompilerImpl.Result)

Example 7 with ConfigWebImpl

use of lucee.runtime.config.ConfigWebImpl 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 8 with ConfigWebImpl

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

the class ResourceUtil method toResourceExisting.

public static Resource toResourceExisting(PageContext pc, String path, boolean allowRealpath) throws ExpressionException {
    path = path.replace('\\', '/');
    Resource res = pc.getConfig().getResource(path);
    if (res.exists())
        return res;
    else if (!allowRealpath)
        throw new ExpressionException("file or directory " + path + " not exist");
    if (res.isAbsolute() && res.exists()) {
        return res;
    }
    if (StringUtil.startsWith(path, '/')) {
        PageContextImpl pci = (PageContextImpl) pc;
        ConfigWebImpl cwi = (ConfigWebImpl) pc.getConfig();
        PageSource[] sources = cwi.getPageSources(pci, pc.getApplicationContext().getMappings(), path, false, pci.useSpecialMappings(), true);
        if (!ArrayUtil.isEmpty(sources)) {
            for (int i = 0; i < sources.length; i++) {
                if (sources[i].exists())
                    return sources[i].getResource();
            }
        }
    }
    res = getRealResource(pc, path, res);
    if (res.exists())
        return res;
    throw new ExpressionException("file or directory " + path + " not exist");
}
Also used : ConfigWebImpl(lucee.runtime.config.ConfigWebImpl) HTTPResource(lucee.commons.io.res.type.http.HTTPResource) Resource(lucee.commons.io.res.Resource) PageContextImpl(lucee.runtime.PageContextImpl) ExpressionException(lucee.runtime.exp.ExpressionException) PageSource(lucee.runtime.PageSource)

Example 9 with ConfigWebImpl

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

the class ResourceUtil method toResourceNotExisting.

public static Resource toResourceNotExisting(PageContext pc, String destination, boolean allowRealpath, boolean checkComponentMappings) {
    destination = destination.replace('\\', '/');
    Resource res = pc.getConfig().getResource(destination);
    if (!allowRealpath || res.exists()) {
        return res;
    }
    boolean isUNC;
    if (!(isUNC = isUNCPath(destination)) && StringUtil.startsWith(destination, '/')) {
        PageContextImpl pci = (PageContextImpl) pc;
        ConfigWebImpl cwi = (ConfigWebImpl) pc.getConfig();
        PageSource[] sources = cwi.getPageSources(pci, pc.getApplicationContext().getMappings(), destination, false, pci.useSpecialMappings(), SystemUtil.isWindows(), checkComponentMappings);
        if (!ArrayUtil.isEmpty(sources)) {
            for (int i = 0; i < sources.length; i++) {
                res = sources[i].getResource();
                if (res != null)
                    return res;
            }
        }
    // Resource res2 = pc.getPhysical(destination,SystemUtil.isWindows());
    // if(res2!=null) return res2;
    }
    if (isUNC) {
        res = pc.getConfig().getResource(destination.replace('/', '\\'));
    } else if (!destination.startsWith(".."))
        res = pc.getConfig().getResource(destination);
    if (res != null && res.isAbsolute())
        return res;
    return getRealResource(pc, destination, res);
}
Also used : ConfigWebImpl(lucee.runtime.config.ConfigWebImpl) HTTPResource(lucee.commons.io.res.type.http.HTTPResource) Resource(lucee.commons.io.res.Resource) PageContextImpl(lucee.runtime.PageContextImpl) PageSource(lucee.runtime.PageSource)

Example 10 with ConfigWebImpl

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

the class ResourceUtil method toResourceExistingParent.

public static Resource toResourceExistingParent(PageContext pc, String destination, boolean allowRealpath) throws ExpressionException {
    destination = destination.replace('\\', '/');
    Resource res = pc.getConfig().getResource(destination);
    // not allow realpath
    if (!allowRealpath) {
        if (res.exists() || parentExists(res))
            return res;
        throw new ExpressionException("parent directory " + res.getParent() + "  for file " + destination + " doesn't exist");
    }
    // allow realpath
    if (res.isAbsolute() && (res.exists() || parentExists(res))) {
        return res;
    }
    if (StringUtil.startsWith(destination, '/')) {
        PageContextImpl pci = (PageContextImpl) pc;
        ConfigWebImpl cwi = (ConfigWebImpl) pc.getConfig();
        PageSource[] sources = cwi.getPageSources(pci, pc.getApplicationContext().getMappings(), destination, false, pci.useSpecialMappings(), true);
        // Resource[] reses = cwi.getPhysicalResourcesX(pc,pc.getApplicationContext().getMappings(),destination,false,pci.useSpecialMappings(),true);
        if (!ArrayUtil.isEmpty(sources)) {
            for (int i = 0; i < sources.length; i++) {
                if (sources[i].exists() || parentExists(sources[i])) {
                    res = sources[i].getResource();
                    if (res != null)
                        return res;
                }
            }
        }
    }
    res = getRealResource(pc, destination, res);
    if (res != null && (res.exists() || parentExists(res)))
        return res;
    throw new ExpressionException("parent directory " + res.getParent() + "  for file " + destination + " doesn't exist");
}
Also used : ConfigWebImpl(lucee.runtime.config.ConfigWebImpl) HTTPResource(lucee.commons.io.res.type.http.HTTPResource) Resource(lucee.commons.io.res.Resource) PageContextImpl(lucee.runtime.PageContextImpl) ExpressionException(lucee.runtime.exp.ExpressionException) 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