Java Code Examples for com.rometools.rome.feed.atom.Feed#setEntries()

The following examples show how to use com.rometools.rome.feed.atom.Feed#setEntries() . 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: Atom10Generator.java    From rome with Apache License 2.0 6 votes vote down vote up
/**
 * Utility method to serialize an entry to writer.
 */
public static void serializeEntry(final Entry entry, final Writer writer) throws IllegalArgumentException, FeedException, IOException {

    // Build a feed containing only the entry
    final List<Entry> entries = new ArrayList<Entry>();
    entries.add(entry);
    final Feed feed1 = new Feed();
    feed1.setFeedType("atom_1.0");
    feed1.setEntries(entries);

    // Get Rome to output feed as a JDOM document
    final WireFeedOutput wireFeedOutput = new WireFeedOutput();
    final Document feedDoc = wireFeedOutput.outputJDom(feed1);

    // Grab entry element from feed and get JDOM to serialize it
    final Element entryElement = feedDoc.getRootElement().getChildren().get(0);

    final XMLOutputter outputter = new XMLOutputter();
    outputter.output(entryElement, writer);
}
 
Example 2
Source File: AbstractAtomFeedView.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Invokes {@link #buildFeedEntries(Map, HttpServletRequest, HttpServletResponse)}
 * to get a list of feed entries.
 */
@Override
protected final void buildFeedEntries(Map<String, Object> model, Feed feed,
		HttpServletRequest request, HttpServletResponse response) throws Exception {

	List<Entry> entries = buildFeedEntries(model, request, response);
	feed.setEntries(entries);
}
 
Example 3
Source File: AtomFeedHttpMessageConverterTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void write() throws IOException, SAXException {
	Feed feed = new Feed("atom_1.0");
	feed.setTitle("title");

	Entry entry1 = new Entry();
	entry1.setId("id1");
	entry1.setTitle("title1");

	Entry entry2 = new Entry();
	entry2.setId("id2");
	entry2.setTitle("title2");

	List<Entry> entries = new ArrayList<>(2);
	entries.add(entry1);
	entries.add(entry2);
	feed.setEntries(entries);

	MockHttpOutputMessage outputMessage = new MockHttpOutputMessage();
	converter.write(feed, null, outputMessage);

	assertEquals("Invalid content-type", new MediaType("application", "atom+xml", StandardCharsets.UTF_8),
			outputMessage.getHeaders().getContentType());
	String expected = "<feed xmlns=\"http://www.w3.org/2005/Atom\">" + "<title>title</title>" +
			"<entry><id>id1</id><title>title1</title></entry>" +
			"<entry><id>id2</id><title>title2</title></entry></feed>";
	NodeMatcher nm = new DefaultNodeMatcher(ElementSelectors.byName);
	assertThat(outputMessage.getBodyAsString(StandardCharsets.UTF_8),
			isSimilarTo(expected).ignoreWhitespace().withNodeMatcher(nm));
}
 
Example 4
Source File: AbstractAtomFeedView.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Invokes {@link #buildFeedEntries(Map, HttpServletRequest, HttpServletResponse)}
 * to get a list of feed entries.
 */
@Override
protected final void buildFeedEntries(Map<String, Object> model, Feed feed,
		HttpServletRequest request, HttpServletResponse response) throws Exception {

	List<Entry> entries = buildFeedEntries(model, request, response);
	feed.setEntries(entries);
}
 
Example 5
Source File: AtomFeedHttpMessageConverterTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void write() throws IOException, SAXException {
	Feed feed = new Feed("atom_1.0");
	feed.setTitle("title");

	Entry entry1 = new Entry();
	entry1.setId("id1");
	entry1.setTitle("title1");

	Entry entry2 = new Entry();
	entry2.setId("id2");
	entry2.setTitle("title2");

	List<Entry> entries = new ArrayList<>(2);
	entries.add(entry1);
	entries.add(entry2);
	feed.setEntries(entries);

	MockHttpOutputMessage outputMessage = new MockHttpOutputMessage();
	converter.write(feed, null, outputMessage);

	assertEquals("Invalid content-type", new MediaType("application", "atom+xml", StandardCharsets.UTF_8),
			outputMessage.getHeaders().getContentType());
	String expected = "<feed xmlns=\"http://www.w3.org/2005/Atom\">" + "<title>title</title>" +
			"<entry><id>id1</id><title>title1</title></entry>" +
			"<entry><id>id2</id><title>title2</title></entry></feed>";
	NodeMatcher nm = new DefaultNodeMatcher(ElementSelectors.byName);
	assertThat(outputMessage.getBodyAsString(StandardCharsets.UTF_8),
			isSimilarTo(expected).ignoreWhitespace().withNodeMatcher(nm));
}
 
Example 6
Source File: AbstractAtomFeedView.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Invokes {@link #buildFeedEntries(Map, HttpServletRequest, HttpServletResponse)}
 * to get a list of feed entries.
 */
@Override
protected final void buildFeedEntries(Map<String, Object> model, Feed feed,
		HttpServletRequest request, HttpServletResponse response) throws Exception {

	List<Entry> entries = buildFeedEntries(model, request, response);
	feed.setEntries(entries);
}
 
Example 7
Source File: AbstractAtomFeedView.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Invokes {@link #buildFeedEntries(Map, HttpServletRequest, HttpServletResponse)}
 * to get a list of feed entries.
 */
@Override
protected final void buildFeedEntries(Map<String, Object> model, Feed feed,
		HttpServletRequest request, HttpServletResponse response) throws Exception {

	List<Entry> entries = buildFeedEntries(model, request, response);
	feed.setEntries(entries);
}
 
Example 8
Source File: AtomFeedHttpMessageConverterTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void write() throws IOException, SAXException {
	Feed feed = new Feed("atom_1.0");
	feed.setTitle("title");

	Entry entry1 = new Entry();
	entry1.setId("id1");
	entry1.setTitle("title1");

	Entry entry2 = new Entry();
	entry2.setId("id2");
	entry2.setTitle("title2");

	List<Entry> entries = new ArrayList<Entry>(2);
	entries.add(entry1);
	entries.add(entry2);
	feed.setEntries(entries);

	MockHttpOutputMessage outputMessage = new MockHttpOutputMessage();
	converter.write(feed, null, outputMessage);

	assertEquals("Invalid content-type", new MediaType("application", "atom+xml", utf8),
			outputMessage.getHeaders().getContentType());
	String expected = "<feed xmlns=\"http://www.w3.org/2005/Atom\">" + "<title>title</title>" +
			"<entry><id>id1</id><title>title1</title></entry>" +
			"<entry><id>id2</id><title>title2</title></entry></feed>";
	assertXMLEqual(expected, outputMessage.getBodyAsString(utf8));
}
 
Example 9
Source File: Atom10Parser.java    From rome with Apache License 2.0 5 votes vote down vote up
protected WireFeed parseFeed(final Element eFeed, final Locale locale) throws FeedException {

        String baseURI = null;
        try {
            baseURI = findBaseURI(eFeed);
        } catch (final Exception e) {
            throw new FeedException("ERROR while finding base URI of feed", e);
        }

        final Feed feed = parseFeedMetadata(baseURI, eFeed, locale);
        feed.setStyleSheet(getStyleSheet(eFeed.getDocument()));

        final String xmlBase = eFeed.getAttributeValue("base", Namespace.XML_NAMESPACE);
        if (xmlBase != null) {
            feed.setXmlBase(xmlBase);
        }

        feed.setModules(parseFeedModules(eFeed, locale));

        final List<Element> eList = eFeed.getChildren("entry", getAtomNamespace());
        if (!eList.isEmpty()) {
            feed.setEntries(parseEntries(feed, baseURI, eList, locale));
        }

        final List<Element> foreignMarkup = extractForeignMarkup(eFeed, feed, getAtomNamespace());
        if (!foreignMarkup.isEmpty()) {
            feed.setForeignMarkup(foreignMarkup);
        }
        return feed;
    }
 
Example 10
Source File: Atom03Parser.java    From rome with Apache License 2.0 4 votes vote down vote up
protected WireFeed parseFeed(final Element eFeed, final Locale locale) {

        final String type = getType();
        final Document document = eFeed.getDocument();
        final String styleSheet = getStyleSheet(document);

        final Feed feed = new Feed(type);
        feed.setStyleSheet(styleSheet);

        final Element title = eFeed.getChild("title", getAtomNamespace());
        if (title != null) {
            feed.setTitleEx(parseContent(title));
        }

        final List<Element> links = eFeed.getChildren("link", getAtomNamespace());
        feed.setAlternateLinks(parseAlternateLinks(links));
        feed.setOtherLinks(parseOtherLinks(links));

        final Element author = eFeed.getChild("author", getAtomNamespace());
        if (author != null) {
            final List<SyndPerson> authors = new ArrayList<SyndPerson>();
            authors.add(parsePerson(author));
            feed.setAuthors(authors);
        }

        final List<Element> contributors = eFeed.getChildren("contributor", getAtomNamespace());
        if (!contributors.isEmpty()) {
            feed.setContributors(parsePersons(contributors));
        }

        final Element tagline = eFeed.getChild("tagline", getAtomNamespace());
        if (tagline != null) {
            feed.setTagline(parseContent(tagline));
        }

        final Element id = eFeed.getChild("id", getAtomNamespace());
        if (id != null) {
            feed.setId(id.getText());
        }

        final Element generator = eFeed.getChild("generator", getAtomNamespace());
        if (generator != null) {
            final Generator gen = new Generator();
            gen.setValue(generator.getText());
            String att = getAttributeValue(generator, "url");
            if (att != null) {
                gen.setUrl(att);
            }
            att = getAttributeValue(generator, "version");
            if (att != null) {
                gen.setVersion(att);
            }
            feed.setGenerator(gen);
        }

        final Element copyright = eFeed.getChild("copyright", getAtomNamespace());
        if (copyright != null) {
            feed.setCopyright(copyright.getText());
        }

        final Element info = eFeed.getChild("info", getAtomNamespace());
        if (info != null) {
            feed.setInfo(parseContent(info));
        }

        final Element modified = eFeed.getChild("modified", getAtomNamespace());
        if (modified != null) {
            feed.setModified(DateParser.parseDate(modified.getText(), locale));
        }

        feed.setModules(parseFeedModules(eFeed, locale));

        final List<Element> entries = eFeed.getChildren("entry", getAtomNamespace());
        if (!entries.isEmpty()) {
            feed.setEntries(parseEntries(entries, locale));
        }

        final List<Element> foreignMarkup = extractForeignMarkup(eFeed, feed, getAtomNamespace());
        if (!foreignMarkup.isEmpty()) {
            feed.setForeignMarkup(foreignMarkup);
        }

        return feed;

    }