use of org.mycore.frontend.xeditor.MCRRepeatBinding in project mycore by MyCoRe-Org.
the class MCRSwapInsertTargetTest method testSwap.
@Test
public void testSwap() throws JaxenException, JDOMException {
Element template = new MCRNodeBuilder().buildElement("parent[name='a'][note][foo][name='b'][note[2]]", null, null);
Document doc = new Document(template);
MCRBinding root = new MCRBinding(doc);
MCRRepeatBinding repeat = new MCRRepeatBinding("parent/name", root, 2, 0, "build");
assertEquals(2, repeat.getBoundNodes().size());
assertEquals("a", doc.getRootElement().getChildren().get(0).getText());
assertEquals("b", doc.getRootElement().getChildren().get(3).getText());
assertEquals("a", ((Element) (repeat.getBoundNodes().get(0))).getText());
assertEquals("b", ((Element) (repeat.getBoundNodes().get(1))).getText());
repeat.bindRepeatPosition();
String swapParam = MCRSwapTarget.getSwapParameter(repeat, MCRSwapTarget.MOVE_DOWN);
new MCRSwapTarget().handle(swapParam, root);
assertEquals("b", doc.getRootElement().getChildren().get(0).getText());
assertEquals("a", doc.getRootElement().getChildren().get(3).getText());
}
use of org.mycore.frontend.xeditor.MCRRepeatBinding in project mycore by MyCoRe-Org.
the class MCRSwapInsertTarget method handle.
public void handle(String swapParameter, MCRBinding root) throws JaxenException, JDOMException {
String[] tokens = swapParameter.split("\\|");
String parentXPath = tokens[0];
String posString = tokens[1];
int pos = Integer.parseInt(posString);
String method = tokens[2];
String elementNameWithPredicates = swapParameter.substring(parentXPath.length() + posString.length() + method.length() + 3);
MCRBinding parentBinding = new MCRBinding(parentXPath, false, root);
MCRRepeatBinding repeatBinding = new MCRRepeatBinding(elementNameWithPredicates, parentBinding, method);
handle(pos, repeatBinding);
repeatBinding.detach();
parentBinding.detach();
}
Aggregations