Return-Path: Delivered-To: apmail-incubator-geronimo-cvs-archive@www.apache.org Received: (qmail 98791 invoked from network); 1 Jan 2004 22:42:50 -0000 Received: from daedalus.apache.org (HELO mail.apache.org) (208.185.179.12) by minotaur-2.apache.org with SMTP; 1 Jan 2004 22:42:50 -0000 Received: (qmail 36816 invoked by uid 500); 1 Jan 2004 22:42:36 -0000 Delivered-To: apmail-incubator-geronimo-cvs-archive@incubator.apache.org Received: (qmail 36703 invoked by uid 500); 1 Jan 2004 22:42:35 -0000 Mailing-List: contact geronimo-cvs-help@incubator.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: list-post: Reply-To: geronimo-dev@incubator.apache.org Delivered-To: mailing list geronimo-cvs@incubator.apache.org Received: (qmail 36690 invoked from network); 1 Jan 2004 22:42:35 -0000 Received: from unknown (HELO minotaur.apache.org) (209.237.227.194) by daedalus.apache.org with SMTP; 1 Jan 2004 22:42:35 -0000 Received: (qmail 98785 invoked by uid 1712); 1 Jan 2004 22:42:48 -0000 Date: 1 Jan 2004 22:42:48 -0000 Message-ID: <20040101224248.98784.qmail@minotaur.apache.org> From: djencks@apache.org To: incubator-geronimo-cvs@apache.org Subject: cvs commit: incubator-geronimo/modules/core/src/java/org/apache/geronimo/xml/deployment LoaderUtil.java X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N djencks 2004/01/01 14:42:48 Modified: modules/core/src/java/org/apache/geronimo/xml/deployment LoaderUtil.java Log: Geronimo-137, improved null/missing element handling Revision Changes Path 1.10 +35 -24 incubator-geronimo/modules/core/src/java/org/apache/geronimo/xml/deployment/LoaderUtil.java Index: LoaderUtil.java =================================================================== RCS file: /home/cvs/incubator-geronimo/modules/core/src/java/org/apache/geronimo/xml/deployment/LoaderUtil.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- LoaderUtil.java 18 Nov 2003 02:12:33 -0000 1.9 +++ LoaderUtil.java 1 Jan 2004 22:42:48 -0000 1.10 @@ -59,11 +59,11 @@ import java.io.IOException; import java.io.Reader; import java.util.LinkedList; + import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; + import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; @@ -77,24 +77,26 @@ * @version $Revision$ $Date$ */ public final class LoaderUtil { - private static final Log log = LogFactory.getLog(LoaderUtil.class); public static String getContent(Element element) { + if (element == null) { + return null; + } LinkedList nodes = new LinkedList(); nodes.add(element); StringBuffer buf = new StringBuffer(100); while (!nodes.isEmpty()) { Node node = (Node) nodes.removeFirst(); switch (node.getNodeType()) { - case Node.ELEMENT_NODE: - for (Node child = node.getLastChild(); child != null; child = child.getPreviousSibling()) { - nodes.addFirst(child); - } - break; - case Node.TEXT_NODE: - case Node.CDATA_SECTION_NODE: - buf.append(node.getNodeValue()); - break; + case Node.ELEMENT_NODE: + for (Node child = node.getLastChild(); child != null; child = child.getPreviousSibling()) { + nodes.addFirst(child); + } + break; + case Node.TEXT_NODE: + case Node.CDATA_SECTION_NODE: + buf.append(node.getNodeValue()); + break; } } String content = buf.toString().trim(); @@ -106,14 +108,16 @@ } public static String getAttribute(Element element, String attribute) { - if (element.hasAttribute(attribute)) { + if (element != null && element.hasAttribute(attribute)) { return element.getAttribute(attribute); - } else { - return null; } + return null; } public static Element getChild(Element element, String child) { + if (element == null || child == null) { + return null; + } for (Node node = element.getFirstChild(); node != null; node = node.getNextSibling()) { if (node instanceof Element == false) { continue; @@ -127,21 +131,23 @@ } /** - * Gets an array of the direct children of this node with the specified - * tag name + * @return an array of the direct children of this node with the specified + * tag name; never null */ public static Element[] getChildren(Element root, String childName) { + if (root == null || childName == null) { + return new Element[0]; + } NodeList nl = root.getChildNodes(); int max = nl.getLength(); LinkedList list = new LinkedList(); - for(int i=0; i