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());
}
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");
}
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;
}
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);
}
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);
}
}
Aggregations