com.rometools.rome.feed.synd.SyndContent Java Examples

The following examples show how to use com.rometools.rome.feed.synd.SyndContent. 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: SyndEntrySerializer.java    From streams with Apache License 2.0 6 votes vote down vote up
private void serializeDescription(ObjectNode root, JsonNodeFactory factory, SyndContent synd) {
  if (synd == null) {
    return;
  }
  ObjectNode content = factory.objectNode();
  if (synd.getValue() != null) {
    content.put("value", synd.getValue());
  }
  if (synd.getMode() != null) {
    content.put("mode", synd.getMode());
  }
  if (synd.getType() != null) {
    content.put("type", synd.getType());
  }
  root.put("description", content);
}
 
Example #2
Source File: Entry.java    From commafeed with Apache License 2.0 6 votes vote down vote up
public SyndEntry asRss() {
	SyndEntry entry = new SyndEntryImpl();

	entry.setUri(getGuid());
	entry.setTitle(getTitle());
	entry.setAuthor(getAuthor());

	SyndContentImpl content = new SyndContentImpl();
	content.setValue(getContent());
	entry.setContents(Arrays.<SyndContent> asList(content));

	if (getEnclosureUrl() != null) {
		SyndEnclosureImpl enclosure = new SyndEnclosureImpl();
		enclosure.setType(getEnclosureType());
		enclosure.setUrl(getEnclosureUrl());
		entry.setEnclosures(Arrays.<SyndEnclosure> asList(enclosure));
	}

	entry.setLink(getUrl());
	entry.setPublishedDate(getDate());
	return entry;
}
 
Example #3
Source File: ConverterForRSS091Userland.java    From rome with Apache License 2.0 6 votes vote down vote up
@Override
protected Item createRSSItem(final SyndEntry sEntry) {

    final Item item = super.createRSSItem(sEntry);

    item.setComments(sEntry.getComments());

    final SyndContent sContent = sEntry.getDescription();

    if (sContent != null) {
        item.setDescription(createItemDescription(sContent));
    }

    final List<SyndContent> contents = sEntry.getContents();

    if (Lists.isNotEmpty(contents)) {
        final SyndContent syndContent = contents.get(0);
        final Content cont = new Content();
        cont.setValue(syndContent.getValue());
        cont.setType(syndContent.getType());
        item.setContent(cont);
    }

    return item;
}
 
Example #4
Source File: ConverterForRSS10.java    From rome with Apache License 2.0 6 votes vote down vote up
@Override
protected Item createRSSItem(final SyndEntry sEntry) {

    final Item item = super.createRSSItem(sEntry);

    final SyndContent desc = sEntry.getDescription();
    if (desc != null) {
        item.setDescription(createItemDescription(desc));
    }

    final List<SyndContent> contents = sEntry.getContents();
    if (Lists.isNotEmpty(contents)) {
        item.setContent(createItemContent(contents.get(0)));
    }

    final String uri = sEntry.getUri();
    if (uri != null) {
        item.setUri(uri);
    }

    return item;
}
 
Example #5
Source File: SyndicationServlet.java    From BIMserver with GNU Affero General Public License v3.0 5 votes vote down vote up
private void writeRevisionsFeed(HttpServletRequest request, HttpServletResponse response, ServiceMap serviceMap) throws IOException, FeedException, ServiceException, PublicInterfaceNotFoundException {
	long poid = Long.parseLong(request.getParameter("poid"));
	SProject sProject = serviceMap.getServiceInterface().getProjectByPoid(poid);

	SyndFeed feed = new SyndFeedImpl();
	feed.setFeedType(FEED_TYPE);

	feed.setTitle("BIMserver.org revisions feed for project '" + sProject.getName() + "'");
	feed.setLink(request.getContextPath());
	feed.setDescription("This feed represents all the revisions of project '" + sProject.getName() + "'");

	List<SyndEntry> entries = new ArrayList<SyndEntry>();
	try {
		List<SRevision> allRevisionsOfProject = serviceMap.getServiceInterface().getAllRevisionsOfProject(poid);
		Collections.sort(allRevisionsOfProject, new SRevisionIdComparator(false));
		for (SRevision sVirtualRevision : allRevisionsOfProject) {
			SUser user = serviceMap.getServiceInterface().getUserByUoid(sVirtualRevision.getUserId());
			SyndEntry entry = new SyndEntryImpl();
			entry.setTitle("Revision " + sVirtualRevision.getOid());
			entry.setLink(request.getContextPath() + "/revision.jsp?poid=" + sVirtualRevision.getOid() + "&roid=" + sVirtualRevision.getOid());
			entry.setPublishedDate(sVirtualRevision.getDate());
			SyndContent description = new SyndContentImpl();
			description.setType("text/html");
			description.setValue("<table><tr><td>User</td><td>" + user.getUsername() + "</td></tr><tr><td>Comment</td><td>" + sVirtualRevision.getComment()
					+ "</td></tr></table>");
			entry.setDescription(description);
			entries.add(entry);
		}
	} catch (ServiceException e) {
		LOGGER.error("", e);
	}
	feed.setEntries(entries);
	SyndFeedOutput output = new SyndFeedOutput();
	output.output(feed, response.getWriter());
}
 
