use of org.mycore.frontend.xeditor.MCRBinding in project mycore by MyCoRe-Org.
the class MCRXEditorValidator method isValid.
public boolean isValid() throws JDOMException, JaxenException {
MCRBinding root = session.getRootBinding();
for (MCRValidator rule : validationRules) {
rule.validate(results, root);
}
session.getVariables().put(XED_VALIDATION_FAILED, String.valueOf(!results.isValid()));
return results.isValid();
}
use of org.mycore.frontend.xeditor.MCRBinding in project mycore by MyCoRe-Org.
the class MCRXPathTestValidator method validateBinding.
@Override
public boolean validateBinding(MCRValidationResults results, MCRBinding binding) {
// all nodes must validate
boolean isValid = true;
List<Object> boundNodes = binding.getBoundNodes();
for (int i = 0; i < boundNodes.size(); i++) {
Object node = boundNodes.get(i);
String absPath = MCRXPathBuilder.buildXPath(node);
if (results.hasError(absPath)) {
continue;
}
MCRBinding nodeBinding = new MCRBinding(i + 1, binding);
MCRXPathEvaluator evaluator = nodeBinding.getXPathEvaluator();
boolean result = evaluator.test(xPathExpression);
nodeBinding.detach();
results.mark(absPath, result, this);
isValid = isValid && result;
}
return isValid;
}
use of org.mycore.frontend.xeditor.MCRBinding in project mycore by MyCoRe-Org.
the class MCRRemoveTarget method handleRepeaterControl.
protected void handleRepeaterControl(ServletContext context, MCRServletJob job, MCREditorSession session, String xPath) throws Exception {
MCRBinding binding = new MCRBinding(xPath, false, session.getRootBinding());
binding.removeBoundNode(0);
binding.detach();
session.setBreakpoint("After handling target remove " + xPath);
}
use of org.mycore.frontend.xeditor.MCRBinding in project mycore by MyCoRe-Org.
the class MCRSubselectReturnTarget method bindsFirstOrMoreThanOneElement.
private boolean bindsFirstOrMoreThanOneElement(String xPath, MCREditorSession session) throws JaxenException, JDOMException {
MCRBinding binding = new MCRBinding(xPath, false, session.getRootBinding());
boolean result = (binding.getBoundNode() instanceof Element) && !xPath.endsWith("]");
binding.detach();
return result;
}
use of org.mycore.frontend.xeditor.MCRBinding 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());
}
Aggregations