Search in sources :

Example 1 with SyndElement

use of de.danoeh.antennapod.core.syndication.namespace.SyndElement in project AntennaPod by AntennaPod.

the class NSAtom method handleElementStart.

@Override
public SyndElement handleElementStart(String localName, HandlerState state, Attributes attributes) {
    if (ENTRY.equals(localName)) {
        state.setCurrentItem(new FeedItem());
        state.getItems().add(state.getCurrentItem());
        state.getCurrentItem().setFeed(state.getFeed());
    } else if (localName.matches(isText)) {
        String type = attributes.getValue(TEXT_TYPE);
        return new AtomText(localName, this, type);
    } else if (LINK.equals(localName)) {
        String href = attributes.getValue(LINK_HREF);
        String rel = attributes.getValue(LINK_REL);
        SyndElement parent = state.getTagstack().peek();
        if (parent.getName().matches(isFeedItem)) {
            if (LINK_REL_ALTERNATE.equals(rel)) {
                state.getCurrentItem().setLink(href);
            } else if (LINK_REL_ENCLOSURE.equals(rel)) {
                String strSize = attributes.getValue(LINK_LENGTH);
                long size = 0;
                try {
                    if (strSize != null) {
                        size = Long.parseLong(strSize);
                    }
                } catch (NumberFormatException e) {
                    Log.d(TAG, "Length attribute could not be parsed.");
                }
                String type = attributes.getValue(LINK_TYPE);
                if (type == null) {
                    type = SyndTypeUtils.getMimeTypeFromUrl(href);
                }
                if (SyndTypeUtils.enclosureTypeValid(type)) {
                    FeedItem currItem = state.getCurrentItem();
                    if (currItem != null && !currItem.hasMedia()) {
                        currItem.setMedia(new FeedMedia(currItem, href, size, type));
                    }
                }
            } else if (LINK_REL_PAYMENT.equals(rel)) {
                state.getCurrentItem().setPaymentLink(href);
            }
        } else if (parent.getName().matches(isFeed)) {
            if (LINK_REL_ALTERNATE.equals(rel)) {
                String type = attributes.getValue(LINK_TYPE);
                /*
                     * Use as link if a) no type-attribute is given and
					 * feed-object has no link yet b) type of link is
					 * LINK_TYPE_HTML or LINK_TYPE_XHTML
					 */
                if (state.getFeed() != null && ((type == null && state.getFeed().getLink() == null) || (LINK_TYPE_HTML.equals(type) || LINK_TYPE_XHTML.equals(type)))) {
                    state.getFeed().setLink(href);
                } else if (LINK_TYPE_ATOM.equals(type) || LINK_TYPE_RSS.equals(type)) {
                    // treat as podlove alternate feed
                    String title = attributes.getValue(LINK_TITLE);
                    if (TextUtils.isEmpty(title)) {
                        title = href;
                    }
                    state.addAlternateFeedUrl(title, href);
                }
            } else if (LINK_REL_ARCHIVES.equals(rel) && state.getFeed() != null) {
                String type = attributes.getValue(LINK_TYPE);
                if (LINK_TYPE_ATOM.equals(type) || LINK_TYPE_RSS.equals(type)) {
                    String title = attributes.getValue(LINK_TITLE);
                    if (TextUtils.isEmpty(title)) {
                        title = href;
                    }
                    state.addAlternateFeedUrl(title, href);
                } else if (LINK_TYPE_HTML.equals(type) || LINK_TYPE_XHTML.equals(type)) {
                //A Link such as to a directory such as iTunes
                }
            } else if (LINK_REL_PAYMENT.equals(rel) && state.getFeed() != null) {
                state.getFeed().setPaymentLink(href);
            } else if (LINK_REL_NEXT.equals(rel) && state.getFeed() != null) {
                state.getFeed().setPaged(true);
                state.getFeed().setNextPageLink(href);
            }
        }
    }
    return new SyndElement(localName, this);
}
Also used : FeedItem(de.danoeh.antennapod.core.feed.FeedItem) SyndElement(de.danoeh.antennapod.core.syndication.namespace.SyndElement) FeedMedia(de.danoeh.antennapod.core.feed.FeedMedia)

Example 2 with SyndElement

use of de.danoeh.antennapod.core.syndication.namespace.SyndElement in project AntennaPod by AntennaPod.

the class HandlerState method getSecondTag.

/**
     * Returns the SyndElement that comes after the top element of the tagstack.
     */
public SyndElement getSecondTag() {
    SyndElement top = tagstack.pop();
    SyndElement second = tagstack.peek();
    tagstack.push(top);
    return second;
}
Also used : SyndElement(de.danoeh.antennapod.core.syndication.namespace.SyndElement)

Example 3 with SyndElement

use of de.danoeh.antennapod.core.syndication.namespace.SyndElement in project AntennaPod by AntennaPod.

the class SyndHandler method startElement.

@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
    state.contentBuf = new StringBuffer();
    Namespace handler = getHandlingNamespace(uri, qName);
    if (handler != null) {
        SyndElement element = handler.handleElementStart(localName, state, attributes);
        state.tagstack.push(element);
    }
}
Also used : SyndElement(de.danoeh.antennapod.core.syndication.namespace.SyndElement) Namespace(de.danoeh.antennapod.core.syndication.namespace.Namespace)

