X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=src%2Fde%2Fj32%2Futil%2FXmlUtil.java;h=9eb50782ad6b0d451b22d4e6824ba254bde183ac;hb=5ac05364dc652686046f01849b810da6ffef1192;hp=693e4025027b775b050ff1bc9d0cdaf2d339a29b;hpb=aeb7d91db3d650d30a9191cbe84192d6b3b23df7;p=jpim.git diff --git a/src/de/j32/util/XmlUtil.java b/src/de/j32/util/XmlUtil.java index 693e402..9eb5078 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; @@ -19,83 +18,83 @@ import org.xml.sax.SAXException; public class XmlUtil { - public static Document parse(InputStream is) - throws SAXException, IOException - { - try { - DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); - factory.setValidating(false); - factory.setExpandEntityReferences(false); - DocumentBuilder builder = factory.newDocumentBuilder(); - builder.setEntityResolver(new EntityResolver() { - public InputSource resolveEntity(String publicId, String systemId) - throws SAXException, IOException - { - return new InputSource(new StringReader("")); - }}); - return builder.parse(is); - } - catch (ParserConfigurationException e) { - throw new AssertionError("SAX/DOM parser configuration error"); - } - } - - public static Iterable iterateElements(final NodeList nodes) - { - return new Iterable() { - public Iterator iterator() { - return new NodeListIterator(nodes, Element.class); - } - }; - } + public static Document parse(InputStream is) throws SAXException, IOException + { + try { + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + factory.setValidating(false); + factory.setExpandEntityReferences(false); + DocumentBuilder builder = factory.newDocumentBuilder(); + builder.setEntityResolver(new EntityResolver() { + public InputSource resolveEntity(String publicId, String systemId) + throws SAXException, IOException + { + return new InputSource(new StringReader("")); + } + }); + return builder.parse(is); + } + catch (ParserConfigurationException e) { + throw new AssertionError("SAX/DOM parser configuration error"); + } + } - static class NodeListIterator - implements Iterator - { - Class nodeType_; - NodeList nodes_; - int i_ = 0; - E next_; - - public NodeListIterator(NodeList nodes, Class nodeType) - { - nodes_ = nodes; - nodeType_ = nodeType; - advance(); - } - - @Override - public boolean hasNext() - { - return next_ != null; - } + public static Iterable iterate(final NodeList nodes, final Class type) + { + return new Iterable() { + public Iterator iterator() + { + return new NodeListIterator(nodes, type); + } + }; + } - @Override - public E next() - { - E rv = next_; - advance(); - return rv; - } + static class NodeListIterator implements Iterator + { + Class nodeType_; + NodeList nodes_; + int i_ = 0; + E next_; - @Override - public void remove() - { - throw new UnsupportedOperationException(); - } - - @SuppressWarnings("unchecked") - void advance() - { - while (i_ < nodes_.getLength()) { - Node n = nodes_.item(i_); - ++ i_; - if (nodeType_.isInstance(n)) { - next_ = (E) n; - return; - } - } - next_ = null; - } - } + public NodeListIterator(NodeList nodes, Class nodeType) + { + nodes_ = nodes; + nodeType_ = nodeType; + advance(); + } + + @Override + public boolean hasNext() + { + return next_ != null; + } + + @Override + public E next() + { + E rv = next_; + advance(); + return rv; + } + + @Override + public void remove() + { + throw new UnsupportedOperationException(); + } + + @SuppressWarnings("unchecked") + void advance() + { + while (i_ < nodes_.getLength()) { + Node n = nodes_.item(i_); + ++i_; + if (nodeType_.isInstance(n)) { + next_ = (E) n; + return; + } + } + next_ = null; + } + } }