[Yanel-commits] rev 28435 -
public/yanel/trunk/src/core/java/org/wyona/yanel/core/util
michi at wyona.com
michi at wyona.com
Sat Nov 3 08:51:19 CET 2007
Author: michi
Date: 2007-11-03 08:51:17 +0100 (Sat, 03 Nov 2007)
New Revision: 28435
Modified:
public/yanel/trunk/src/core/java/org/wyona/yanel/core/util/ConfigurationUtil.java
Log:
bug fixed re very first text node
Modified: public/yanel/trunk/src/core/java/org/wyona/yanel/core/util/ConfigurationUtil.java
===================================================================
--- public/yanel/trunk/src/core/java/org/wyona/yanel/core/util/ConfigurationUtil.java 2007-11-03 00:46:01 UTC (rev 28434)
+++ public/yanel/trunk/src/core/java/org/wyona/yanel/core/util/ConfigurationUtil.java 2007-11-03 07:51:17 UTC (rev 28435)
@@ -23,10 +23,7 @@
import org.w3c.dom.Element;
/**
- * Configuration utility allowing for custom configuration fragments
- *
- * @author ok at ncode.ch
- *
+ * Configuration utility to copy an avalon configuration into a DOM document
*/
public class ConfigurationUtil {
@@ -46,29 +43,35 @@
* The target namespace
* @return
*/
- public static Document getCustomConfiguration(Configuration repoConfigElement, String rootName,
- String rootNamespace) {
- if (repoConfigElement == null || repoConfigElement.getChildren() == null
- || repoConfigElement.getChildren().length == 0) {
- log.debug("Did not find any child elements in " + repoConfigElement);
- return null;
- }
+ public static Document getCustomConfiguration(Configuration repoConfigElement, String rootName, String rootNamespace) {
+ try {
+ if (repoConfigElement == null || repoConfigElement.getChildren() == null || repoConfigElement.getChildren().length == 0) {
+ if (repoConfigElement.getValue() == null) {
+ log.warn("Did not find any child elements nor text within " + repoConfigElement);
+ return null;
+ }
+ }
- log.debug("Creating custom config - rootName=" + rootName + ", rootNamespace="
- + rootNamespace);
+ if (log.isDebugEnabled()) log.debug("Creating custom config - rootName=" + rootName + ", rootNamespace=" + rootNamespace);
- Document doc = null;
- DocumentBuilderFactory dbf = javax.xml.parsers.DocumentBuilderFactory.newInstance();
- dbf.setNamespaceAware(true);
- try {
+ Document doc = null;
+ DocumentBuilderFactory dbf = javax.xml.parsers.DocumentBuilderFactory.newInstance();
+ dbf.setNamespaceAware(true);
javax.xml.parsers.DocumentBuilder parser = dbf.newDocumentBuilder();
org.w3c.dom.DOMImplementation impl = parser.getDOMImplementation();
org.w3c.dom.DocumentType doctype = null;
doc = impl.createDocument(rootNamespace, rootName, doctype);
+ // Copy the very first text node in order to stay backwards compatible
+ Element rootElement = doc.getDocumentElement();
+ if (repoConfigElement.getValue() != null) {
+ if (log.isDebugEnabled()) log.debug("Very first text node: " + repoConfigElement.getValue());
+ rootElement.appendChild(doc.createTextNode(repoConfigElement.getValue()));
+ }
+
+ // Copy elements
Configuration[] children = repoConfigElement.getChildren();
if (children.length > 0) {
- Element rootElement = doc.getDocumentElement();
log.debug("root element " + rootElement);
for (int i = 0; i < children.length; i++) {
rootElement.appendChild(ConfigurationUtil.createElement(children[i], doc));
More information about the Yanel-commits
mailing list