Search in sources :

Example 1 with ComponentImpl

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

the class TagUtil method addTagMetaData.

private static void addTagMetaData(PageContext pc, TagLib tl, TagLibTag tlt, String filename, boolean isWeb) {
    if (pc == null)
        return;
    try {
        ConfigWebImpl config = (ConfigWebImpl) pc.getConfig();
        PageSource ps = isWeb ? config.getTagMapping().getPageSource(filename) : config.getServerTagMapping().getPageSource(filename);
        // Page p = ps.loadPage(pc);
        ComponentImpl c = ComponentLoader.loadComponent(pc, ps, filename, true, true);
        ComponentSpecificAccess cw = ComponentSpecificAccess.toComponentSpecificAccess(Component.ACCESS_PRIVATE, c);
        Struct meta = Caster.toStruct(cw.get(KeyConstants._metadata, null), null);
        // TODO handle all metadata here and make checking at runtime useless
        if (meta != null) {
            // parse body
            boolean rtexprvalue = Caster.toBooleanValue(meta.get(KeyConstants._parsebody, Boolean.FALSE), false);
            tlt.setParseBody(rtexprvalue);
            // hint
            String hint = Caster.toString(meta.get(KeyConstants._hint, null), null);
            if (!StringUtil.isEmpty(hint))
                tlt.setDescription(hint);
        }
    } catch (Throwable t) {
        ExceptionUtil.rethrowIfNecessary(t);
    }
}
Also used : ConfigWebImpl(lucee.runtime.config.ConfigWebImpl) ComponentSpecificAccess(lucee.runtime.ComponentSpecificAccess) ComponentImpl(lucee.runtime.ComponentImpl) PageSource(lucee.runtime.PageSource) Struct(lucee.runtime.type.Struct)

Example 2 with ComponentImpl

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

the class ComponentLoader method _search.

private static Object _search(PageContext pc, PageSource loadingLocation, String rawPath, Boolean searchLocal, Boolean searchRoot, boolean executeConstr, short returnType, final boolean isExtendedComponent) throws PageException {
    PageSource currPS = pc.getCurrentPageSource(null);
    ImportDefintion[] importDefintions = null;
    if (currPS != null) {
        Page currP;
        Component cfc = pc.getActiveComponent();
        if (cfc instanceof ComponentImpl && currPS.equals(cfc.getPageSource())) {
            importDefintions = ((ComponentImpl) cfc)._getImportDefintions();
        } else if ((currP = currPS.loadPage(pc, false, null)) != null) {
            importDefintions = currP.getImportDefintions();
        }
    }
    int dialect = currPS == null ? pc.getCurrentTemplateDialect() : currPS.getDialect();
    // first try for the current dialect
    Object obj = _search(pc, loadingLocation, rawPath, searchLocal, searchRoot, executeConstr, returnType, currPS, importDefintions, dialect, isExtendedComponent);
    // then we try the opposite dialect
    if (obj == null && ((ConfigImpl) pc.getConfig()).allowLuceeDialect()) {
        // only when the lucee dialect is enabled we have to check the opposite
        obj = _search(pc, loadingLocation, rawPath, searchLocal, searchRoot, executeConstr, returnType, currPS, importDefintions, dialect == CFMLEngine.DIALECT_CFML ? CFMLEngine.DIALECT_LUCEE : CFMLEngine.DIALECT_CFML, isExtendedComponent);
    }
    if (obj == null)
        throw new ExpressionException("invalid " + toStringType(returnType, dialect) + " definition, can't find " + toStringType(returnType, dialect) + " [" + rawPath + "]");
    return obj;
}
Also used : Page(lucee.runtime.Page) CIPage(lucee.runtime.CIPage) CIObject(lucee.runtime.CIObject) Component(lucee.runtime.Component) ComponentImpl(lucee.runtime.ComponentImpl) ExpressionException(lucee.runtime.exp.ExpressionException) PageSource(lucee.runtime.PageSource)

Example 3 with ComponentImpl

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

the class ComponentLoader method initComponent.

