Search in sources :

Example 71 with Selection

use of com.dexels.navajo.document.Selection in project navajo by Dexels.

the class TestSelection method testIsSelectedWithInteger2.

@Test
public void testIsSelectedWithInteger2() {
    Selection selectionRet = NavajoFactory.getInstance().createSelection(testDoc, "firstselection", "0", 11);
    selectionRet.setValue("1");
    Assert.assertTrue(selectionRet.isSelected());
}
Also used : Selection(com.dexels.navajo.document.Selection) Test(org.junit.Test)

Example 72 with Selection

use of com.dexels.navajo.document.Selection in project navajo by Dexels.

the class TestSelection method testSetName.

@Test
public void testSetName() {
    Selection selectionRet = NavajoFactory.getInstance().createSelection(testDoc, "firstselection", "0", true);
    selectionRet.setName("another");
    Assert.assertEquals(selectionRet.getName(), "another");
}
Also used : Selection(com.dexels.navajo.document.Selection) Test(org.junit.Test)

Example 73 with Selection

use of com.dexels.navajo.document.Selection in project navajo by Dexels.

the class GetSelectedName 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 GetSelectedName: Parameter null");
    }
    if (o instanceof Property) {
        Property p = (Property) o;
        if (p.getSelected() != null) {
            return (p.getAllSelectedSelections().size() > 0 ? p.getSelected().getName() : null);
        } else {
            return null;
        }
    }
    if (!(o instanceof List)) {
        throw new TMLExpressionException(this, "Invalid function call in GetSelectedName: Not a selection property, but (" + o.getClass() + ")");
    }
    List<Selection> l = (List<Selection>) o;
    for (Selection selection : l) {
        if (selection.isSelected()) {
            return selection.getName();
        }
    }
    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 74 with Selection

use of com.dexels.navajo.document.Selection in project navajo by Dexels.

the class Size method main.

public static void main(String[] args) throws Exception {
    Navajo n = NavajoFactory.getInstance().createNavajo();
    Message m = NavajoFactory.getInstance().createMessage(n, "Aap");
    n.addMessage(m);
    Property p = NavajoFactory.getInstance().createProperty(n, "Selection", "+", "", "out");
    m.addProperty(p);
    Selection s = NavajoFactory.getInstance().createSelection(n, "Aap", "0", false);
    p.addSelection(s);
    n.write(System.err);
    Operand o = Expression.evaluate("GetPropertyType('/Aap/Selection') == 'selection' AND Size([Aap/Selection]) == 0", n);
    System.err.println("o " + o.value + ", type: " + o.type);
}
Also used : Message(com.dexels.navajo.document.Message) Selection(com.dexels.navajo.document.Selection) Operand(com.dexels.navajo.document.Operand) Navajo(com.dexels.navajo.document.Navajo) Property(com.dexels.navajo.document.Property)

Example 75 with Selection

use of com.dexels.navajo.document.Selection in project navajo by Dexels.

the class PropertyMap method store.

@Override
public void store() throws MappableException, UserException {
    try {
        Message msg = access.getCurrentOutMessage();
        if (msg == null) {
            throw new UserException(-1, "PropertyMap adapter can only be called from within a constructed output message");
        }
        Property prop = null;
        prop = msg.getProperty(name);
        if (prop != null && !removeExisting) {
            throw new UserException(-1, "Cannot add already existing property " + name + " when removeExisting is false.");
        }
        // this will create if property not found and otherwise update value and other attributes, except for subtype and the options
        // Do not have to pass inDoc as we're not creating a param
        prop = MappingUtils.setProperty(false, msg, name, currentValue, type, null, direction, description, length == null ? -1 : length, outMessage, null, false);
        if (subtype != null) {
            prop.setSubType(subtype);
        }
        // For the selection property, parse the given optionList and the multiple setting
        if (Property.SELECTION_PROPERTY.equals(type)) {
            if (optionList != null) {
                prop.clearSelections();
                for (Option o : optionList) {
                    Selection sel = NavajoFactory.getInstance().createSelection(outMessage, o.getName(), o.getValue(), o.getSelected());
                    prop.addSelectionWithoutReplace(sel);
                }
            }
            prop.setCardinality(multiple ? "+" : "1");
        }
    } catch (Exception e) {
        throw new UserException(-1, e.getMessage(), e);
    }
}
Also used : Message(com.dexels.navajo.document.Message) Selection(com.dexels.navajo.document.Selection) UserException(com.dexels.navajo.script.api.UserException) Property(com.dexels.navajo.document.Property) UserException(com.dexels.navajo.script.api.UserException) MappableException(com.dexels.navajo.script.api.MappableException)

Aggregations

Selection (com.dexels.navajo.document.Selection)78 Property (com.dexels.navajo.document.Property)36 Test (org.junit.Test)32 Message (com.dexels.navajo.document.Message)24 Navajo (com.dexels.navajo.document.Navajo)21 Access (com.dexels.navajo.script.api.Access)14 ImmutableMessage (com.dexels.immutable.api.ImmutableMessage)13 ContextExpression (com.dexels.navajo.expression.api.ContextExpression)12 TipiLink (com.dexels.navajo.expression.api.TipiLink)12 MappableTreeNode (com.dexels.navajo.script.api.MappableTreeNode)12 ArrayList (java.util.ArrayList)12 Optional (java.util.Optional)12 Operand (com.dexels.navajo.document.Operand)11 TMLExpressionException (com.dexels.navajo.expression.api.TMLExpressionException)11 List (java.util.List)8 NavajoException (com.dexels.navajo.document.NavajoException)6 UserException (com.dexels.navajo.script.api.UserException)4 Binary (com.dexels.navajo.document.types.Binary)3 FunctionClassification (com.dexels.navajo.expression.api.FunctionClassification)3 StringTokenizer (java.util.StringTokenizer)3