Search in sources :

Example 1 with MCRRepeatBinding

use of org.mycore.frontend.xeditor.MCRRepeatBinding in project mycore by MyCoRe-Org.

the class MCRSwapInsertTargetTest method testBuildInsertParam.

@Test
public void testBuildInsertParam() throws JaxenException, JDOMException {
    String x = "mods:mods[mods:name[@type='personal']='p1'][mods:name[@type='personal'][2]='p2'][mods:name[@type='corporate']='c1']";
    Element template = new MCRNodeBuilder().buildElement(x, null, null);
    Document doc = new Document(template);
    MCRBinding root = new MCRBinding(doc);
    MCRRepeatBinding repeat = new MCRRepeatBinding("mods:mods/mods:name[@type='personal']", root, 2, 10, "build");
    repeat.bindRepeatPosition();
    String insertParam = MCRInsertTarget.getInsertParameter(repeat);
    assertEquals("/mods:mods|1|build|mods:name[(@type = \"personal\")]", insertParam);
    repeat.detach();
    new MCRInsertTarget().handle(insertParam, root);
    repeat = new MCRRepeatBinding("mods:mods/mods:name[@type='personal']", root, 1, 10, "build");
    assertEquals(3, repeat.getBoundNodes().size());
    assertEquals("p1", ((Element) (repeat.getBoundNodes().get(0))).getText());
    assertEquals("", ((Element) (repeat.getBoundNodes().get(1))).getText());
    assertEquals("name", ((Element) (repeat.getBoundNodes().get(1))).getName());
    assertEquals("personal", ((Element) (repeat.getBoundNodes().get(1))).getAttributeValue("type"));
    assertEquals("p2", ((Element) (repeat.getBoundNodes().get(2))).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 2 with MCRRepeatBinding

use of org.mycore.frontend.xeditor.MCRRepeatBinding in project mycore by MyCoRe-Org.

the class MCRSwapInsertTargetTest method testCloneInsertParam.

@Test
public void testCloneInsertParam() throws JaxenException, JDOMException {
    String x = "mods:mods[mods:name[@type='personal']='p1'][mods:name[@type='personal'][2]='p2'][mods:name[@type='corporate']='c1']";
    Element template = new MCRNodeBuilder().buildElement(x, null, null);
    Document doc = new Document(template);
    MCRBinding root = new MCRBinding(doc);
    MCRRepeatBinding repeat = new MCRRepeatBinding("mods:mods/mods:name[@type='personal']", root, 2, 10, "clone");
    repeat.bindRepeatPosition();
    String insertParam = MCRInsertTarget.getInsertParameter(repeat);
    assertEquals("/mods:mods|1|clone|mods:name[(@type = \"personal\")]", insertParam);
    repeat.detach();
    new MCRInsertTarget().handle(insertParam, root);
    repeat = new MCRRepeatBinding("mods:mods/mods:name[@type='personal']", root, 1, 10, "build");
    assertEquals(3, repeat.getBoundNodes().size());
    assertEquals("p1", ((Element) (repeat.getBoundNodes().get(0))).getText());
    assertEquals("p1", ((Element) (repeat.getBoundNodes().get(1))).getText());
    assertEquals("name", ((Element) (repeat.getBoundNodes().get(1))).getName());
    assertEquals("personal", ((Element) (repeat.getBoundNodes().get(1))).getAttributeValue("type"));
    assertEquals("p2", ((Element) (repeat.getBoundNodes().get(2))).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 3 with MCRRepeatBinding

use of org.mycore.frontend.xeditor.MCRRepeatBinding in project mycore by MyCoRe-Org.

the class MCRSwapInsertTargetTest method testSwapParameter.

@Test
public void testSwapParameter() throws JaxenException, JDOMException {
    Element template = new MCRNodeBuilder().buildElement("parent[name='aa'][name='ab'][name='bc'][name='ac']", null, null);
    Document doc = new Document(template);
    MCRBinding root = new MCRBinding(doc);
    MCRRepeatBinding repeat = new MCRRepeatBinding("parent/name[contains(text(),'a')]", root, 0, 0, "build");
    assertEquals(3, repeat.getBoundNodes().size());
    repeat.bindRepeatPosition();
    repeat.bindRepeatPosition();
    assertEquals("/parent|1|build|name[contains(text(), \"a\")]", MCRSwapTarget.getSwapParameter(repeat, MCRSwapTarget.MOVE_UP));
    assertEquals("/parent|2|build|name[contains(text(), \"a\")]", MCRSwapTarget.getSwapParameter(repeat, MCRSwapTarget.MOVE_DOWN));
}
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 4 with MCRRepeatBinding

use of org.mycore.frontend.xeditor.MCRRepeatBinding in project mycore by MyCoRe-Org.

the class MCRSwapInsertTargetTest method testBuildInsert.

@Test
public void testBuildInsert() throws JaxenException, JDOMException {
    String x = "mods:mods[mods:name[@type='personal']='p1'][mods:name[@type='personal'][2]='p2'][mods:name[@type='corporate']='c1']";
    Element template = new MCRNodeBuilder().buildElement(x, null, null);
    Document doc = new Document(template);
    MCRBinding root = new MCRBinding(doc);
    MCRRepeatBinding repeat = new MCRRepeatBinding("mods:mods/mods:name[@type='personal']", root, 3, 10, "build");
    assertEquals("mods:name[(@type = \"personal\")]", repeat.getElementNameWithPredicates());
    assertEquals(3, repeat.getBoundNodes().size());
    assertEquals("p1", ((Element) (repeat.getBoundNodes().get(0))).getText());
    assertEquals("p2", ((Element) (repeat.getBoundNodes().get(1))).getText());
    assertEquals("", ((Element) (repeat.getBoundNodes().get(2))).getText());
    assertEquals("name", ((Element) (repeat.getBoundNodes().get(2))).getName());
    assertEquals("personal", ((Element) (repeat.getBoundNodes().get(2))).getAttributeValue("type"));
    repeat.insert(1);
    assertEquals(4, repeat.getBoundNodes().size());
    assertEquals("p1", ((Element) (repeat.getBoundNodes().get(0))).getText());
    assertEquals("", ((Element) (repeat.getBoundNodes().get(1))).getText());
    assertEquals("name", ((Element) (repeat.getBoundNodes().get(1))).getName());
    assertEquals("personal", ((Element) (repeat.getBoundNodes().get(1))).getAttributeValue("type"));
    assertEquals("p2", ((Element) (repeat.getBoundNodes().get(2))).getText());
    repeat = new MCRRepeatBinding("mods:mods/mods:name[@type='corporate']", root, 1, 10, "build");
    assertEquals(1, repeat.getBoundNodes().size());
    assertEquals("mods:name[(@type = \"corporate\")]", repeat.getElementNameWithPredicates());
}
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 5 with MCRRepeatBinding

use of org.mycore.frontend.xeditor.MCRRepeatBinding in project mycore by MyCoRe-Org.

the class MCRSwapInsertTargetTest method testCloneInsert.

@Test
public void testCloneInsert() throws JaxenException, JDOMException {
    String x = "mods:mods[mods:name[@type='personal']='p1'][mods:name[@type='personal'][2]='p2'][mods:name[@type='corporate']='c1']";
    Element template = new MCRNodeBuilder().buildElement(x, null, null);
    Document doc = new Document(template);
    MCRBinding root = new MCRBinding(doc);
    MCRRepeatBinding repeat = new MCRRepeatBinding("mods:mods/mods:name[@type='personal']", root, 3, 10, "clone");
    assertEquals("mods:name[(@type = \"personal\")]", repeat.getElementNameWithPredicates());
    assertEquals(3, repeat.getBoundNodes().size());
    assertEquals("p1", ((Element) (repeat.getBoundNodes().get(0))).getText());
    assertEquals("p2", ((Element) (repeat.getBoundNodes().get(1))).getText());
    assertEquals("p2", ((Element) (repeat.getBoundNodes().get(2))).getText());
    assertEquals("name", ((Element) (repeat.getBoundNodes().get(2))).getName());
    assertEquals("personal", ((Element) (repeat.getBoundNodes().get(2))).getAttributeValue("type"));
    repeat.insert(1);
    assertEquals(4, repeat.getBoundNodes().size());
    assertEquals("p1", ((Element) (repeat.getBoundNodes().get(0))).getText());
    assertEquals("p1", ((Element) (repeat.getBoundNodes().get(1))).getText());
    assertEquals("name", ((Element) (repeat.getBoundNodes().get(1))).getName());
    assertEquals("personal", ((Element) (repeat.getBoundNodes().get(1))).getAttributeValue("type"));
    assertEquals("p2", ((Element) (repeat.getBoundNodes().get(2))).getText());
    repeat = new MCRRepeatBinding("mods:mods/mods:name[@type='corporate']", root, 1, 10, "build");
    assertEquals(1, repeat.getBoundNodes().size());
    assertEquals("mods:name[(@type = \"corporate\")]", repeat.getElementNameWithPredicates());
}
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)

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