11/*
2- * Copyright 2002-2012 the original author or authors.
2+ * Copyright 2002-2013 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
3939 * @author Costin Leau
4040 * @author Arjen Poutsma
4141 * @author Luke Taylor
42+ * @since 1.2
4243 * @see org.w3c.dom.Node
4344 * @see org.w3c.dom.Element
44- * @since 1.2
4545 */
4646public abstract class DomUtils {
4747
4848 /**
49- * Retrieve all child elements of the given DOM element that match any of the given element names. Only look at the
50- * direct child level of the given element; do not go into further depth (in contrast to the DOM API's
51- * {@code getElementsByTagName} method).
52- *
53- * @param ele the DOM element to analyze
49+ * Retrieves all child elements of the given DOM element that match any of the given element names.
50+ * Only looks at the direct child level of the given element; do not go into further depth
51+ * (in contrast to the DOM API's {@code getElementsByTagName} method).
52+ * @param ele the DOM element to analyze
5453 * @param childEleNames the child element names to look for
5554 * @return a List of child {@code org.w3c.dom.Element} instances
5655 * @see org.w3c.dom.Element
@@ -72,11 +71,10 @@ public static List<Element> getChildElementsByTagName(Element ele, String[] chil
7271 }
7372
7473 /**
75- * Retrieve all child elements of the given DOM element that match the given element name. Only look at the direct
76- * child level of the given element; do not go into further depth (in contrast to the DOM API's
77- * {@code getElementsByTagName} method).
78- *
79- * @param ele the DOM element to analyze
74+ * Retrieves all child elements of the given DOM element that match the given element name.
75+ * Only look at the direct child level of the given element; do not go into further depth
76+ * (in contrast to the DOM API's {@code getElementsByTagName} method).
77+ * @param ele the DOM element to analyze
8078 * @param childEleName the child element name to look for
8179 * @return a List of child {@code org.w3c.dom.Element} instances
8280 * @see org.w3c.dom.Element
@@ -88,8 +86,7 @@ public static List<Element> getChildElementsByTagName(Element ele, String childE
8886
8987 /**
9088 * Utility method that returns the first child element identified by its name.
91- *
92- * @param ele the DOM element to analyze
89+ * @param ele the DOM element to analyze
9390 * @param childEleName the child element name to look for
9491 * @return the {@code org.w3c.dom.Element} instance, or {@code null} if none found
9592 */
@@ -108,8 +105,7 @@ public static Element getChildElementByTagName(Element ele, String childEleName)
108105
109106 /**
110107 * Utility method that returns the first child element value identified by its name.
111- *
112- * @param ele the DOM element to analyze
108+ * @param ele the DOM element to analyze
113109 * @param childEleName the child element name to look for
114110 * @return the extracted text value, or {@code null} if no child element found
115111 */
@@ -119,9 +115,8 @@ public static String getChildElementValueByTagName(Element ele, String childEleN
119115 }
120116
121117 /**
122- * Retrieve all child elements of the given DOM element
123-
124- * @param ele the DOM element to analyze
118+ * Retrieves all child elements of the given DOM element
119+ * @param ele the DOM element to analyze
125120 * @return a List of child {@code org.w3c.dom.Element} instances
126121 */
127122 public static List <Element > getChildElements (Element ele ) {
@@ -138,9 +133,10 @@ public static List<Element> getChildElements(Element ele) {
138133 }
139134
140135 /**
141- * Extract the text value from the given DOM element, ignoring XML comments. <p>Appends all CharacterData nodes and
142- * EntityReference nodes into a single String value, excluding Comment nodes.
143- *
136+ * Extracts the text value from the given DOM element, ignoring XML comments.
137+ * <p>Appends all CharacterData nodes and EntityReference nodes into a single
138+ * String value, excluding Comment nodes. Only exposes actual user-specified
139+ * text, no default values of any kind.
144140 * @see CharacterData
145141 * @see EntityReference
146142 * @see Comment
@@ -159,8 +155,9 @@ public static String getTextValue(Element valueEle) {
159155 }
160156
161157 /**
162- * Namespace-aware equals comparison. Returns {@code true} if either {@link Node#getLocalName} or {@link
163- * Node#getNodeName} equals {@code desiredName}, otherwise returns {@code false}.
158+ * Namespace-aware equals comparison. Returns {@code true} if either
159+ * {@link Node#getLocalName} or {@link Node#getNodeName} equals
160+ * {@code desiredName}, otherwise returns {@code false}.
164161 */
165162 public static boolean nodeNameEquals (Node node , String desiredName ) {
166163 Assert .notNull (node , "Node must not be null" );
@@ -170,20 +167,23 @@ public static boolean nodeNameEquals(Node node, String desiredName) {
170167
171168 /**
172169 * Returns a SAX {@code ContentHandler} that transforms callback calls to DOM {@code Node}s.
173- *
174170 * @param node the node to publish events to
175171 * @return the content handler
176172 */
177173 public static ContentHandler createContentHandler (Node node ) {
178174 return new DomContentHandler (node );
179175 }
180176
181- /** Matches the given node's name and local name against the given desired name. */
177+ /**
178+ * Matches the given node's name and local name against the given desired name.
179+ */
182180 private static boolean nodeNameMatch (Node node , String desiredName ) {
183181 return (desiredName .equals (node .getNodeName ()) || desiredName .equals (node .getLocalName ()));
184182 }
185183
186- /** Matches the given node's name and local name against the given desired names. */
184+ /**
185+ * Matches the given node's name and local name against the given desired names.
186+ */
187187 private static boolean nodeNameMatch (Node node , Collection desiredNames ) {
188188 return (desiredNames .contains (node .getNodeName ()) || desiredNames .contains (node .getLocalName ()));
189189 }
0 commit comments