Search in sources :

Example 6 with FeedException

use of com.sun.syndication.io.FeedException in project eol-globi-data by jhpoelen.

the class StudyImporterForArthopodEasyCapture method getStudyImportersForRSSFeed.

public static List<StudyImporter> getStudyImportersForRSSFeed(Dataset datasetOrig, ParserFactory parserFactory, NodeFactory nodeFactory) throws StudyImporterException {
    SyndFeedInput input = new SyndFeedInput();
    SyndFeed feed;
    String rss = getRss(datasetOrig);
    try {
        feed = input.build(new XmlReader(new URL(rss)));
    } catch (FeedException | IOException e) {
        throw new StudyImporterException("failed to read rss feed [" + rss + "]", e);
    }
    List<StudyImporter> importers = new ArrayList<StudyImporter>();
    final List entries = feed.getEntries();
    for (Object entry : entries) {
        if (entry instanceof SyndEntry) {
            SyndEntry syndEntry = (SyndEntry) entry;
            Dataset dataset = embeddedDatasetFor(datasetOrig, StringUtils.trim(syndEntry.getDescription().getValue()), URI.create(StringUtils.trim(syndEntry.getLink())));
            final StudyImporterForSeltmann studyImporter = new StudyImporterForSeltmann(parserFactory, nodeFactory);
            studyImporter.setDataset(dataset);
            importers.add(studyImporter);
        }
    }
    return importers;
}
Also used : SyndEntry(com.sun.syndication.feed.synd.SyndEntry) Dataset(org.eol.globi.service.Dataset) FeedException(com.sun.syndication.io.FeedException) ArrayList(java.util.ArrayList) XmlReader(com.sun.syndication.io.XmlReader) IOException(java.io.IOException) URL(java.net.URL) SyndFeed(com.sun.syndication.feed.synd.SyndFeed) SyndFeedInput(com.sun.syndication.io.SyndFeedInput) ArrayList(java.util.ArrayList) List(java.util.List)

Example 7 with FeedException

use of com.sun.syndication.io.FeedException in project maven-plugins by apache.

the class FeedGenerator method export.

/**
 * Extract a feed and export it to a Writer.
 *
 * @param releases the List of Releases. Only the last release is used in the feed.
 * @param feedType The type of the feed to generate. See {@link #isSupportedFeedType(java.lang.String)} for
 *            supported values.
 * @param writer a Writer. Note that this is not flushed nor closed upon exit.
 * @throws IOException if an error occurs during export.
 */
public void export(final List<Release> releases, final String feedType, final Writer writer) throws IOException {
    feed.setFeedType(feedType);
    feed.setTitle(title);
    feed.setAuthor(author);
    feed.setPublishedDate(new Date());
    feed.setLink(link);
    feed.setDescription(rbundle.getString("report.changes.text.rssfeed.description"));
    feed.setLanguage(rbundle.getLocale().getLanguage());
    // feed.setCopyright( );
    // feed.setEncoding();
    feed.setEntries(getEntries(releases));
    try {
        new SyndFeedOutput().output(feed, writer);
    } catch (FeedException ex) {
        IOException ioex = new IOException(ex.getMessage());
        ioex.initCause(ex);
        throw ioex;
    }
}
Also used : FeedException(com.sun.syndication.io.FeedException) SyndFeedOutput(com.sun.syndication.io.SyndFeedOutput) IOException(java.io.IOException) Date(java.util.Date)

Example 8 with FeedException

use of com.sun.syndication.io.FeedException in project jersey by jersey.

the class FeedEntriesAtomBodyWriter method writeSyndFeed.

private void writeSyndFeed(OutputStream entityStream, SyndFeed feed) {
    try {
        OutputStreamWriter writer = new OutputStreamWriter(entityStream);
        SyndFeedOutput output = new SyndFeedOutput();
        output.output(feed, writer);
        writer.close();
    } catch (FeedException | IOException e) {
        LOG.warn("An error occurred during writing a synd feed.", e);
    }
}
Also used : FeedException(com.sun.syndication.io.FeedException) OutputStreamWriter(java.io.OutputStreamWriter) SyndFeedOutput(com.sun.syndication.io.SyndFeedOutput) IOException(java.io.IOException)

Example 9 with FeedException

use of com.sun.syndication.io.FeedException 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 10 with FeedException

use of com.sun.syndication.io.FeedException in project liferay-ide by liferay.

the class KBArticleServiceImpl method exportToRSS.

