Search in sources :

Example 41 with PageContextImpl

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

the class ModernAppListener method onSessionEnd.

@Override
public void onSessionEnd(CFMLFactory factory, String applicationName, String cfid) throws PageException {
    Component app = apps.get(applicationName);
    if (app == null || !app.containsKey(ON_SESSION_END))
        return;
    PageContextImpl pc = null;
    try {
        pc = createPageContext(factory, app, applicationName, cfid, ON_SESSION_END, true, -1);
        call(app, pc, ON_SESSION_END, new Object[] { pc.sessionScope(false), pc.applicationScope() }, true);
    } finally {
        if (pc != null) {
            factory.releaseLuceePageContext(pc, true);
        }
    }
}
Also used : PageContextImpl(lucee.runtime.PageContextImpl) Component(lucee.runtime.Component)

Example 42 with PageContextImpl

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

the class CreateDynamicProxy method _call.

public static Object _call(PageContext pc, Object oCFC, Object oInterfaces) throws PageException, IOException {
    if (SystemUtil.getLoaderVersion() < 5.9D)
        throw new ApplicationException("You need to update your lucee.jar to execute the function [createDynamicProxy], you can download the latest jar from http://download.lucee.org.");
    // Component
    Component cfc;
    if (oCFC instanceof Component)
        cfc = (Component) oCFC;
    else
        cfc = pc.loadComponent(Caster.toString(oCFC));
    // string list to array
    if (Decision.isString(oInterfaces)) {
        String list = Caster.toString(oInterfaces);
        oInterfaces = ListUtil.listToStringArray(list, ',');
    }
    Class[] interfaces = null;
    if (Decision.isArray(oInterfaces)) {
        Object[] arr = Caster.toNativeArray(oInterfaces);
        ClassLoader cl = ((PageContextImpl) pc).getClassLoader();
        interfaces = new Class[arr.length];
        for (int i = 0; i < arr.length; i++) {
            if (arr[i] instanceof JavaObject)
                interfaces[i] = ((JavaObject) arr[i]).getClazz();
            else
                interfaces[i] = ClassUtil.loadClass(cl, Caster.toString(arr[i]));
        }
    // strInterfaces=ListUtil.toStringArray(Caster.toArray(oInterfaces));
    } else if (oInterfaces instanceof JavaObject) {
        interfaces = new Class[] { ((JavaObject) oInterfaces).getClazz() };
    } else
        throw new FunctionException(pc, "CreateDynamicProxy", 2, "interfaces", "invalid type [" + Caster.toClassName(oInterfaces) + "] for class defintion");
    // check if all classes are interfaces
    for (int i = 0; i < interfaces.length; i++) {
        if (!interfaces[i].isInterface())
            throw new FunctionException(pc, "CreateDynamicProxy", 2, "interfaces", "definition [" + interfaces[i].getClass() + "] is a class and not a interface");
    }
    return JavaProxyFactory.createProxy(pc, cfc, null, interfaces);
}
Also used : ApplicationException(lucee.runtime.exp.ApplicationException) JavaObject(lucee.runtime.java.JavaObject) FunctionException(lucee.runtime.exp.FunctionException) JavaObject(lucee.runtime.java.JavaObject) PageContextImpl(lucee.runtime.PageContextImpl) Component(lucee.runtime.Component)

Example 43 with PageContextImpl

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

the class GetTagData method _call.

private static Struct _call(PageContext pc, String nameSpace, String strTagName, int dialect) throws PageException {
    TagLib[] tlds;
    tlds = ((ConfigImpl) pc.getConfig()).getTLDs(dialect);
    TagLib tld = null;
    TagLibTag tag = null;
    for (int i = 0; i < tlds.length; i++) {
        tld = tlds[i];
        if (tld.getNameSpaceAndSeparator().equalsIgnoreCase(nameSpace)) {
            tag = tld.getTag(strTagName.toLowerCase());
            if (tag != null)
                break;
        }
    }
    if (tag == null)
        throw new ExpressionException("tag [" + nameSpace + strTagName + "] is not a built in tag");
    // CFML Based Function
    Class clazz = null;
    try {
        clazz = tag.getTagClassDefinition().getClazz();
    } catch (Throwable t) {
        ExceptionUtil.rethrowIfNecessary(t);
    }
    if (clazz == CFTagCore.class) {
        PageContextImpl pci = (PageContextImpl) pc;
        boolean prior = pci.useSpecialMappings(true);
        try {
            return cfmlBasedTag(pc, tld, tag);
        } finally {
            pci.useSpecialMappings(prior);
        }
    }
    return javaBasedTag(tld, tag);
}
Also used : TagLibTag(lucee.transformer.library.tag.TagLibTag) TagLib(lucee.transformer.library.tag.TagLib) PageContextImpl(lucee.runtime.PageContextImpl) ExpressionException(lucee.runtime.exp.ExpressionException)

Example 44 with PageContextImpl

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

the class ToBinary method call.

public static byte[] call(PageContext pc, Object data, String charset) throws PageException {
    if (!StringUtil.isEmpty(charset)) {
        charset = charset.trim().toLowerCase();
        Charset cs;
        if ("web".equalsIgnoreCase(charset))
            cs = pc.getWebCharset();
        if ("resource".equalsIgnoreCase(charset))
            cs = ((PageContextImpl) pc).getResourceCharset();
        else
            cs = CharsetUtil.toCharset(charset);
        String str = Caster.toString(data);
        return str.getBytes(cs);
    }
    return Caster.toBinary(data);
}
Also used : Charset(java.nio.charset.Charset) PageContextImpl(lucee.runtime.PageContextImpl)

Example 45 with PageContextImpl

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

the class ValueList method toColumn.

protected static QueryColumn toColumn(PageContext pc, String strQueryColumn) throws PageException {
    // if(strQueryColumn.indexOf('.')<1)
    // throw new ExpressionException("invalid query column definition ["+strQueryColumn+"]");
    VariableReference ref = ((PageContextImpl) pc).getVariableReference(strQueryColumn);
    if (ref.getParent() instanceof Scope)
        throw new ExpressionException("invalid query column definition [" + strQueryColumn + "]");
    Query query = Caster.toQuery(ref.getParent());
    return query.getColumn(ref.getKey());
}
Also used : VariableReference(lucee.runtime.type.ref.VariableReference) Scope(lucee.runtime.type.scope.Scope) Query(lucee.runtime.type.Query) PageContextImpl(lucee.runtime.PageContextImpl) ExpressionException(lucee.runtime.exp.ExpressionException)

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