Author: richard.opalka(a)jboss.com
Date: 2007-09-10 04:33:00 -0400 (Mon, 10 Sep 2007)
New Revision: 4536
Modified:
common/branches/ropalka/trunk/src/main/java/org/jboss/wsf/common/DOMUtils.java
Log:
adding new methods + minor refactoring
Modified: common/branches/ropalka/trunk/src/main/java/org/jboss/wsf/common/DOMUtils.java
===================================================================
---
common/branches/ropalka/trunk/src/main/java/org/jboss/wsf/common/DOMUtils.java 2007-09-10
08:31:54 UTC (rev 4535)
+++
common/branches/ropalka/trunk/src/main/java/org/jboss/wsf/common/DOMUtils.java 2007-09-10
08:33:00 UTC (rev 4536)
@@ -31,6 +31,7 @@
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
+import java.util.List;
import java.util.Map;
import javax.xml.namespace.QName;
@@ -401,6 +402,24 @@
}
}
+ /** True if the node has text child elements only
+ */
+ public static boolean hasTextChildNodesOnly(Node node)
+ {
+ NodeList nodeList = node.getChildNodes();
+ if (nodeList.getLength() == 0)
+ return false;
+
+ for (int i = 0; i < nodeList.getLength(); i++)
+ {
+ Node acksToChildNode = nodeList.item(i);
+ if (acksToChildNode.getNodeType() != Node.TEXT_NODE)
+ return false;
+ }
+
+ return true;
+ }
+
/** True if the node has child elements
*/
public static boolean hasChildElements(Node node)
@@ -494,10 +513,20 @@
{
return getChildElementsIntern(node, nodeName);
}
-
- private static Iterator getChildElementsIntern(Node node, QName nodeName)
+
+ public static List<Element> getChildElementsAsList(Node node, String nodeName)
{
- ArrayList list = new ArrayList();
+ return getChildElementsAsListIntern(node, new QName(nodeName));
+ }
+
+ public static List<Element> getChildElementsAsList(Node node, QName nodeName)
+ {
+ return getChildElementsAsListIntern(node, nodeName);
+ }
+
+ private static List<Element> getChildElementsAsListIntern(Node node, QName
nodeName)
+ {
+ List<Element> list = new ArrayList<Element>();
NodeList nlist = node.getChildNodes();
for (int i = 0; i < nlist.getLength(); i++)
{
@@ -506,7 +535,7 @@
{
if (nodeName == null)
{
- list.add(child);
+ list.add((Element)child);
}
else
{
@@ -521,14 +550,19 @@
}
if (qname.equals(nodeName))
{
- list.add(child);
+ list.add((Element)child);
}
}
}
}
- return list.iterator();
+ return list;
}
+ private static Iterator getChildElementsIntern(Node node, QName nodeName)
+ {
+ return getChildElementsAsListIntern(node, nodeName).iterator();
+ }
+
/** Gets parent element or null if there is none
*/
public static Element getParentElement(Node node)
Show replies by date