Search in sources :

Example 16 with Mapping

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

the class AppListenerUtil method toMappings.

private static Mapping[] toMappings(ConfigWeb cw, String type, Object o, boolean useStructNames, Resource source) throws PageException {
    ConfigWebImpl config = (ConfigWebImpl) cw;
    Array array;
    if (o instanceof String) {
        array = ListUtil.listToArrayRemoveEmpty(Caster.toString(o), ',');
    } else if (o instanceof Struct) {
        Struct sct = (Struct) o;
        if (useStructNames) {
            Iterator<Entry<Key, Object>> it = sct.entryIterator();
            List<Mapping> list = new ArrayList<Mapping>();
            Entry<Key, Object> e;
            String virtual;
            while (it.hasNext()) {
                e = it.next();
                virtual = e.getKey().getString();
                if (virtual.length() == 0)
                    virtual = "/";
                if (!virtual.startsWith("/"))
                    virtual = "/" + virtual;
                if (!virtual.equals("/") && virtual.endsWith("/"))
                    virtual = virtual.substring(0, virtual.length() - 1);
                MappingData md = toMappingData(e.getValue(), source);
                list.add(config.getApplicationMapping(type, virtual, md.physical, md.archive, md.physicalFirst, true));
            }
            return list.toArray(new Mapping[list.size()]);
        }
        array = new ArrayImpl();
        Iterator<Object> it = sct.valueIterator();
        while (it.hasNext()) {
            array.append(it.next());
        }
    } else {
        array = Caster.toArray(o);
    }
    MappingImpl[] mappings = new MappingImpl[array.size()];
    for (int i = 0; i < mappings.length; i++) {
        MappingData md = toMappingData(array.getE(i + 1), source);
        mappings[i] = (MappingImpl) config.getApplicationMapping(type, "/" + i, md.physical, md.archive, md.physicalFirst, true);
    }
    return mappings;
}
Also used : ArrayImpl(lucee.runtime.type.ArrayImpl) Mapping(lucee.runtime.Mapping) MappingImpl(lucee.runtime.MappingImpl) Struct(lucee.runtime.type.Struct) Array(lucee.runtime.type.Array) ConfigWebImpl(lucee.runtime.config.ConfigWebImpl) Entry(java.util.Map.Entry) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList) Key(lucee.runtime.type.Collection.Key)

Example 17 with Mapping

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

the class Admin method doGetComponentMappings.

private void doGetComponentMappings() throws PageException {
    Mapping[] mappings = config.getComponentMappings();
    lucee.runtime.type.Query qry = new QueryImpl(new String[] { "archive", "strarchive", "physical", "strphysical", "virtual", "hidden", "physicalFirst", "readonly", "inspect" }, mappings.length, "query");
    for (int i = 0; i < mappings.length; i++) {
        MappingImpl m = (MappingImpl) mappings[i];
        int row = i + 1;
        qry.setAt("archive", row, m.getArchive());
        qry.setAt("strarchive", row, m.getStrArchive());
        qry.setAt("physical", row, m.getPhysical());
        qry.setAt("strphysical", row, m.getStrPhysical());
        qry.setAt("virtual", row, m.getVirtual());
        qry.setAt("hidden", row, Caster.toBoolean(m.isHidden()));
        qry.setAt("physicalFirst", row, Caster.toBoolean(m.isPhysicalFirst()));
        qry.setAt("readonly", row, Caster.toBoolean(m.isReadonly()));
        qry.setAt("inspect", row, ConfigWebUtil.inspectTemplate(m.getInspectTemplateRaw(), ""));
    }
    pageContext.setVariable(getString("admin", action, "returnVariable"), qry);
}
Also used : QueryImpl(lucee.runtime.type.QueryImpl) Mapping(lucee.runtime.Mapping) MappingImpl(lucee.runtime.MappingImpl) Query(lucee.runtime.type.Query)

Example 18 with Mapping

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

the class Admin method doGetMappings.

