use of org.jdom2.JDOMException 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());
}
use of org.jdom2.JDOMException 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());
}
use of org.jdom2.JDOMException 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));
}
use of org.jdom2.JDOMException 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());
}
use of org.jdom2.JDOMException in project mycore by MyCoRe-Org.
the class MCRXEditorValidatorTest method addRule.
private void addRule(MCREditorSession session, String baseXPath, String... attributes) throws JDOMException {
Element rule = new Element("validation-rule");
for (int i = 0; i < attributes.length; ) {
rule.setAttribute(attributes[i++], attributes[i++]);
}
new Document(rule);
org.w3c.dom.Element ruleAsDOMElement = new DOMOutputter().output(rule);
session.getValidator().addRule(baseXPath, ruleAsDOMElement);
}
Aggregations