Java Code Examples for com.sun.syndication.feed.synd.SyndContent#setValue()

The following examples show how to use com.sun.syndication.feed.synd.SyndContent#setValue() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RSSGenServlet.java    From jivejdon with Apache License 2.0 6 votes vote down vote up
private void addSitemapUrl(String url, List<SyndEntrySorted> entries, Url urlsm, HttpServletRequest request) {
	try {
		SyndEntrySorted entry = new SyndEntrySorted();
		entry.setTitle(urlsm.getName());
		entry.setLink(urlsm.getIoc());

		Date publishedDate = Constants.parseDateTime(urlsm.getCreationDate());
		entry.setPublishedDate(publishedDate);
		entry.setUpdatedDate(publishedDate);

		SyndContent description = new SyndContentImpl();
		description.setType("text/html");
		description.setValue("");
		entry.setDescription(description);

		entries.add(entry);
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
Example 2
Source File: RSSGenServlet.java    From jivejdon with Apache License 2.0 5 votes vote down vote up
private void addMessage(String url, List<SyndEntrySorted> entries, ForumMessage message, HttpServletRequest request) {
	try {
		SyndEntrySorted entry = new SyndEntrySorted();
		entry.setTitle(message.getMessageVO().getSubject());
		entry.setLink(getItemLink(url, message, request));

		Date publishedDate = Constants.parseDateTime(message.getCreationDate());
		entry.setPublishedDate(publishedDate);
		entry.setAuthor(message.getAccount().getUsername());
		Date updateDate = Constants.parseDateTime(message.getModifiedDate());
		entry.setUpdatedDate(updateDate);

		SyndContent description = new SyndContentImpl();
		description.setType("text/html");
		description.setValue(message.getMessageVO().getShortBody(300));
		entry.setDescription(description);

		if (message.isRoot()) {
			List<SyndCategory> cats = new ArrayList<SyndCategory>();
			for (Object o : message.getForumThread().getTags()) {
				ThreadTag tag = (ThreadTag) o;
				SyndCategory cat = new SyndCategoryImpl();

				cat.setTaxonomyUri(url + "/tags/" + tag.getTagID());
				cat.setName(tag.getTitle());
				cats.add(cat);
			}
			entry.setCategories(cats);
		}
		entries.add(entry);
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
Example 3
Source File: RSSFeed.java    From olat with Apache License 2.0 4 votes vote down vote up
/**
    * Constructor. The identityKey is needed to generate personal URLs for the corresponding user.
    */
protected RSSFeed(final Feed feed, final Identity identity, final Long courseId, final String nodeId,final Translator translator, RepositoryService repositoryService) {
       super();

       // This helper object is required for generating the appropriate URLs for
       // the given user (identity)
	final FeedViewHelper helper = new FeedViewHelper(feed, identity, courseId, nodeId, translator, repositoryService);

       setFeedType("rss_2.0");
       setEncoding(RSSServlet.DEFAULT_ENCODING);
       setTitle(feed.getTitle());
       // According to the rss specification, the feed channel description is not
       // (explicitly) allowed to contain html tags.
       String strippedDescription = FilterFactory.getHtmlTagsFilter().filter(feed.getDescription());
       strippedDescription = strippedDescription.replaceAll("&nbsp;", " "); // TODO: remove when filter
       // does it
       setDescription(strippedDescription);
       setLink(helper.getJumpInLink());

       setPublishedDate(feed.getLastModified());
       // The image
       if (feed.getImageName() != null) {
           final SyndImage image = new SyndImageImpl();
           image.setDescription(feed.getDescription());
           image.setTitle(feed.getTitle());
           image.setLink(getLink());
           image.setUrl(helper.getImageUrl());
           setImage(image);
       }

       final List<SyndEntry> episodes = new ArrayList<SyndEntry>();
       for (final Item item : feed.getPublishedItems()) {
           final SyndEntry entry = new SyndEntryImpl();
           entry.setTitle(item.getTitle());

           final SyndContent itemDescription = new SyndContentImpl();
           itemDescription.setType("text/plain");
           itemDescription.setValue(helper.getItemDescriptionForBrowser(item));
           entry.setDescription(itemDescription);

           // Link will also be converted to the rss guid tag. Except if there's an
           // enclosure, then the enclosure url is used.
           // Use jump-in link far all entries. This will be overriden if the item
           // has an enclosure.
           entry.setLink(helper.getJumpInLink() + "#" + item.getGuid());
           entry.setPublishedDate(item.getPublishDate());
           entry.setUpdatedDate(item.getLastModified());

           // The enclosure is the media (audio or video) file of the episode
           final Enclosure media = item.getEnclosure();
           if (media != null) {
               final SyndEnclosure enclosure = new SyndEnclosureImpl();
               enclosure.setUrl(helper.getMediaUrl(item));
               enclosure.setType(media.getType());
               enclosure.setLength(media.getLength());
               // Also set the item link to point to the enclosure
               entry.setLink(helper.getMediaUrl(item));
               final List<SyndEnclosure> enclosures = new ArrayList<SyndEnclosure>();
               enclosures.add(enclosure);
               entry.setEnclosures(enclosures);
           }

           episodes.add(entry);
       }
       setEntries(episodes);
   }
 
Example 4
Source File: RSSFeed.java    From olat with Apache License 2.0 4 votes vote down vote up
/**
 * Constructor. The identityKey is needed to generate personal URLs for the corresponding user.
 */
protected RSSFeed(final Feed feed, final Identity identity, final Long courseId, final String nodeId, final Translator translator, RepositoryService repositoryService) {
    super();

    // This helper object is required for generating the appropriate URLs for
    // the given user (identity)
    final FeedViewHelper helper = new FeedViewHelper(feed, identity, courseId, nodeId, translator, repositoryService);

    setFeedType("rss_2.0");
    setEncoding(DEFAULT_ENCODING);
    setTitle(feed.getTitle());
    // According to the rss specification, the feed channel description is not
    // (explicitly) allowed to contain html tags.
    String strippedDescription = FilterFactory.getHtmlTagsFilter().filter(feed.getDescription());
    strippedDescription = strippedDescription.replaceAll("&nbsp;", " "); // TODO: remove when filter
    // does it
    setDescription(strippedDescription);
    setLink(helper.getJumpInLink());

    setPublishedDate(feed.getLastModified());
    // The image
    if (feed.getImageName() != null) {
        final SyndImage image = new SyndImageImpl();
        image.setDescription(feed.getDescription());
        image.setTitle(feed.getTitle());
        image.setLink(getLink());
        image.setUrl(helper.getImageUrl());
        setImage(image);
    }

    final List<SyndEntry> episodes = new ArrayList<SyndEntry>();
    for (final Item item : feed.getPublishedItems()) {
        final SyndEntry entry = new SyndEntryImpl();
        entry.setTitle(item.getTitle());

        final SyndContent itemDescription = new SyndContentImpl();
        itemDescription.setType("text/plain");
        itemDescription.setValue(helper.getItemDescriptionForBrowser(item));
        entry.setDescription(itemDescription);

        // Link will also be converted to the rss guid tag. Except if there's an
        // enclosure, then the enclosure url is used.
        // Use jump-in link far all entries. This will be overriden if the item
        // has an enclosure.
        entry.setLink(helper.getJumpInLink() + "#" + item.getGuid());
        entry.setPublishedDate(item.getPublishDate());
        entry.setUpdatedDate(item.getLastModified());

        // The enclosure is the media (audio or video) file of the episode
        final Enclosure media = item.getEnclosure();
        if (media != null) {
            final SyndEnclosure enclosure = new SyndEnclosureImpl();
            enclosure.setUrl(helper.getMediaUrl(item));
            enclosure.setType(media.getType());
            enclosure.setLength(media.getLength());
            // Also set the item link to point to the enclosure
            entry.setLink(helper.getMediaUrl(item));
            final List<SyndEnclosure> enclosures = new ArrayList<SyndEnclosure>();
            enclosures.add(enclosure);
            entry.setEnclosures(enclosures);
        }

        episodes.add(entry);
    }
    setEntries(episodes);
}