protected String exportToRSS(String rssDisplayStyle, String rssFormat, String name, String description, String feedURL, List<KBArticle> kbArticles, ThemeDisplay themeDisplay) throws SystemException {
    SyndFeed syndFeed = new SyndFeedImpl();
    syndFeed.setDescription(description);
    List<SyndEntry> syndEntries = new ArrayList<SyndEntry>();
    syndFeed.setEntries(syndEntries);
    for (KBArticle kbArticle : kbArticles) {
        SyndEntry syndEntry = new SyndEntryImpl();
        String author = PortalUtil.getUserName(kbArticle);
        syndEntry.setAuthor(author);
        SyndContent syndContent = new SyndContentImpl();
        syndContent.setType(RSSUtil.ENTRY_TYPE_DEFAULT);
        String value = null;
        if (rssDisplayStyle.equals(RSSUtil.DISPLAY_STYLE_ABSTRACT)) {
            value = HtmlUtil.extractText(kbArticle.getDescription());
            if (Validator.isNull(value)) {
                value = StringUtil.shorten(HtmlUtil.extractText(kbArticle.getContent()), 200);
            }
        } else if (rssDisplayStyle.equals(RSSUtil.DISPLAY_STYLE_TITLE)) {
            value = StringPool.BLANK;
        } else {
            value = StringUtil.replace(kbArticle.getContent(), new String[] { "href=\"/", "src=\"/" }, new String[] { "href=\"" + themeDisplay.getURLPortal() + "/", "src=\"" + themeDisplay.getURLPortal() + "/" });
        }
        syndContent.setValue(value);
        syndEntry.setDescription(syndContent);
        String link = KnowledgeBaseUtil.getKBArticleURL(themeDisplay.getPlid(), kbArticle.getResourcePrimKey(), kbArticle.getStatus(), themeDisplay.getPortalURL(), false);
        syndEntry.setLink(link);
        syndEntry.setPublishedDate(kbArticle.getCreateDate());
        syndEntry.setTitle(kbArticle.getTitle());
        syndEntry.setUpdatedDate(kbArticle.getModifiedDate());
        syndEntry.setUri(syndEntry.getLink());
        syndEntries.add(syndEntry);
    }
    String feedType = RSSUtil.getFeedType(RSSUtil.getFormatType(rssFormat), RSSUtil.getFormatVersion(rssFormat));
    syndFeed.setFeedType(feedType);
    List<SyndLink> syndLinks = new ArrayList<SyndLink>();
    syndFeed.setLinks(syndLinks);
    SyndLink selfSyndLink = new SyndLinkImpl();
    syndLinks.add(selfSyndLink);
    selfSyndLink.setHref(feedURL);
    selfSyndLink.setRel("self");
    syndFeed.setPublishedDate(new Date());
    syndFeed.setTitle(name);
    syndFeed.setUri(feedURL);
    try {
        return RSSUtil.export(syndFeed);
    } catch (FeedException fe) {
        throw new SystemException(fe);
    }
}
Also used : SyndEntry(com.sun.syndication.feed.synd.SyndEntry) SyndContentImpl(com.sun.syndication.feed.synd.SyndContentImpl) FeedException(com.sun.syndication.io.FeedException) ArrayList(java.util.ArrayList) SyndLinkImpl(com.sun.syndication.feed.synd.SyndLinkImpl) Date(java.util.Date) SyndFeed(com.sun.syndication.feed.synd.SyndFeed) KBArticle(com.liferay.knowledgebase.model.KBArticle) SyndContent(com.sun.syndication.feed.synd.SyndContent) SystemException(com.liferay.portal.kernel.exception.SystemException) SyndEntryImpl(com.sun.syndication.feed.synd.SyndEntryImpl) SyndFeedImpl(com.sun.syndication.feed.synd.SyndFeedImpl) SyndLink(com.sun.syndication.feed.synd.SyndLink)

Aggregations

FeedException (com.sun.syndication.io.FeedException)15 SyndFeed (com.sun.syndication.feed.synd.SyndFeed)9 IOException (java.io.IOException)7 ArrayList (java.util.ArrayList)7 SyndEntry (com.sun.syndication.feed.synd.SyndEntry)5 SyndFeedOutput (com.sun.syndication.io.SyndFeedOutput)5 Date (java.util.Date)5 SyndFeedInput (com.sun.syndication.io.SyndFeedInput)4 SyndEntryImpl (com.sun.syndication.feed.synd.SyndEntryImpl)3 SyndFeedImpl (com.sun.syndication.feed.synd.SyndFeedImpl)3 XmlReader (com.sun.syndication.io.XmlReader)3 SyndContent (com.sun.syndication.feed.synd.SyndContent)2 SyndContentImpl (com.sun.syndication.feed.synd.SyndContentImpl)2 URL (java.net.URL)2 HashMap (java.util.HashMap)2 ArtifactMetadata (org.apache.archiva.metadata.model.ArtifactMetadata)2 MetadataRepositoryException (org.apache.archiva.metadata.repository.MetadataRepositoryException)2 RssFeedEntry (org.apache.archiva.rss.RssFeedEntry)2 GitBlitException (com.gitblit.GitBlitException)1 FeedEntryModel (com.gitblit.models.FeedEntryModel)1