Search in sources :

Example 1 with MCRXPathEvaluator

use of org.mycore.common.xml.MCRXPathEvaluator 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 2 with MCRXPathEvaluator

use of org.mycore.common.xml.MCRXPathEvaluator in project mycore by MyCoRe-Org.

the class MCRJaxenXPathFactoryTest method setUp.

@Before
@Override
public void setUp() throws Exception {
    super.setUp();
    String builder = "document[name/@id='n1'][note/@href='#n1'][location/@href='#n1'][name[@id='n2']][location[@href='#n2']]";
    Element document = new MCRNodeBuilder().buildElement(builder, null, null);
    new Document(document);
    Map<String, Object> variables = new HashMap<>();
    variables.put("CurrentUser", "gast");
    evaluator = new MCRXPathEvaluator(variables, document);
}
Also used : MCRNodeBuilder(org.mycore.common.xml.MCRNodeBuilder) HashMap(java.util.HashMap) Element(org.jdom2.Element) MCRXPathEvaluator(org.mycore.common.xml.MCRXPathEvaluator) Document(org.jdom2.Document) Before(org.junit.Before)

Aggregations

MCRXPathEvaluator (org.mycore.common.xml.MCRXPathEvaluator)2 HashMap (java.util.HashMap)1 Document (org.jdom2.Document)1 Element (org.jdom2.Element)1 Before (org.junit.Before)1 MCRNodeBuilder (org.mycore.common.xml.MCRNodeBuilder)1 MCRBinding (org.mycore.frontend.xeditor.MCRBinding)1