Search in sources :

Example 11 with MCRBinding

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

the class MCRSwapInsertTargetTest method testSwap.

@Test
public void testSwap() throws JaxenException, JDOMException {
    Element template = new MCRNodeBuilder().buildElement("parent[name='a'][note][foo][name='b'][note[2]]", null, null);
    Document doc = new Document(template);
    MCRBinding root = new MCRBinding(doc);
    MCRRepeatBinding repeat = new MCRRepeatBinding("parent/name", root, 2, 0, "build");
    assertEquals(2, repeat.getBoundNodes().size());
    assertEquals("a", doc.getRootElement().getChildren().get(0).getText());
    assertEquals("b", doc.getRootElement().getChildren().get(3).getText());
    assertEquals("a", ((Element) (repeat.getBoundNodes().get(0))).getText());
    assertEquals("b", ((Element) (repeat.getBoundNodes().get(1))).getText());
    repeat.bindRepeatPosition();
    String swapParam = MCRSwapTarget.getSwapParameter(repeat, MCRSwapTarget.MOVE_DOWN);
    new MCRSwapTarget().handle(swapParam, root);
    assertEquals("b", doc.getRootElement().getChildren().get(0).getText());
    assertEquals("a", doc.getRootElement().getChildren().get(3).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 12 with MCRBinding

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

the class MCRChangeTrackerTest method testRemoveChangeTracking.

@Test
public void testRemoveChangeTracking() throws JaxenException, JDOMException {
    String template = "document[titles[title][title[2]]][authors/author[first='John'][last='Doe']]";
    Document doc = new Document(new MCRNodeBuilder().buildElement(template, null, null));
    MCRChangeTracker tracker = new MCRChangeTracker();
    Element titles = (Element) (new MCRBinding("document/titles", true, new MCRBinding(doc)).getBoundNode());
    Element title = new Element("title").setAttribute("type", "alternative");
    titles.addContent(2, title);
    tracker.track(MCRAddedElement.added(title));
    Attribute lang = new Attribute("lang", "de");
    doc.getRootElement().setAttribute(lang);
    tracker.track(MCRAddedAttribute.added(lang));
    Element author = (Element) (new MCRBinding("document/authors/author", true, new MCRBinding(doc)).getBoundNode());
    tracker.track(MCRRemoveElement.remove(author));
    doc = MCRChangeTracker.removeChangeTracking(doc);
    assertFalse(doc.getDescendants(Filters.processinginstruction()).iterator().hasNext());
}
Also used : MCRNodeBuilder(org.mycore.common.xml.MCRNodeBuilder) Attribute(org.jdom2.Attribute) Element(org.jdom2.Element) Document(org.jdom2.Document) MCRBinding(org.mycore.frontend.xeditor.MCRBinding) Test(org.junit.Test)

Example 13 with MCRBinding

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

the class MCRChangeTrackerTest method testCompleteUndo.

@Test
public void testCompleteUndo() throws JaxenException, JDOMException {
    String template = "document[titles[title][title[2]]][authors/author[first='John'][last='Doe']]";
    Document doc = new Document(new MCRNodeBuilder().buildElement(template, null, null));
    Document before = doc.clone();
    MCRChangeTracker tracker = new MCRChangeTracker();
    Element titles = (Element) (new MCRBinding("document/titles", true, new MCRBinding(doc)).getBoundNode());
    Element title = new Element("title").setAttribute("type", "alternative");
    titles.addContent(2, title);
    tracker.track(MCRAddedElement.added(title));
    Attribute lang = new Attribute("lang", "de");
    doc.getRootElement().setAttribute(lang);
    tracker.track(MCRAddedAttribute.added(lang));
    Element author = (Element) (new MCRBinding("document/authors/author", true, new MCRBinding(doc)).getBoundNode());
    tracker.track(MCRRemoveElement.remove(author));
    tracker.undoChanges(doc);
    assertTrue(MCRXMLHelper.deepEqual(before, doc));
}
Also used : MCRNodeBuilder(org.mycore.common.xml.MCRNodeBuilder) Attribute(org.jdom2.Attribute) Element(org.jdom2.Element) Document(org.jdom2.Document) MCRBinding(org.mycore.frontend.xeditor.MCRBinding) Test(org.junit.Test)

Example 14 with MCRBinding

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

the class MCRValidator method validate.

public boolean validate(MCRValidationResults results, MCRBinding root) throws JaxenException, JDOMException {
    MCRBinding binding = new MCRBinding(xPath, false, root);
    boolean isValid = validateBinding(results, binding);
    binding.detach();
    return isValid;
}
Also used : MCRBinding(org.mycore.frontend.xeditor.MCRBinding)

Example 15 with MCRBinding

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

the class MCRSubselectTarget method handleSubmission.

public void handleSubmission(ServletContext context, MCRServletJob job, MCREditorSession session, String parameter) throws Exception {
    session.getSubmission().setSubmittedValues(job.getRequest().getParameterMap());
    int pos = parameter.lastIndexOf(":");
    String xPath = parameter.substring(0, pos);
    String href = decode(parameter.substring(pos + 1));
    LOGGER.info("New subselect for {} using pattern {}", xPath, href);
    MCRBinding binding = new MCRBinding(xPath, false, session.getRootBinding());
    href = binding.getXPathEvaluator().replaceXPaths(href, true);
    binding.detach();
    session.setBreakpoint("After starting subselect at " + href + " for " + xPath);
    href += (href.contains("?") ? "&" : "?") + PARAM_SUBSELECT_SESSION + "=" + session.getCombinedSessionStepID();
    LOGGER.info("Redirecting to subselect {}", href);
    job.getResponse().sendRedirect(job.getResponse().encodeRedirectURL(href));
}
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