Search in sources :

Example 6 with SyndContent

use of com.sun.syndication.feed.synd.SyndContent in project eclipse-integration-commons by spring-projects.

the class DashboardMainPage method getDescription.

private String getDescription(SyndEntry entry) {
    SyndContent content = entry.getDescription();
    if (content == null) {
        List nestedContent = entry.getContents();
        if (!nestedContent.isEmpty()) {
            Object obj = nestedContent.get(0);
            if (obj instanceof SyndContent) {
                content = (SyndContent) obj;
            }
        }
    }
    if (content == null) {
        return "";
    }
    String value = content.getValue();
    if (value == null) {
        return "";
    }
    if (value.startsWith("<form>")) {
        return value;
    }
    return removeHtmlEntities(value);
}
Also used : SyndContent(com.sun.syndication.feed.synd.SyndContent) ArrayList(java.util.ArrayList) List(java.util.List)

Example 7 with SyndContent

use of com.sun.syndication.feed.synd.SyndContent in project gitblit by gitblit.

the class SyndicationUtils method toRSS.

/**
 * Outputs an RSS feed of the list of entries to the outputstream.
 *
 * @param hostUrl
 * @param feedLink
 * @param title
 * @param description
 * @param entryModels
 * @param os
 * @throws IOException
 * @throws FeedException
 */
public static void toRSS(String hostUrl, String feedLink, String title, String description, List<FeedEntryModel> entryModels, OutputStream os) throws IOException, FeedException {
    SyndFeed feed = new SyndFeedImpl();
    feed.setFeedType("rss_2.0");
    feed.setEncoding("UTF-8");
    feed.setTitle(title);
    feed.setLink(feedLink);
    if (StringUtils.isEmpty(description)) {
        feed.setDescription(title);
    } else {
        feed.setDescription(description);
    }
    SyndImageImpl image = new SyndImageImpl();
    image.setTitle(Constants.NAME);
    image.setUrl(hostUrl + "/gitblt_25.png");
    image.setLink(hostUrl);
    feed.setImage(image);
    List<SyndEntry> entries = new ArrayList<SyndEntry>();
    for (FeedEntryModel entryModel : entryModels) {
        SyndEntry entry = new SyndEntryImpl();
        entry.setTitle(entryModel.title);
        entry.setAuthor(entryModel.author);
        entry.setLink(entryModel.link);
        entry.setPublishedDate(entryModel.published);
        if (entryModel.tags != null && entryModel.tags.size() > 0) {
            List<SyndCategory> tags = new ArrayList<SyndCategory>();
            for (String tag : entryModel.tags) {
                SyndCategoryImpl cat = new SyndCategoryImpl();
                cat.setName(tag);
                tags.add(cat);
            }
            entry.setCategories(tags);
        }
        SyndContent content = new SyndContentImpl();
        if (StringUtils.isEmpty(entryModel.contentType) || entryModel.contentType.equalsIgnoreCase("text/plain")) {
            content.setType("text/html");
            content.setValue(StringUtils.breakLinesForHtml(entryModel.content));
        } else {
            content.setType(entryModel.contentType);
            content.setValue(entryModel.content);
        }
        entry.setDescription(content);
        entries.add(entry);
    }
    feed.setEntries(entries);
    OutputStreamWriter writer = new OutputStreamWriter(os, "UTF-8");
    SyndFeedOutput output = new SyndFeedOutput();
    output.output(feed, writer);
    writer.close();
}
Also used : SyndCategory(com.sun.syndication.feed.synd.SyndCategory) SyndImageImpl(com.sun.syndication.feed.synd.SyndImageImpl) FeedEntryModel(com.gitblit.models.FeedEntryModel) SyndEntry(com.sun.syndication.feed.synd.SyndEntry) SyndContentImpl(com.sun.syndication.feed.synd.SyndContentImpl) ArrayList(java.util.ArrayList) SyndFeedOutput(com.sun.syndication.io.SyndFeedOutput) SyndFeed(com.sun.syndication.feed.synd.SyndFeed) SyndCategoryImpl(com.sun.syndication.feed.synd.SyndCategoryImpl) SyndContent(com.sun.syndication.feed.synd.SyndContent) SyndEntryImpl(com.sun.syndication.feed.synd.SyndEntryImpl) SyndFeedImpl(com.sun.syndication.feed.synd.SyndFeedImpl) OutputStreamWriter(java.io.OutputStreamWriter)

Example 8 with SyndContent

