Author: julien(a)jboss.com
Date: 2008-06-01 19:30:25 -0400 (Sun, 01 Jun 2008)
New Revision: 10894
Modified:
modules/common/trunk/common/src/main/java/org/jboss/portal/common/xml/XMLTools.java
Log:
add XMLTools.getChildren(Element) to get all the element nodes of an element
Modified:
modules/common/trunk/common/src/main/java/org/jboss/portal/common/xml/XMLTools.java
===================================================================
---
modules/common/trunk/common/src/main/java/org/jboss/portal/common/xml/XMLTools.java 2008-06-01
23:15:21 UTC (rev 10893)
+++
modules/common/trunk/common/src/main/java/org/jboss/portal/common/xml/XMLTools.java 2008-06-01
23:30:25 UTC (rev 10894)
@@ -345,6 +345,18 @@
}
/**
+ * Return an iterator for all the children of the given element.
+ *
+ * @param element the parent element
+ * @return an iterator for the designated elements
+ * @throws IllegalArgumentException if the element is null or the name is null
+ */
+ public static Iterator<Element> getChildrenIterator(Element element) throws
IllegalArgumentException
+ {
+ return getChildren(element).iterator();
+ }
+
+ /**
* Return an iterator for all the children of the given element having the specified
name.
*
* @param element the parent element
@@ -373,6 +385,18 @@
}
/**
+ * Return all the children of the given element. The collection object can be
modified.
+ *
+ * @param element the parent element
+ * @return a list of elements
+ * @throws IllegalArgumentException if the element is null or the name is null
+ */
+ public static List<Element> getChildren(Element element) throws
IllegalArgumentException
+ {
+ return getChildren(element, null, null);
+ }
+
+ /**
* Return all the children of the given element having the specified name. The
collection object can be modified.
*
* @param element the parent element
@@ -386,14 +410,22 @@
}
/**
- * Return all the children of the given element having the specified name and the
optionally specified namespace URI.
- * The collection object can be modified.
+ * <p>Return all the children of the given element having the optionally
specified name and the namespace URI.</p>
*
+ * <p>If the URI is specified then the element must have the same URI namespace
in order to be included otherwise
+ * it will be included. If the URI is specified the name matching will be done against
the element local name
+ * otherwise it will be done against the element tag name.</p>
+ *
+ * <p>If the name is specified then the element must have the same tag name or
the same local name to be retained
+ * otherwise it will be included.</p>
+ *
+ * <p>The resulting element collection can be safely modified.</p>
+ *
* @param element the parent element
* @param uri the children uri
* @param name the children name
* @return a list of elements
- * @throws IllegalArgumentException if the element is null or the name is null
+ * @throws IllegalArgumentException if the element is null
*/
public static List<Element> getChildren(Element element, String uri, String
name) throws IllegalArgumentException
{
@@ -401,10 +433,6 @@
{
throw new IllegalArgumentException("No element found");
}
- if (name == null)
- {
- throw new IllegalArgumentException("No name specified");
- }
ArrayList<Element> result = new ArrayList<Element>();
NodeList list = element.getChildNodes();
for (int i = 0; i < list.getLength(); i++)
@@ -417,14 +445,14 @@
//
if (uri == null)
{
- if (childElt.getTagName().equals(name))
+ if (name == null || childElt.getTagName().equals(name))
{
result.add(childElt);
}
}
else if (uri.equals(childElt.getNamespaceURI()))
{
- if (childElt.getLocalName().equals(name))
+ if (name == null || childElt.getLocalName().equals(name))
{
result.add(childElt);
}
Show replies by date