/** * Create a new Feed instance to hold the entries. * <p>By default returns an Atom 1.0 feed, but the subclass can specify any Feed. * @see #setFeedType(String) */ @Override protected Feed newFeed() { return new Feed(this.feedType); }
@Override protected void buildFeedMetadata(Map<String, Object>model, Feed feed, HttpServletRequest request) { feed.setTitle("Test Feed"); }
/** * 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); }
@Override protected List<Entry> buildFeedEntries(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) { List<Entry> entries = new ArrayList<>(); for (String name : model.keySet()) { Entry entry = new Entry(); entry.setTitle(name); Content content = new Content(); content.setValue((String) model.get(name)); entry.setSummary(content); entries.add(entry); } return entries; } }
@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)); }
@Test public void read() throws IOException { InputStream is = getClass().getResourceAsStream("atom.xml"); MockHttpInputMessage inputMessage = new MockHttpInputMessage(is); inputMessage.getHeaders().setContentType(new MediaType("application", "atom+xml", StandardCharsets.UTF_8)); Feed result = converter.read(Feed.class, inputMessage); assertEquals("title", result.getTitle()); assertEquals("subtitle", result.getSubtitle().getValue()); List<?> entries = result.getEntries(); assertEquals(2, entries.size()); Entry entry1 = (Entry) entries.get(0); assertEquals("id1", entry1.getId()); assertEquals("title1", entry1.getTitle()); Entry entry2 = (Entry) entries.get(1); assertEquals("id2", entry2.getId()); assertEquals("title2", entry2.getTitle()); }
@Test public void writeOtherCharset() throws IOException, SAXException { Feed feed = new Feed("atom_1.0"); feed.setTitle("title"); String encoding = "ISO-8859-1"; feed.setEncoding(encoding); MockHttpOutputMessage outputMessage = new MockHttpOutputMessage(); converter.write(feed, null, outputMessage); assertEquals("Invalid content-type", new MediaType("application", "atom+xml", Charset.forName(encoding)), outputMessage.getHeaders().getContentType()); }
/** * Returns the entry title. * <p> * * @return the entry title, <b>null</b> if none. * */ public String getTitle() { if (title != null) { return title.getValue(); } return null; }
private Entry findEntry(final String id, final Feed feed) { for (final Entry entry : feed.getEntries()) { if (id.equals(entry.getId())) { return entry; } } return null; }
@Override public void setCreated(final Date d) { // protected against null created property (an old Atom 0.3 property) if (d != null) { super.setCreated(d); } } }
/** * Returns the feed title. * <p> * * @return the feed title, <b>null</b> if none. * */ public String getTitle() { if (title != null) { return title.getValue(); } return null; }
/** * Create a new Feed instance to hold the entries. * <p>By default returns an Atom 1.0 feed, but the subclass can specify any Feed. * @see #setFeedType(String) */ @Override protected Feed newFeed() { return new Feed(this.feedType); }
/** * 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); }
/** * Returns the entry title. * <p> * * @return the entry title, <b>null</b> if none. * */ public String getTitle() { if (title != null) { return title.getValue(); } return null; }
/** * Create a new Feed instance to hold the entries. * <p>By default returns an Atom 1.0 feed, but the subclass can specify any Feed. * @see #setFeedType(String) */ @Override protected Feed newFeed() { return new Feed(this.feedType); }
/** * Returns the feed title. * <p> * * @return the feed title, <b>null</b> if none. * */ public String getTitle() { if (title != null) { return title.getValue(); } return null; }