Webiyo

This page was generated using Webiyo. See its source code and unit tests.

org/webiyo/examples/sourceforge/News.java

package org.webiyo.examples.sourceforge;

import org.w3c.dom.Element;
import org.webiyo.web.Link;
import org.webiyo.xml.Xml;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;

class News implements Iterable<NewsItem> {

    private final String description;
    private final List<NewsItem> newsItems;

    public News(Link newsFeed) throws IOException {
        Element root = newsFeed.fetchXml().getDocumentElement();

        String fullDescription = Xml.selectElement(root, "//channel/description").getTextContent();
        description = fullDescription.substring(fullDescription.indexOf('-') + 2);

        List<NewsItem> items = new ArrayList<NewsItem>();
        List<Element> itemElts = Xml.select(root, "//item", Element.class);
        for (Element itemElt : itemElts) {
            items.add(new NewsItem(itemElt));
        }

        newsItems = Collections.unmodifiableList(items);
    }

    public String getProjectDescription() {
        return description;
    }

    public Iterator<NewsItem> iterator() {
        return newsItems.iterator();
    }


}
SourceForge