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);
}
}
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;
}
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;
}
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;
}
Aggregations