summaryrefslogtreecommitdiffstats
path: root/sca-cpp/trunk/modules/atom
diff options
context:
space:
mode:
Diffstat (limited to 'sca-cpp/trunk/modules/atom')
-rw-r--r--sca-cpp/trunk/modules/atom/atom-test.cpp20
-rw-r--r--sca-cpp/trunk/modules/atom/atom.hpp29
2 files changed, 46 insertions, 3 deletions
diff --git a/sca-cpp/trunk/modules/atom/atom-test.cpp b/sca-cpp/trunk/modules/atom/atom-test.cpp
index 316e8b44db..4acc720816 100644
--- a/sca-cpp/trunk/modules/atom/atom-test.cpp
+++ b/sca-cpp/trunk/modules/atom/atom-test.cpp
@@ -48,6 +48,14 @@ string itemEntry("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"<link href=\"cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b\"/>"
"</entry>\n");
+string itemTextEntry("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+ "<entry xmlns=\"http://www.w3.org/2005/Atom\">"
+ "<title type=\"text\">item</title>"
+ "<id>cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b</id>"
+ "<content type=\"text\">Apple</content>"
+ "<link href=\"cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b\"/>"
+ "</entry>\n");
+
string incompleteEntry("<entry xmlns=\"http://www.w3.org/2005/Atom\">"
"<title>item</title><content type=\"text/xml\">"
"<Item xmlns=\"http://services/\">"
@@ -80,12 +88,24 @@ bool testEntry() {
assert(str(os) == itemEntry);
}
{
+ const list<value> a = mklist<value>(string("item"), string("cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b"), string("Apple"));
+ ostringstream os;
+ writeATOMEntry<ostream*>(writer, &os, a);
+ assert(str(os) == itemTextEntry);
+ }
+ {
const list<value> a = content(readATOMEntry(mklist(itemEntry)));
ostringstream os;
writeATOMEntry<ostream*>(writer, &os, a);
assert(str(os) == itemEntry);
}
{
+ const list<value> a = content(readATOMEntry(mklist(itemTextEntry)));
+ ostringstream os;
+ writeATOMEntry<ostream*>(writer, &os, a);
+ assert(str(os) == itemTextEntry);
+ }
+ {
const list<value> a = content(readATOMEntry(mklist(incompleteEntry)));
ostringstream os;
writeATOMEntry<ostream*>(writer, &os, a);
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)));
}