diff options
| author | Michael Williamson <mike@zwobble.org> | 2015-12-31 16:32:17 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2015-12-31 16:32:17 +0000 |
| commit | b4bb718158ed274e664ea2796198597b1c1dfa9c (patch) | |
| tree | 8f5915fcac93e1897d5a7d264a585048dae81c09 /src/main/java/org/zwobble/mammoth/xml/XmlElement.java | |
| parent | 36deaa6002a0e85d7da6efd7e569d91f976d9949 (diff) | |
Read defaults from content types XML
Diffstat (limited to 'src/main/java/org/zwobble/mammoth/xml/XmlElement.java')
| -rw-r--r-- | src/main/java/org/zwobble/mammoth/xml/XmlElement.java | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/src/main/java/org/zwobble/mammoth/xml/XmlElement.java b/src/main/java/org/zwobble/mammoth/xml/XmlElement.java index f138917..a42a1b7 100644 --- a/src/main/java/org/zwobble/mammoth/xml/XmlElement.java +++ b/src/main/java/org/zwobble/mammoth/xml/XmlElement.java @@ -1,10 +1,14 @@ package org.zwobble.mammoth.xml; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Iterables; + import java.util.List; import java.util.Map; +import java.util.Optional; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; +import static com.google.common.collect.Iterables.filter; public class XmlElement implements XmlNode { public XmlElement(String name) { @@ -33,6 +37,11 @@ public class XmlElement implements XmlNode { return attributes; } + public String getAttribute(String name) { + // TODO: throw more informative error message + return Optional.ofNullable(attributes.get(name)).get(); + } + public List<XmlNode> getChildren() { return children; } @@ -51,4 +60,11 @@ public class XmlElement implements XmlNode { return "XmlElement(name=" + name + ", attributes=" + attributes + ", children=" + children + ")"; } + + public XmlElementList findChildren(String name) { + Iterable<XmlElement> filtered = filter( + filter(children, XmlElement.class), + child -> child.getName().equals(name)); + return new XmlElementList(ImmutableList.copyOf(filtered)); + } } |
