Added initial ATOM and RSS feed parser and generator.

(work in progress)
This commit is contained in:
2015-09-07 19:22:50 +02:00
parent 1f1e2abbda
commit 39887c8bdb
22 changed files with 1820 additions and 0 deletions

View File

@@ -0,0 +1,88 @@
note
description: "Summary description for {FEED}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
FEED
inherit
FEED_HELPERS
create
make
feature {NONE} -- Initialization
make (a_title: READABLE_STRING_GENERAL)
do
create title.make_from_string_general (a_title)
create entries.make (1)
create links.make (1)
end
feature -- Access
title: IMMUTABLE_STRING_32
-- Title of the feed/channel.
description: detachable IMMUTABLE_STRING_32
-- Associated description/subtitle.
id: detachable IMMUTABLE_STRING_32
-- Id associated with Current feed if any.
date: detachable DATE_TIME
-- Build date.
links: STRING_TABLE [FEED_LINK]
-- Url indexed by relation
entries: ARRAYED_LIST [FEED_ENTRY]
-- List of feed items.
feature -- Element change
set_description (a_description: detachable READABLE_STRING_GENERAL)
do
if a_description = Void then
description := Void
else
create description.make_from_string_general (a_description)
end
end
set_id (a_id: detachable READABLE_STRING_GENERAL)
do
if a_id = Void then
id := Void
else
create id.make_from_string_general (a_id)
end
end
set_updated_date_with_text (a_date_text: detachable READABLE_STRING_32)
do
if a_date_text = Void then
date := Void
else
date := date_time (a_date_text)
end
end
add_entry (e: FEED_ENTRY)
do
entries.force (e)
end
feature -- Visitor
accept (vis: FEED_VISITOR)
do
vis.visit_feed (Current)
end
invariant
end

View File

@@ -0,0 +1,46 @@
note
description: "Summary description for {FEED_AUTHOR}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
FEED_AUTHOR
create
make
feature {NONE} -- Initialization
make (a_name: READABLE_STRING_GENERAL)
do
create name.make_from_string_general (a_name)
end
feature -- Access
name: IMMUTABLE_STRING_32
email: detachable READABLE_STRING_8
feature -- Element change
set_email (a_email: detachable READABLE_STRING_GENERAL)
do
if a_email = Void then
email := Void
elseif a_email.is_valid_as_string_8 then
email := a_email.as_string_8
else
email := Void
end
end
feature -- Visitor
accept (vis: FEED_VISITOR)
do
vis.visit_author (Current)
end
end

View File

@@ -0,0 +1,175 @@
note
description: "Summary description for {FEED_ENTRY}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
FEED_ENTRY
inherit
FEED_HELPERS
undefine
is_equal
end
COMPARABLE
create
make
feature {NONE} -- Initialization
make (a_title: READABLE_STRING_GENERAL)
do
create title.make_from_string_general (a_title)
create links.make (1)
end
feature -- Access
title: IMMUTABLE_STRING_32
-- Title of associated feed item.
description: detachable IMMUTABLE_STRING_32
-- Optional description (or summary).
content: detachable IMMUTABLE_STRING_32
-- Content of Current feed item.
content_type: detachable READABLE_STRING_8
-- Optional content type for `content'.
-- By default, this should be text/html.
content_type_or_default (dft: READABLE_STRING_8): READABLE_STRING_8
do
if attached content_type as l_type then
Result := l_type
else
Result := dft
end
end
id: detachable IMMUTABLE_STRING_32
-- Identifier of current feed item, if any/
date: detachable DATE_TIME
-- Publishing date.
links: STRING_TABLE [FEED_LINK]
-- Url indexed by relation
categories: detachable LIST [READABLE_STRING_32]
-- Categories
author: detachable FEED_AUTHOR
-- Author information.
feature -- Status report
has_category (cat: READABLE_STRING_GENERAL): BOOLEAN
-- Has category `cat'?
--| note: case insensitive.
do
if attached categories as cats then
Result := across cats as ic some cat.is_case_insensitive_equal (ic.item) end
end
end
feature -- Comparison
is_less alias "<" (other: like Current): BOOLEAN
-- Is current object less than `other'?
local
d1,d2: like date
do
d1 := date
d2 := other.date
if d1 = Void and d2 = Void then
Result := title < other.title
elseif d1 = Void then
Result := True
elseif d2 = Void then
Result := False
else
if d1 ~ d2 then
Result := title < other.title
else
Result := d1 < d2
end
end
end
feature -- Element change
set_id (a_id: detachable READABLE_STRING_GENERAL)
do
if a_id = Void then
id := Void
else
create id.make_from_string_general (a_id)
end
end
set_description (a_description: detachable READABLE_STRING_GENERAL)
do
if a_description = Void then
description := Void
else
create description.make_from_string_general (a_description)
end
end
set_content (a_content: detachable READABLE_STRING_GENERAL; a_type: detachable READABLE_STRING_GENERAL)
do
if a_content = Void then
content := Void
content_type := Void
else
create content.make_from_string_general (a_content)
if a_type = Void then
content_type := Void
else
content_type := a_type.as_string_8
end
end
end
set_updated_date_with_text (a_date_text: detachable READABLE_STRING_32)
do
if a_date_text = Void then
date := Void
else
date := date_time (a_date_text)
end
end
set_author (a_author: detachable FEED_AUTHOR)
do
author := a_author
end
set_category (cat: READABLE_STRING_GENERAL)
local
cats: like categories
do
cats := categories
if cats = Void then
create {ARRAYED_LIST [READABLE_STRING_32]} cats.make (1)
categories := cats
end
cats.force (cat.as_string_32)
ensure
cat_set: has_category (cat)
end
feature -- Visitor
accept (vis: FEED_VISITOR)
do
vis.visit_entry (Current)
end
invariant
end

View File

@@ -0,0 +1,56 @@
note
description: "Summary description for {FEED_LINK}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
FEED_LINK
create
make
feature {NONE} -- Initialization
make (a_href: READABLE_STRING_8)
do
href := a_href
set_relation (Void)
end
feature -- Access
href: READABLE_STRING_8
relation: READABLE_STRING_32
type: detachable READABLE_STRING_8
feature -- Element change
set_relation (rel: detachable READABLE_STRING_GENERAL)
do
if rel = Void then
relation := ""
else
relation := rel.as_string_8
end
end
set_type (a_type: detachable READABLE_STRING_GENERAL)
do
if a_type = Void then
type := Void
else
type := a_type.as_string_8
end
end
feature -- Visitor
accept (vis: FEED_VISITOR)
do
vis.visit_link (Current)
end
end