summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68>2010-12-30 08:52:44 +0000
committerjsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68>2010-12-30 08:52:44 +0000
commit910ecec91d3de8d43eee9eef9201dd3fb1e00060 (patch)
treed355820ae11b2b4c0f75dafed195c450040d47d2
parentfc4d80fd2083d48e6923faac1b6a038247079e50 (diff)
Support ATOM and RSS entries with no content or description.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1053822 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--sca-cpp/trunk/modules/atom/atom-test.cpp19
-rw-r--r--sca-cpp/trunk/modules/atom/atom.hpp9
-rw-r--r--sca-cpp/trunk/modules/rss/rss-test.cpp18
-rw-r--r--sca-cpp/trunk/modules/rss/rss.hpp6
4 files changed, 45 insertions, 7 deletions
diff --git a/sca-cpp/trunk/modules/atom/atom-test.cpp b/sca-cpp/trunk/modules/atom/atom-test.cpp
index 4acc720816..762331d528 100644
--- a/sca-cpp/trunk/modules/atom/atom-test.cpp
+++ b/sca-cpp/trunk/modules/atom/atom-test.cpp
@@ -56,6 +56,13 @@ string itemTextEntry("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"<link href=\"cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b\"/>"
"</entry>\n");
+string itemNoContentEntry("<?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>"
+ "<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/\">"
@@ -94,6 +101,12 @@ bool testEntry() {
assert(str(os) == itemTextEntry);
}
{
+ const list<value> a = mklist<value>(string("item"), string("cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b"), list<value>());
+ ostringstream os;
+ writeATOMEntry<ostream*>(writer, &os, a);
+ assert(str(os) == itemNoContentEntry);
+ }
+ {
const list<value> a = content(readATOMEntry(mklist(itemEntry)));
ostringstream os;
writeATOMEntry<ostream*>(writer, &os, a);
@@ -106,6 +119,12 @@ bool testEntry() {
assert(str(os) == itemTextEntry);
}
{
+ const list<value> a = content(readATOMEntry(mklist(itemNoContentEntry)));
+ ostringstream os;
+ writeATOMEntry<ostream*>(writer, &os, a);
+ assert(str(os) == itemNoContentEntry);
+ }
+ {
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 ff172170f7..0201995f9c 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, elementValue(car(lc)));
+ return mklist<value>(t, i, isNil(lc)? (value)list<value>() : elementValue(car(lc)));
}
/**
@@ -89,7 +89,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), isList(car(v))? (value)cdr<value>(car(v)) : car(v)));
+ return cons(car(e), mklist<value>(cadr(e), isList(car(v))? (isNil((list<value>)car(v))? car(v) : (value)cdr<value>(car(v))) : car(v)));
}
/**
@@ -129,8 +129,9 @@ 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" + (isList(caddr(l))? "application/xml" : "text")) + caddr(l))
+ + (isNil(cddr(l))?
+ list<value>() :
+ 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)));
}
diff --git a/sca-cpp/trunk/modules/rss/rss-test.cpp b/sca-cpp/trunk/modules/rss/rss-test.cpp
index 9bfd620835..0b773ba31e 100644
--- a/sca-cpp/trunk/modules/rss/rss-test.cpp
+++ b/sca-cpp/trunk/modules/rss/rss-test.cpp
@@ -54,6 +54,12 @@ string itemTextEntry("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"<description>Apple</description>"
"</item>\n");
+string itemNoDescriptionEntry("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+ "<item>"
+ "<title>fruit</title>"
+ "<link>cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b</link>"
+ "</item>\n");
+
string incompleteEntry("<item>"
"<title>fruit</title><description>"
"<Item xmlns=\"http://services/\">"
@@ -92,6 +98,12 @@ bool testEntry() {
assert(str(os) == itemTextEntry);
}
{
+ const list<value> a = mklist<value>(string("fruit"), string("cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b"), list<value>());
+ ostringstream os;
+ writeRSSEntry<ostream*>(writer, &os, a);
+ assert(str(os) == itemNoDescriptionEntry);
+ }
+ {
const list<value> a = content(readRSSEntry(mklist(itemEntry)));
ostringstream os;
writeRSSEntry<ostream*>(writer, &os, a);
@@ -104,6 +116,12 @@ bool testEntry() {
assert(str(os) == itemTextEntry);
}
{
+ const list<value> a = content(readRSSEntry(mklist(itemNoDescriptionEntry)));
+ ostringstream os;
+ writeRSSEntry<ostream*>(writer, &os, a);
+ assert(str(os) == itemNoDescriptionEntry);
+ }
+ {
const list<value> a = content(readRSSEntry(mklist(incompleteEntry)));
ostringstream os;
writeRSSEntry<ostream*>(writer, &os, a);
diff --git a/sca-cpp/trunk/modules/rss/rss.hpp b/sca-cpp/trunk/modules/rss/rss.hpp
index 506d1f4a6d..646a8fd030 100644
--- a/sca-cpp/trunk/modules/rss/rss.hpp
+++ b/sca-cpp/trunk/modules/rss/rss.hpp
@@ -44,7 +44,7 @@ const list<value> entryElementsToValues(const list<value>& e) {
const list<value> li = filter<value>(selector(mklist<value>(element, "link")), e);
const value i = isNil(li)? value(emptyString) : elementValue(car(li));
const list<value> ld = filter<value>(selector(mklist<value>(element, "description")), e);
- return mklist<value>(t, i, elementValue(car(ld)));
+ return mklist<value>(t, i, isNil(ld)? (value)list<value>() : elementValue(car(ld)));
}
/**
@@ -80,7 +80,7 @@ const failable<list<value> > readRSSEntry(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), isList(car(v))? (value)cdr<value>(car(v)) : car(v)));
+ return cons(car(e), mklist<value>(cadr(e), isList(car(v))? (isNil((list<value>)car(v))? car(v) : (value)cdr<value>(car(v))) : car(v)));
}
/**
@@ -121,7 +121,7 @@ const list<value> entryElement(const list<value>& l) {
+ element + "item"
+ (list<value>() + element + "title" + car(l))
+ (list<value>() + element + "link" + cadr(l))
- + (list<value>() + element + "description" + caddr(l));
+ + (isNil(cddr(l))? list<value>() : list<value>() + element + "description" + caddr(l));
}
/**