use of com.dexels.navajo.expression.api.TMLExpressionException in project navajo by Dexels.
the class ExistsProperty method evaluate.
@Override
public Object evaluate() throws TMLExpressionException {
if (getOperands().size() != 1) {
throw new TMLExpressionException(this, "Invalid function call");
}
Object o = getOperand(0);
if (!(o instanceof String)) {
throw new TMLExpressionException(this, "Invalid function call");
}
Navajo in = getNavajo();
return (in.getProperty((String) o) != null);
}
use of com.dexels.navajo.expression.api.TMLExpressionException in project navajo by Dexels.
the class GetSelectedValue method evaluate.
@Override
@SuppressWarnings("unchecked")
public Object evaluate() throws com.dexels.navajo.expression.api.TMLExpressionException {
if (getOperands().size() != 1) {
throw new TMLExpressionException(this, "Invalid function call, need one parameter");
}
Object o = operand(0).value;
if (o == null) {
throw new TMLExpressionException(this, "Invalid function call in GetSelectedValue: Parameter null");
}
if (o instanceof Property) {
Property p = (Property) o;
if (p.getSelected() != null) {
return (p.getAllSelectedSelections().size() > 0 ? p.getSelected().getValue() : null);
} else {
return null;
}
}
if (!(o instanceof List)) {
throw new TMLExpressionException(this, "Invalid function call in GetSelectedValue: Not a selection property");
}
List<Selection> l = (List<Selection>) o;
for (Selection selection : l) {
if (selection.isSelected()) {
return selection.getValue();
}
}
return null;
}
use of com.dexels.navajo.expression.api.TMLExpressionException in project navajo by Dexels.
the class GetUrlSize method evaluate.
@Override
public final Object evaluate() throws TMLExpressionException {
// input (ArrayList, Object).
if (this.getOperands().size() != 1)
throw new TMLExpressionException("GetUrlSize(String) expected");
Object a = this.getOperands().get(0);
if (a == null) {
return null;
}
if (!(a instanceof String))
throw new TMLExpressionException("GetUrlSize(String) expected");
URL u;
try {
u = new URL((String) a);
} catch (MalformedURLException e) {
throw new TMLExpressionException("GetUrlSize: bad url: " + a);
}
return Integer.valueOf(getUrlLength(u));
}
use of com.dexels.navajo.expression.api.TMLExpressionException in project navajo by Dexels.
the class GetVersionInfo method evaluate.
@Override
public final Object evaluate() throws TMLExpressionException {
Object o = getOperand(0);
String packageName = o + "";
try {
Class<?> c = null;
if (DispatcherFactory.getInstance().getNavajoConfig().getClassloader() == null) {
c = Class.forName(packageName + ".Version");
} else {
c = Class.forName(packageName + ".Version", true, DispatcherFactory.getInstance().getNavajoConfig().getClassloader());
}
AbstractVersion v = (AbstractVersion) c.getDeclaredConstructor().newInstance();
return v.toString();
} catch (Exception e) {
throw new TMLExpressionException(this, "Could not find version object for package: " + packageName);
}
}
use of com.dexels.navajo.expression.api.TMLExpressionException in project navajo by Dexels.
the class GetInitials method evaluate.
@Override
public final Object evaluate() throws com.dexels.navajo.expression.api.TMLExpressionException {
Object a = this.getOperands().get(0);
String text;
try {
text = (String) a;
} catch (ClassCastException e) {
text = a.toString();
}
if (text == null) {
throw new TMLExpressionException("GetInitials(): failed because the input was null");
}
StringTokenizer tokens = new StringTokenizer(text, " ");
String result = "";
while (tokens.hasMoreTokens()) {
String name = tokens.nextToken();
result = result + name.substring(0, 1) + ".";
}
return result.trim();
}
Aggregations