/** * 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); }
@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()); }
@Override public WireFeed createRealFeed(final SyndFeed syndFeed) { final Feed aFeed = new Feed(getType()); aFeed.setModules(ModuleUtils.cloneModules(syndFeed.getModules())); aFeed.setEncoding(syndFeed.getEncoding()); aFeed.setStyleSheet(syndFeed.getStyleSheet()); aFeed.setId(syndFeed.getUri()); title.setType(sTitle.getType()); title.setValue(sTitle.getValue()); aFeed.setTitleEx(title); subtitle.setType(sDesc.getType()); subtitle.setValue(sDesc.getValue()); aFeed.setSubtitle(subtitle); aFeed.setAlternateLinks(alternateLinks); aFeed.setOtherLinks(otherLinks); aFeed.setCategories(aCats); aFeed.setAuthors(ConverterForAtom03.createAtomPersons(authors)); aFeed.setContributors(ConverterForAtom03.createAtomPersons(contributors)); aFeed.setLogo(image.getUrl());
final com.rometools.rome.feed.atom.Feed feed = new com.rometools.rome.feed.atom.Feed(getType()); c.setValue(parseTextConstructToString(title)); c.setType(getAttributeValue(title, "type")); feed.setTitleEx(c); feed.setAlternateLinks(parseAlternateLinks(feed, null, baseURI, links)); feed.setOtherLinks(parseOtherLinks(feed, null, baseURI, links)); feed.setCategories(parseCategories(baseURI, categories)); feed.setAuthors(parsePersons(baseURI, authors, locale)); feed.setContributors(parsePersons(baseURI, contributors, locale)); content.setValue(parseTextConstructToString(subtitle)); content.setType(getAttributeValue(subtitle, "type")); feed.setSubtitle(content); feed.setId(id.getText()); feed.setGenerator(gen); feed.setRights(parseTextConstructToString(rights)); feed.setIcon(icon.getText()); feed.setLogo(logo.getText());
final Feed feed = new Feed(type); feed.setStyleSheet(styleSheet); feed.setTitleEx(parseContent(title)); feed.setAlternateLinks(parseAlternateLinks(links)); feed.setOtherLinks(parseOtherLinks(links)); final List<SyndPerson> authors = new ArrayList<SyndPerson>(); authors.add(parsePerson(author)); feed.setAuthors(authors); feed.setContributors(parsePersons(contributors)); feed.setTagline(parseContent(tagline)); feed.setId(id.getText()); feed.setGenerator(gen); feed.setCopyright(copyright.getText()); feed.setInfo(parseContent(info)); feed.setModified(DateParser.parseDate(modified.getText(), locale)); feed.setModules(parseFeedModules(eFeed, locale)); feed.setEntries(parseEntries(entries, locale));
Feed feed = new Feed(); feed.setId(atomURL +"/"+website.getHandle() + "/resources/" + path + start); feed.setTitle(website.getName()); link.setRel("alternate"); link.setType("text/html"); feed.setAlternateLinks(Collections.singletonList(link)); if (count == 0) { feed.setUpdated(entry.getUpdated()); otherLinks.add(prevLink); feed.setOtherLinks(otherLinks); feed.setEntries(atomEntries);
@Override protected void buildFeedMetadata(Map<String, Object> model, Feed feed, HttpServletRequest request) { feed.setId("https://github.com/mploed/event-driven-spring-boot/credit-decision"); feed.setTitle("Approved Credit Applications"); List<Link> alternateLinks = new ArrayList<>(); Link link = new Link(); link.setRel("self"); link.setHref(baseUrl(request) + "feed"); alternateLinks.add(link); List<SyndPerson> authors = new ArrayList<SyndPerson>(); Person person = new Person(); person.setName("Big Pug Bank"); authors.add(person); feed.setAuthors(authors); feed.setAlternateLinks(alternateLinks); feed.setUpdated(decisionMemoRepository.lastUpdate()); Content subtitle = new Content(); subtitle.setValue("List of all APPROVED credit applications"); feed.setSubtitle(subtitle); }
@Override public WireFeed createRealFeed(final SyndFeed syndFeed) { final Feed aFeed = new Feed(getType()); aFeed.setModules(ModuleUtils.cloneModules(syndFeed.getModules())); aFeed.setEncoding(syndFeed.getEncoding()); aFeed.setStyleSheet(syndFeed.getStyleSheet()); aFeed.setId(syndFeed.getUri()); aFeed.setTitleEx(title); aFeed.setAlternateLinks(alternateLinks); aFeed.setOtherLinks(otherLinks); final Content tagline = new Content(); tagline.setValue(sDesc); aFeed.setTagline(tagline); aFeed.setLanguage(syndFeed.getLanguage()); aFeed.setAuthors(createAtomPersons(authors)); aFeed.setCopyright(syndFeed.getCopyright()); aFeed.setModified(syndFeed.getPublishedDate()); aFeed.setEntries(createAtomEntries(sEntries));
syndFeed.setModules(ModuleUtils.cloneModules(aFeed.getModules())); syndFeed.setEncoding(aFeed.getEncoding()); syndFeed.setStyleSheet(aFeed.getStyleSheet()); final String logo = aFeed.getLogo(); final String icon = aFeed.getIcon(); syndFeed.setUri(aFeed.getId()); syndFeed.setTitle(aFeed.getTitle()); final List<Link> alternateLinks = aFeed.getAlternateLinks(); if (Lists.isNotEmpty(alternateLinks)) { final Link link = alternateLinks.get(0); final List<Link> otherLinks = aFeed.getOtherLinks(); if (Lists.isNotEmpty(otherLinks)) { syndLinks.addAll(createSyndLinks(otherLinks)); final Content tagline = aFeed.getTagline(); if (tagline != null) { syndFeed.setDescription(tagline.getValue()); final List<Entry> aEntries = aFeed.getEntries(); if (Lists.isNotEmpty(aEntries)) { syndFeed.setEntries(createSyndEntries(aEntries, syndFeed.isPreservingWireFeed())); final String language = aFeed.getLanguage();
syndFeed.setModules(ModuleUtils.cloneModules(aFeed.getModules())); syndFeed.setEncoding(aFeed.getEncoding()); syndFeed.setStyleSheet(aFeed.getStyleSheet()); final String logo = aFeed.getLogo(); if (logo != null) { final SyndImage image = new SyndImageImpl(); final String icon = aFeed.getIcon(); if (icon != null) { final SyndImage image = new SyndImageImpl(); syndFeed.setUri(aFeed.getId()); final Content aTitle = aFeed.getTitleEx(); if (aTitle != null) { final SyndContent c = new SyndContentImpl(); final Content aSubtitle = aFeed.getSubtitle(); if (aSubtitle != null) { final SyndContent c = new SyndContentImpl(); final List<Link> alternateLinks = aFeed.getAlternateLinks(); if (Lists.isNotEmpty(alternateLinks)) { final Link theLink = alternateLinks.get(0); final List<Link> otherLinks = aFeed.getOtherLinks(); if (Lists.isNotEmpty(otherLinks)) {
private InputStream createDefaultFeedDocument(final String uri) throws AtomException { final Feed f = new Feed(); f.setTitle("Feed"); f.setId(uri); f.setFeedType(FEED_TYPE); final Link selfLink = new Link(); selfLink.setRel("self"); selfLink.setHref(uri); f.getOtherLinks().add(selfLink); try { final WireFeedOutput wireFeedOutput = new WireFeedOutput(); final Document feedDoc = wireFeedOutput.outputJDom(f); final XMLOutputter outputter = new XMLOutputter(); // outputter.setFormat(Format.getCompactFormat()); final OutputStream fos = FileStore.getFileStore().getFileOutputStream(getFeedPath()); outputter.output(feedDoc, new OutputStreamWriter(fos, "UTF-8")); } catch (final FeedException ex) { throw new AtomException(ex); } catch (final IOException ex) { throw new AtomException(ex); } catch (final Exception e) { e.printStackTrace(); } return FileStore.getFileStore().getFileInputStream(getFeedPath()); }
/** * 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); }
/** * Parse entry from reader. */ public static Entry parseEntry(final Reader rd, final String baseURI, final Locale locale) throws JDOMException, IOException, IllegalArgumentException, FeedException { // Parse entry into JDOM tree final SAXBuilder builder = new SAXBuilder(); final Document entryDoc = builder.build(rd); final Element fetchedEntryElement = entryDoc.getRootElement(); fetchedEntryElement.detach(); // Put entry into a JDOM document with 'feed' root so that Rome can // handle it final Feed feed = new Feed(); feed.setFeedType("atom_1.0"); final WireFeedOutput wireFeedOutput = new WireFeedOutput(); final Document feedDoc = wireFeedOutput.outputJDom(feed); feedDoc.getRootElement().addContent(fetchedEntryElement); if (baseURI != null) { feedDoc.getRootElement().setAttribute("base", baseURI, Namespace.XML_NAMESPACE); } final WireFeedInput input = new WireFeedInput(false, locale); final Feed parsedFeed = (Feed) input.build(feedDoc); return parsedFeed.getEntries().get(0); }
@Override protected void buildFeedMetadata(Map<String, Object> model, Feed feed, HttpServletRequest request) { feed.setId("tag:springsource.org"); feed.setTitle("Veterinarians"); feed.setUpdated(new Date()); }
private Entry findEntry(final String id, final Feed feed) { for (final Entry entry : feed.getEntries()) { if (id.equals(entry.getId())) { return entry; } } return null; }
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; }
@Override protected void buildFeedMetadata(Map<String, Object>model, Feed feed, HttpServletRequest request) { feed.setTitle("Test Feed"); }
feed.setTitle(atomFeed.getTitle()); for (Link link : (List<Link>)atomFeed.getAlternateLinks()) { if ("text/html".equals(link.getType())) feed.setLink(link.getHref()); for (Entry entry : (List<Entry>)atomFeed.getEntries()) { String href = ""; for (Link link : (List<Link>)entry.getAlternateLinks()) {