Search in sources :

Example 1 with FeedException

use of com.sun.syndication.io.FeedException in project wildfly-camel by wildfly-extras.

the class RSSFeedServlet method doGet.

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    SyndFeed feed = new SyndFeedImpl();
    feed.setFeedType("rss_2.0");
    feed.setTitle("WildFly-Camel Test RSS Feed");
    feed.setLink("http://localhost:8080/rss-tests");
    feed.setDescription("Test RSS feed for the camel-rss component");
    List<SyndEntry> entries = new ArrayList<>();
    for (int i = 1; i <= 5; i++) {
        entries.add(createFeedEntry("Test entry: ", "Test content: ", i));
    }
    feed.setEntries(entries);
    SyndFeedOutput output = new SyndFeedOutput();
    try {
        output.output(feed, response.getWriter());
    } catch (FeedException e) {
        throw new IllegalStateException("Error generating RSS feed", e);
    }
}
Also used : SyndFeed(com.sun.syndication.feed.synd.SyndFeed) SyndEntry(com.sun.syndication.feed.synd.SyndEntry) FeedException(com.sun.syndication.io.FeedException) ArrayList(java.util.ArrayList) SyndFeedImpl(com.sun.syndication.feed.synd.SyndFeedImpl) SyndFeedOutput(com.sun.syndication.io.SyndFeedOutput)

Example 2 with FeedException

use of com.sun.syndication.io.FeedException in project archiva by apache.

the class NewArtifactsRssFeedProcessor method processNewArtifactsInRepo.

private SyndFeed processNewArtifactsInRepo(String repoId, MetadataRepository metadataRepository) throws FeedException {
    Calendar greaterThanThisDate = Calendar.getInstance(GMT_TIME_ZONE);
    greaterThanThisDate.add(Calendar.DATE, -(getNumberOfDaysBeforeNow()));
    greaterThanThisDate.clear(Calendar.MILLISECOND);
    List<ArtifactMetadata> artifacts;
    try {
        artifacts = metadataRepository.getArtifactsByDateRange(repoId, greaterThanThisDate.getTime(), null);
    } catch (MetadataRepositoryException e) {
        throw new FeedException("Unable to construct feed, metadata could not be retrieved: " + e.getMessage(), e);
    }
    long tmp = 0;
    RssFeedEntry entry = null;
    List<RssFeedEntry> entries = new ArrayList<>();
    String description = "";
    int idx = 0;
    for (ArtifactMetadata artifact : artifacts) {
        long whenGathered = artifact.getWhenGathered().getTime();
        String id = artifact.getNamespace() + "/" + artifact.getProject() + "/" + artifact.getId();
        if (tmp != whenGathered) {
            if (entry != null) {
                entry.setDescription(description);
                entries.add(entry);
                entry = null;
            }
            String repoId1 = artifact.getRepositoryId();
            entry = new RssFeedEntry(this.getTitle() + "\'" + repoId1 + "\'" + " as of " + new Date(whenGathered));
            entry.setPublishedDate(artifact.getWhenGathered());
            description = this.getDescription() + "\'" + repoId1 + "\'" + ": \n" + id + " | ";
        } else {
            description = description + id + " | ";
        }
        if (idx == (artifacts.size() - 1)) {
            entry.setDescription(description);
            entries.add(entry);
        }
        tmp = whenGathered;
        idx++;
    }
    return generator.generateFeed(getTitle() + "\'" + repoId + "\'", "New artifacts found in repository " + "\'" + repoId + "\'" + " during repository scan.", entries);
}
Also used : MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) Calendar(java.util.Calendar) FeedException(com.sun.syndication.io.FeedException) ArrayList(java.util.ArrayList) RssFeedEntry(org.apache.archiva.rss.RssFeedEntry) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata) Date(java.util.Date)

Example 3 with FeedException

use of com.sun.syndication.io.FeedException in project archiva by apache.

the class NewVersionsOfArtifactRssFeedProcessor method processNewVersionsOfArtifact.

