]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-6329: Added XML element text node editing. Handle null values for attribute...
authorAron Roberts <aron@socrates.berkeley.edu>
Tue, 4 Mar 2014 03:19:19 +0000 (19:19 -0800)
committerAron Roberts <aron@socrates.berkeley.edu>
Tue, 4 Mar 2014 03:19:19 +0000 (19:19 -0800)
3rdparty/nuxeo/nuxeo-server/5.5-HF07/config/proto-repo-config.xml
services/common/src/main/java/org/collectionspace/services/common/ServiceMain.java
services/common/src/main/java/org/collectionspace/services/common/XmlTools.java

index 88fca73b0b0416dc2e710a4367b4a385efa00a1d..87f8f86da07d90feff620cbe75477b0d6002a68c 100644 (file)
@@ -1,12 +1,12 @@
 <?xml version="1.0"?>
 <component name="config:default-repository">
     <extension target="org.nuxeo.ecm.core.repository.RepositoryService"
-                   point="repository">
+               point="repository">
         <repository name="default"
-                            factory="org.nuxeo.ecm.core.storage.sql.ra.PoolingRepositoryFactory">
+                    factory="org.nuxeo.ecm.core.storage.sql.ra.PoolingRepositoryFactory">
             <repository name="default">
                 <pool minPoolSize="0" maxPoolSize="20"
-                                      blockingTimeoutMillis="100" idleTimeoutMinutes="10" />
+                      blockingTimeoutMillis="100" idleTimeoutMinutes="10" />
                 <clustering enabled="false" delay="1000" />
                 <binaryStore path="" />
                 <!-- The transactional datasource for Nuxeo -->
@@ -21,7 +21,7 @@
     </extension>
 
     <extension target="org.nuxeo.ecm.core.api.repository.RepositoryManager"
-                   point="repositories">
+               point="repositories">
         <documentation>The default repository</documentation>
         <repository name="default" label="Default Repository" />
     </extension>
index 7971a95c0237667f0ce6058f1bda7e1b13ca69a8..bdba40bbd0fecf2d80c5a1044bbab345c865a150 100644 (file)
@@ -182,6 +182,8 @@ public class ServiceMain {
                         logger.warn("After second attribute edit=\n" + repoDoc.asXML());\r
                         repoDoc = XmlTools.setAttributeValue(repoDoc, "/component/extension[@point='repositories']/repository", "name", repositoryName);\r
                         logger.warn("After third attribute edit=\n" + repoDoc.asXML());\r
+                        repoDoc = XmlTools.setElementValue(repoDoc, "/component/extension[@point='repository']/repository/repository/property[@name='DatabaseName']", repositoryName);\r
+                        logger.warn("After first element edit=\n" + repoDoc.asXML());\r
                         // FIXME: Edit additional element and/or attribute values.\r
                         // FIXME: Emit serialized XML and write it to an appropriately named file\r
                         // in the Nuxeo server config directory.\r
@@ -189,6 +191,9 @@ public class ServiceMain {
                     }\r
                 }\r
             }\r
+        } else {\r
+            logger.error(String.format("Could not either find, or read, the prototype Nuxeo config file '%s'",\r
+                    prototypeNuxeoConfigFile.getCanonicalPath()));\r
         }\r
         //\r
         // Start up and initialize our embedded Nuxeo server instance\r
index ca958aee02276356192ddc56b175183f4773e806..baaa526b36ebe3f6c7b0c54aa756fcff1e875f4b 100644 (file)
@@ -121,6 +121,35 @@ public class XmlTools {
         return doc;
     }
     
+    /**
+     * Sets the (text node) value of a specified element in a dom4j XML document.
+     * @param   doc  A dom4j XML document.
+     * @param   xpathExpr  An XPath expression intended to match a single element
+     * in the XML document, in the default namespace.
+     * @param   elementValue  The value that the element should contain.
+     * @return  The document with the (text node) value of the matched element, if
+     * any, set to the provided value.
+     */
+    public static Document setElementValue(Document doc, String xpathExpr,
+            String elementValue) {
+        if (Tools.isBlank(xpathExpr)) {
+            return doc;
+        }
+        try {
+            Node node = doc.selectSingleNode(xpathExpr);
+            if ((node == null) || (node.getNodeType() != Node.ELEMENT_NODE)) {
+                return doc;
+            }
+            Element element = (Element) node;
+            element.setText(elementValue == null ? "" : elementValue);
+            return doc;
+        } catch (Exception e) {
+            System.out.println(e.getStackTrace());
+        } finally {
+            return doc;
+        }
+    }
+    
     /**
      * Sets the value of a specified attribute in a dom4j XML document.
      * @param   doc  A dom4j XML document.
@@ -144,7 +173,7 @@ public class XmlTools {
                 return doc;
             }
             Element element = (Element) node;
-            element.addAttribute(attributeName, attributeValue);
+            element.addAttribute(attributeName, attributeValue == null ? "" : attributeValue);
             return doc;
         } catch (Exception e) {
             System.out.println(e.getStackTrace());