From 29670a41b526ec16411eaf7920b30752f0ee6883 Mon Sep 17 00:00:00 2001 From: Mathieu Baudier Date: Tue, 6 Jul 2021 12:01:29 +0200 Subject: [PATCH] Implement remove if empty paragraph. --- .../src/org/argeo/docbook/DbkUtils.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) 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 { -- 2.30.2