Search in sources :

Example 6 with MCRRepeatBinding

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());
}
Also used : MCRNodeBuilder(org.mycore.common.xml.MCRNodeBuilder) MCRRepeatBinding(org.mycore.frontend.xeditor.MCRRepeatBinding) Element(org.jdom2.Element) Document(org.jdom2.Document) MCRBinding(org.mycore.frontend.xeditor.MCRBinding) Test(org.junit.Test)

Example 7 with MCRRepeatBinding

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();
}
Also used : MCRRepeatBinding(org.mycore.frontend.xeditor.MCRRepeatBinding) MCRBinding(org.mycore.frontend.xeditor.MCRBinding)

Aggregations

MCRBinding (org.mycore.frontend.xeditor.MCRBinding)7 MCRRepeatBinding (org.mycore.frontend.xeditor.MCRRepeatBinding)7 Document (org.jdom2.Document)6 Element (org.jdom2.Element)6 Test (org.junit.Test)6 MCRNodeBuilder (org.mycore.common.xml.MCRNodeBuilder)6