private void doGetMappings() throws PageException {
    Mapping[] mappings = config.getMappings();
    lucee.runtime.type.Query qry = new QueryImpl(new String[] { "archive", "strarchive", "physical", "strphysical", "virtual", "hidden", "physicalFirst", "readonly", "inspect", "toplevel" }, mappings.length, "query");
    for (int i = 0; i < mappings.length; i++) {
        MappingImpl m = (MappingImpl) mappings[i];
        int row = i + 1;
        qry.setAt("archive", row, m.getArchive());
        qry.setAt("strarchive", row, m.getStrArchive());
        qry.setAt("physical", row, m.getPhysical());
        qry.setAt("strphysical", row, m.getStrPhysical());
        qry.setAt("virtual", row, m.getVirtual());
        qry.setAt("hidden", row, Caster.toBoolean(m.isHidden()));
        qry.setAt("physicalFirst", row, Caster.toBoolean(m.isPhysicalFirst()));
        qry.setAt("readonly", row, Caster.toBoolean(m.isReadonly()));
        qry.setAt("inspect", row, ConfigWebUtil.inspectTemplate(m.getInspectTemplateRaw(), ""));
        qry.setAt("toplevel", row, Caster.toBoolean(m.isTopLevel()));
    }
    pageContext.setVariable(getString("admin", action, "returnVariable"), qry);
}
Also used : QueryImpl(lucee.runtime.type.QueryImpl) Mapping(lucee.runtime.Mapping) MappingImpl(lucee.runtime.MappingImpl) Query(lucee.runtime.type.Query)

Example 19 with Mapping

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

the class CFTag method cfcStartTag.

// CFC
private int cfcStartTag() throws PageException {
    callerScope.initialize(pageContext);
    try {
        cfc = ComponentLoader.loadComponent(pageContext, source.getPageSource(), ResourceUtil.removeExtension(source.getFilename(), source.getFilename()), false, true);
    } catch (PageException e) {
        Mapping m = source.getPageSource().getMapping();
        ConfigWebImpl c = (ConfigWebImpl) pageContext.getConfig();
        if (m == c.getTagMapping())
            m = c.getServerTagMapping();
        else
            m = null;
        // is te page source from a tag mapping, so perhaps it was moved from server to web context
        if (m != null) {
            PageSource ps = m.getPageSource(source.getFilename());
            try {
                cfc = ComponentLoader.loadComponent(pageContext, ps, ResourceUtil.removeExtension(source.getFilename(), source.getFilename()), false, true);
            } catch (PageException e1) {
                throw e;
            }
        } else
            throw e;
    }
    validateAttributes(cfc, attributesScope, StringUtil.ucFirst(ListUtil.last(source.getPageSource().getComponentName(), '.')));
    boolean exeBody = false;
    try {
        Object rtn = Boolean.TRUE;
        if (cfc.contains(pageContext, KeyConstants._init)) {
            Tag parent = getParent();
            while (parent != null && !(parent instanceof CFTag && ((CFTag) parent).isCFCBasedCustomTag())) {
                parent = parent.getParent();
            }
            Struct args = new StructImpl(Struct.TYPE_LINKED);
            args.set(KeyConstants._HASENDTAG, Caster.toBoolean(hasBody));
            if (parent instanceof CFTag) {
                args.set(PARENT, ((CFTag) parent).getComponent());
            }
            rtn = cfc.callWithNamedValues(pageContext, KeyConstants._init, args);
        }
        if (cfc.contains(pageContext, ON_START_TAG)) {
            Struct args = new StructImpl();
            args.set(KeyConstants._ATTRIBUTES, attributesScope);
            setCaller(pageContext, args);
            rtn = cfc.callWithNamedValues(pageContext, ON_START_TAG, args);
        }
        exeBody = Caster.toBooleanValue(rtn, true);
    } catch (Throwable t) {
        ExceptionUtil.rethrowIfNecessary(t);
        _doCFCCatch(t, "start", true);
    }
    return exeBody ? EVAL_BODY_BUFFERED : SKIP_BODY;
}
Also used : PageException(lucee.runtime.exp.PageException) ConfigWebImpl(lucee.runtime.config.ConfigWebImpl) StructImpl(lucee.runtime.type.StructImpl) Mapping(lucee.runtime.Mapping) TagLibTag(lucee.transformer.library.tag.TagLibTag) Tag(javax.servlet.jsp.tagext.Tag) AppendixTag(lucee.runtime.ext.tag.AppendixTag) PageSource(lucee.runtime.PageSource) Struct(lucee.runtime.type.Struct)

Example 20 with Mapping

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

the class ComponentUtil method getComponentJavaAccess.

// private static final Method INVOKE_PROPERTY = new Method("invoke",Types.OBJECT,new Type[]{Types.STRING,Types.OBJECT_ARRAY});
/**
 * generate a ComponentJavaAccess (CJA) class from a component
 * a CJA is a dynamic genarted java class that has all method defined inside a component as java methods.
 *
 * This is used to generated server side Webservices.
 * @param component
 * @param isNew
 * @return
 * @throws PageException
 */
