com.rometools.rome.feed.rss.Guid Java Examples

The following examples show how to use com.rometools.rome.feed.rss.Guid. 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: HotArticleRssContentView.java    From kaif with Apache License 2.0 5 votes vote down vote up
private Item convertArticle(Article article) {
  Item entry = new Item();
  Guid guid = new Guid();
  guid.setValue(article.getArticleId().toString());
  entry.setGuid(guid);
  entry.setTitle(cleanXml10Characters(article.getTitle()));
  entry.setPubDate(Date.from(article.getCreateTime()));
  Description summary = new Description();
  summary.setType("html");
  summary.setValue(buildSummary(article));
  entry.setDescription(summary);
  entry.setLink(articleUrl(article));
  return entry;
}
 
Example #2
Source File: RSS20Generator.java    From rome with Apache License 2.0 5 votes vote down vote up
@Override
public void populateItem(final Item item, final Element eItem, final int index) {

    super.populateItem(item, eItem, index);

    final Element description = eItem.getChild("description", getFeedNamespace());
    if (description != null) {
        description.removeAttribute("type");
    }

    final String author = item.getAuthor();
    if (author != null) {
        eItem.addContent(generateSimpleElement("author", author));
    }

    final String comments = item.getComments();
    if (comments != null) {
        eItem.addContent(generateSimpleElement("comments", comments));
    }

    final Guid guid = item.getGuid();
    if (guid != null) {
        final Element eGuid = generateSimpleElement("guid", guid.getValue());
        if (!guid.isPermaLink()) {
            eGuid.setAttribute("isPermaLink", "false");
        }
        eItem.addContent(eGuid);
    }
}
 
Example #3
Source File: BasicPodfeedService.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
/**
 * This add a particular podcast to the feed.
 * 
 * @param title
 *            The title for this podcast
 * @param mp3link
 *            The URL where the podcast is stored
 * @param date
 *            The publish date for this podcast
 * @param blogContent
 *            The description of this podcast
 * @param cat
 *            The category of entry this is (Podcast)
 * @param author
 *            The author of this podcast
 * 
 * @return 
 * 			 A SyndEntryImpl for this podcast
 */
private Item addPodcast(Map values) 
{
	final Item item = new Item();

	// set title for this podcast
	item.setTitle((String) values.get("title"));

       // Replace all occurrences of pattern (ie, spaces) in input
       // with hex equivalent (%20)
       Pattern pattern = Pattern.compile(" ");
       String url = (String) values.get("url");
       Matcher matcher = pattern.matcher(url);
       url = matcher.replaceAll("%20");
       item.setLink(url);

       // Set Publish date for this podcast/episode
       // NOTE: date has local time, but when feed rendered,
       // converts it to GMT
	item.setPubDate((Date) values.get("date"));

	// Set description for this podcast/episode
	final Description itemDescription = new Description();
	itemDescription.setType(DESCRIPTION_CONTENT_TYPE);
	itemDescription.setValue((String) values.get("description"));
	item.setDescription(itemDescription);

	// Set guid for this podcast/episode
	item.setGuid(new Guid());
	item.getGuid().setValue((String) values.get("guid"));
	item.getGuid().setPermaLink(false);

	// This creates the enclosure so podcatchers (iTunes) can
	// find the podcasts		
	List enclosures = new ArrayList();

	final Enclosure enc = new Enclosure();
	enc.setUrl(url);
	enc.setType((String) values.get("type"));
	enc.setLength((Long) values.get("len"));

	enclosures.add(enc);

	item.setEnclosures(enclosures);

	// Currently uses 2 modules:
	//  iTunes for podcasting
	//  DCmodule since validators want email with author tag, 
	//    so use dc:creator instead
	List modules = new ArrayList();
	
	// Generate the iTunes tags
	final EntryInformation iTunesModule = new EntryInformationImpl();

	iTunesModule.setAuthor(getMessageBundleString(FEED_ITEM_AUTHOR_STRING));
	iTunesModule.setSummary((String) values.get("description"));

	// Set dc:creator tag
	final DCModuleImpl dcModule = new DCModuleImpl();
	
	dcModule.setCreator((String) values.get("author"));
	
	modules.add(iTunesModule);
	modules.add(dcModule);
	
	item.setModules(modules);
	
	return item;
}
 
Example #4
Source File: BasicPodfeedService.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
/**
 * This add a particular podcast to the feed.
 * 
 * @param title
 *            The title for this podcast
 * @param mp3link
 *            The URL where the podcast is stored
 * @param date
 *            The publish date for this podcast
 * @param blogContent
 *            The description of this podcast
 * @param cat
 *            The category of entry this is (Podcast)
 * @param author
 *            The author of this podcast
 * 
 * @return 
 * 			 A SyndEntryImpl for this podcast
 */
