Search in sources :

Example 6 with Page

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

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

the class ComponentUtil method getMetaData.

public static Struct getMetaData(PageContext pc, UDFPropertiesBase udf) throws PageException {
    StructImpl func = new StructImpl();
    pc = ThreadLocalPageContext.get(pc);
    // TODO func.set("roles", value);
    // TODO func.set("userMetadata", value); neo unterstuetzt irgendwelche a
    // meta data
    Struct meta = udf.getMeta();
    if (meta != null)
        StructUtil.copy(meta, func, true);
    func.setEL(KeyConstants._closure, Boolean.FALSE);
    func.set(KeyConstants._access, ComponentUtil.toStringAccess(udf.getAccess()));
    String hint = udf.getHint();
    if (!StringUtil.isEmpty(hint))
        func.set(KeyConstants._hint, hint);
    String displayname = udf.getDisplayName();
    if (!StringUtil.isEmpty(displayname))
        func.set(KeyConstants._displayname, displayname);
    func.set(KeyConstants._name, udf.getFunctionName());
    func.set(KeyConstants._output, Caster.toBoolean(udf.getOutput()));
    func.set(KeyConstants._returntype, udf.getReturnTypeAsString());
    func.set("modifier", udf.getModifier() == Component.MODIFIER_NONE ? "" : ComponentUtil.toModifier(udf.getModifier(), ""));
    func.set(KeyConstants._description, udf.getDescription());
    if (udf.getLocalMode() != null)
        func.set("localMode", AppListenerUtil.toLocalMode(udf.getLocalMode().intValue(), ""));
    if (udf.getPageSource() != null)
        func.set(KeyConstants._owner, udf.getPageSource().getDisplayPath());
    if (udf.getStartLine() > 0 && udf.getEndLine() > 0) {
        Struct pos = new StructImpl();
        pos.set("start", udf.getStartLine());
        pos.set("end", udf.getEndLine());
        func.setEL("position", pos);
    }
    int format = udf.getReturnFormat();
    if (format < 0 || format == UDF.RETURN_FORMAT_WDDX)
        func.set(KeyConstants._returnFormat, "wddx");
    else if (format == UDF.RETURN_FORMAT_PLAIN)
        func.set(KeyConstants._returnFormat, "plain");
    else if (format == UDF.RETURN_FORMAT_JSON)
        func.set(KeyConstants._returnFormat, "json");
    else if (format == UDF.RETURN_FORMAT_SERIALIZE)
        func.set(KeyConstants._returnFormat, "cfml");
    FunctionArgument[] args = udf.getFunctionArguments();
    Array params = new ArrayImpl();
    // Object defaultValue;
    Struct m;
    // Object defaultValue;
    for (int y = 0; y < args.length; y++) {
        StructImpl param = new StructImpl();
        param.set(KeyConstants._name, args[y].getName().getString());
        param.set(KeyConstants._required, Caster.toBoolean(args[y].isRequired()));
        param.set(KeyConstants._type, args[y].getTypeAsString());
        displayname = args[y].getDisplayName();
        if (!StringUtil.isEmpty(displayname))
            param.set(KeyConstants._displayname, displayname);
        int defType = args[y].getDefaultType();
        if (defType == FunctionArgument.DEFAULT_TYPE_RUNTIME_EXPRESSION) {
            param.set(KeyConstants._default, "[runtime expression]");
        } else if (defType == FunctionArgument.DEFAULT_TYPE_LITERAL) {
            Page p = udf.getPage(pc);
            param.set(KeyConstants._default, p.udfDefaultValue(pc, udf.getIndex(), y, null));
        }
        hint = args[y].getHint();
        if (!StringUtil.isEmpty(hint))
            param.set(KeyConstants._hint, hint);
        // TODO func.set("userMetadata", value); neo unterstuetzt irgendwelche attr, die dann hier ausgebenen werden bloedsinn
        // meta data
        m = args[y].getMetaData();
        if (m != null)
            StructUtil.copy(m, param, true);
        params.append(param);
    }
    func.set(KeyConstants._parameters, params);
    return func;
}
Also used : Array(lucee.runtime.type.Array) StructImpl(lucee.runtime.type.StructImpl) ArrayImpl(lucee.runtime.type.ArrayImpl) Page(lucee.runtime.Page) LitString(lucee.transformer.expression.literal.LitString) FunctionArgument(lucee.runtime.type.FunctionArgument) Struct(lucee.runtime.type.Struct)

