Search in sources :

Example 31 with PageContextImpl

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

the class FileRead method call.

public static Object call(PageContext pc, Object obj, Object charsetOrSize) throws PageException {
    if (charsetOrSize == null)
        return call(pc, obj);
    if (obj instanceof FileStreamWrapper) {
        return _call((FileStreamWrapper) obj, Caster.toIntValue(charsetOrSize));
    }
    Resource res = Caster.toResource(pc, obj, true);
    String charset = Caster.toString(charsetOrSize);
    if (Decision.isInteger(charset)) {
        charset = ((PageContextImpl) pc).getResourceCharset().name();
        return _call(pc, res, charset, Caster.toIntValue(charset));
    }
    return _call(pc, res, charset);
}
Also used : Resource(lucee.commons.io.res.Resource) PageContextImpl(lucee.runtime.PageContextImpl)

Example 32 with PageContextImpl

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

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

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

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

the class ComponentUtil method _getComponentPropertiesClass.

private static Class _getComponentPropertiesClass(PageContext pc, Component component) throws PageException, IOException, ClassNotFoundException {
    ASMProperty[] props = ASMUtil.toASMProperties(component.getProperties(false, true, false, false));
    String className = getClassname(component, props);
    String real = className.replace('.', '/');
    Mapping mapping = component.getPageSource().getMapping();
    PhysicalClassLoader cl = (PhysicalClassLoader) ((PageContextImpl) pc).getRPCClassLoader(false);
    Resource classFile = cl.getDirectory().getRealResource(real.concat(".class"));
    // get component class information
    String classNameOriginal = component.getPageSource().getClassName();
    String realOriginal = classNameOriginal.replace('.', '/');
    Resource classFileOriginal = mapping.getClassRootDirectory().getRealResource(realOriginal.concat(".class"));
    // load existing class when pojo is still newer than component class file
    if (classFile.lastModified() >= classFileOriginal.lastModified()) {
        try {
            Class clazz = cl.loadClass(className);
            // ClassUtil.loadInstance(clazz);
            if (clazz != null && !hasChangesOfChildren(classFile.lastModified(), clazz))
                return clazz;
        } catch (Throwable t) {
            ExceptionUtil.rethrowIfNecessary(t);
        }
    }
    // extends
    String strExt = component.getExtends();
    Class<?> ext = Object.class;
    if (!StringUtil.isEmpty(strExt, true)) {
        ext = Caster.cfTypeToClass(strExt);
    }
    // 
    // create file
    byte[] barr = ASMUtil.createPojo(real, props, ext, new Class[] { Pojo.class }, component.getPageSource().getDisplayPath());
    ResourceUtil.touch(classFile);
    IOUtil.copy(new ByteArrayInputStream(barr), classFile, true);
    cl = (PhysicalClassLoader) ((PageContextImpl) pc).getRPCClassLoader(true);
    // ClassUtil.loadInstance(cl.loadClass(className));
    return cl.loadClass(className);
}
Also used : Resource(lucee.commons.io.res.Resource) Mapping(lucee.runtime.Mapping) LitString(lucee.transformer.expression.literal.LitString) PageContextImpl(lucee.runtime.PageContextImpl) ASMProperty(lucee.transformer.bytecode.util.ASMProperty) PhysicalClassLoader(lucee.commons.lang.PhysicalClassLoader) ByteArrayInputStream(java.io.ByteArrayInputStream)

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