Search in sources :

Example 21 with PageSource

use of lucee.runtime.PageSource 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 22 with PageSource

use of lucee.runtime.PageSource 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)

Example 23 with PageSource

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

the class MappingUtil method searchMappingRecursive.

public static PageSource searchMappingRecursive(Mapping mapping, String name, boolean onlyCFC) {
    if (name.indexOf('/') == -1) {
        // TODO handle this as well?
        Config config = mapping.getConfig();
        ExtensionResourceFilter ext = null;
        if (onlyCFC)
            ext = new ExtensionResourceFilter(Constants.getComponentExtensions(), true, true);
        else {
            ext = new ExtensionResourceFilter(Constants.getExtensions(), true, true);
        // ext.addExtension(config.getComponentExtension());
        }
        if (mapping.isPhysicalFirst()) {
            PageSource ps = searchPhysical(mapping, name, ext);
            if (ps != null)
                return ps;
            ps = searchArchive(mapping, name, onlyCFC);
            if (ps != null)
                return ps;
        } else {
            PageSource ps = searchArchive(mapping, name, onlyCFC);
            if (ps != null)
                return ps;
            ps = searchPhysical(mapping, name, ext);
            if (ps != null)
                return ps;
        }
    }
    return null;
}
Also used : Config(lucee.runtime.config.Config) ExtensionResourceFilter(lucee.commons.io.res.filter.ExtensionResourceFilter) PageSource(lucee.runtime.PageSource)

Example 24 with PageSource

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

the class MappingUtil method searchArchive.

private static PageSource searchArchive(Mapping mapping, String name, boolean onlyCFC) {
    Resource archive = mapping.getArchive();
    if (archive != null && archive.isFile()) {
        ZipInputStream zis = null;
        try {
            zis = new ZipInputStream(archive.getInputStream());
            ZipEntry entry;
            Class<?> clazz;
            while ((entry = zis.getNextEntry()) != null) {
                if (entry.isDirectory() || !entry.getName().endsWith(".class"))
                    continue;
                clazz = mapping.getArchiveClass(toClassName(entry.getName()), null);
                if (clazz == null)
                    continue;
                SourceInfo srcInf = ASMUtil.getSourceInfo(mapping.getConfig(), clazz, onlyCFC);
                if (name.equalsIgnoreCase(srcInf.name)) {
                    PageSource ps = mapping.getPageSource(srcInf.relativePath);
                    return ps;
                }
            }
        } catch (IOException ioe) {
            SystemOut.printDate(ioe);
        } finally {
            IOUtil.closeEL(zis);
        }
    }
    // TODO Auto-generated method stub
    return null;
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) SourceInfo(lucee.transformer.bytecode.util.SourceNameClassVisitor.SourceInfo) ZipEntry(java.util.zip.ZipEntry) Resource(lucee.commons.io.res.Resource) IOException(java.io.IOException) PageSource(lucee.runtime.PageSource)

Example 25 with PageSource

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

the class HTTPUtil method optimizeRealPath.

/*public static URL toURL(HttpMethod httpMethod) {
		HostConfiguration config = httpMethod.getHostConfiguration();
		
		try {
			String qs = httpMethod.getQueryString();
			if(StringUtil.isEmpty(qs))
				return new URL(config.getProtocol().getScheme(),config.getHost(),config.getPort(),httpMethod.getPath());
			return new URL(config.getProtocol().getScheme(),config.getHost(),config.getPort(),httpMethod.getPath()+"?"+qs);
		} catch (MalformedURLException e) {
			return null;
		}
	}*/
public static String optimizeRealPath(PageContext pc, String realPath) {
    int index;
    String requestURI = realPath, queryString = null;
    if ((index = realPath.indexOf('?')) != -1) {
        requestURI = realPath.substring(0, index);
        queryString = realPath.substring(index + 1);
    }
    PageSource ps = PageSourceImpl.best(((PageContextImpl) pc).getRelativePageSources(requestURI));
    requestURI = ps.getRealpathWithVirtual();
    if (queryString != null)
        return requestURI + "?" + queryString;
    return requestURI;
}
Also used : PageSource(lucee.runtime.PageSource)

Aggregations

PageSource (lucee.runtime.PageSource)59 PageContextImpl (lucee.runtime.PageContextImpl)19 Resource (lucee.commons.io.res.Resource)16 Struct (lucee.runtime.type.Struct)10 ConfigWebImpl (lucee.runtime.config.ConfigWebImpl)8 Mapping (lucee.runtime.Mapping)7 PageException (lucee.runtime.exp.PageException)7 StructImpl (lucee.runtime.type.StructImpl)7 ConfigImpl (lucee.runtime.config.ConfigImpl)6 ConfigWeb (lucee.runtime.config.ConfigWeb)6 ExpressionException (lucee.runtime.exp.ExpressionException)6 ArrayList (java.util.ArrayList)5 Component (lucee.runtime.Component)5 PageSourceCode (lucee.transformer.util.PageSourceCode)5 IOException (java.io.IOException)4 MissingIncludeException (lucee.runtime.exp.MissingIncludeException)4 Array (lucee.runtime.type.Array)4 LitString (lucee.transformer.expression.literal.LitString)4 HTTPResource (lucee.commons.io.res.type.http.HTTPResource)3 Entry (java.util.Map.Entry)2