Search in sources :

Example 6 with MCRBinding

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

Example 7 with MCRBinding

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

Example 8 with MCRBinding

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

Example 9 with MCRBinding

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

Example 10 with MCRBinding

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());
}
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)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