From: Mathieu Baudier Date: Fri, 6 Nov 2020 09:16:53 +0000 (+0100) Subject: Get XML text returns null if not found. X-Git-Tag: argeo-commons-2.1.89~38 X-Git-Url: https://git.argeo.org/?p=lgpl%2Fargeo-commons.git;a=commitdiff_plain;h=8ee499d4a3d1883512a0e4c5994417fede7c2585 Get XML text returns null if not found. --- diff --git a/org.argeo.jcr/src/org/argeo/jcr/JcrxApi.java b/org.argeo.jcr/src/org/argeo/jcr/JcrxApi.java index ab34c730e..e35495da5 100644 --- a/org.argeo.jcr/src/org/argeo/jcr/JcrxApi.java +++ b/org.argeo.jcr/src/org/argeo/jcr/JcrxApi.java @@ -35,8 +35,15 @@ public class JcrxApi { public static String getXmlValue(Node node, String name) { try { if (!node.hasNode(name)) - throw new IllegalArgumentException("No XML text named " + name); - return node.getNode(name).getNode(Jcr.JCR_XMLTEXT).getProperty(Jcr.JCR_XMLCHARACTERS).getString(); + return null; + Node child = node.getNode(name); + if (child.hasNode(Jcr.JCR_XMLTEXT)) + return null; + Node xmlText = child.getNode(Jcr.JCR_XMLTEXT); + if (!xmlText.hasProperty(Jcr.JCR_XMLCHARACTERS)) + throw new IllegalArgumentException( + "Node " + xmlText + " has no " + Jcr.JCR_XMLCHARACTERS + " property"); + return xmlText.getProperty(Jcr.JCR_XMLCHARACTERS).getString(); } catch (RepositoryException e) { throw new IllegalStateException("Cannot get " + name + " as XML text", e); }