From c88394b9fd2f003dcfd541688cdbb283567f6367 Mon Sep 17 00:00:00 2001 From: Jocelyn Fiat Date: Fri, 24 Jun 2016 13:03:09 +0200 Subject: [PATCH] Added support for category in ATOM format (input and output). --- .../text/parser/feed/src/atom/atom_feed_generator.e | 7 +++++++ library/text/parser/feed/src/atom/atom_feed_parser.e | 12 ++++++++++++ .../text/parser/feed/src/support/feed_generator.e | 2 +- library/text/parser/feed/tests/atom_test_set.e | 1 + 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/library/text/parser/feed/src/atom/atom_feed_generator.e b/library/text/parser/feed/src/atom/atom_feed_generator.e index 4f15a225..f4d87916 100644 --- a/library/text/parser/feed/src/atom/atom_feed_generator.e +++ b/library/text/parser/feed/src/atom/atom_feed_generator.e @@ -72,6 +72,13 @@ feature -- Visitor if attached a_entry.date as dt then append_content_tag_to ("updated", Void, date_to_string (dt), buffer) end + if attached a_entry.categories as cats then + across + cats as ic + loop + append_content_tag_to ("category", <<["term", ic.item]>>, Void, buffer) + end + end append_content_tag_to ("summary", Void, a_entry.description, buffer) if attached a_entry.content as l_content then 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 d486598b..0c16b2cc 100644 --- a/library/text/parser/feed/src/atom/atom_feed_parser.e +++ b/library/text/parser/feed/src/atom/atom_feed_parser.e @@ -81,6 +81,7 @@ feature -- Access if attached x_entry.element_by_name ("content") as x_content then e.set_content (xml_element_code (x_content), xml_attribute_text (x_content, "type")) end + if attached x_entry.element_by_name ("author") as x_author then if attached x_author.element_by_name ("name") as x_name and then attached x_name.text as l_author_name @@ -92,6 +93,17 @@ feature -- Access e.set_author (l_author) end end + + -- Optional "category" + if attached x_entry.elements_by_name ("category") as x_categories then + across + x_categories as cats_ic + loop + if attached xml_attribute_text (cats_ic.item, "term") as l_term then + e.set_category (l_term) + end + end + end Result.extend (e) end end diff --git a/library/text/parser/feed/src/support/feed_generator.e b/library/text/parser/feed/src/support/feed_generator.e index efbb8b8e..cad90cc0 100644 --- a/library/text/parser/feed/src/support/feed_generator.e +++ b/library/text/parser/feed/src/support/feed_generator.e @@ -66,7 +66,7 @@ feature {NONE} -- Helpers end end if a_content = Void then - a_output.append ("/>") + a_output.append ("/>%N") else a_output.append (">") a_output.append (escaped_unicode_xml (a_content.as_string_32)) diff --git a/library/text/parser/feed/tests/atom_test_set.e b/library/text/parser/feed/tests/atom_test_set.e index 68eab06e..1ffaa2f3 100644 --- a/library/text/parser/feed/tests/atom_test_set.e +++ b/library/text/parser/feed/tests/atom_test_set.e @@ -65,6 +65,7 @@ feature {NONE} -- Data John Doe johndoe@example.com +