Example 4 with SyndElement

use of de.danoeh.antennapod.core.syndication.namespace.SyndElement in project AntennaPod by AntennaPod.

the class NSAtom method handleElementEnd.

@Override
public void handleElementEnd(String localName, HandlerState state) {
    if (ENTRY.equals(localName)) {
        if (state.getCurrentItem() != null && state.getTempObjects().containsKey(NSITunes.DURATION)) {
            FeedItem currentItem = state.getCurrentItem();
            if (currentItem.hasMedia()) {
                Integer duration = (Integer) state.getTempObjects().get(NSITunes.DURATION);
                currentItem.getMedia().setDuration(duration);
            }
            state.getTempObjects().remove(NSITunes.DURATION);
        }
        state.setCurrentItem(null);
    }
    if (state.getTagstack().size() >= 2) {
        AtomText textElement = null;
        String content;
        if (state.getContentBuf() != null) {
            content = state.getContentBuf().toString();
        } else {
            content = "";
        }
        SyndElement topElement = state.getTagstack().peek();
        String top = topElement.getName();
        SyndElement secondElement = state.getSecondTag();
        String second = secondElement.getName();
        if (top.matches(isText)) {
            textElement = (AtomText) topElement;
            textElement.setContent(content);
        }
        if (ID.equals(top)) {
            if (FEED.equals(second) && state.getFeed() != null) {
                state.getFeed().setFeedIdentifier(content);
            } else if (ENTRY.equals(second) && state.getCurrentItem() != null) {
                state.getCurrentItem().setItemIdentifier(content);
            }
        } else if (TITLE.equals(top) && textElement != null) {
            if (FEED.equals(second) && state.getFeed() != null) {
                state.getFeed().setTitle(textElement.getProcessedContent());
            } else if (ENTRY.equals(second) && state.getCurrentItem() != null) {
                state.getCurrentItem().setTitle(textElement.getProcessedContent());
            }
        } else if (SUBTITLE.equals(top) && FEED.equals(second) && textElement != null && state.getFeed() != null) {
            state.getFeed().setDescription(textElement.getProcessedContent());
        } else if (CONTENT.equals(top) && ENTRY.equals(second) && textElement != null && state.getCurrentItem() != null) {
            state.getCurrentItem().setDescription(textElement.getProcessedContent());
        } else if (SUMMARY.equals(top) && ENTRY.equals(second) && textElement != null && state.getCurrentItem() != null && state.getCurrentItem().getDescription() == null) {
            state.getCurrentItem().setDescription(textElement.getProcessedContent());
        } else if (UPDATED.equals(top) && ENTRY.equals(second) && state.getCurrentItem() != null && state.getCurrentItem().getPubDate() == null) {
            state.getCurrentItem().setPubDate(DateUtils.parse(content));
        } else if (PUBLISHED.equals(top) && ENTRY.equals(second) && state.getCurrentItem() != null) {
            state.getCurrentItem().setPubDate(DateUtils.parse(content));
        } else if (IMAGE_LOGO.equals(top) && state.getFeed() != null && state.getFeed().getImage() == null) {
            state.getFeed().setImage(new FeedImage(state.getFeed(), content, null));
        } else if (IMAGE_ICON.equals(top) && state.getFeed() != null) {
            state.getFeed().setImage(new FeedImage(state.getFeed(), content, null));
        } else if (AUTHOR_NAME.equals(top) && AUTHOR.equals(second) && state.getFeed() != null && state.getCurrentItem() == null) {
            String currentName = state.getFeed().getAuthor();
            if (currentName == null) {
                state.getFeed().setAuthor(content);
            } else {
                state.getFeed().setAuthor(currentName + ", " + content);
            }
        }
    }
}
Also used : FeedImage(de.danoeh.antennapod.core.feed.FeedImage) FeedItem(de.danoeh.antennapod.core.feed.FeedItem) SyndElement(de.danoeh.antennapod.core.syndication.namespace.SyndElement)

Example 5 with SyndElement

use of de.danoeh.antennapod.core.syndication.namespace.SyndElement in project AntennaPod by AntennaPod.

the class HandlerState method getThirdTag.

public SyndElement getThirdTag() {
    SyndElement top = tagstack.pop();
    SyndElement second = tagstack.pop();
    SyndElement third = tagstack.peek();
    tagstack.push(second);
    tagstack.push(top);
    return third;
}
Also used : SyndElement(de.danoeh.antennapod.core.syndication.namespace.SyndElement)

Aggregations

SyndElement (de.danoeh.antennapod.core.syndication.namespace.SyndElement)5 FeedItem (de.danoeh.antennapod.core.feed.FeedItem)2 FeedImage (de.danoeh.antennapod.core.feed.FeedImage)1 FeedMedia (de.danoeh.antennapod.core.feed.FeedMedia)1 Namespace (de.danoeh.antennapod.core.syndication.namespace.Namespace)1