|
|
|
|
@ -1,5 +1,5 @@
@@ -1,5 +1,5 @@
|
|
|
|
|
/* |
|
|
|
|
* Copyright 2002-2012 the original author or authors. |
|
|
|
|
* Copyright 2002-2013 the original author or authors. |
|
|
|
|
* |
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
|
@ -39,18 +39,17 @@ import org.springframework.util.Assert;
@@ -39,18 +39,17 @@ import org.springframework.util.Assert;
|
|
|
|
|
* @author Costin Leau |
|
|
|
|
* @author Arjen Poutsma |
|
|
|
|
* @author Luke Taylor |
|
|
|
|
* @since 1.2 |
|
|
|
|
* @see org.w3c.dom.Node |
|
|
|
|
* @see org.w3c.dom.Element |
|
|
|
|
* @since 1.2 |
|
|
|
|
*/ |
|
|
|
|
public abstract class DomUtils { |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Retrieve all child elements of the given DOM element that match any of the given element names. Only look at the |
|
|
|
|
* direct child level of the given element; do not go into further depth (in contrast to the DOM API's |
|
|
|
|
* {@code getElementsByTagName} method). |
|
|
|
|
* |
|
|
|
|
* @param ele the DOM element to analyze |
|
|
|
|
* Retrieves all child elements of the given DOM element that match any of the given element names. |
|
|
|
|
* Only looks at the direct child level of the given element; do not go into further depth |
|
|
|
|
* (in contrast to the DOM API's {@code getElementsByTagName} method). |
|
|
|
|
* @param ele the DOM element to analyze |
|
|
|
|
* @param childEleNames the child element names to look for |
|
|
|
|
* @return a List of child {@code org.w3c.dom.Element} instances |
|
|
|
|
* @see org.w3c.dom.Element |
|
|
|
|
@ -72,11 +71,10 @@ public abstract class DomUtils {
@@ -72,11 +71,10 @@ public abstract class DomUtils {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Retrieve all child elements of the given DOM element that match the given element name. Only look at the direct |
|
|
|
|
* child level of the given element; do not go into further depth (in contrast to the DOM API's |
|
|
|
|
* {@code getElementsByTagName} method). |
|
|
|
|
* |
|
|
|
|
* @param ele the DOM element to analyze |
|
|
|
|
* Retrieves all child elements of the given DOM element that match the given element name. |
|
|
|
|
* Only look at the direct child level of the given element; do not go into further depth |
|
|
|
|
* (in contrast to the DOM API's {@code getElementsByTagName} method). |
|
|
|
|
* @param ele the DOM element to analyze |
|
|
|
|
* @param childEleName the child element name to look for |
|
|
|
|
* @return a List of child {@code org.w3c.dom.Element} instances |
|
|
|
|
* @see org.w3c.dom.Element |
|
|
|
|
@ -88,8 +86,7 @@ public abstract class DomUtils {
@@ -88,8 +86,7 @@ public abstract class DomUtils {
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Utility method that returns the first child element identified by its name. |
|
|
|
|
* |
|
|
|
|
* @param ele the DOM element to analyze |
|
|
|
|
* @param ele the DOM element to analyze |
|
|
|
|
* @param childEleName the child element name to look for |
|
|
|
|
* @return the {@code org.w3c.dom.Element} instance, or {@code null} if none found |
|
|
|
|
*/ |
|
|
|
|
@ -108,8 +105,7 @@ public abstract class DomUtils {
@@ -108,8 +105,7 @@ public abstract class DomUtils {
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Utility method that returns the first child element value identified by its name. |
|
|
|
|
* |
|
|
|
|
* @param ele the DOM element to analyze |
|
|
|
|
* @param ele the DOM element to analyze |
|
|
|
|
* @param childEleName the child element name to look for |
|
|
|
|
* @return the extracted text value, or {@code null} if no child element found |
|
|
|
|
*/ |
|
|
|
|
@ -119,9 +115,8 @@ public abstract class DomUtils {
@@ -119,9 +115,8 @@ public abstract class DomUtils {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Retrieve all child elements of the given DOM element |
|
|
|
|
|
|
|
|
|
* @param ele the DOM element to analyze |
|
|
|
|
* Retrieves all child elements of the given DOM element |
|
|
|
|
* @param ele the DOM element to analyze |
|
|
|
|
* @return a List of child {@code org.w3c.dom.Element} instances |
|
|
|
|
*/ |
|
|
|
|
public static List<Element> getChildElements(Element ele) { |
|
|
|
|
@ -138,9 +133,10 @@ public abstract class DomUtils {
@@ -138,9 +133,10 @@ public abstract class DomUtils {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Extract the text value from the given DOM element, ignoring XML comments. <p>Appends all CharacterData nodes and |
|
|
|
|
* EntityReference nodes into a single String value, excluding Comment nodes. |
|
|
|
|
* |
|
|
|
|
* Extracts the text value from the given DOM element, ignoring XML comments. |
|
|
|
|
* <p>Appends all CharacterData nodes and EntityReference nodes into a single |
|
|
|
|
* String value, excluding Comment nodes. Only exposes actual user-specified |
|
|
|
|
* text, no default values of any kind. |
|
|
|
|
* @see CharacterData |
|
|
|
|
* @see EntityReference |
|
|
|
|
* @see Comment |
|
|
|
|
@ -159,8 +155,9 @@ public abstract class DomUtils {
@@ -159,8 +155,9 @@ public abstract class DomUtils {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Namespace-aware equals comparison. Returns {@code true} if either {@link Node#getLocalName} or {@link |
|
|
|
|
* Node#getNodeName} equals {@code desiredName}, otherwise returns {@code false}. |
|
|
|
|
* Namespace-aware equals comparison. Returns {@code true} if either |
|
|
|
|
* {@link Node#getLocalName} or {@link Node#getNodeName} equals |
|
|
|
|
* {@code desiredName}, otherwise returns {@code false}. |
|
|
|
|
*/ |
|
|
|
|
public static boolean nodeNameEquals(Node node, String desiredName) { |
|
|
|
|
Assert.notNull(node, "Node must not be null"); |
|
|
|
|
@ -170,7 +167,6 @@ public abstract class DomUtils {
@@ -170,7 +167,6 @@ public abstract class DomUtils {
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Returns a SAX {@code ContentHandler} that transforms callback calls to DOM {@code Node}s. |
|
|
|
|
* |
|
|
|
|
* @param node the node to publish events to |
|
|
|
|
* @return the content handler |
|
|
|
|
*/ |
|
|
|
|
@ -178,12 +174,16 @@ public abstract class DomUtils {
@@ -178,12 +174,16 @@ public abstract class DomUtils {
|
|
|
|
|
return new DomContentHandler(node); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** Matches the given node's name and local name against the given desired name. */ |
|
|
|
|
/** |
|
|
|
|
* Matches the given node's name and local name against the given desired name. |
|
|
|
|
*/ |
|
|
|
|
private static boolean nodeNameMatch(Node node, String desiredName) { |
|
|
|
|
return (desiredName.equals(node.getNodeName()) || desiredName.equals(node.getLocalName())); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** Matches the given node's name and local name against the given desired names. */ |
|
|
|
|
/** |
|
|
|
|
* Matches the given node's name and local name against the given desired names. |
|
|
|
|
*/ |
|
|
|
|
private static boolean nodeNameMatch(Node node, Collection desiredNames) { |
|
|
|
|
return (desiredNames.contains(node.getNodeName()) || desiredNames.contains(node.getLocalName())); |
|
|
|
|
} |
|
|
|
|
|