From: Mathieu Baudier Date: Tue, 6 Jul 2021 10:01:29 +0000 (+0200) Subject: Implement remove if empty paragraph. X-Git-Tag: argeo-suite-2.3.1~34 X-Git-Url: https://git.argeo.org/?p=gpl%2Fargeo-suite.git;a=commitdiff_plain;h=29670a41b526ec16411eaf7920b30752f0ee6883 Implement remove if empty paragraph. --- diff --git a/publishing/org.argeo.publishing.ui/src/org/argeo/docbook/DbkUtils.java b/publishing/org.argeo.publishing.ui/src/org/argeo/docbook/DbkUtils.java index 44346b2..b654c73 100644 --- a/publishing/org.argeo.publishing.ui/src/org/argeo/docbook/DbkUtils.java +++ b/publishing/org.argeo.publishing.ui/src/org/argeo/docbook/DbkUtils.java @@ -106,6 +106,32 @@ public class DbkUtils { return p; } + /** + * Removes a paragraph if it empty. The sesison is not saved. + * + * @return true if the paragraph was empty and it was removed + */ + public static boolean removeIfEmptyParagraph(Node node) { + try { + if (isDbk(node, DbkType.para)) { + NodeIterator nit = node.getNodes(); + if (!nit.hasNext()) + return false;// log this unexpected situation? + Node first = nit.nextNode(); + if (nit.hasNext()) + return false; + String str = JcrxApi.getXmlValue(first); + if (str != null && str.trim().equals("")) { + node.remove(); + return true; + } + } + return false; + } catch (RepositoryException e) { + throw new JcrException("Cannot remove possibly empty paragraph", e); + } + } + public static Node insertImageAfter(Node sibling) { try {