public static Class getComponentJavaAccess(PageContext pc, Component component, RefBoolean isNew, boolean create, boolean writeLog, boolean suppressWSbeforeArg, boolean output, boolean returnValue) throws PageException {
    isNew.setValue(false);
    String classNameOriginal = component.getPageSource().getClassName();
    String className = getClassname(component, null).concat("_wrap");
    String real = className.replace('.', '/');
    String realOriginal = classNameOriginal.replace('.', '/');
    Mapping mapping = component.getPageSource().getMapping();
    PhysicalClassLoader cl = null;
    try {
        cl = (PhysicalClassLoader) ((PageContextImpl) pc).getRPCClassLoader(false);
    } catch (IOException e) {
        throw Caster.toPageException(e);
    }
    Resource classFile = cl.getDirectory().getRealResource(real.concat(".class"));
    Resource classFileOriginal = mapping.getClassRootDirectory().getRealResource(realOriginal.concat(".class"));
    // check last Mod
    if (classFile.lastModified() >= classFileOriginal.lastModified()) {
        try {
            Class clazz = cl.loadClass(className);
            if (clazz != null && !hasChangesOfChildren(classFile.lastModified(), clazz))
                return registerTypeMapping(clazz);
        } catch (Throwable t) {
            ExceptionUtil.rethrowIfNecessary(t);
        }
    }
    if (!create)
        return null;
    isNew.setValue(true);
    // print.out("new");
    // CREATE CLASS
    ClassWriter cw = ASMUtil.getClassWriter();
    cw.visit(Opcodes.V1_6, Opcodes.ACC_PUBLIC, real, null, "java/lang/Object", null);
    // GeneratorAdapter ga = new GeneratorAdapter(Opcodes.ACC_PUBLIC,Page.STATIC_CONSTRUCTOR,null,null,cw);
    // StaticConstrBytecodeContext statConstr = null;//new BytecodeContext(null,null,null,cw,real,ga,Page.STATIC_CONSTRUCTOR);
    // /ga = new GeneratorAdapter(Opcodes.ACC_PUBLIC,Page.CONSTRUCTOR,null,null,cw);
    // new BytecodeContext(null,null,null,cw,real,ga,Page.CONSTRUCTOR);
    ConstrBytecodeContext constr = null;
    // field component
    // FieldVisitor fv = cw.visitField(Opcodes.ACC_PRIVATE, "c", "Llucee/runtime/ComponentImpl;", null, null);
    // fv.visitEnd();
    java.util.List<LitString> _keys = new ArrayList<LitString>();
    // remote methods
    Collection.Key[] keys = component.keys(Component.ACCESS_REMOTE);
    int max;
    for (int i = 0; i < keys.length; i++) {
        max = -1;
        while ((max = createMethod(constr, _keys, cw, real, component.get(keys[i]), max, writeLog, suppressWSbeforeArg, output, returnValue)) != -1) {
            // for overload remove this
            break;
        }
    }
    // Constructor
    GeneratorAdapter adapter = new GeneratorAdapter(Opcodes.ACC_PUBLIC, CONSTRUCTOR_OBJECT, null, null, cw);
    adapter.loadThis();
    adapter.invokeConstructor(Types.OBJECT, CONSTRUCTOR_OBJECT);
    lucee.transformer.bytecode.Page.registerFields(new BytecodeContext(null, constr, getPage(constr), _keys, cw, real, adapter, CONSTRUCTOR_OBJECT, writeLog, suppressWSbeforeArg, output, returnValue), _keys);
    adapter.returnValue();
    adapter.endMethod();
    cw.visitEnd();
    byte[] barr = cw.toByteArray();
    try {
        ResourceUtil.touch(classFile);
        IOUtil.copy(new ByteArrayInputStream(barr), classFile, true);
        cl = (PhysicalClassLoader) ((PageContextImpl) pc).getRPCClassLoader(true);
        return registerTypeMapping(cl.loadClass(className, barr));
    } catch (Throwable t) {
        ExceptionUtil.rethrowIfNecessary(t);
        throw Caster.toPageException(t);
    }
}
Also used : Resource(lucee.commons.io.res.Resource) ArrayList(java.util.ArrayList) Mapping(lucee.runtime.Mapping) LitString(lucee.transformer.expression.literal.LitString) PageContextImpl(lucee.runtime.PageContextImpl) IOException(java.io.IOException) ConstrBytecodeContext(lucee.transformer.bytecode.ConstrBytecodeContext) ClassWriter(org.objectweb.asm.ClassWriter) LitString(lucee.transformer.expression.literal.LitString) PhysicalClassLoader(lucee.commons.lang.PhysicalClassLoader) ByteArrayInputStream(java.io.ByteArrayInputStream) GeneratorAdapter(org.objectweb.asm.commons.GeneratorAdapter) Key(lucee.runtime.type.Collection.Key) BytecodeContext(lucee.transformer.bytecode.BytecodeContext) ConstrBytecodeContext(lucee.transformer.bytecode.ConstrBytecodeContext)

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