Example 8 with Page

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

the class UDFPropertiesBase method getPage.

public final Page getPage(PageContext pc) throws PageException {
    // MUST no page source
    PageException pe = null;
    if (getPageSource() != null) {
        try {
            return ComponentUtil.getPage(pc, getPageSource());
        } catch (PageException e) {
            pe = e;
        }
    }
    Page p = getPage();
    if (p != null)
        return p;
    if (pe != null)
        throw pe;
    throw new ApplicationException("missing Page Source");
}
Also used : PageException(lucee.runtime.exp.PageException) ApplicationException(lucee.runtime.exp.ApplicationException) Page(lucee.runtime.Page)

Example 9 with Page

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

the class Renderer method loadClass.

private static Class<? extends Page> loadClass(ConfigWeb config, String className, String cfml, int dialect, boolean ignoreScopes) throws Exception {
    ConfigWebImpl cw = (ConfigWebImpl) config;
    CFMLCompilerImpl compiler = cw.getCompiler();
    // create className based o the content
    Class<? extends Page> clazz = null;
    if (mcl == null) {
        mcl = createMemoryClassLoader(cw);
    } else
        clazz = ClassUtil.loadClass(mcl, className, null);
    if (clazz != null)
        return clazz;
    SourceCode sc = new SourceCode(cfml, false, dialect);
    // compile
    lucee.runtime.compiler.CFMLCompilerImpl.Result result = compiler.compile(cw, sc, cw.getTLDs(dialect), cw.getFLDs(dialect), null, className, true, ignoreScopes);
    // before we add a new class, we make sure we are still in range
    if (mcl.getSize() + result.barr.length > MAX_SIZE) {
        mcl = createMemoryClassLoader(cw);
        pages.clear();
    }
    return (Class<? extends Page>) mcl.loadClass(className, result.barr);
}
Also used : ConfigWebImpl(lucee.runtime.config.ConfigWebImpl) SourceCode(lucee.transformer.util.SourceCode) Page(lucee.runtime.Page)

Example 10 with Page

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

the class MetadataUtil method hasChanged.

private static boolean hasChanged(PageContext pc, long lastMetaCreation, ComponentImpl component) throws PageException {
    if (component == null)
        return false;
    // check the component
    Page p = getPage(pc, component._getPageSource());
    if (p == null || hasChanged(p.getCompileTime(), lastMetaCreation))
        return true;
    // check interfaces
    Interface[] interfaces = component.getInterfaces();
    if (!ArrayUtil.isEmpty(interfaces)) {
        if (hasChanged(pc, lastMetaCreation, interfaces))
            return true;
    }
    // check base
    return hasChanged(pc, lastMetaCreation, (ComponentImpl) component.getBaseComponent());
}
Also used : Page(lucee.runtime.Page) Interface(lucee.runtime.Interface)

Aggregations

Page (lucee.runtime.Page)10 ConfigWebImpl (lucee.runtime.config.ConfigWebImpl)3 PageException (lucee.runtime.exp.PageException)3 Component (lucee.runtime.Component)2 PageContextImpl (lucee.runtime.PageContextImpl)2 PageSource (lucee.runtime.PageSource)2 ConfigImpl (lucee.runtime.config.ConfigImpl)2 ExpressionException (lucee.runtime.exp.ExpressionException)2 Struct (lucee.runtime.type.Struct)2 StructImpl (lucee.runtime.type.StructImpl)2 Entry (java.util.Map.Entry)1 DevNullOutputStream (lucee.commons.io.DevNullOutputStream)1 Log (lucee.commons.io.log.Log)1 Pair (lucee.commons.lang.Pair)1 CIObject (lucee.runtime.CIObject)1 CIPage (lucee.runtime.CIPage)1 ComponentImpl (lucee.runtime.ComponentImpl)1 Interface (lucee.runtime.Interface)1 Mapping (lucee.runtime.Mapping)1 PageContext (lucee.runtime.PageContext)1