Improve form framework.
[lgpl/argeo-commons.git] / org.argeo.jcr / src / org / argeo / jcr / JcrxApi.java
index 64f22b6034a5c59750bc787837e20abe28758d27..8f1ee9fa9a4f67752dd1661c460f08cb662b72d3 100644 (file)
@@ -54,13 +54,24 @@ public class JcrxApi {
         */
        public static void setXmlValue(Node node, String name, String value) {
                try {
-                       if (node.hasNode(name))
-                               node.getNode(name).getNode(Jcr.JCR_XMLTEXT).setProperty(Jcr.JCR_XMLCHARACTERS, value);
-                       else
+                       if (node.hasNode(name)) {
+                               Node child = node.getNode(name);
+                               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);
                }
        }