From 5fee483fd911c828c2d0362b15d426046737e32d Mon Sep 17 00:00:00 2001 From: Jocelyn Fiat Date: Thu, 8 Oct 2015 10:10:08 +0200 Subject: [PATCH] Added FEED + FEED operator to merge two feeds. Added FEED sorting routine. Added FEED_ITEM.link: detachable FEED_LINK that represents the main feed link. Comments. --- library/text/parser/feed/feed-safe.ecf | 1 + library/text/parser/feed/feed.ecf | 1 + .../parser/feed/src/atom/atom_feed_parser.e | 2 +- library/text/parser/feed/src/kernel/feed.e | 37 ++++++++++++++++++- .../text/parser/feed/src/kernel/feed_item.e | 15 ++++++++ .../parser/feed/src/rss/rss_2_feed_parser.e | 2 +- .../parser/feed/src/support/feed_helpers.e | 3 +- .../feed/src/support/feed_parser_utilities.e | 5 +-- 8 files changed, 58 insertions(+), 8 deletions(-) diff --git a/library/text/parser/feed/feed-safe.ecf b/library/text/parser/feed/feed-safe.ecf index fce34157..63c57f4a 100644 --- a/library/text/parser/feed/feed-safe.ecf +++ b/library/text/parser/feed/feed-safe.ecf @@ -3,6 +3,7 @@ + diff --git a/library/text/parser/feed/feed.ecf b/library/text/parser/feed/feed.ecf index 7b873468..6e0fb7cb 100644 --- a/library/text/parser/feed/feed.ecf +++ b/library/text/parser/feed/feed.ecf @@ -5,6 +5,7 @@ + diff --git a/library/text/parser/feed/src/atom/atom_feed_parser.e b/library/text/parser/feed/src/atom/atom_feed_parser.e index ae945cf7..d486598b 100644 --- a/library/text/parser/feed/src/atom/atom_feed_parser.e +++ b/library/text/parser/feed/src/atom/atom_feed_parser.e @@ -92,7 +92,7 @@ feature -- Access e.set_author (l_author) end end - Result.add_item (e) + Result.extend (e) end end end diff --git a/library/text/parser/feed/src/kernel/feed.e b/library/text/parser/feed/src/kernel/feed.e index b5e85730..9b788db2 100644 --- a/library/text/parser/feed/src/kernel/feed.e +++ b/library/text/parser/feed/src/kernel/feed.e @@ -88,12 +88,47 @@ feature -- Element change end end - add_item (a_item: FEED_ITEM) + extend (a_item: FEED_ITEM) -- Add item `a_item' to feed `items'. do items.force (a_item) end + extended alias "+" (a_feed: FEED): FEED + -- New feed object made from Current merged with a_feed. + local + l_title: STRING_32 + do + create l_title.make (title.count + a_feed.title.count) + l_title.append_character ('(') + l_title.append (title) + l_title.append_character (')') + l_title.append_character ('+') + l_title.append_character ('(') + l_title.append (a_feed.title) + l_title.append_character (')') + create Result.make (l_title) + Result.items.append (items) + across + a_feed.items as ic + loop + -- FIXME jfiat [2015/10/07] : check there is no duplication! (same id, or link, ...) + Result.extend (ic.item) + end + Result.sort + end + + sort + -- Sort `items', (recent first). + local + s: QUICK_SORTER [FEED_ITEM] + comp: COMPARABLE_COMPARATOR [FEED_ITEM] + do + create comp + create s.make (comp) + s.reverse_sort (items) + end + feature -- Visitor accept (vis: FEED_VISITOR) diff --git a/library/text/parser/feed/src/kernel/feed_item.e b/library/text/parser/feed/src/kernel/feed_item.e index 8fc6a8c4..f2b7e9ea 100644 --- a/library/text/parser/feed/src/kernel/feed_item.e +++ b/library/text/parser/feed/src/kernel/feed_item.e @@ -61,6 +61,21 @@ feature -- Access date: detachable DATE_TIME -- Publishing date. + link: detachable FEED_LINK + -- Main link for the entry, if any. + do + if attached links as l_links then + Result := l_links.item ("") + across + l_links as ic + until + Result /= Void + loop + Result := ic.item + end + end + end + links: STRING_TABLE [FEED_LINK] -- Url indexed by relation diff --git a/library/text/parser/feed/src/rss/rss_2_feed_parser.e b/library/text/parser/feed/src/rss/rss_2_feed_parser.e index 3a8eafdb..e841edd6 100644 --- a/library/text/parser/feed/src/rss/rss_2_feed_parser.e +++ b/library/text/parser/feed/src/rss/rss_2_feed_parser.e @@ -112,7 +112,7 @@ feature -- Access else e.set_content (xml_element_code (x_content), Void) end - Result.add_item (e) + Result.extend (e) end end end diff --git a/library/text/parser/feed/src/support/feed_helpers.e b/library/text/parser/feed/src/support/feed_helpers.e index 772fed81..c911d75e 100644 --- a/library/text/parser/feed/src/support/feed_helpers.e +++ b/library/text/parser/feed/src/support/feed_helpers.e @@ -1,6 +1,5 @@ note - description: "Summary description for {FEED_HELPERS}." - author: "" + description: "Helpers routine for feed library." date: "$Date$" revision: "$Revision$" diff --git a/library/text/parser/feed/src/support/feed_parser_utilities.e b/library/text/parser/feed/src/support/feed_parser_utilities.e index c03952fa..1f38c1e2 100644 --- a/library/text/parser/feed/src/support/feed_parser_utilities.e +++ b/library/text/parser/feed/src/support/feed_parser_utilities.e @@ -1,6 +1,5 @@ note - description: "Summary description for {FEED_PARSER_UTILITIES}." - author: "" + description: "Helpers routine for feed xml parsers." date: "$Date$" revision: "$Revision$" @@ -80,5 +79,5 @@ feature -- Access end end end - + end