private Item addPodcast(Map values) 
{
	final Item item = new Item();

	// set title for this podcast
	item.setTitle((String) values.get("title"));

       // Replace all occurrences of pattern (ie, spaces) in input
       // with hex equivalent (%20)
       Pattern pattern = Pattern.compile(" ");
       String url = (String) values.get("url");
       Matcher matcher = pattern.matcher(url);
       url = matcher.replaceAll("%20");
       item.setLink(url);

       // Set Publish date for this podcast/episode
       // NOTE: date has local time, but when feed rendered,
       // converts it to GMT
	item.setPubDate((Date) values.get("date"));

	// Set description for this podcast/episode
	final Description itemDescription = new Description();
	itemDescription.setType(DESCRIPTION_CONTENT_TYPE);
	itemDescription.setValue((String) values.get("description"));
	item.setDescription(itemDescription);

	// Set guid for this podcast/episode
	item.setGuid(new Guid());
	item.getGuid().setValue((String) values.get("guid"));
	item.getGuid().setPermaLink(false);

	// This creates the enclosure so podcatchers (iTunes) can
	// find the podcasts		
	List enclosures = new ArrayList();

	final Enclosure enc = new Enclosure();
	enc.setUrl(url);
	enc.setType((String) values.get("type"));
	enc.setLength((Long) values.get("len"));

	enclosures.add(enc);

	item.setEnclosures(enclosures);

	// Currently uses 2 modules:
	//  iTunes for podcasting
	//  DCmodule since validators want email with author tag, 
	//    so use dc:creator instead
	List modules = new ArrayList();
	
	// Generate the iTunes tags
	final EntryInformation iTunesModule = new EntryInformationImpl();

	iTunesModule.setAuthor(getMessageBundleString(FEED_ITEM_AUTHOR_STRING));
	iTunesModule.setSummary((String) values.get("description"));

	// Set dc:creator tag
	final DCModuleImpl dcModule = new DCModuleImpl();
	
	dcModule.setCreator((String) values.get("author"));
	
	modules.add(iTunesModule);
	modules.add(dcModule);
	
	item.setModules(modules);
	
	return item;
}
 
Example #5
Source File: ConverterForRSS094.java    From rome with Apache License 2.0 4 votes vote down vote up
@Override
protected SyndEntry createSyndEntry(final Item item, final boolean preserveWireItem) {

    final SyndEntry syndEntry = super.createSyndEntry(item, preserveWireItem);

    // adding native feed author to DC creators list
    final String author = item.getAuthor();
    if (author != null) {
        final List<String> creators = ((DCModule) syndEntry.getModule(DCModule.URI)).getCreators();
        if (!creators.contains(author)) {

            // using a set to remove duplicates
            final Set<String> s = new LinkedHashSet<String>();

            // DC creators
            s.addAll(creators);

            // feed native author
            s.add(author);

            creators.clear();
            creators.addAll(s);
        }
    }

    final Guid guid = item.getGuid();
    final String itemLink = item.getLink();
    if (guid != null) {
        final String guidValue = guid.getValue();
        syndEntry.setUri(guidValue);
        if (itemLink == null && guid.isPermaLink()) {
            syndEntry.setLink(guidValue);
        }
    } else {
        syndEntry.setUri(itemLink);
    }

    if (item.getComments() != null) {
        final SyndLinkImpl comments = new SyndLinkImpl();
        comments.setRel("comments");
        comments.setHref(item.getComments());
        comments.setType("text/html");
    }

    return syndEntry;

}
 
Example #6
Source File: RSS094Parser.java    From rome with Apache License 2.0 3 votes vote down vote up
@Override
public Item parseItem(final Element rssRoot, final Element eItem, final Locale locale) {

    final Item item = super.parseItem(rssRoot, eItem, locale);

    item.setExpirationDate(null);

    final Element author = eItem.getChild("author", getRSSNamespace());
    if (author != null) {
        item.setAuthor(author.getText());
    }

    final Element eGuid = eItem.getChild("guid", getRSSNamespace());
    if (eGuid != null) {

        final Guid guid = new Guid();

        // getRSSNamespace()); DONT KNOW WHY DOESN'T WORK
        final String att = eGuid.getAttributeValue("isPermaLink");
        if (att != null) {
            guid.setPermaLink(att.equalsIgnoreCase("true"));
        }

        guid.setValue(eGuid.getText());

        item.setGuid(guid);

    }

    final Element comments = eItem.getChild("comments", getRSSNamespace());
    if (comments != null) {
        item.setComments(comments.getText());
    }

    return item;

}