diff options
author | jsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68> | 2013-08-26 03:04:23 +0000 |
---|---|---|
committer | jsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68> | 2013-08-26 03:04:23 +0000 |
commit | 7905926c413e843d9497948cb824059f2c017f6a (patch) | |
tree | 0f88f849a2b6a170319b9ba22b6434ab586a1283 /sca-cpp/trunk/modules | |
parent | 64fed3fe80c115c775d45f9b46f661a4d6043e5a (diff) |
Support sorting database search results by rank, and add a rank attribute to ATOM entries.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1517412 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-cpp/trunk/modules')
-rw-r--r-- | sca-cpp/trunk/modules/atom/atom-test.cpp | 17 | ||||
-rw-r--r-- | sca-cpp/trunk/modules/atom/atom.hpp | 11 | ||||
-rw-r--r-- | sca-cpp/trunk/modules/js/htdocs/atomutil.js | 48 | ||||
-rw-r--r-- | sca-cpp/trunk/modules/js/htdocs/elemutil.js | 26 | ||||
-rw-r--r-- | sca-cpp/trunk/modules/wsgi/atomutil.py | 3 |
5 files changed, 75 insertions, 30 deletions
diff --git a/sca-cpp/trunk/modules/atom/atom-test.cpp b/sca-cpp/trunk/modules/atom/atom-test.cpp index 056e9ea965..e2e07a8608 100644 --- a/sca-cpp/trunk/modules/atom/atom-test.cpp +++ b/sca-cpp/trunk/modules/atom/atom-test.cpp @@ -77,6 +77,17 @@ const string itemNoContentEntry("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" "<link href=\"cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b\"/>" "</entry>\n"); +const string itemEmptyTitleEntry("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<entry xmlns=\"http://www.w3.org/2005/Atom\">" + "<title type=\"text\"></title>" + "<id>cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b</id>" + "<author>" + "<name>jane</name>" + "</author>" + "<updated>Fri Jan 01 08:11:36 PDT 2012</updated>" + "<link href=\"cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b\"/>" + "</entry>\n"); + const string incompleteEntry("<entry xmlns=\"http://www.w3.org/2005/Atom\">\n" "<title>item</title>" "<content type=\"text/xml\">" @@ -155,6 +166,12 @@ const bool testEntry() { assert(str(os) == itemNoContentEntry); } { + const list<value> a = content(readATOMEntry(mklist(itemEmptyTitleEntry))); + ostringstream os; + writeATOMEntry<ostream*>(writer, &os, a); + assert(str(os) == itemEmptyTitleEntry); + } + { 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 b6f2788b1e..49763a4b38 100644 --- a/sca-cpp/trunk/modules/atom/atom.hpp +++ b/sca-cpp/trunk/modules/atom/atom.hpp @@ -46,7 +46,7 @@ const value entry("entry"); */ const list<value> entryElementValues(const list<value>& e) { const list<value> lt = elementChildren("title", e); - const list<value> t = nilListValue + element + value("title") + (isNull(lt)? value(emptyString) : elementValue(car(lt))); + const list<value> t = nilListValue + element + value("title") + (isNull(lt) || !elementHasValue(car(lt))? value(emptyString) : elementValue(car(lt))); const list<value> li = elementChildren("id", e); const list<value> i = nilListValue + element + value("id") + (isNull(li)? value(emptyString) : elementValue(car(li))); @@ -60,11 +60,14 @@ const list<value> entryElementValues(const list<value>& e) { const list<value> lu = elementChildren("updated", e); const list<value> u = isNull(lu)? nilListValue : mklist<value>(nilListValue + element + value("updated") + elementValue(car(lu))); + const list<value> lr = elementChildren("rank", e); + const list<value> r = isNull(lr)? nilListValue : mklist<value>(nilListValue + element + value("rank") + elementValue(car(lr))); + const list<value> lc = elementChildren("content", e); const list<value> c = isNull(lc)? nilListValue : isAttribute(elementValue(car(lc)))? nilListValue : mklist<value>(nilListValue + element + value("content") + elementValue(car(lc))); - return append<value>(append<value>(append<value>(nilListValue + element + entry + value(t) + value(i), a), u), c); + return append<value>(append<value>(append<value>(append<value>(nilListValue + element + entry + value(t) + value(i), a), u), r), c); } /** @@ -138,15 +141,17 @@ const list<value> entryElement(const list<value>& l) { const value author = elementChild("author", l); const bool email = isNull(author)? false : contains(elementValue(author), "@"); const value updated = elementChild("updated", l); + const value rank = elementChild("rank", l); const value content = elementChild("content", l); const bool text = isNull(content)? false : elementHasValue(content); return nilListValue + element + entry + (nilListValue + attribute + "xmlns" + "http://www.w3.org/2005/Atom") - + (nilListValue + element + "title" + (nilListValue + attribute + "type" + "text") + elementValue(title)) + + (nilListValue + element + "title" + (nilListValue + attribute + "type" + "text") + (elementHasValue(title)? elementValue(title) : value(""))) + (nilListValue + element + "id" + elementValue(id)) + (isNull(author)? nilListValue : (nilListValue + element + "author" + (email? (nilListValue + element + "email" + elementValue(author)) : (nilListValue + element + "name" + elementValue(author))))) + (isNull(updated)? nilListValue : (nilListValue + element + "updated" + elementValue(updated))) + + (isNull(rank)? nilListValue : (nilListValue + element + "rank" + elementValue(rank))) + (isNull(content)? nilListValue : append<value>(nilListValue + element + "content" + (nilListValue + attribute + "type" + (text? "text" : "application/xml")), diff --git a/sca-cpp/trunk/modules/js/htdocs/atomutil.js b/sca-cpp/trunk/modules/js/htdocs/atomutil.js index 4b57b36fb4..8fe95c16a1 100644 --- a/sca-cpp/trunk/modules/js/htdocs/atomutil.js +++ b/sca-cpp/trunk/modules/js/htdocs/atomutil.js @@ -27,24 +27,27 @@ var atom = {}; */ atom.entryElementValues = function(e) { var lt = filter(selector(mklist(element, "'title")), e); - var t = mklist(element, "'title", isNull(lt)? '' : elementValue(car(lt))); + var t = mklist(element, "'title", isNull(lt) || !elementHasValue(car(lt))? '' : elementValue(car(lt))); var li = filter(selector(mklist(element, "'id")), e); var i = mklist(element, "'id", isNull(li)? '' : elementValue(car(li))); var la = filter(selector(mklist(element, "'author")), e); - var lan = isNull(la)? mklist() : filter(selector(mklist(element, "'name")), car(la)); - var lae = isNull(la)? mklist() : filter(selector(mklist(element, "'email")), car(la)); + var lan = isNull(la)? nil : filter(selector(mklist(element, "'name")), car(la)); + var lae = isNull(la)? nil : filter(selector(mklist(element, "'email")), car(la)); var laa = isNull(lan)? lae : lan; - var a = isNull(laa)? mklist() : mklist(mklist(element, "'author", elementValue(car(laa)))); + var a = isNull(laa)? nil : mklist(mklist(element, "'author", elementValue(car(laa)))); var lu = filter(selector(mklist(element, "'updated")), e); - var u = isNull(lu)? mklist() : mklist(mklist(element, "'updated", elementValue(car(lu)))); + var u = isNull(lu)? nil : mklist(mklist(element, "'updated", elementValue(car(lu)))); + + var lr = filter(selector(mklist(element, "'rank")), e); + var r = isNull(lr)? nil : mklist(mklist(element, "'rank", elementValue(car(lr)))); var lc = filter(selector(mklist(element, "'content")), e); - var c = isNull(lc)? mklist() : isAttribute(elementValue(car(lc)))? mklist() : mklist(mklist(element, "'content", elementValue(car(lc)))); + var c = isNull(lc)? nil : isAttribute(elementValue(car(lc)))? nil : mklist(mklist(element, "'content", elementValue(car(lc)))); - return append(append(append(mklist(element, "'entry", t, i), a), u), c); + return append(append(append(append(mklist(element, "'entry", t, i), a), u), r), c); }; /** @@ -71,7 +74,7 @@ atom.isATOMEntry = function(l) { atom.readATOMEntryDocument = function(doc) { var e = readXMLDocument(doc); if (isNull(e)) - return mklist(); + return nil; return mklist(atom.entryElementValues(car(e))); }; @@ -97,7 +100,7 @@ atom.isATOMFeed = function(l) { atom.readATOMFeedDocument = function(doc) { var f = readXMLDocument(doc); if (isNull(f)) - return mklist(); + return nil; var t = filter(selector(mklist(element, "'title")), car(f)); var i = filter(selector(mklist(element, "'id")), car(f)); var e = filter(selector(mklist(element, "'entry")), car(f)); @@ -117,20 +120,23 @@ atom.readATOMFeed = function(l) { * Convert a list of values representy an ATOM entry to a list of elements. */ atom.entryElement = function(l) { - var title = elementValue(namedElementChild("'title", l)); + var etitle = namedElementChild("'title", l); + var title = elementHasValue(etitle)? elementValue(etitle) : ''; var id = elementValue(namedElementChild("'id", l)); var author = namedElementChild("'author", l); var email = isNull(author)? false : (elementValue(author).indexOf('@') != -1); var updated = namedElementChild("'updated", l); + var rank = namedElementChild("'rank", l); var content = namedElementChild("'content", l); var text = isNull(content)? false : elementHasValue(content); - return append(append(append(append( + return append(append(append(append(append( mklist(element, "'entry", mklist(attribute, "'xmlns", "http://www.w3.org/2005/Atom"), mklist(element, "'title", mklist(attribute, "'type", "text"), title), mklist(element, "'id", id)), - isNull(author)? mklist() : mklist(mklist(element, "'author", + isNull(author)? nil : mklist(mklist(element, "'author", (email? mklist(element, "'email", elementValue(author)) : mklist(element, "'name", elementValue(author)))))), - isNull(updated)? mklist() : mklist(mklist(element, "'updated", elementValue(updated)))), - isNull(content)? mklist() : + isNull(updated)? nil : mklist(mklist(element, "'updated", elementValue(updated)))), + isNull(rank)? nil : mklist(mklist(element, "'rank", elementValue(rank)))), + isNull(content)? nil : mklist(append(mklist(element, "'content", mklist(attribute, "'type", text? "text" : "application/xml")), text? mklist(elementValue(content)) : elementChildren(content)))), mklist(mklist(element, "'link", mklist(attribute, "'href", id)))); @@ -182,3 +188,17 @@ atom.writeATOMFeed = function(ll) { return writeXML(mklist(fe), true); }; +/** + * Uncomment to test. + */ +/* +(function testAtom() { + console.log('Testing...'); + var entry = mklist("'entry", mklist("'title", 'test'), mklist("'id", 'test'), mklist("'content", mklist("'rating", '1'))); + var entryxml = car(atom.writeATOMEntry(valuesToElements(mklist(entry)))); + assert(entryxml == '<?xml version="1.0" encoding="UTF-8"?>\n' + + '<entry xmlns="http://www.w3.org/2005/Atom"><title type="text">test</title><id>test</id><content type="application/xml"><rating>1</rating></content><link href="test"/></entry>\n'); + console.log('OK'); +})(); +*/ + diff --git a/sca-cpp/trunk/modules/js/htdocs/elemutil.js b/sca-cpp/trunk/modules/js/htdocs/elemutil.js index 62050f5953..01dfcf2664 100644 --- a/sca-cpp/trunk/modules/js/htdocs/elemutil.js +++ b/sca-cpp/trunk/modules/js/htdocs/elemutil.js @@ -42,45 +42,47 @@ function isAttribute(v) { /** * Return the name of an attribute. */ -attributeName = cadr; +var attributeName = cadr; /** * Return the value of an attribute. */ -attributeValue = caddr; +var attributeValue = caddr; /** * Return the name of an element. */ -elementName = cadr; +var elementName = cadr; /** * Return true if an element has children. */ function elementHasChildren(l) { - return !isNull(cddr(l)); + return !isNull(l) && !isNull(cddr(l)); } /** * Return the children of an element. */ -elementChildren = cddr; +var elementChildren = cddr; /** * Return true if an element has a value. */ function elementHasValue(l) { - var r = reverse(l); - if (isSymbol(car(r))) + if (isNull(l)) + return false; + var v = last(l); + if (isSymbol(v)) return false; - return (!(isList(car(r)) && !isNull(car(r)) && isSymbol(car(car(r))))) + return (!(isList(v) && !isNull(v) && isSymbol(car(v)))) } /** * Return the value of an element. */ function elementValue(l) { - return car(reverse(l)); + return last(l); } /** @@ -140,7 +142,7 @@ function elementsToValues(e) { function valueToElement(t) { if (isList(t) && !isNull(t) && isSymbol(car(t))) { var n = car(t); - var v = isNull(cdr(t))? mklist() : cadr(t); + var v = isNull(cdr(t))? nil : cadr(t); if (!isList(v)) { if (n.substring(0, 2) == atsign) return mklist(attribute, "'" + n.substring(2), v); @@ -171,7 +173,7 @@ function selector(s) { function evalSelect(s, v) { if (isNull(s)) return true; - if (isNull(v)) + if (!isList(v) || isNull(v)) return false; if (car(s) != car(v)) return false; @@ -230,7 +232,7 @@ function namedElementChild(name, l) { * Set the contents of an element. */ function setElement(l, e) { - setlist(l, e); + setList(l, e); l.memo = {}; } diff --git a/sca-cpp/trunk/modules/wsgi/atomutil.py b/sca-cpp/trunk/modules/wsgi/atomutil.py index d65b26c41c..92ad023449 100644 --- a/sca-cpp/trunk/modules/wsgi/atomutil.py +++ b/sca-cpp/trunk/modules/wsgi/atomutil.py @@ -70,7 +70,8 @@ def readATOMFeed(l): # Convert a list of values representy an ATOM entry to a list of elements def entryElement(l): - title = elementValue(namedElementChild("'title", l)) + etitle = namedElementChild("'title", l) + title = elementValue(etitle) if elementHasValue(etitle) else '' id = elementValue(namedElementChild("'id", l)) content = namedElementChild("'content", l) text = False if isNull(content) else elementHasValue(content) |