Search in sources :

Example 11 with SyndFeedInput

use of com.sun.syndication.io.SyndFeedInput in project eclipse-integration-commons by spring-projects.

the class CachedFeedsManager method readCachedFeeds.

public void readCachedFeeds(IProgressMonitor monitor) throws FeedException {
    SyndFeedInput input = new SyndFeedInput();
    File[] cachedFiles = getCachedFeeds();
    for (File cachedFile : cachedFiles) {
        String fileName = cachedFile.getName().replaceAll(".xml", "");
        String iconPath = hashedFeedsToIconsMap.get(fileName);
        try {
            reader.readFeeds(new FileReader(cachedFile), input, iconPath);
        } catch (FileNotFoundException e) {
            StatusHandler.log(new Status(IStatus.ERROR, IdeUiPlugin.PLUGIN_ID, "An unexpected error occurred while retrieving feed content from cache.", e));
        }
    }
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) SyndFeedInput(com.sun.syndication.io.SyndFeedInput) FileNotFoundException(java.io.FileNotFoundException) FileReader(java.io.FileReader) File(java.io.File)

Example 12 with SyndFeedInput

use of com.sun.syndication.io.SyndFeedInput 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)

Example 13 with SyndFeedInput

use of com.sun.syndication.io.SyndFeedInput in project xwiki-platform by xwiki.

the class DefaultRomeFeedFactory method createFeed.

@Override
public SyndFeed createFeed(RssMacroParameters parameters) throws MacroExecutionException {
    if (StringUtils.isEmpty(parameters.getFeed())) {
        throw new MacroExecutionException("The required 'feed' parameter is missing");
    }
    SyndFeedInput syndFeedInput = new SyndFeedInput();
    SyndFeed feed;
    try {
        if (StringUtils.startsWith(parameters.getFeed().toLowerCase(), "https")) {
            HttpsURLConnection httpsURLConnection = (HttpsURLConnection) parameters.getFeedURL().openConnection();
            httpsURLConnection.setConnectTimeout(TIMEOUT_MILLISECONDS);
            httpsURLConnection.setRequestProperty(USER_AGENT_HEADER, USER_AGENT);
            feed = syndFeedInput.build(new XmlReader(httpsURLConnection.getInputStream(), true, parameters.getEncoding()));
        } else {
            URLConnection httpURLConnection = parameters.getFeedURL().openConnection();
            httpURLConnection.setConnectTimeout(TIMEOUT_MILLISECONDS);
            httpURLConnection.setRequestProperty(USER_AGENT_HEADER, USER_AGENT);
            feed = syndFeedInput.build(new XmlReader(httpURLConnection.getInputStream(), true, parameters.getEncoding()));
        }
    } catch (SocketTimeoutException ex) {
        throw new MacroExecutionException(MessageFormat.format("Connection timeout when trying to reach [{0}]", parameters.getFeedURL()));
    } catch (Exception ex) {
        throw new MacroExecutionException(MessageFormat.format("Error processing [{0}] : {1}", parameters.getFeedURL(), ex.getMessage()), ex);
    }
    if (feed == null) {
        throw new MacroExecutionException(MessageFormat.format("No feed found at [{0}]", parameters.getFeedURL()));
    }
    return feed;
}
Also used : SyndFeed(com.sun.syndication.feed.synd.SyndFeed) SocketTimeoutException(java.net.SocketTimeoutException) SyndFeedInput(com.sun.syndication.io.SyndFeedInput) MacroExecutionException(org.xwiki.rendering.macro.MacroExecutionException) XmlReader(com.sun.syndication.io.XmlReader) HttpsURLConnection(javax.net.ssl.HttpsURLConnection) HttpsURLConnection(javax.net.ssl.HttpsURLConnection) URLConnection(java.net.URLConnection) MacroExecutionException(org.xwiki.rendering.macro.MacroExecutionException) SocketTimeoutException(java.net.SocketTimeoutException)

Example 14 with SyndFeedInput

use of com.sun.syndication.io.SyndFeedInput in project xwiki-platform by xwiki.

the class RSSValidator method validate.

@Override
protected void validate(Document document) {
    try {
        SyndFeedInput input = new SyndFeedInput();
        input.build(getDocument());
    } catch (IllegalArgumentException e) {
        throw new RuntimeException(e);
    } catch (FeedException e) {
        if (e instanceof ParsingFeedException) {
            ParsingFeedException pfe = (ParsingFeedException) e;
            addError(Type.ERROR, pfe.getLineNumber(), pfe.getColumnNumber(), e.getMessage());
        } else {
            addError(Type.ERROR, -1, -1, e.getMessage());
        }
    }
}
Also used : ParsingFeedException(com.sun.syndication.io.ParsingFeedException) SyndFeedInput(com.sun.syndication.io.SyndFeedInput) FeedException(com.sun.syndication.io.FeedException) ParsingFeedException(com.sun.syndication.io.ParsingFeedException)

Example 15 with SyndFeedInput

use of com.sun.syndication.io.SyndFeedInput in project play-cookbook by spinscale.

the class FeedTest method getFeed.

private SyndFeed getFeed(Response response) throws Exception {
    SyndFeedInput input = new SyndFeedInput();
    InputSource s = new InputSource(IOUtils.toInputStream(getContent(response)));
    return input.build(s);
}
Also used : InputSource(org.xml.sax.InputSource) SyndFeedInput(com.sun.syndication.io.SyndFeedInput)

Aggregations

SyndFeedInput (com.sun.syndication.io.SyndFeedInput)18 XmlReader (com.sun.syndication.io.XmlReader)13 SyndFeed (com.sun.syndication.feed.synd.SyndFeed)9 URL (java.net.URL)7 SyndEntry (com.sun.syndication.feed.synd.SyndEntry)6 ArrayList (java.util.ArrayList)5 InputStream (java.io.InputStream)4 URLConnection (java.net.URLConnection)4 FeedException (com.sun.syndication.io.FeedException)3 IOException (java.io.IOException)3 SyndCategory (com.sun.syndication.feed.synd.SyndCategory)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 File (java.io.File)2 List (java.util.List)2 IStatus (org.eclipse.core.runtime.IStatus)2 Status (org.eclipse.core.runtime.Status)2 InputSource (org.xml.sax.InputSource)2 GitBlitException (com.gitblit.GitBlitException)1 FeedEntryModel (com.gitblit.models.FeedEntryModel)1 SyndEnclosure (com.sun.syndication.feed.synd.SyndEnclosure)1