use of lucee.runtime.exp.ExpressionException in project Lucee by lucee.
the class UDFImpl method defineArguments.
private void defineArguments(PageContext pageContext, FunctionArgument[] funcArgs, Struct values, Argument newArgs) throws PageException {
// argumentCollection
UDFUtil.argumentCollection(values, funcArgs);
// print.out(values.size());
Object value;
Collection.Key name;
for (int i = 0; i < funcArgs.length; i++) {
// argument defined
name = funcArgs[i].getName();
value = values.remove(name, NullSupportHelper.NULL(pageContext));
if (value != NullSupportHelper.NULL(pageContext)) {
newArgs.set(name, castToAndClone(pageContext, funcArgs[i], value, i + 1));
continue;
}
value = values.remove(ArgumentIntKey.init(i + 1), NullSupportHelper.NULL(pageContext));
if (value != NullSupportHelper.NULL(pageContext)) {
newArgs.set(name, castToAndClone(pageContext, funcArgs[i], value, i + 1));
continue;
}
// default argument or exception
// funcArgs[i].getDefaultValue();
Object defaultValue = getDefaultValue(pageContext, i, NullSupportHelper.NULL(pageContext));
if (defaultValue == NullSupportHelper.NULL(pageContext)) {
if (funcArgs[i].isRequired()) {
throw new ExpressionException("The parameter " + funcArgs[i].getName() + " to function " + getFunctionName() + " is required but was not passed in.");
}
if (pageContext.getCurrentTemplateDialect() == CFMLEngine.DIALECT_CFML && !pageContext.getConfig().getFullNullSupport())
newArgs.set(name, Argument.NULL);
} else
newArgs.set(name, castTo(pageContext, funcArgs[i], defaultValue, i + 1));
}
Iterator<Entry<Key, Object>> it = values.entryIterator();
Entry<Key, Object> e;
while (it.hasNext()) {
e = it.next();
newArgs.set(e.getKey(), e.getValue());
}
}
use of lucee.runtime.exp.ExpressionException in project Lucee by lucee.
the class UDFSetterProperty method callWithNamedValues.
@Override
public Object callWithNamedValues(PageContext pageContext, Struct values, boolean doIncludePath) throws PageException {
UDFUtil.argumentCollection(values, getFunctionArguments());
Object value = values.get(propName, null);
if (value == null) {
Key[] keys = CollectionUtil.keys(values);
if (keys.length == 1) {
value = values.get(keys[0]);
} else
throw new ExpressionException("The parameter " + prop.getName() + " to function " + getFunctionName() + " is required but was not passed in.");
}
component.getComponentScope().set(propName, cast(pageContext, arguments[0], value, 1));
// make sure it is reconized that set is called by hibernate
// if(component.isPersistent())ORMUtil.getSession(pageContext);
ApplicationContext appContext = pageContext.getApplicationContext();
if (appContext.isORMEnabled() && component.isPersistent())
ORMUtil.getSession(pageContext);
return component;
}
use of lucee.runtime.exp.ExpressionException in project Lucee by lucee.
the class ArraySet method call.
public static boolean call(PageContext pc, Array array, double from, double to, Object value) throws PageException {
int f = (int) from;
int t = (int) to;
if (f < 1)
throw new ExpressionException("Second parameter of the function arraySet must be greater than zero; now [" + f + "]");
if (f > t)
throw new ExpressionException("Third parameter of the function arraySet must be greater than the second parameter; now [second:" + f + ", third:" + t + "]");
if (array.getDimension() > 1)
throw new ExpressionException("Function arraySet can only be used with a one-dimensional array; this array has " + array.getDimension() + " dimensions");
for (int i = f; i <= t; i++) {
array.setE(i, Duplicator.duplicate(value, true));
}
return true;
}
use of lucee.runtime.exp.ExpressionException in project Lucee by lucee.
the class CacheGetDefaultCacheName method call.
public static String call(PageContext pc, String strType) throws PageException {
int type = CacheUtil.toType(strType, Config.CACHE_TYPE_NONE);
if (type == Config.CACHE_TYPE_NONE)
throw new FunctionException(pc, "CacheGetDefaultCacheName", 1, "type", "invalid type defintion [" + strType + "], valid types are [object,resource,template,query]");
ConfigImpl config = (ConfigImpl) pc.getConfig();
CacheConnection conn = config.getCacheDefaultConnection(type);
if (conn == null)
throw new ExpressionException("there is no default cache defined for type [" + strType + "]");
return conn.getName();
}
use of lucee.runtime.exp.ExpressionException in project Lucee by lucee.
the class XMLConfigAdmin method updateCacheConnection.
public void updateCacheConnection(String name, ClassDefinition cd, int _default, Struct custom, boolean readOnly, boolean storage) throws PageException {
checkWriteAccess();
boolean hasAccess = ConfigWebUtil.hasAccess(config, SecurityManagerImpl.TYPE_CACHE);
if (!hasAccess)
throw new SecurityException("no access to update cache connection");
// check parameters
name = name.trim();
if (StringUtil.isEmpty(name))
throw new ExpressionException("name can't be a empty value");
try {
Class clazz;
if (cd.getClassName() != null && cd.getClassName().endsWith(".EHCacheLite"))
clazz = ClassUtil.loadClass(config.getClassLoader(), "org.lucee.extension.cache.eh.EHCache");
else
clazz = ClassUtil.loadClass(config.getClassLoader(), cd.getClassName());
if (!Reflector.isInstaneOf(clazz, Cache.class))
throw new ExpressionException("class [" + clazz.getName() + "] is not of type [" + Cache.class.getName() + "]");
} catch (ClassException e) {
throw new ExpressionException(e.getMessage());
}
Element parent = _getRootElement("cache");
if (name.equalsIgnoreCase(parent.getAttribute("default-template")))
parent.removeAttribute("default-template");
if (name.equalsIgnoreCase(parent.getAttribute("default-object")))
parent.removeAttribute("default-object");
if (name.equalsIgnoreCase(parent.getAttribute("default-query")))
parent.removeAttribute("default-query");
if (name.equalsIgnoreCase(parent.getAttribute("default-resource")))
parent.removeAttribute("default-resource");
if (name.equalsIgnoreCase(parent.getAttribute("default-function")))
parent.removeAttribute("default-function");
if (name.equalsIgnoreCase(parent.getAttribute("default-include")))
parent.removeAttribute("default-include");
if (_default == ConfigImpl.CACHE_TYPE_OBJECT) {
parent.setAttribute("default-object", name);
} else if (_default == ConfigImpl.CACHE_TYPE_TEMPLATE) {
parent.setAttribute("default-template", name);
} else if (_default == ConfigImpl.CACHE_TYPE_QUERY) {
parent.setAttribute("default-query", name);
} else if (_default == ConfigImpl.CACHE_TYPE_RESOURCE) {
parent.setAttribute("default-resource", name);
} else if (_default == ConfigImpl.CACHE_TYPE_FUNCTION) {
parent.setAttribute("default-function", name);
} else if (_default == ConfigImpl.CACHE_TYPE_INCLUDE) {
parent.setAttribute("default-include", name);
} else if (_default == ConfigImpl.CACHE_TYPE_HTTP) {
parent.setAttribute("default-http", name);
} else if (_default == ConfigImpl.CACHE_TYPE_FILE) {
parent.setAttribute("default-file", name);
} else if (_default == ConfigImpl.CACHE_TYPE_WEBSERVICE) {
parent.setAttribute("default-webservice", name);
}
// Update
// boolean isUpdate=false;
Element[] children = XMLConfigWebFactory.getChildren(parent, "connection");
for (int i = 0; i < children.length; i++) {
String n = children[i].getAttribute("name");
Element el = children[i];
if (n.equalsIgnoreCase(name)) {
setClass(el, null, "", cd);
el.setAttribute("custom", toStringURLStyle(custom));
el.setAttribute("read-only", Caster.toString(readOnly));
el.setAttribute("storage", Caster.toString(storage));
return;
}
}
// Insert
Element el = doc.createElement("connection");
parent.appendChild(el);
el.setAttribute("name", name);
setClass(el, null, "", cd);
el.setAttribute("custom", toStringURLStyle(custom));
el.setAttribute("read-only", Caster.toString(readOnly));
el.setAttribute("storage", Caster.toString(storage));
}
Aggregations