Search in sources :

Example 61 with Selection

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

the class BasePropertyImpl method setAllSelected.

public final void setAllSelected(boolean b) {
    for (int i = 0; i < selectionList.size(); i++) {
        Selection current = selectionList.get(i);
        current.setSelected(b);
    }
}
Also used : Selection(com.dexels.navajo.document.Selection)

Example 62 with Selection

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

the class BaseNavajoImpl method getSelection.

@Override
public Selection getSelection(String property) {
    Selection sel = null;
    Property prop = null;
    StringTokenizer tok = new StringTokenizer(property, Navajo.MESSAGE_SEPARATOR);
    Message message = null;
    int count = tok.countTokens();
    int index = 0;
    while (tok.hasMoreElements()) {
        property = tok.nextToken();
        // Check if last message/property reached.
        if (index == (count - 1)) {
            // Reached property field.
            if (message != null) {
                // Check if name contains ":", which denotes a selection.
                if (property.indexOf(':') != -1) {
                    StringTokenizer tok2 = new StringTokenizer(property, ":");
                    String propName = tok2.nextToken();
                    String selName = tok2.nextToken();
                    prop = message.getProperty(propName);
                    sel = prop.getSelection(selName);
                } else {
                    // Does not contain a selection option.
                    return null;
                }
            }
        } else {
            // Descent message tree.
            if (// First message.
            index == 0)
                message = this.getMessage(property);
            else // Subsequent messages.
            if (message == null)
                return null;
            else
                message = message.getMessage(property);
        }
        index++;
    }
    return sel;
}
Also used : StringTokenizer(java.util.StringTokenizer) Message(com.dexels.navajo.document.Message) Selection(com.dexels.navajo.document.Selection) Property(com.dexels.navajo.document.Property)

Example 63 with Selection

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

the class TestSelection method testIsSelectedWithObject0.

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

Example 64 with Selection

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

the class TestSelection method testIsSelectedWithObject4.

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

Example 65 with Selection

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

the class ArraySelection method evaluate.

@Override
public Object evaluate() throws com.dexels.navajo.expression.api.TMLExpressionException {
    if (getOperands().size() < 3) {
        throw new TMLExpressionException(this, usage());
    }
    String messageName = getStringOperand(0);
    String propertyName = getStringOperand(1);
    String valuePropertyName = getStringOperand(2);
    // Message parent = getCurrentMessage();
    Navajo doc = getNavajo();
    Message array = doc.getMessage(messageName);
    if (array == null) {
        throw new TMLExpressionException(this, "Empty or non existing array message: " + messageName);
    }
    List<Message> arrayMsg = array.getAllMessages();
    List<Selection> result = new ArrayList<Selection>();
    if (arrayMsg == null) {
        throw new TMLExpressionException(this, "Empty or non existing array message: " + messageName);
    }
    for (int i = 0; i < arrayMsg.size(); i++) {
        Message m = arrayMsg.get(i);
        Property p = m.getProperty(propertyName);
        Property val = m.getProperty(valuePropertyName);
        Selection s = NavajoFactory.getInstance().createSelection(doc, "" + p.getTypedValue(), "" + val.getTypedValue(), false);
        result.add(s);
    }
    return result;
}
Also used : Message(com.dexels.navajo.document.Message) Selection(com.dexels.navajo.document.Selection) ArrayList(java.util.ArrayList) Navajo(com.dexels.navajo.document.Navajo) TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException) Property(com.dexels.navajo.document.Property)

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