Search in sources :

Example 11 with Mapping

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

the class MappingUtil method getMatch.

public static SourceInfo getMatch(PageContext pc, Config config, StackTraceElement trace) {
    if (trace.getFileName() == null)
        return null;
    if (pc == null && config == null)
        config = ThreadLocalPageContext.getConfig();
    // PageContext pc = ThreadLocalPageContext.get();
    Mapping[] mappings = pc != null ? ConfigWebUtil.getAllMappings(pc) : ConfigWebUtil.getAllMappings(config);
    if (pc != null)
        config = pc.getConfig();
    Mapping mapping;
    Class clazz;
    for (int i = 0; i < mappings.length; i++) {
        mapping = mappings[i];
        // print.e("virtual:"+mapping.getVirtual()+"+"+trace.getClassName());
        // look for the class in that mapping
        clazz = ((MappingImpl) mapping).loadClass(trace.getClassName());
        if (clazz == null)
            continue;
        // classname is not distinct, because of that we must check class content
        try {
            SourceInfo si = ASMUtil.getSourceInfo(config, clazz, false);
            if (si != null && trace.getFileName() != null && trace.getFileName().equals(si.absolutePath(pc)))
                return si;
        } catch (IOException e) {
        }
    }
    return null;
}
Also used : SourceInfo(lucee.transformer.bytecode.util.SourceNameClassVisitor.SourceInfo) Mapping(lucee.runtime.Mapping) IOException(java.io.IOException)

Example 12 with Mapping

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

Example 13 with Mapping

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

the class SourceLastModifiedClassAdapter method registerString.

/**
 * return null if not possible to register
 * @param bc
 * @param str
 * @return
 * @throws IOException
 */
public Range registerString(BytecodeContext bc, String str) throws IOException {
    boolean append = true;
    if (staticTextLocation == null) {
        if (bc.getPageSource() == null)
            return null;
        PageSource ps = bc.getPageSource();
        Mapping m = ps.getMapping();
        staticTextLocation = m.getClassRootDirectory();
        staticTextLocation.mkdirs();
        staticTextLocation = staticTextLocation.getRealResource(ps.getClassName().replace('.', '/') + ".txt");
        if (staticTextLocation.exists())
            append = false;
        else
            staticTextLocation.createFile(true);
        off = 0;
    }
    IOUtil.write(staticTextLocation, str, CharsetUtil.UTF8, append);
    Range r = new Range(off, str.length());
    off += str.length();
    return r;
}
Also used : Mapping(lucee.runtime.Mapping) PageSource(lucee.runtime.PageSource)

Example 14 with Mapping

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

the class CFFunction method loadUDF.

public static UDF loadUDF(PageContext pc, String filename, Collection.Key name, boolean isweb) throws PageException {
    ConfigWebImpl config = (ConfigWebImpl) pc.getConfig();
    String key = isweb ? name.getString() + config.getIdentification().getId() : name.getString();
    UDF udf = config.getFromFunctionCache(key);
    if (udf != null)
        return udf;
    Mapping mapping = isweb ? config.getFunctionMapping() : config.getServerFunctionMapping();
    Page p = mapping.getPageSource(filename).loadPage(pc, false);
    // execute page
    Variables old = pc.variablesScope();
    pc.setVariablesScope(VAR);
    boolean wasSilent = pc.setSilent();
    try {
        p.call(pc);
        Object o = pc.variablesScope().get(name, null);
        if (o instanceof UDF) {
            udf = (UDF) o;
            config.putToFunctionCache(key, udf);
            return udf;
        }
        throw new ExpressionException("there is no Function defined with name [" + name + "] in template [" + mapping.getStrPhysical() + File.separator + filename + "]");
    } catch (Throwable t) {
        ExceptionUtil.rethrowIfNecessary(t);
        throw Caster.toPageException(t);
    } finally {
        pc.setVariablesScope(old);
        if (!wasSilent)
            pc.unsetSilent();
    }
}
Also used : Variables(lucee.runtime.type.scope.Variables) ConfigWebImpl(lucee.runtime.config.ConfigWebImpl) UDF(lucee.runtime.type.UDF) Mapping(lucee.runtime.Mapping) Page(lucee.runtime.Page) ExpressionException(lucee.runtime.exp.ExpressionException)

Example 15 with Mapping

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

the class AppListenerUtil method toMappings.

public static Mapping[] toMappings(ConfigWeb cw, Object o, Resource source) throws PageException {
    Struct sct = Caster.toStruct(o);
    Iterator<Entry<Key, Object>> it = sct.entryIterator();
    Entry<Key, Object> e;
    java.util.List<Mapping> mappings = new ArrayList<Mapping>();
    ConfigWebImpl config = (ConfigWebImpl) cw;
    String virtual;
    while (it.hasNext()) {
        e = it.next();
        virtual = translateMappingVirtual(e.getKey().getString());
        MappingData md = toMappingData(e.getValue(), source);
        mappings.add(config.getApplicationMapping("application", virtual, md.physical, md.archive, md.physicalFirst, false));
    }
    return mappings.toArray(new Mapping[mappings.size()]);
}
Also used : ArrayList(java.util.ArrayList) Mapping(lucee.runtime.Mapping) Struct(lucee.runtime.type.Struct) ConfigWebImpl(lucee.runtime.config.ConfigWebImpl) Entry(java.util.Map.Entry) Key(lucee.runtime.type.Collection.Key)

Aggregations

Mapping (lucee.runtime.Mapping)30 MappingImpl (lucee.runtime.MappingImpl)11 PageSource (lucee.runtime.PageSource)7 ConfigWebImpl (lucee.runtime.config.ConfigWebImpl)7 ArrayList (java.util.ArrayList)6 PageContextImpl (lucee.runtime.PageContextImpl)6 Resource (lucee.commons.io.res.Resource)5 Struct (lucee.runtime.type.Struct)5 Iterator (java.util.Iterator)4 Entry (java.util.Map.Entry)4 lucee.aprint (lucee.aprint)4 Query (lucee.runtime.type.Query)4 QueryImpl (lucee.runtime.type.QueryImpl)4 Element (org.w3c.dom.Element)4 HashMap (java.util.HashMap)3 LinkedHashMap (java.util.LinkedHashMap)3 ApplicationException (lucee.runtime.exp.ApplicationException)3 ExpressionException (lucee.runtime.exp.ExpressionException)3 Key (lucee.runtime.type.Collection.Key)3 StructImpl (lucee.runtime.type.StructImpl)3