use of com.sun.syndication.feed.synd.SyndContent in project scoold by Erudika.

the class SearchController method getFeed.

private SyndFeed getFeed() throws IOException, FeedException {
    List<Post> questions = pc.findQuery(Utils.type(Question.class), "*");
    List<SyndEntry> entries = new ArrayList<SyndEntry>();
    String baseurl = ScooldServer.getServerURL();
    baseurl = baseurl.endsWith("/") ? baseurl : baseurl + "/";
    SyndFeed feed = new SyndFeedImpl();
    feed.setFeedType("atom_1.0");
    feed.setTitle(Config.APP_NAME + " - Recent questions");
    feed.setLink(baseurl);
    feed.setDescription("A summary of the most recent questions on " + Config.APP_NAME);
    for (Post post : questions) {
        SyndEntry entry;
        SyndContent description;
        String baselink = baseurl.concat("question/").concat(post.getId());
        entry = new SyndEntryImpl();
        entry.setTitle(post.getTitle());
        entry.setLink(baselink);
        entry.setPublishedDate(new Date(post.getTimestamp()));
        entry.setAuthor(baseurl.concat("profile/").concat(post.getCreatorid()));
        entry.setUri(baselink.concat("/").concat(Utils.stripAndTrim(post.getTitle()).replaceAll("\\p{Z}+", "-").toLowerCase()));
        description = new SyndContentImpl();
        description.setType("text/html");
        description.setValue(Utils.markdownToHtml(post.getBody()));
        entry.setDescription(description);
        entries.add(entry);
    }
    feed.setEntries(entries);
    return feed;
}
Also used : Post(com.erudika.scoold.core.Post) SyndEntry(com.sun.syndication.feed.synd.SyndEntry) SyndContentImpl(com.sun.syndication.feed.synd.SyndContentImpl) ArrayList(java.util.ArrayList) Date(java.util.Date) SyndFeed(com.sun.syndication.feed.synd.SyndFeed) SyndContent(com.sun.syndication.feed.synd.SyndContent) SyndEntryImpl(com.sun.syndication.feed.synd.SyndEntryImpl) Question(com.erudika.scoold.core.Question) SyndFeedImpl(com.sun.syndication.feed.synd.SyndFeedImpl)

Example 9 with SyndContent

use of com.sun.syndication.feed.synd.SyndContent in project jersey by jersey.

the class FeedEntriesAtomBodyWriter method writeTo.

@Override
public void writeTo(List<FeedEntry> entries, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException {
    List<SyndEntry> syndEntries = entries.parallelStream().map(entry -> {
        SyndContent description = new SyndContentImpl();
        description.setType(MediaType.TEXT_PLAIN);
        description.setValue(entry.getDescription());
        SyndEntry syndEntry = new SyndEntryImpl();
        syndEntry.setTitle(entry.getTitle());
        syndEntry.setLink(entry.getLink());
        syndEntry.setPublishedDate(entry.getPublishDate());
        syndEntry.setDescription(description);
        return syndEntry;
    }).collect(Collectors.toList());
    SyndFeed feed = new SyndFeedImpl();
    feed.setFeedType("atom_1.0");
    feed.setTitle("Combined Feed");
    feed.setDescription("Combined Feed created by a feed-combiner application");
    feed.setPublishedDate(new Date());
    feed.setEntries(syndEntries);
    writeSyndFeed(entityStream, feed);
}
Also used : SyndEntry(com.sun.syndication.feed.synd.SyndEntry) Produces(javax.ws.rs.Produces) Provider(javax.ws.rs.ext.Provider) FeedEntry(org.glassfish.jersey.examples.feedcombiner.model.FeedEntry) Date(java.util.Date) SyndFeedImpl(com.sun.syndication.feed.synd.SyndFeedImpl) LoggerFactory(org.slf4j.LoggerFactory) MessageBodyWriter(javax.ws.rs.ext.MessageBodyWriter) FeedException(com.sun.syndication.io.FeedException) MediaType(javax.ws.rs.core.MediaType) SyndContentImpl(com.sun.syndication.feed.synd.SyndContentImpl) OutputStreamWriter(java.io.OutputStreamWriter) OutputStream(java.io.OutputStream) Logger(org.slf4j.Logger) Collection(java.util.Collection) IOException(java.io.IOException) SyndFeedOutput(com.sun.syndication.io.SyndFeedOutput) Collectors(java.util.stream.Collectors) SyndContent(com.sun.syndication.feed.synd.SyndContent) MultivaluedMap(javax.ws.rs.core.MultivaluedMap) List(java.util.List) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) SyndEntryImpl(com.sun.syndication.feed.synd.SyndEntryImpl) Annotation(java.lang.annotation.Annotation) WebApplicationException(javax.ws.rs.WebApplicationException) SyndFeed(com.sun.syndication.feed.synd.SyndFeed) SyndFeed(com.sun.syndication.feed.synd.SyndFeed) SyndContent(com.sun.syndication.feed.synd.SyndContent) SyndContentImpl(com.sun.syndication.feed.synd.SyndContentImpl) SyndEntry(com.sun.syndication.feed.synd.SyndEntry) SyndEntryImpl(com.sun.syndication.feed.synd.SyndEntryImpl) SyndFeedImpl(com.sun.syndication.feed.synd.SyndFeedImpl) Date(java.util.Date)

