From: Stefan Bund Date: Mon, 20 Sep 2010 20:35:29 +0000 (+0200) Subject: XmlUtil cleanup X-Git-Url: http://g0dil.de/git?a=commitdiff_plain;h=276d9a69fa796728169c2992921a1e4bd875f549;p=jpim.git XmlUtil cleanup --- diff --git a/src/de/j32/pimstuff/conduit/FritzAddressbookImporter.java b/src/de/j32/pimstuff/conduit/FritzAddressbookImporter.java index 5330cc6..f434185 100644 --- a/src/de/j32/pimstuff/conduit/FritzAddressbookImporter.java +++ b/src/de/j32/pimstuff/conduit/FritzAddressbookImporter.java @@ -33,7 +33,7 @@ public class FritzAddressbookImporter @Override public void sendTo(EntryConsumer consumer) { - for (Element node : XmlUtil.iterateElements(xml_.getElementsByTagName("contact"))) { + for (Element node : XmlUtil.iterate(xml_.getElementsByTagName("contact"),Element.class)) { /* subnodes: * category (unused, always 0) * person/realName @@ -47,7 +47,7 @@ public class FritzAddressbookImporter try { entry.name(node.getElementsByTagName("realName").item(0).getTextContent()); - for (Element phone : XmlUtil.iterateElements(node.getElementsByTagName("number"))) { + for (Element phone : XmlUtil.iterate(node.getElementsByTagName("number"),Element.class)) { entry.attribute("phone", phone.getAttribute("type"), phone.getTextContent()); } diff --git a/src/de/j32/util/Util.java b/src/de/j32/util/Util.java index 95a3f78..db43919 100644 --- a/src/de/j32/util/Util.java +++ b/src/de/j32/util/Util.java @@ -8,25 +8,29 @@ import java.util.Iterator; public class Util { - public static E nonnull(E ob) { + public static E nonnull(E ob) + { if (ob == null) throw new NullPointerException(); return ob; } public static void transfer(InputStream is, OutputStream os) - throws IOException { + throws IOException + { byte[] buffer = new byte[16384]; int len = -1; while ((len = is.read(buffer)) != -1) os.write(buffer, 0, len); } - public static void nothrowClose(Closeable c) { + public static void nothrowClose(Closeable c) + { if (c != null) { try { c.close(); - } catch (IOException e) {} + } + catch (IOException e) {} } } diff --git a/src/de/j32/util/XmlUtil.java b/src/de/j32/util/XmlUtil.java index 693e402..0bc9ebc 100644 --- a/src/de/j32/util/XmlUtil.java +++ b/src/de/j32/util/XmlUtil.java @@ -10,7 +10,6 @@ import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import org.w3c.dom.Document; -import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; import org.xml.sax.EntityResolver; @@ -40,24 +39,24 @@ public class XmlUtil } } - public static Iterable iterateElements(final NodeList nodes) + public static Iterable iterate(final NodeList nodes, final Class type) { - return new Iterable() { - public Iterator iterator() { - return new NodeListIterator(nodes, Element.class); + return new Iterable() { + public Iterator iterator() { + return new NodeListIterator(nodes, type); } }; } - + static class NodeListIterator implements Iterator { - Class nodeType_; + Class nodeType_; NodeList nodes_; int i_ = 0; E next_; - public NodeListIterator(NodeList nodes, Class nodeType) + public NodeListIterator(NodeList nodes, Class nodeType) { nodes_ = nodes; nodeType_ = nodeType;