private static ComponentImpl initComponent(PageContext pc, CIPage page, String callPath, boolean isRealPath, final boolean isExtendedComponent, boolean executeConstr) throws PageException {
    // is not a component, then it has to be a interface
    if (!(page instanceof ComponentPageImpl))
        throw new ApplicationException("you cannot instantiate the interface [" + page.getPageSource().getDisplayPath() + "] as a component (" + page.getClass().getName() + "" + (page instanceof InterfacePageImpl) + ")");
    ComponentPageImpl cp = (ComponentPageImpl) page;
    ComponentImpl c = cp.newInstance(pc, callPath, isRealPath, isExtendedComponent, executeConstr);
    // abstract/final check
    if (!isExtendedComponent) {
        if (c.getModifier() == Component.MODIFIER_ABSTRACT)
            throw new ApplicationException("you cannot instantiate an abstract component [" + page.getPageSource().getDisplayPath() + "], this component can only be extended by other components");
    } else if (c.getModifier() == Component.MODIFIER_FINAL)
        throw new ApplicationException("you cannot extend a final component [" + page.getPageSource().getDisplayPath() + "]");
    c.setInitalized(true);
    return c;
}
Also used : InterfacePageImpl(lucee.runtime.InterfacePageImpl) ApplicationException(lucee.runtime.exp.ApplicationException) ComponentPageImpl(lucee.runtime.ComponentPageImpl) ComponentImpl(lucee.runtime.ComponentImpl)

Example 4 with ComponentImpl

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

the class ComponentLoader method _loadComponent.

private static ComponentImpl _loadComponent(PageContext pc, CIPage page, String callPath, boolean isRealPath, final boolean isExtendedComponent, boolean executeConstr) throws PageException {
    ComponentImpl rtn = null;
    if (pc.getConfig().debug()) {
        DebugEntryTemplate debugEntry = pc.getDebugger().getEntry(pc, page.getPageSource());
        pc.addPageSource(page.getPageSource(), true);
        long currTime = pc.getExecutionTime();
        long exeTime = 0;
        long time = System.nanoTime();
        try {
            debugEntry.updateFileLoadTime((int) (System.nanoTime() - time));
            exeTime = System.nanoTime();
            rtn = initComponent(pc, page, callPath, isRealPath, isExtendedComponent, executeConstr);
        } finally {
            if (rtn != null)
                rtn.setLoaded(true);
            long diff = ((System.nanoTime() - exeTime) - (pc.getExecutionTime() - currTime));
            pc.setExecutionTime(pc.getExecutionTime() + (System.nanoTime() - time));
            debugEntry.updateExeTime(diff);
            pc.removeLastPageSource(true);
        }
    } else // no debug
    {
        pc.addPageSource(page.getPageSource(), true);
        try {
            rtn = initComponent(pc, page, callPath, isRealPath, isExtendedComponent, executeConstr);
        } finally {
            if (rtn != null)
                rtn.setLoaded(true);
            pc.removeLastPageSource(true);
        }
    }
    return rtn;
}
Also used : DebugEntryTemplate(lucee.runtime.debug.DebugEntryTemplate) ComponentImpl(lucee.runtime.ComponentImpl)

Aggregations

ComponentImpl (lucee.runtime.ComponentImpl)4 PageSource (lucee.runtime.PageSource)2 CIObject (lucee.runtime.CIObject)1 CIPage (lucee.runtime.CIPage)1 Component (lucee.runtime.Component)1 ComponentPageImpl (lucee.runtime.ComponentPageImpl)1 ComponentSpecificAccess (lucee.runtime.ComponentSpecificAccess)1 InterfacePageImpl (lucee.runtime.InterfacePageImpl)1 Page (lucee.runtime.Page)1 ConfigWebImpl (lucee.runtime.config.ConfigWebImpl)1 DebugEntryTemplate (lucee.runtime.debug.DebugEntryTemplate)1 ApplicationException (lucee.runtime.exp.ApplicationException)1 ExpressionException (lucee.runtime.exp.ExpressionException)1 Struct (lucee.runtime.type.Struct)1