Search in sources :

Example 1 with MCRBinding

use of org.mycore.frontend.xeditor.MCRBinding 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 MCRBinding

use of org.mycore.frontend.xeditor.MCRBinding 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 MCRBinding

use of org.mycore.frontend.xeditor.MCRBinding 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 MCRBinding

use of org.mycore.frontend.xeditor.MCRBinding 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 MCRBinding

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

the class MCRXEditorValidatorTest method checkResult.

private void checkResult(MCREditorSession session, String xPath, String marker) throws JaxenException, JDOMException {
    MCRBinding binding = new MCRBinding(xPath, false, session.getRootBinding());
    session.getValidator().setValidationMarker(binding);
    assertEquals(marker, session.getVariables().get(MCRXEditorValidator.XED_VALIDATION_MARKER));
}
Also used : MCRBinding(org.mycore.frontend.xeditor.MCRBinding)

Aggregations

MCRBinding (org.mycore.frontend.xeditor.MCRBinding)16 Element (org.jdom2.Element)9 Document (org.jdom2.Document)8 Test (org.junit.Test)8 MCRNodeBuilder (org.mycore.common.xml.MCRNodeBuilder)8 MCRRepeatBinding (org.mycore.frontend.xeditor.MCRRepeatBinding)7 Attribute (org.jdom2.Attribute)2 MCRXPathEvaluator (org.mycore.common.xml.MCRXPathEvaluator)1