Example #6
Source File: Utilities.java    From SimpleNews with Apache License 2.0 5 votes vote down vote up
static Entry getEntryFromRSSItem(SyndEntry item, Long feedId, String source, long categoryId) {
    if (item != null) {
        if (item.getTitle() == null) {
            return null;
        }

        Object url = item.getLink();
        if (url == null) {
            return null;
        }

        Date pubDate = item.getPublishedDate();
        Long time = null;
        if (pubDate != null) {
            time = pubDate.getTime();
        }

        SyndContent desc = item.getDescription();
        String description = null;
        if (desc != null && desc.getValue() != null) {
            description = desc.getValue();
            description = description.replaceAll("<.*?>", "").replace("()", "").replace("&nbsp;", "").trim();
        }

        return new Entry(null, feedId, categoryId, item.getTitle().trim(), description, time, source, url.toString(), null, null, null, null,
                false);
    }
    return null;
}
 
Example #7
Source File: RSSFeedServlet.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
private SyndEntry createFeedEntry(String title, String content, int index) {
    SyndEntry entry = new SyndEntryImpl();
    entry.setTitle(title + index);
    entry.setLink("http://localhost:8080/rss-tests/" + index);
    entry.setPublishedDate(new Date());

    SyndContent description = new SyndContentImpl();
    description.setType("text/plain");
    description.setValue(content + index);
    entry.setDescription(description);
    return entry;
}
 
Example #8
Source File: ConverterForRSS091Userland.java    From rome with Apache License 2.0 5 votes vote down vote up
@Override
protected SyndEntry createSyndEntry(final Item item, final boolean preserveWireItem) {

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

    final Description desc = item.getDescription();

    syndEntry.setComments(item.getComments());

    // DublinCoreTest will be failed without this row
    // I don't have better solution
    if (syndEntry.getPublishedDate() == null)
        syndEntry.setPublishedDate(item.getPubDate());

    if (desc != null) {
        final SyndContent descContent = new SyndContentImpl();
        descContent.setType(desc.getType());
        descContent.setValue(desc.getValue());
        syndEntry.setDescription(descContent);
    }

    final Content cont = item.getContent();

    if (cont != null) {
        final SyndContent content = new SyndContentImpl();
        content.setType(cont.getType());
        content.setValue(cont.getValue());

        final List<SyndContent> syndContents = new ArrayList<SyndContent>();
        syndContents.add(content);
        syndEntry.setContents(syndContents);
    }

    return syndEntry;
}
 
Example #9
Source File: ConverterForRSS10.java    From rome with Apache License 2.0 5 votes vote down vote up
@Override
protected SyndEntry createSyndEntry(final Item item, final boolean preserveWireItem) {

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

    final Description desc = item.getDescription();
    if (desc != null) {
        final SyndContent descContent = new SyndContentImpl();
        descContent.setType(desc.getType());
        descContent.setValue(desc.getValue());
        syndEntry.setDescription(descContent);
    }

    final Content cont = item.getContent();
    if (cont != null) {

        final SyndContent contContent = new SyndContentImpl();
        contContent.setType(cont.getType());
        contContent.setValue(cont.getValue());

        final List<SyndContent> contents = new ArrayList<SyndContent>();
        contents.add(contContent);
        syndEntry.setContents(contents);

    }

    return syndEntry;

}
 
Example #10
Source File: ConverterForAtom10.java    From rome with Apache License 2.0 5 votes vote down vote up
protected List<Content> createAtomContents(final List<SyndContent> syndContents) {
    final List<Content> atomContents = new ArrayList<Content>();
    for (final SyndContent syndContent : syndContents) {
        atomContents.add(createAtomContent(syndContent));
    }
    return atomContents;
}
 