private SyndFeed processNewVersionsOfArtifact(String groupId, String artifactId, MetadataRepository metadataRepository) throws FeedException {
    List<ArtifactMetadata> artifacts = new ArrayList<>();
    try {
        for (String repoId : metadataRepository.getRepositories()) {
            Collection<String> versions = metadataRepository.getProjectVersions(repoId, groupId, artifactId);
            for (String version : versions) {
                artifacts.addAll(metadataRepository.getArtifacts(repoId, groupId, artifactId, version));
            }
        }
    } catch (MetadataRepositoryException e) {
        throw new FeedException("Unable to construct feed, metadata could not be retrieved: " + e.getMessage(), e);
    } catch (MetadataResolutionException e) {
        throw new FeedException("Unable to construct feed, metadata could not be retrieved: " + e.getMessage(), e);
    }
    long tmp = 0;
    RssFeedEntry entry = null;
    List<RssFeedEntry> entries = new ArrayList<>();
    String description = "";
    int idx = 0;
    for (ArtifactMetadata artifact : artifacts) {
        long whenGathered = artifact.getWhenGathered().getTime();
        if (tmp != whenGathered) {
            if (entry != null) {
                entry.setDescription(description);
                entries.add(entry);
                entry = null;
            }
            entry = new RssFeedEntry(this.getTitle() + "\'" + groupId + ":" + artifactId + "\'" + " as of " + new Date(whenGathered));
            entry.setPublishedDate(artifact.getWhenGathered());
            description = this.getDescription() + "\'" + groupId + ":" + artifactId + "\'" + ": \n" + artifact.getId() + " | ";
        } else {
            description = description + artifact.getId() + " | ";
        }
        if (idx == (artifacts.size() - 1)) {
            entry.setDescription(description);
            entries.add(entry);
        }
        tmp = whenGathered;
        idx++;
    }
    String key = groupId + ":" + artifactId;
    return generator.generateFeed(getTitle() + "\'" + key + "\'", "New versions of artifact " + "\'" + key + "\' found during repository scan.", entries);
}
Also used : MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) FeedException(com.sun.syndication.io.FeedException) ArrayList(java.util.ArrayList) RssFeedEntry(org.apache.archiva.rss.RssFeedEntry) MetadataResolutionException(org.apache.archiva.metadata.repository.MetadataResolutionException) Date(java.util.Date) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata)

Example 4 with FeedException

use of com.sun.syndication.io.FeedException in project ofbiz-framework by apache.

the class RomeEventHandler method invoke.

/**
 * @see org.apache.ofbiz.webapp.event.EventHandler#invoke(ConfigXMLReader.Event, ConfigXMLReader.RequestMap, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
 */
public String invoke(Event event, RequestMap requestMap, HttpServletRequest request, HttpServletResponse response) throws EventHandlerException {
    RequestHandler handler = (RequestHandler) request.getSession().getServletContext().getAttribute("_REQUEST_HANDLER_");
    if (handler == null) {
        throw new EventHandlerException("No request handler found in servlet context!");
    }
    // generate the main and entry links
    String entryLinkReq = request.getParameter("entryLinkReq");
    String mainLinkReq = request.getParameter("mainLinkReq");
    // create the links; but the query string must be created by the service
    String entryLink = handler.makeLink(request, response, entryLinkReq, true, false, false);
    String mainLink = handler.makeLink(request, response, mainLinkReq, true, false, false);
    request.setAttribute("entryLink", entryLink);
    request.setAttribute("mainLink", mainLink);
    String feedType = request.getParameter("feedType");
    if (feedType == null) {
        request.setAttribute("feedType", defaultFeedType);
    }
    // invoke the feed generator service (implements rssFeedInterface)
    String respCode = service.invoke(event, requestMap, request, response);
    // pull out the RSS feed from the request attributes
    WireFeed wireFeed = (WireFeed) request.getAttribute("wireFeed");
    response.setContentType(mime);
    try {
        out.output(wireFeed, response.getWriter());
    } catch (IOException e) {
        throw new EventHandlerException("Unable to get response writer", e);
    } catch (FeedException e) {
        throw new EventHandlerException("Unable to write RSS feed", e);
    }
    return respCode;
}
Also used : RequestHandler(org.apache.ofbiz.webapp.control.RequestHandler) FeedException(com.sun.syndication.io.FeedException) IOException(java.io.IOException) WireFeed(com.sun.syndication.feed.WireFeed)

Example 5 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)

Aggregations

FeedException (com.sun.syndication.io.FeedException)14 SyndFeed (com.sun.syndication.feed.synd.SyndFeed)8 ArrayList (java.util.ArrayList)7 IOException (java.io.IOException)6 SyndEntry (com.sun.syndication.feed.synd.SyndEntry)5 SyndFeedOutput (com.sun.syndication.io.SyndFeedOutput)5 Date (java.util.Date)5 SyndEntryImpl (com.sun.syndication.feed.synd.SyndEntryImpl)3 SyndFeedImpl (com.sun.syndication.feed.synd.SyndFeedImpl)3 SyndFeedInput (com.sun.syndication.io.SyndFeedInput)3 SyndContent (com.sun.syndication.feed.synd.SyndContent)2 SyndContentImpl (com.sun.syndication.feed.synd.SyndContentImpl)2 XmlReader (com.sun.syndication.io.XmlReader)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