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