Search in sources :

Example 1 with SyndEnclosure

use of com.sun.syndication.feed.synd.SyndEnclosure in project UniversalMediaServer by UniversalMediaServer.

the class Feed method parse.

@SuppressWarnings("unchecked")
public void parse() throws Exception {
    SyndFeedInput input = new SyndFeedInput();
    byte[] b = downloadAndSendBinary(url);
    if (b != null) {
        SyndFeed feed = input.build(new XmlReader(new ByteArrayInputStream(b)));
        name = feed.getTitle();
        if (feed.getCategories() != null && feed.getCategories().size() > 0) {
            SyndCategory category = (SyndCategory) feed.getCategories().get(0);
            tempCategory = category.getName();
        }
        List<SyndEntry> entries = feed.getEntries();
        for (SyndEntry entry : entries) {
            tempItemTitle = entry.getTitle();
            tempItemLink = entry.getLink();
            tempFeedLink = entry.getUri();
            tempItemThumbURL = null;
            ArrayList<Element> elements = (ArrayList<Element>) entry.getForeignMarkup();
            for (Element elt : elements) {
                if ("group".equals(elt.getName()) && "media".equals(elt.getNamespacePrefix())) {
                    List<Content> subElts = elt.getContent();
                    for (Content subelt : subElts) {
                        if (subelt instanceof Element) {
                            parseElement((Element) subelt, false);
                        }
                    }
                }
                parseElement(elt, true);
            }
            List<SyndEnclosure> enclosures = entry.getEnclosures();
            for (SyndEnclosure enc : enclosures) {
                if (StringUtils.isNotBlank(enc.getUrl())) {
                    tempItemLink = enc.getUrl();
                }
            }
            manageItem();
        }
    }
    setLastModified(System.currentTimeMillis());
}
Also used : SyndCategory(com.sun.syndication.feed.synd.SyndCategory) SyndEntry(com.sun.syndication.feed.synd.SyndEntry) Element(org.jdom.Element) ArrayList(java.util.ArrayList) XmlReader(com.sun.syndication.io.XmlReader) SyndFeed(com.sun.syndication.feed.synd.SyndFeed) ByteArrayInputStream(java.io.ByteArrayInputStream) SyndFeedInput(com.sun.syndication.io.SyndFeedInput) Content(org.jdom.Content) SyndEnclosure(com.sun.syndication.feed.synd.SyndEnclosure)

Aggregations

SyndCategory (com.sun.syndication.feed.synd.SyndCategory)1 SyndEnclosure (com.sun.syndication.feed.synd.SyndEnclosure)1 SyndEntry (com.sun.syndication.feed.synd.SyndEntry)1 SyndFeed (com.sun.syndication.feed.synd.SyndFeed)1 SyndFeedInput (com.sun.syndication.io.SyndFeedInput)1 XmlReader (com.sun.syndication.io.XmlReader)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ArrayList (java.util.ArrayList)1 Content (org.jdom.Content)1 Element (org.jdom.Element)1