diff options
Diffstat (limited to 'src/main/java/io/trygvis/esper/testing/XmlUtil.java')
-rw-r--r-- | src/main/java/io/trygvis/esper/testing/XmlUtil.java | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/main/java/io/trygvis/esper/testing/XmlUtil.java b/src/main/java/io/trygvis/esper/testing/XmlUtil.java new file mode 100644 index 0000000..612667f --- /dev/null +++ b/src/main/java/io/trygvis/esper/testing/XmlUtil.java @@ -0,0 +1,38 @@ +package io.trygvis.esper.testing; + +import fj.*; +import fj.data.*; +import static fj.data.Option.*; +import org.jdom2.*; + +import java.net.*; + +public class XmlUtil { + public static F<String, Option<Integer>> parseInt = new F<String, Option<Integer>>() { + public Option<Integer> f(String s) { + try { + return some(Integer.parseInt(s)); + } catch (NumberFormatException e) { + return none(); + } + } + }; + + public static F<String, Option<URI>> parseUri = new F<String, Option<URI>>() { + public Option<URI> f(String s) { + try { + return some(URI.create(s)); + } catch (Throwable e) { + return none(); + } + } + }; + + public static Option<String> childText(Element e, String childName) { + return fromNull(e.getChildText(childName)); + } + + public static Option<Element> child(Element e, String childName) { + return fromNull(e.getChild(childName)); + } +} |