X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=publishing%2Forg.argeo.publishing.ui%2Fsrc%2Forg%2Fargeo%2Fdocbook%2FDbkUtils.java;h=b654c73178646597e50badabdbe2c6e13989a725;hb=29670a41b526ec16411eaf7920b30752f0ee6883;hp=6bcecb7b3e9fec2d3efa61161f8d94acffe57210;hpb=d0515f4d4549e59e787803708027ec85057c5a5a;p=gpl%2Fargeo-suite.git 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 6bcecb7..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 @@ -53,6 +53,16 @@ public class DbkUtils { return Jcr.getName(node).equals(type.get()); } + /** Whether this node is a DocBook type. */ + public static boolean isDbk(Node node) { + String name = Jcr.getName(node); + for (DbkType type : DbkType.values()) { + if (name.equals(type.get())) + return true; + } + return false; + } + public static String getTitle(Node node) { return JcrxApi.getXmlValue(node, DbkType.title.get()); } @@ -96,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 {