+ refresh(section);
+ layoutPage();
+ for (Control control : section.getChildren()) {
+ if (control instanceof SectionPart) {
+ SectionPart sectionPart = (SectionPart) control;
+ Node partNode = sectionPart.getNode();
+ if (partNode.getPath().equals(node.getPath()))
+ return sectionPart;
+ }
+ }
+ throw new IllegalStateException("New section part " + node + "not found");
+ } catch (RepositoryException e) {
+ throw new JcrException("Cannot insert part " + node + " in section " + section.getNode(), e);
+ }
+ }
+
+ void addParagraph(SectionPart partBefore, String txt) {
+ Section section = partBefore.getSection();
+ SectionPart nextSectionPart = section.nextSectionPart(partBefore);
+ Node newNode = addDbk(section.getNode(), para);
+ textInterpreter.write(newNode, txt != null ? txt : "");
+ if (nextSectionPart != null) {
+ try {
+ Node nextNode = nextSectionPart.getNode();
+ section.getNode().orderBefore(Jcr.getIndexedName(newNode), Jcr.getIndexedName(nextNode));
+ } catch (RepositoryException e) {
+ throw new JcrException("Cannot order " + newNode + " before " + nextSectionPart.getNode(), e);
+ }
+ }
+ Jcr.save(newNode);
+ Paragraph paragraph = (Paragraph) insertPart(partBefore.getSection(), newNode);
+ edit(paragraph, 0);
+ }
+
+ void deletePart(SectionPart sectionPart) {
+ try {
+ Node node = sectionPart.getNode();
+ Session session = node.getSession();
+ if (sectionPart instanceof DbkImg) {
+ if (!isDbk(node, DbkType.mediaobject))
+ throw new IllegalArgumentException("Node " + node + " is not a media object.");
+ }
+ node.remove();
+ session.save();
+ if (sectionPart instanceof Control)
+ ((Control) sectionPart).dispose();
+ layoutPage();
+ } catch (RepositoryException e1) {
+ throw new JcrException("Cannot delete " + sectionPart, e1);
+ }
+ }
+
+ void deleteSection(Section section) {
+ try {
+ Node node = section.getNode();
+ Session session = node.getSession();
+ node.remove();