Example #11
Source File: SyndicationServlet.java    From BIMserver with GNU Affero General Public License v3.0 5 votes vote down vote up
private void writeCheckoutsFeed(HttpServletRequest request, HttpServletResponse response, ServiceMap serviceMap) throws ServiceException, IOException, FeedException, PublicInterfaceNotFoundException {
	long poid = Long.parseLong(request.getParameter("poid"));
	SProject sProject = serviceMap.getServiceInterface().getProjectByPoid(poid);

	SyndFeed feed = new SyndFeedImpl();
	feed.setFeedType(FEED_TYPE);

	feed.setTitle("BIMserver.org checkouts feed for project '" + sProject.getName() + "'");
	feed.setLink(request.getContextPath());
	feed.setDescription("This feed represents all the checkouts of project '" + sProject.getName() + "'");

	List<SyndEntry> entries = new ArrayList<SyndEntry>();
	try {
		List<SCheckout> allCheckoutsOfProject = serviceMap.getServiceInterface().getAllCheckoutsOfProjectAndSubProjects(poid);
		for (SCheckout sCheckout : allCheckoutsOfProject) {
			SRevision revision = serviceMap.getServiceInterface().getRevision(sCheckout.getRevision().getOid());
			SProject project = serviceMap.getServiceInterface().getProjectByPoid(sCheckout.getProjectId());
			SUser user = serviceMap.getServiceInterface().getUserByUoid(sCheckout.getUserId());
			SyndEntry entry = new SyndEntryImpl();
			entry.setTitle("Checkout on " + project.getName() + ", revision " + revision.getId());
			entry.setLink(request.getContextPath() + "/project.jsp?poid=" + sProject.getOid());
			entry.setPublishedDate(sCheckout.getDate());
			SyndContent description = new SyndContentImpl();
			description.setType("text/plain");
			description
					.setValue("<table><tr><td>User</td><td>" + user.getUsername() + "</td></tr><tr><td>Revision</td><td>" + sCheckout.getRevision().getOid() + "</td></tr></table>");
			entry.setDescription(description);
			entries.add(entry);
		}
	} catch (UserException e) {
		LOGGER.error("", e);
	}
	feed.setEntries(entries);
	SyndFeedOutput output = new SyndFeedOutput();
	output.output(feed, response.getWriter());
}
 
Example #12
Source File: ConverterForRSS10.java    From rome with Apache License 2.0 4 votes vote down vote up
protected Description createItemDescription(final SyndContent sContent) {
    final Description desc = new Description();
    desc.setValue(sContent.getValue());
    desc.setType(sContent.getType());
    return desc;
}
 
Example #13
Source File: ConverterForRSS10.java    From rome with Apache License 2.0 4 votes vote down vote up
protected Content createItemContent(final SyndContent sContent) {
    final Content cont = new Content();
    cont.setValue(sContent.getValue());
    cont.setType(sContent.getType());
    return cont;
}
 
Example #14
Source File: ConverterForRSS091Userland.java    From rome with Apache License 2.0 4 votes vote down vote up
protected Description createItemDescription(final SyndContent sContent) {
    final Description desc = new Description();
    desc.setValue(sContent.getValue());
    desc.setType(sContent.getType());
    return desc;
}
 
Example #15
Source File: ConverterForAtom10.java    From rome with Apache License 2.0 4 votes vote down vote up
protected Content createAtomContent(final SyndContent sContent) {
    final Content content = new Content();
    content.setType(sContent.getType());
    content.setValue(sContent.getValue());
    return content;
}
 
Example #16
Source File: FeedParserBolt.java    From storm-crawler with Apache License 2.0 4 votes vote down vote up
private List<Outlink> parseFeed(String url, byte[] content,
        Metadata parentMetadata) throws Exception {
    List<Outlink> links = new ArrayList<>();

    SyndFeed feed = null;
    try (ByteArrayInputStream is = new ByteArrayInputStream(content)) {
        SyndFeedInput input = new SyndFeedInput();
        feed = input.build(new InputSource(is));
    }

    URL sURL = new URL(url);

    List<SyndEntry> entries = feed.getEntries();
    for (SyndEntry entry : entries) {
        String targetURL = entry.getLink();
        // targetURL can be null?!?
        // e.g. feed does not use links but guid
        if (StringUtils.isBlank(targetURL)) {
            targetURL = entry.getUri();
            if (StringUtils.isBlank(targetURL)) {
                continue;
            }
        }
        Outlink newLink = filterOutlink(sURL, targetURL, parentMetadata);
        if (newLink == null)
            continue;

        String title = entry.getTitle();
        if (StringUtils.isNotBlank(title)) {
            newLink.getMetadata().setValue("feed.title", title.trim());
        }

        Date publishedDate = entry.getPublishedDate();
        if (publishedDate != null) {
            // filter based on the published date
            if (filterHoursSincePub != -1) {
                Calendar rightNow = Calendar.getInstance();
                rightNow.add(Calendar.HOUR, -filterHoursSincePub);
                if (publishedDate.before(rightNow.getTime())) {
                    LOG.info(
                            "{} has a published date {} which is more than {} hours old",
                            targetURL, publishedDate.toString(),
                            filterHoursSincePub);
                    continue;
                }
            }
            newLink.getMetadata().setValue("feed.publishedDate",
                    publishedDate.toString());
        }

        SyndContent description = entry.getDescription();
        if (description != null
                && StringUtils.isNotBlank(description.getValue())) {
            newLink.getMetadata().setValue("feed.description",
                    description.getValue());
        }

        links.add(newLink);
    }

    return links;
}
 
Example #17
Source File: ConverterForAtom10.java    From rome with Apache License 2.0 4 votes vote down vote up
protected SyndContent createSyndContent(final Content content) {
    final SyndContent sContent = new SyndContentImpl();
    sContent.setType(content.getType());
    sContent.setValue(content.getValue());
    return sContent;
}