diff options
Diffstat (limited to 'sca-cpp/trunk/modules/atom/atom.hpp')
-rw-r--r-- | sca-cpp/trunk/modules/atom/atom.hpp | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/sca-cpp/trunk/modules/atom/atom.hpp b/sca-cpp/trunk/modules/atom/atom.hpp index fadb482e0d..bb39e7c262 100644 --- a/sca-cpp/trunk/modules/atom/atom.hpp +++ b/sca-cpp/trunk/modules/atom/atom.hpp @@ -44,7 +44,7 @@ const list<value> entryElementsToValues(const list<value>& e) { const list<value> li = filter<value>(selector(mklist<value>(element, "id")), e); const value i = isNil(li)? value(emptyString) : elementValue(car(li)); const list<value> lc = filter<value>(selector(mklist<value>(element, "content")), e); - return mklist<value>(t, i, cadr(elementChildren(car(lc)))); + return mklist<value>(t, i, elementValue(car(lc))); } /** @@ -57,6 +57,15 @@ const list<value> entriesElementsToValues(const list<value>& e) { } /** + * Return true if a list of strings contains an RSS feed. + */ +const bool isATOMFeed(const list<string>& ls) { + if (!isXML(ls)) + return false; + return contains(car(ls), "<feed"); +} + +/** * Convert a list of strings to a list of values representing an ATOM entry. */ const failable<list<value> > readATOMEntry(const list<string>& ilist) { @@ -71,7 +80,7 @@ const failable<list<value> > readATOMEntry(const list<string>& ilist) { */ const value entryValue(const list<value>& e) { const list<value> v = elementsToValues(mklist<value>(caddr(e))); - return cons(car(e), mklist<value>(cadr(e), cdr<value>(car(v)))); + return cons(car(e), mklist<value>(cadr(e), isList(car(v))? (value)cdr<value>(car(v)) : car(v))); } /** @@ -90,6 +99,19 @@ const failable<list<value> > readATOMFeed(const list<string>& ilist) { } /** + * Convert an ATOM feed containing elements to an ATOM feed containing values. + */ +const list<value> feedValuesLoop(const list<value> e) { + if (isNil(e)) + return e; + return cons<value>(entryValue(car(e)), feedValuesLoop(cdr(e))); +} + +const list<value> feedValues(const list<value>& e) { + return cons(car<value>(e), cons<value>(cadr<value>(e), feedValuesLoop(cddr<value>(e)))); +} + +/** * Convert a list of values representing an ATOM entry to a list of elements. * The first two values in the list are the entry title and id. */ @@ -98,7 +120,8 @@ const list<value> entryElement(const list<value>& l) { + element + "entry" + (list<value>() + attribute + "xmlns" + "http://www.w3.org/2005/Atom") + (list<value>() + element + "title" + (list<value>() + attribute + "type" + "text") + car(l)) + (list<value>() + element + "id" + cadr(l)) - + (list<value>() + element + "content" + (list<value>() + attribute + "type" + "application/xml") + caddr(l)) + + (list<value>() + element + "content" + + (list<value>() + attribute + "type" + (isList(caddr(l))? "application/xml" : "text")) + caddr(l)) + (list<value>() + element + "link" + (list<value>() + attribute + "href" + cadr(l))); } |