Search in sources :

Example 26 with TMLExpressionException

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);
}
Also used : Navajo(com.dexels.navajo.document.Navajo) TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException)

Example 27 with TMLExpressionException

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;
}
Also used : Selection(com.dexels.navajo.document.Selection) List(java.util.List) TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException) Property(com.dexels.navajo.document.Property)

Example 28 with TMLExpressionException

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));
}
Also used : MalformedURLException(java.net.MalformedURLException) TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException) URL(java.net.URL)

Example 29 with TMLExpressionException

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);
    }
}
Also used : AbstractVersion(com.dexels.navajo.version.AbstractVersion) TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException) TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException)

Example 30 with TMLExpressionException

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();
}
Also used : StringTokenizer(java.util.StringTokenizer) TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException)

Aggregations

TMLExpressionException (com.dexels.navajo.expression.api.TMLExpressionException)129 Message (com.dexels.navajo.document.Message)26 Navajo (com.dexels.navajo.document.Navajo)26 Binary (com.dexels.navajo.document.types.Binary)23 Property (com.dexels.navajo.document.Property)17 ArrayList (java.util.ArrayList)16 Operand (com.dexels.navajo.document.Operand)15 List (java.util.List)13 NavajoException (com.dexels.navajo.document.NavajoException)12 IOException (java.io.IOException)12 Selection (com.dexels.navajo.document.Selection)11 Access (com.dexels.navajo.script.api.Access)10 Calendar (java.util.Calendar)10 ContextExpression (com.dexels.navajo.expression.api.ContextExpression)9 Test (org.junit.Test)9 Money (com.dexels.navajo.document.types.Money)8 SystemException (com.dexels.navajo.script.api.SystemException)8 StringTokenizer (java.util.StringTokenizer)8 ImmutableMessage (com.dexels.immutable.api.ImmutableMessage)7 ClockTime (com.dexels.navajo.document.types.ClockTime)7