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