From 8ee499d4a3d1883512a0e4c5994417fede7c2585 Mon Sep 17 00:00:00 2001 From: Mathieu Baudier Date: Fri, 6 Nov 2020 10:16:53 +0100 Subject: [PATCH] Get XML text returns null if not found. --- org.argeo.jcr/src/org/argeo/jcr/JcrxApi.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) 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); } -- 2.30.2