com.rometools.rome.feed.rss.Item Java Examples
The following examples show how to use
com.rometools.rome.feed.rss.Item.
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: RSS091UserlandGenerator.java From rome with Apache License 2.0 | 6 votes |
@Override protected void populateItem(final Item item, final Element eItem, final int index) { super.populateItem(item, eItem, index); final Description description = item.getDescription(); if (description != null) { eItem.addContent(generateSimpleElement("description", description.getValue())); } final Namespace contentNamespace = getContentNamespace(); final Content content = item.getContent(); if (item.getModule(contentNamespace.getURI()) == null && content != null) { final Element elem = new Element("encoded", contentNamespace); elem.addContent(content.getValue()); eItem.addContent(elem); } }
Example #2
Source File: RssChannelHttpMessageConverterTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void read() throws IOException { InputStream is = getClass().getResourceAsStream("rss.xml"); MockHttpInputMessage inputMessage = new MockHttpInputMessage(is); inputMessage.getHeaders().setContentType(new MediaType("application", "rss+xml", StandardCharsets.UTF_8)); Channel result = converter.read(Channel.class, inputMessage); assertEquals("title", result.getTitle()); assertEquals("http://example.com", result.getLink()); assertEquals("description", result.getDescription()); List<?> items = result.getItems(); assertEquals(2, items.size()); Item item1 = (Item) items.get(0); assertEquals("title1", item1.getTitle()); Item item2 = (Item) items.get(1); assertEquals("title2", item2.getTitle()); }
Example #3
Source File: RssChannelHttpMessageConverterTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void read() throws IOException { InputStream is = getClass().getResourceAsStream("rss.xml"); MockHttpInputMessage inputMessage = new MockHttpInputMessage(is); inputMessage.getHeaders().setContentType(new MediaType("application", "rss+xml", StandardCharsets.UTF_8)); Channel result = converter.read(Channel.class, inputMessage); assertEquals("title", result.getTitle()); assertEquals("https://example.com", result.getLink()); assertEquals("description", result.getDescription()); List<?> items = result.getItems(); assertEquals(2, items.size()); Item item1 = (Item) items.get(0); assertEquals("title1", item1.getTitle()); Item item2 = (Item) items.get(1); assertEquals("title2", item2.getTitle()); }
Example #4
Source File: RssChannelHttpMessageConverterTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void writeOtherCharset() throws IOException, SAXException { Channel channel = new Channel("rss_2.0"); channel.setTitle("title"); channel.setLink("http://example.com"); channel.setDescription("description"); String encoding = "ISO-8859-1"; channel.setEncoding(encoding); Item item1 = new Item(); item1.setTitle("title1"); MockHttpOutputMessage outputMessage = new MockHttpOutputMessage(); converter.write(channel, null, outputMessage); assertEquals("Invalid content-type", new MediaType("application", "rss+xml", Charset.forName(encoding)), outputMessage.getHeaders().getContentType()); }
Example #5
Source File: ArticleFeedView.java From tutorials with MIT License | 6 votes |
@Override protected List<Item> buildFeedItems(Map<String, Object> map, HttpServletRequest httpStRequest, HttpServletResponse httpStResponse) throws Exception { List list = new ArrayList<Item>(); Item item1 = new Item(); item1.setLink("http://www.baeldung.com/netty-exception-handling"); item1.setTitle("Exceptions in Netty"); Description description1 = new Description(); description1.setValue("In this quick article, we’ll be looking at exception handling in Netty."); item1.setDescription(description1); item1.setPubDate(new Date()); item1.setAuthor("Carlos"); Item item2 = new Item(); item2.setLink("http://www.baeldung.com/cockroachdb-java"); item2.setTitle("Guide to CockroachDB in Java"); Description description2 = new Description(); description2.setValue("This tutorial is an introductory guide to using CockroachDB with Java."); item2.setDescription(description2); item2.setPubDate(new Date()); item2.setAuthor("Baeldung"); list.add(item1); list.add(item2); return list; }
Example #6
Source File: ArticleRssController.java From tutorials with MIT License | 6 votes |
private Channel buildChannel(List<Article> articles){ Channel channel = new Channel("rss_2.0"); channel.setLink("http://localhost:8080/spring-mvc-simple/rss"); channel.setTitle("Article Feed"); channel.setDescription("Article Feed Description"); channel.setPubDate(new Date()); List<Item> items = new ArrayList<>(); for (Article article : articles) { Item item = new Item(); item.setLink(article.getLink()); item.setTitle(article.getTitle()); Description description1 = new Description(); description1.setValue(article.getDescription()); item.setDescription(description1); item.setPubDate(article.getPublishedDate()); item.setAuthor(article.getAuthor()); items.add(item); } channel.setItems(items); return channel; }
Example #7
Source File: RssChannelHttpMessageConverterTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void writeOtherCharset() throws IOException, SAXException { Channel channel = new Channel("rss_2.0"); channel.setTitle("title"); channel.setLink("https://example.com"); channel.setDescription("description"); String encoding = "ISO-8859-1"; channel.setEncoding(encoding); Item item1 = new Item(); item1.setTitle("title1"); MockHttpOutputMessage outputMessage = new MockHttpOutputMessage(); converter.write(channel, null, outputMessage); assertEquals("Invalid content-type", new MediaType("application", "rss+xml", Charset.forName(encoding)), outputMessage.getHeaders().getContentType()); }
Example #8
Source File: RSS092Generator.java From rome with Apache License 2.0 | 6 votes |
@Override protected void populateItem(final Item item, final Element eItem, final int index) { super.populateItem(item, eItem, index); final Source source = item.getSource(); if (source != null) { eItem.addContent(generateSourceElement(source)); } final List<Enclosure> enclosures = item.getEnclosures(); for (int i = 0; i < getNumberOfEnclosures(enclosures); i++) { eItem.addContent(generateEnclosure(enclosures.get(i))); } final List<Category> categories = item.getCategories(); for (final Category category : categories) { eItem.addContent(generateCategoryElement(category)); } }
Example #9
Source File: ArticleFeedView.java From tutorials with MIT License | 6 votes |
@Override protected List<Item> buildFeedItems(Map<String, Object> map, HttpServletRequest httpStRequest, HttpServletResponse httpStResponse) throws Exception { List list = new ArrayList<Item>(); Item item1 = new Item(); item1.setLink("http://www.baeldung.com/netty-exception-handling"); item1.setTitle("Exceptions in Netty"); Description description1 = new Description(); description1.setValue("In this quick article, we’ll be looking at exception handling in Netty."); item1.setDescription(description1); item1.setPubDate(new Date()); item1.setAuthor("Carlos"); Item item2 = new Item(); item2.setLink("http://www.baeldung.com/cockroachdb-java"); item2.setTitle("Guide to CockroachDB in Java"); Description description2 = new Description(); description2.setValue("This tutorial is an introductory guide to using CockroachDB with Java."); item2.setDescription(description2); item2.setPubDate(new Date()); item2.setAuthor("Baeldung"); list.add(item1); list.add(item2); return list; }
Example #10
Source File: RssChannelHttpMessageConverterTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void read() throws IOException { InputStream is = getClass().getResourceAsStream("rss.xml"); MockHttpInputMessage inputMessage = new MockHttpInputMessage(is); inputMessage.getHeaders().setContentType(new MediaType("application", "rss+xml", utf8)); Channel result = converter.read(Channel.class, inputMessage); assertEquals("title", result.getTitle()); assertEquals("http://example.com", result.getLink()); assertEquals("description", result.getDescription()); List<?> items = result.getItems(); assertEquals(2, items.size()); Item item1 = (Item) items.get(0); assertEquals("title1", item1.getTitle()); Item item2 = (Item) items.get(1); assertEquals("title2", item2.getTitle()); }
Example #11
Source File: HrmsRssViewBuilder.java From Spring-MVC-Blueprints with MIT License | 6 votes |
@SuppressWarnings("unchecked") @Override protected List<Item> buildFeedItems(Map<String, Object> model, HttpServletRequest req, HttpServletResponse resp) throws Exception { // get data model which is passed by the Spring container List<HrmsNews> news = (List<HrmsNews>) model.get("allNews"); List<Item> items = new ArrayList<Item>(news.size()); for(HrmsNews topic : news ){ Item item = new Item(); Content content = new Content(); content.setValue(topic.getSummary()); item.setContent(content); item.setTitle(topic.getDescription()); item.setLink(topic.getLink()); item.setPubDate(new Date()); items.add(item); } return items; }
Example #12
Source File: RssChannelHttpMessageConverterTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void writeOtherCharset() throws IOException, SAXException { Channel channel = new Channel("rss_2.0"); channel.setTitle("title"); channel.setLink("http://example.com"); channel.setDescription("description"); String encoding = "ISO-8859-1"; channel.setEncoding(encoding); Item item1 = new Item(); item1.setTitle("title1"); MockHttpOutputMessage outputMessage = new MockHttpOutputMessage(); converter.write(channel, null, outputMessage); assertEquals("Invalid content-type", new MediaType("application", "rss+xml", Charset.forName(encoding)), outputMessage.getHeaders().getContentType()); }
Example #13
Source File: RSS10Generator.java From rome with Apache License 2.0 | 6 votes |
@Override protected void populateItem(final Item item, final Element eItem, final int index) { super.populateItem(item, eItem, index); final String link = item.getLink(); final String uri = item.getUri(); if (uri != null) { eItem.setAttribute("about", uri, getRDFNamespace()); } else if (link != null) { eItem.setAttribute("about", link, getRDFNamespace()); } final Description description = item.getDescription(); if (description != null) { eItem.addContent(generateSimpleElement("description", description.getValue())); } if (item.getModule(getContentNamespace().getURI()) == null && item.getContent() != null) { final Element elem = new Element("encoded", getContentNamespace()); elem.addContent(item.getContent().getValue()); eItem.addContent(elem); } }
Example #14
Source File: RSS10Generator.java From rome with Apache License 2.0 | 6 votes |
@Override protected void populateChannel(final Channel channel, final Element eChannel) { super.populateChannel(channel, eChannel); final String channelUri = channel.getUri(); if (channelUri != null) { eChannel.setAttribute("about", channelUri, getRDFNamespace()); } final List<Item> items = channel.getItems(); if (!items.isEmpty()) { final Element eItems = new Element("items", getFeedNamespace()); final Element eSeq = new Element("Seq", getRDFNamespace()); for (final Item item : items) { final Element lis = new Element("li", getRDFNamespace()); final String uri = item.getUri(); if (uri != null) { lis.setAttribute("resource", uri, getRDFNamespace()); } eSeq.addContent(lis); } eItems.addContent(eSeq); eChannel.addContent(eItems); } }
Example #15
Source File: RSS093Parser.java From rome with Apache License 2.0 | 6 votes |
@Override protected Item parseItem(final Element rssRoot, final Element eItem, final Locale locale) { final Item item = super.parseItem(rssRoot, eItem, locale); final Element pubDate = eItem.getChild("pubDate", getRSSNamespace()); if (pubDate != null) { item.setPubDate(DateParser.parseDate(pubDate.getText(), locale)); } final Element expirationDate = eItem.getChild("expirationDate", getRSSNamespace()); if (expirationDate != null) { item.setExpirationDate(DateParser.parseDate(expirationDate.getText(), locale)); } final Element description = eItem.getChild("description", getRSSNamespace()); if (description != null) { final String type = description.getAttributeValue("type"); if (type != null) { item.getDescription().setType(type); } } return item; }
Example #16
Source File: RSS10Parser.java From rome with Apache License 2.0 | 6 votes |
/** * Parses an item element of an RSS document looking for item information. * <p/> * It first invokes super.parseItem and then parses and injects the description property if * present. * <p/> * * @param rssRoot the root element of the RSS document in case it's needed for context. * @param eItem the item element to parse. * @return the parsed RSSItem bean. */ @Override protected Item parseItem(final Element rssRoot, final Element eItem, final Locale locale) { final Item item = super.parseItem(rssRoot, eItem, locale); final Element description = eItem.getChild("description", getRSSNamespace()); if (description != null) { item.setDescription(parseItemDescription(rssRoot, description)); } final Element encoded = eItem.getChild("encoded", getContentNamespace()); if (encoded != null) { final Content content = new Content(); content.setType(Content.HTML); content.setValue(encoded.getText()); item.setContent(content); } final String about = eItem.getAttributeValue("about", getRDFNamespace()); if (about != null) { item.setUri(about); } return item; }
Example #17
Source File: FoundPodcastsRssFeedView.java From podcastpedia-web with MIT License | 6 votes |
protected List buildFeedItems(Map model, HttpServletRequest request, HttpServletResponse response) throws Exception { List<Podcast> podcasts = (List<Podcast>) model.get("list_of_podcasts"); List<Item> items = new ArrayList<Item>(podcasts.size()); for (Podcast podcast : podcasts) { Item item = new Item(); // String date = String.format("%1$tY-%1$tm-%1$td", podcast.getLastEpisode().getPublicationDate()); item.setTitle(podcast.getTitle()); item.setPubDate(podcast.getPublicationDate()); item.setLink(model.get("HOST_AND_PORT_URL") + "/podcasts/" + podcast.getPodcastId() + "/" + podcast.getTitleInUrl()); Description podcastDescription = new Description(); podcastDescription.setValue(podcast.getDescription()); item.setDescription(podcastDescription); items.add(item); } return items; }
Example #18
Source File: RssFeedView.java From wallride with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") @Override protected List<Item> buildFeedItems( Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception { Set<Article> articles = (Set<Article>)model.get("articles"); List<Item> items = new ArrayList<>(articles.size()); for (Article article : articles) { Item item = new Item(); item.setTitle(article.getTitle()); item.setPubDate(Date.from(article.getDate().atZone(ZoneId.systemDefault()).toInstant())); Description description = new Description(); description.setType("text/html"); description.setValue(article.getBody()); item.setDescription(description); item.setLink(link(article)); items.add(item); } return items; }
Example #19
Source File: ConverterForRSS092.java From rome with Apache License 2.0 | 6 votes |
@Override protected Item createRSSItem(final SyndEntry sEntry) { final Item item = super.createRSSItem(sEntry); final List<SyndCategory> sCats = sEntry.getCategories(); // c if (!sCats.isEmpty()) { item.setCategories(createRSSCategories(sCats)); } final List<SyndEnclosure> sEnclosures = sEntry.getEnclosures(); if (!sEnclosures.isEmpty()) { item.setEnclosures(createEnclosures(sEnclosures)); } return item; }
Example #20
Source File: ConverterForRSS091Userland.java From rome with Apache License 2.0 | 6 votes |
@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 #21
Source File: ConverterForRSS10.java From rome with Apache License 2.0 | 6 votes |
@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 #22
Source File: ConverterForRSS090.java From rome with Apache License 2.0 | 6 votes |
protected SyndEntry createSyndEntry(final Item item, final boolean preserveWireItem) { final SyndEntryImpl syndEntry = new SyndEntryImpl(); if (preserveWireItem) { syndEntry.setWireEntry(item); } syndEntry.setModules(ModuleUtils.cloneModules(item.getModules())); final List<Element> foreignMarkup = item.getForeignMarkup(); if (!foreignMarkup.isEmpty()) { syndEntry.setForeignMarkup(foreignMarkup); } syndEntry.setUri(item.getUri()); syndEntry.setLink(item.getLink()); syndEntry.setTitle(item.getTitle()); syndEntry.setLink(item.getLink()); syndEntry.setSource(createSource(item.getSource())); return syndEntry; }
Example #23
Source File: RSS090Generator.java From rome with Apache License 2.0 | 5 votes |
protected void populateItem(final Item item, final Element eItem, final int index) { final String title = item.getTitle(); if (title != null) { eItem.addContent(generateSimpleElement("title", title)); } final String link = item.getLink(); if (link != null) { eItem.addContent(generateSimpleElement("link", link)); } generateForeignMarkup(eItem, item.getForeignMarkup()); }
Example #24
Source File: ConverterForRSS091Userland.java From rome with Apache License 2.0 | 5 votes |
@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 #25
Source File: ConverterForRSS093.java From rome with Apache License 2.0 | 5 votes |
@Override protected SyndEntry createSyndEntry(final Item item, final boolean preserveWireItem) { final SyndEntry syndEntry = super.createSyndEntry(item, preserveWireItem); final Date pubDate = item.getPubDate(); final Date publishedDate = syndEntry.getPublishedDate(); if (pubDate != null && publishedDate == null) { syndEntry.setPublishedDate(pubDate); // c } return syndEntry; }
Example #26
Source File: RSS090DescriptionConverter.java From commafeed with Apache License 2.0 | 5 votes |
@Override protected SyndEntry createSyndEntry(Item item, boolean preserveWireItem) { SyndEntry entry = super.createSyndEntry(item, preserveWireItem); Description desc = item.getDescription(); if (desc != null) { SyndContentImpl syndDesc = new SyndContentImpl(); syndDesc.setValue(desc.getValue()); entry.setDescription(syndDesc); } return entry; }
Example #27
Source File: ConverterForRSS10.java From rome with Apache License 2.0 | 5 votes |
@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 #28
Source File: ConverterForRSS090.java From rome with Apache License 2.0 | 5 votes |
protected List<Item> createRSSItems(final List<SyndEntry> sEntries) { final List<Item> list = new ArrayList<Item>(); for (final SyndEntry syndEntry : sEntries) { list.add(createRSSItem(syndEntry)); } return list; }
Example #29
Source File: RSS094Generator.java From rome with Apache License 2.0 | 5 votes |
@Override protected void populateItem(final Item item, final Element eItem, final int index) { super.populateItem(item, eItem, index); final Description description = item.getDescription(); if (description != null && description.getType() != null) { final Element eDescription = eItem.getChild("description", getFeedNamespace()); eDescription.setAttribute(new Attribute("type", description.getType())); } eItem.removeChild("expirationDate", getFeedNamespace()); }
Example #30
Source File: RSS090DescriptionParser.java From commafeed with Apache License 2.0 | 5 votes |
@Override protected Item parseItem(Element rssRoot, Element eItem, Locale locale) { Item item = super.parseItem(rssRoot, eItem, locale); Element e = eItem.getChild("description", getRSSNamespace()); if (e != null) { Description desc = new Description(); desc.setValue(e.getText()); item.setDescription(desc); } return item; }