use of lucee.runtime.exp.PageException in project Lucee by lucee.
the class VariableInterpreter method getVariableEL.
/**
* get a variable from page context
* @param pc Page Context
* @param var variable string to get value to
* @param defaultValue value returnded if variable was not found
* @return the value or default value if not found
*/
public static Object getVariableEL(PageContext pc, String var, Object defaultValue) {
StringList list = parse(pc, new ParserString(var), false);
if (list == null)
return defaultValue;
int scope = scopeString2Int(pc.ignoreScopes(), list.next());
Object coll = null;
if (scope == Scope.SCOPE_UNDEFINED) {
coll = pc.undefinedScope().get(KeyImpl.init(list.current()), NullSupportHelper.NULL());
if (coll == NullSupportHelper.NULL())
return defaultValue;
} else {
try {
coll = VariableInterpreter.scope(pc, scope, list.hasNext());
// coll=pc.scope(scope);
} catch (PageException e) {
return defaultValue;
}
}
while (list.hasNext()) {
coll = pc.getVariableUtil().get(pc, coll, KeyImpl.init(list.next()), NullSupportHelper.NULL());
if (coll == NullSupportHelper.NULL())
return defaultValue;
}
return coll;
}
use of lucee.runtime.exp.PageException in project Lucee by lucee.
the class JavaObject method get.
public Object get(PageContext pc, String propertyName, Object defaultValue) {
if (isInit) {
return variableUtil.get(pc, object, propertyName, defaultValue);
}
// Field
Field[] fields = Reflector.getFieldsIgnoreCase(clazz, propertyName, null);
if (!ArrayUtil.isEmpty(fields) && Modifier.isStatic(fields[0].getModifiers())) {
try {
return fields[0].get(null);
} catch (Exception e) {
}
}
// Getter
MethodInstance mi = Reflector.getGetterEL(clazz, propertyName);
if (mi != null) {
if (Modifier.isStatic(mi.getMethod().getModifiers())) {
try {
return mi.invoke(null);
} catch (Exception e) {
}
}
}
try {
return variableUtil.get(pc, init(), propertyName, defaultValue);
} catch (PageException e1) {
return defaultValue;
}
}
use of lucee.runtime.exp.PageException in project Lucee by lucee.
the class ScriptEngineImpl method put.
@Override
public void put(String key, Object value) {
PageContext oldPC = ThreadLocalPageContext.get();
PageContext pc = getPageContext(getContext());
try {
pc.undefinedScope().set(KeyImpl.init(key), value);
} catch (PageException e) {
// ignored
} finally {
releasePageContext(pc, oldPC);
}
}
use of lucee.runtime.exp.PageException in project Lucee by lucee.
the class ModernApplicationContext method initJava.
private void initJava() {
if (!initJavaSettings) {
Object o = get(component, JAVA_SETTING, null);
if (o != null && Decision.isStruct(o)) {
Struct sct = Caster.toStruct(o, null);
// loadPaths
Object obj = sct.get(KeyImpl.init("loadPaths"), null);
List<Resource> paths;
if (obj != null) {
paths = loadPaths(ThreadLocalPageContext.get(), obj);
} else
paths = new ArrayList<Resource>();
// loadCFMLClassPath
Boolean loadCFMLClassPath = Caster.toBoolean(sct.get(KeyImpl.init("loadCFMLClassPath"), null), null);
if (loadCFMLClassPath == null)
loadCFMLClassPath = Caster.toBoolean(sct.get(KeyImpl.init("loadColdFusionClassPath"), null), null);
if (loadCFMLClassPath == null)
loadCFMLClassPath = javaSettings.loadCFMLClassPath();
// reloadOnChange
boolean reloadOnChange = Caster.toBooleanValue(sct.get(KeyImpl.init("reloadOnChange"), null), javaSettings.reloadOnChange());
// watchInterval
int watchInterval = Caster.toIntValue(sct.get(KeyImpl.init("watchInterval"), null), javaSettings.watchInterval());
// watchExtensions
obj = sct.get(KeyImpl.init("watchExtensions"), null);
List<String> extensions = new ArrayList<String>();
if (obj != null) {
Array arr;
if (Decision.isArray(obj)) {
try {
arr = Caster.toArray(obj);
} catch (PageException e) {
arr = new ArrayImpl();
}
} else {
arr = lucee.runtime.type.util.ListUtil.listToArrayRemoveEmpty(Caster.toString(obj, ""), ',');
}
Iterator<Object> it = arr.valueIterator();
String ext;
while (it.hasNext()) {
ext = Caster.toString(it.next(), null);
if (StringUtil.isEmpty(ext))
continue;
ext = ext.trim();
if (ext.startsWith("."))
ext = ext.substring(1);
if (ext.startsWith("*."))
ext = ext.substring(2);
extensions.add(ext);
}
}
javaSettings = new JavaSettingsImpl(paths.toArray(new Resource[paths.size()]), loadCFMLClassPath, reloadOnChange, watchInterval, extensions.toArray(new String[extensions.size()]));
}
initJavaSettings = true;
}
}
use of lucee.runtime.exp.PageException in project Lucee by lucee.
the class ObjectLoad method call.
public static Object call(PageContext pc, Object input) throws PageException {
InputStream is;
boolean closeStream = true;
if (Decision.isBinary(input)) {
is = new ByteArrayInputStream(Caster.toBinary(input));
} else if (input instanceof InputStream) {
is = (InputStream) input;
closeStream = false;
} else {
Resource res = ResourceUtil.toResourceExisting(pc, Caster.toString(input));
pc.getConfig().getSecurityManager().checkFileLocation(res);
try {
is = res.getInputStream();
} catch (IOException e) {
throw Caster.toPageException(e);
}
}
try {
return JavaConverter.deserialize(is);
} catch (Exception e) {
throw Caster.toPageException(e);
} finally {
if (closeStream)
IOUtil.closeEL(is);
}
}
Aggregations