summaryrefslogtreecommitdiffstats
path: root/sca-cpp/trunk/modules/atom/atom.hpp
diff options
context:
space:
mode:
authorjsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68>2010-05-31 02:29:45 +0000
committerjsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68>2010-05-31 02:29:45 +0000
commit7808f187b68261a58de9e348a722b6d0e32dcbe9 (patch)
treea1b97c546f15448e46565bc40ff7e20ff5525092 /sca-cpp/trunk/modules/atom/atom.hpp
parent90b55b93704adb3e1fac59d58c2d644d37537bc9 (diff)
Add support for RSS feeds and minor fixes to ATOM support.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@949652 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-cpp/trunk/modules/atom/atom.hpp')
-rw-r--r--sca-cpp/trunk/modules/atom/atom.hpp29
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)));
}