From: Aron Roberts Date: Tue, 4 Mar 2014 03:19:19 +0000 (-0800) Subject: CSPACE-6329: Added XML element text node editing. Handle null values for attribute... X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=43d23f63aa5b2672eaffa74cb548041134ff9f24;p=tmp%2Fjakarta-migration.git CSPACE-6329: Added XML element text node editing. Handle null values for attribute and element values. --- diff --git a/3rdparty/nuxeo/nuxeo-server/5.5-HF07/config/proto-repo-config.xml b/3rdparty/nuxeo/nuxeo-server/5.5-HF07/config/proto-repo-config.xml index 88fca73b0..87f8f86da 100644 --- a/3rdparty/nuxeo/nuxeo-server/5.5-HF07/config/proto-repo-config.xml +++ b/3rdparty/nuxeo/nuxeo-server/5.5-HF07/config/proto-repo-config.xml @@ -1,12 +1,12 @@ + point="repository"> + factory="org.nuxeo.ecm.core.storage.sql.ra.PoolingRepositoryFactory"> + blockingTimeoutMillis="100" idleTimeoutMinutes="10" /> @@ -21,7 +21,7 @@ + point="repositories"> The default repository diff --git a/services/common/src/main/java/org/collectionspace/services/common/ServiceMain.java b/services/common/src/main/java/org/collectionspace/services/common/ServiceMain.java index 7971a95c0..bdba40bbd 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/ServiceMain.java +++ b/services/common/src/main/java/org/collectionspace/services/common/ServiceMain.java @@ -182,6 +182,8 @@ public class ServiceMain { logger.warn("After second attribute edit=\n" + repoDoc.asXML()); repoDoc = XmlTools.setAttributeValue(repoDoc, "/component/extension[@point='repositories']/repository", "name", repositoryName); logger.warn("After third attribute edit=\n" + repoDoc.asXML()); + repoDoc = XmlTools.setElementValue(repoDoc, "/component/extension[@point='repository']/repository/repository/property[@name='DatabaseName']", repositoryName); + logger.warn("After first element edit=\n" + repoDoc.asXML()); // FIXME: Edit additional element and/or attribute values. // FIXME: Emit serialized XML and write it to an appropriately named file // in the Nuxeo server config directory. @@ -189,6 +191,9 @@ public class ServiceMain { } } } + } else { + logger.error(String.format("Could not either find, or read, the prototype Nuxeo config file '%s'", + prototypeNuxeoConfigFile.getCanonicalPath())); } // // Start up and initialize our embedded Nuxeo server instance diff --git a/services/common/src/main/java/org/collectionspace/services/common/XmlTools.java b/services/common/src/main/java/org/collectionspace/services/common/XmlTools.java index ca958aee0..baaa526b3 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/XmlTools.java +++ b/services/common/src/main/java/org/collectionspace/services/common/XmlTools.java @@ -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());