Details
-
Improvement
-
Status: Closed
-
Major
-
Resolution: Fixed
-
None
-
None
Description
I need to be able to distinguish between a missing parameter and a parameter with an empty value.
When I add a parameter like this
<param name="namespace"></param>
to my xwork.xml I expected that the property 'namespace' would be set to an empty string. In fact the setter is not called at all because empty elements are discarded. Here is a patch to fix this:
Index: XmlHelper.java
===================================================================
RCS file: /cvs/xwork/src/java/com/opensymphony/xwork/config/providers/XmlHelper.java,v
retrieving revision 1.3
diff -u -r1.3 XmlHelper.java
— XmlHelper.java 8 Dec 2004 11:51:24 -0000 1.3
+++ XmlHelper.java 23 Apr 2005 15:06:36 -0000
@@ -1,50 +1,54 @@
-/*
- * Copyright (c) 2002-2003 by OpenSymphony
- * All rights reserved.
- */
-package com.opensymphony.xwork.config.providers;
-
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-
-import java.util.HashMap;
-
-
-/** - * Created by IntelliJ IDEA.
- * User: Mike
- * Date: May 6, 2003
- * Time: 12:12:03 PM
- * To change this template use Options | File Templates.
- */
-public class XmlHelper { - //~ Methods ////////////////////////////////////////////////////////////////
- - public static HashMap getParams(Element paramsElement) {
- HashMap params = new HashMap();
- - if (paramsElement == null)
{
- return params;
- }
-
- NodeList childNodes = paramsElement.getChildNodes();
- - for (int i = 0; i < childNodes.getLength(); i++) {
- Node childNode = childNodes.item;
- - if ((childNode.getNodeType() == Node.ELEMENT_NODE) && "param".equals(childNode.getNodeName())) {
- Element paramElement = (Element) childNode;
- String paramName = paramElement.getAttribute("name");
- - if (paramElement.getChildNodes().item(0) != null) { - String paramValue = paramElement.getChildNodes().item(0).getNodeValue(); - if (paramValue != null) paramValue = paramValue.trim(); - params.put(paramName, paramValue); - }
- }
- }
- - return params;
- }
-}
+/*
+ * Copyright (c) 2002-2003 by OpenSymphony
+ * All rights reserved.
+ */
+package com.opensymphony.xwork.config.providers;
+
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+import java.util.HashMap;
+
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: Mike
+ * Date: May 6, 2003
+ * Time: 12:12:03 PM
+ * To change this template use Options | File Templates.
+ */
+public class XmlHelper {
+ //~ Methods ////////////////////////////////////////////////////////////////
+
+ public static HashMap getParams(Element paramsElement) {
+ HashMap params = new HashMap();
+
+ if (paramsElement == null) { + return params; + }+
+ NodeList childNodes = paramsElement.getChildNodes();
+
+ for (int i = 0; i < childNodes.getLength(); i++) {
+ Node childNode = childNodes.item;
+
+ if ((childNode.getNodeType() == Node.ELEMENT_NODE) && "param".equals(childNode.getNodeName()))Unknown macro: {+ Element paramElement = (Element) childNode;+ String paramName = paramElement.getAttribute("name");+ String paramValue;+ if (paramElement.getChildNodes().item(0) != null) { + paramValue = paramElement.getChildNodes().item(0).getNodeValue(); + if (paramValue != null) paramValue = paramValue.trim(); + + }+ else { + paramValue = ""; + }+ params.put(paramName, paramValue);+ }+ }
+
+ return params;
+ }
+}