Example 10 with SyndContent

use of com.sun.syndication.feed.synd.SyndContent in project cubrid-manager by CUBRID.

the class NoticeDashboardEntity method getHtmlContent.

/**
	 * Get HTML content by category.
	 *
	 * @param categories
	 * @return
	 */
public String getHtmlContent(String... categories) {
    Set<String> categorySet = new HashSet<String>();
    if (categories == null) {
        return "";
    }
    for (String category : categories) {
        if (category != null) {
            categorySet.add(category);
        }
    }
    Set<SyndEntry> syndEntries = new HashSet<SyndEntry>();
    if (contents == null || contents.entrySet() == null) {
        return "";
    }
    for (Entry<Set<String>, Set<SyndEntry>> entity : contents.entrySet()) {
        if (entity.getKey().containsAll(categorySet)) {
            syndEntries.addAll(entity.getValue());
        }
    }
    List<SyndEntry> syndEntryList = new ArrayList<SyndEntry>(syndEntries);
    Collections.sort(syndEntryList, new Comparator<SyndEntry>() {

        public int compare(SyndEntry o1, SyndEntry o2) {
            if (o1 == null || o2 == null || o1.getPublishedDate() == null || o2.getPublishedDate() == null) {
                return 0;
            }
            return o2.getPublishedDate().compareTo(o1.getPublishedDate());
        }
    });
    StringBuilder sb = new StringBuilder();
    sb.append("<p>");
    if (syndEntryList != null && !syndEntryList.isEmpty()) {
        for (SyndEntry entry : syndEntryList) {
            SyndContent description = entry.getDescription();
            sb.append("<li>");
            sb.append("<img href=\"icons/action/host_connect.png\"/>");
            sb.append("<a href=\"").append(entry.getLink()).append("\">");
            sb.append(entry.getTitle());
            sb.append("</a>");
            sb.append("</li>");
            if (!StringUtil.isEmpty(description.getValue())) {
                sb.append("<p>");
                sb.append(description.getValue().trim());
                sb.append("</p>");
            }
        }
    } else {
        sb.append("<p>No data.</p>");
    }
    sb.append("</p>");
    return sb.toString();
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) SyndContent(com.sun.syndication.feed.synd.SyndContent) SyndEntry(com.sun.syndication.feed.synd.SyndEntry) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet)

Aggregations

SyndContent (com.sun.syndication.feed.synd.SyndContent)17 SyndContentImpl (com.sun.syndication.feed.synd.SyndContentImpl)12 SyndEntry (com.sun.syndication.feed.synd.SyndEntry)12 SyndEntryImpl (com.sun.syndication.feed.synd.SyndEntryImpl)10 ArrayList (java.util.ArrayList)7 Date (java.util.Date)6 SyndFeed (com.sun.syndication.feed.synd.SyndFeed)5 SyndFeedImpl (com.sun.syndication.feed.synd.SyndFeedImpl)5 IOException (java.io.IOException)4 FeedException (com.sun.syndication.io.FeedException)3 SyndFeedOutput (com.sun.syndication.io.SyndFeedOutput)3 SyndCategory (com.sun.syndication.feed.synd.SyndCategory)2 OutputStreamWriter (java.io.OutputStreamWriter)2 List (java.util.List)2 Post (com.erudika.scoold.core.Post)1 Question (com.erudika.scoold.core.Question)1 FeedEntryModel (com.gitblit.models.FeedEntryModel)1 KBArticle (com.liferay.knowledgebase.model.KBArticle)1 SystemException (com.liferay.portal.kernel.exception.SystemException)1 GeoRSSModule (com.sun.syndication.feed.module.georss.GeoRSSModule)1