X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;ds=sidebyside;f=org.argeo.jcr%2Fsrc%2Forg%2Fargeo%2Fjcr%2FJcrxApi.java;h=666b2593e5992dbb980f8e12e43c194fddb1f5c4;hb=46cc2039ac20703c484aa994b830a2da113f2c97;hp=0223b69444a94054564603947bc4e178e438ae93;hpb=07ca7beb63daec5a9ca19a0879174c953a16e406;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.jcr/src/org/argeo/jcr/JcrxApi.java b/org.argeo.jcr/src/org/argeo/jcr/JcrxApi.java index 0223b6944..666b2593e 100644 --- a/org.argeo.jcr/src/org/argeo/jcr/JcrxApi.java +++ b/org.argeo.jcr/src/org/argeo/jcr/JcrxApi.java @@ -30,22 +30,33 @@ public class JcrxApi { * XML */ /** - * Set as a subnode which will be exported as an XML element. + * Get the XML text of this child node. */ public static String getXmlValue(Node node, String name) { try { if (!node.hasNode(name)) return null; Node child = node.getNode(name); - if (!child.hasNode(Jcr.JCR_XMLTEXT)) + return getXmlValue(child); + } catch (RepositoryException e) { + throw new IllegalStateException("Cannot get " + name + " as XML text", e); + } + } + + /** + * Get the XML text of this node. + */ + public static String getXmlValue(Node node) { + try { + if (!node.hasNode(Jcr.JCR_XMLTEXT)) return null; - Node xmlText = child.getNode(Jcr.JCR_XMLTEXT); + Node xmlText = node.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); + throw new IllegalStateException("Cannot get " + node + " as XML text", e); } } @@ -56,14 +67,22 @@ public class JcrxApi { try { if (node.hasNode(name)) { Node child = node.getNode(name); - if (!child.hasNode(Jcr.JCR_XMLTEXT)) - child.addNode(Jcr.JCR_XMLTEXT, JcrxType.JCRX_XMLTEXT); - child.getNode(Jcr.JCR_XMLTEXT).setProperty(Jcr.JCR_XMLCHARACTERS, value); + setXmlValue(node, child, value); } else node.addNode(name, JcrxType.JCRX_XMLVALUE).addNode(Jcr.JCR_XMLTEXT, JcrxType.JCRX_XMLTEXT) .setProperty(Jcr.JCR_XMLCHARACTERS, value); } catch (RepositoryException e) { - throw new IllegalStateException("Cannot set " + name + " as XML text", e); + throw new JcrException("Cannot set " + name + " as XML text", e); + } + } + + public static void setXmlValue(Node node, Node child, String value) { + try { + if (!child.hasNode(Jcr.JCR_XMLTEXT)) + child.addNode(Jcr.JCR_XMLTEXT, JcrxType.JCRX_XMLTEXT); + child.getNode(Jcr.JCR_XMLTEXT).setProperty(Jcr.JCR_XMLCHARACTERS, value); + } catch (RepositoryException e) { + throw new JcrException("Cannot set " + child + " as XML text", e); } }