summaryrefslogtreecommitdiffstats
path: root/sca-cpp/trunk/modules/js
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--sca-cpp/trunk/modules/js/htdocs/atomutil.js98
-rw-r--r--sca-cpp/trunk/modules/js/htdocs/component.js64
-rw-r--r--sca-cpp/trunk/modules/js/htdocs/util.js27
3 files changed, 66 insertions, 123 deletions
diff --git a/sca-cpp/trunk/modules/js/htdocs/atomutil.js b/sca-cpp/trunk/modules/js/htdocs/atomutil.js
index 21aa16e0fc..182b698596 100644
--- a/sca-cpp/trunk/modules/js/htdocs/atomutil.js
+++ b/sca-cpp/trunk/modules/js/htdocs/atomutil.js
@@ -25,22 +25,23 @@ var atom = {};
/**
* Convert a list of elements to a list of values representing an ATOM entry.
*/
-atom.entryElementsToValues = function(e) {
+atom.entryElementValues = function(e) {
var lt = filter(selector(mklist(element, "'title")), e);
var t = isNil(lt)? '' : elementValue(car(lt));
var li = filter(selector(mklist(element, "'id")), e);
var i = isNil(li)? '' : elementValue(car(li));
var lc = filter(selector(mklist(element, "'content")), e);
- return mklist(t, i, elementValue(car(lc)));
+ return append(mklist(element, "'entry", mklist(element, "'title", t), mklist(element, "'id", i)),
+ isNil(lc)? mklist() : mklist(mklist(element, "'content", elementValue(car(lc)))))
};
/**
* Convert a list of elements to a list of values representing ATOM entries.
*/
-atom.entriesElementsToValues = function(e) {
+atom.entriesElementValues = function(e) {
if (isNil(e))
return e;
- return cons(atom.entryElementsToValues(car(e)), atom.entriesElementsToValues(cdr(e)));
+ return cons(atom.entryElementValues(car(e)), atom.entriesElementValues(cdr(e)));
};
/**
@@ -59,7 +60,7 @@ atom.readATOMEntryDocument = function(doc) {
var e = readXMLDocument(doc);
if (isNil(e))
return mklist();
- return atom.entryElementsToValues(car(e));
+ return mklist(atom.entryElementValues(car(e)));
};
/**
@@ -70,14 +71,6 @@ atom.readATOMEntry = function(l) {
};
/**
- * Convert a list of values representy an ATOM entry to a value.
- */
-atom.entryValue = function(e) {
- var v = elementsToValues(mklist(caddr(e)));
- return cons(car(e), (cadr(e), cdr(car(v))));
-};
-
-/**
* Return true if a list of strings represents an ATOM feed.
*/
atom.isATOMFeed = function(l) {
@@ -96,40 +89,32 @@ atom.readATOMFeedDocument = function(doc) {
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));
- if (isNil(e))
- return mklist(elementValue(car(t)), elementValue(car(i)));
- return cons(elementValue(car(t)), cons(elementValue(car(i)), atom.entriesElementsToValues(e)));
+ return mklist(append(
+ mklist(element, "'feed", mklist(element, "'title", elementValue(car(t))), mklist(element, "'id", elementValue(car(i)))),
+ atom.entriesElementValues(e)));
};
/**
* Convert a list of strings to a list of values representing an ATOM feed.
*/
atom.readATOMFeed = function(l) {
- return atom.readAtomFeedDocument(parseXML(l));
-};
-
-/**
- * Convert an ATOM feed containing elements to an ATOM feed containing values.
- */
-atom.feedValues = function(e) {
- function feedValuesLoop(e) {
- if (isNil(e))
- return e;
- return cons(entryValue(car(e)), feedValuesLoop(cdr(e)));
- }
-
- return cons(car(e), cons(cadr(e), feedValuesLoop(cddr(e))));
+ return atom.readATOMFeedDocument(parseXML(l));
};
/**
* Convert a list of values representy an ATOM entry to a list of elements.
*/
atom.entryElement = function(l) {
- return mklist(element, "'entry", mklist(attribute, "'xmlns", "http://www.w3.org/2005/Atom"),
- mklist(element, "'title", mklist(attribute, "'type", "text"), car(l)),
- mklist(element, "'id", cadr(l)),
- mklist(element, "'content", mklist(attribute, "'type", (isList(caddr(l))? "application/xml" : "text")), caddr(l)),
- mklist(element, "'link", mklist(attribute, "'href", cadr(l))));
+ var title = elementValue(namedElementChild("'title", l));
+ var id = elementValue(namedElementChild("'id", l));
+ var content = namedElementChild("'content", l);
+ var text = isNil(content)? false : elementHasValue(content);
+ return 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)),
+ isNil(content)? mklist() :
+ append(mklist(element, "'content", mklist(attribute, "'type", text? "text" : "application/xml")), text? mklist(elementValue(content)) : elementChildren(content))),
+ mklist(element, "'link", mklist(attribute, "'href", id)));
};
/**
@@ -144,42 +129,37 @@ atom.entriesElements = function(l) {
/**
* Convert a list of values representing an ATOM entry to an ATOM entry.
*/
-atom.writeATOMEntry = function(l) {
+atom.writeATOMEntry = function(ll) {
+ var l = isNil(ll)? ll : car(ll);
return writeXML(mklist(atom.entryElement(l)), true);
};
/**
* Convert a list of values representing an ATOM feed to an ATOM feed.
*/
-atom.writeATOMFeed = function(l) {
+atom.writeATOMFeed = function(ll) {
+ var l = isNil(ll)? ll : car(ll);
+ var lt = filter(selector(mklist(element, "'title")), l);
+ var t = isNil(lt)? '' : elementValue(car(lt));
+ var li = filter(selector(mklist(element, "'id")), l);
+ var i = isNil(li)? '' : elementValue(car(li));
var f = mklist(element, "'feed", mklist(attribute, "'xmlns", "http://www.w3.org/2005/Atom"),
mklist(element, "'title", mklist(attribute, "'type", "text"), car(l)),
mklist(element, "'id", cadr(l)));
- if (isNil(cddr(l)))
- return writeXML(mklist(f), true);
- var fe = append(f, atom.entriesElements(cddr(l)));
- return writeXML(mklist(fe), true);
-};
-/**
- * Convert an ATOM entry containing a value to an ATOM entry containing an item element.
- */
-atom.entryValuesToElements = function(v) {
- if (isList(caddr(v)))
- return cons(car(v), cons(cadr(v), valuesToElements(mklist(cons("'item", caddr(v))))));
- return cons(car(v), cons(cadr(v), valuesToElements(mklist(mklist("'item", caddr(v))))));
-};
+ // Write ATOM entries
+ var le = filter(selector(mklist(element, "'entry")), l);
+ if (isNil(le))
+ return writeXML(mklist(f), true);
-/**
- * Convert an ATOM feed containing values to an ATOM feed containing elements.
- */
-atom.feedValuesToElements = function(v) {
- function feedValuesToElementsLoop(v) {
- if (isNil(v))
- return v;
- return cons(atom.entryValuesToElements(car(v)), feedValuesToElementsLoop(cdr(v)));
+ // Write a single ATOM entry element with a list of values
+ if (!isNil(le) && !isNil(car(le)) && isList(car(caddr(car(le))))) {
+ var fe = append(f, atom.entriesElements(caddr(car(le))));
+ return writeXML(mklist(fe), true);
}
- return cons(car(v), cons(cadr(v), feedValuesToElementsLoop(cddr(v))));
+ // Write separate ATOM entry elements
+ var fe = append(f, atom.entriesElements(le));
+ return writeXML(mklist(fe), true);
};
diff --git a/sca-cpp/trunk/modules/js/htdocs/component.js b/sca-cpp/trunk/modules/js/htdocs/component.js
index 835cc148c2..ecbcdeda5b 100644
--- a/sca-cpp/trunk/modules/js/htdocs/component.js
+++ b/sca-cpp/trunk/modules/js/htdocs/component.js
@@ -174,9 +174,8 @@ HTTPBindingClient.jsonResult = function(http) {
HTTPBindingClient.charset = httpCharset(http);
// Unmarshall the JSON response
- var data = http.responseText;
var obj;
- eval("obj = " + data);
+ eval("obj = " + http.responseText);
if(obj.error)
throw new HTTPBindingClient.Exception(obj.error.code, obj.error.msg);
var res = obj.result;
@@ -224,15 +223,6 @@ HTTPBindingClient.prototype.jsonApply = function(req) {
};
/**
- * Return the XML Document result from an XMLHTTPRequest.
- */
-HTTPBindingClient.xmlResult = function(http) {
- if(!http.responseXML || http.responseXML.childNodes.length == 0)
- return (new DOMParser()).parseFromString(http.responseText, "text/xml");
- return http.responseXML;
-}
-
-/**
* REST ATOMPub GET method.
*/
HTTPBindingClient.prototype.get = function(id, cb) {
@@ -246,15 +236,9 @@ HTTPBindingClient.prototype.get = function(id, cb) {
http.onreadystatechange = function() {
if (http.readyState == 4) {
// Pass the result or exception
- if (http.status == 200) {
- var res = null;
- try {
- res = HTTPBindingClient.xmlResult(http);
- } catch (e) {
- cb(null, e);
- }
- cb(res);
- } else
+ if (http.status == 200)
+ cb(http.responseText);
+ else
cb(null, new HTTPBindingClient.Exception(http.status, http.statusText));
}
};
@@ -267,7 +251,7 @@ HTTPBindingClient.prototype.get = function(id, cb) {
// Send the request and return the result or exception
http.send(null);
if (http.status == 200)
- return HTTPBindingClient.xmlResult(http);
+ return http.responseText;
throw new HTTPBindingClient.Exception(http.status, http.statusText);
};
@@ -286,15 +270,9 @@ HTTPBindingClient.prototype.post = function (entry, cb) {
http.onreadystatechange = function() {
// Pass the result or exception
if (http.readyState == 4) {
- if (http.status == 201) {
- var res = null;
- try {
- res = HTTPBindingClient.xmlResult(http);
- } catch (e) {
- cb(null, e);
- }
- cb(res);
- } else
+ if (http.status == 201)
+ cb(http.responseText);
+ else
cb(null, new HTTPBindingClient.Exception(http.status, http.statusText));
}
};
@@ -306,7 +284,7 @@ HTTPBindingClient.prototype.post = function (entry, cb) {
// Send the request and return the result or exception
http.send(entry);
if (http.status == 201)
- return HTTPBindingClient.xmlResult(http);
+ return http.responseText;
throw new HTTPBindingClient.Exception(http.status, http.statusText);
};
@@ -423,30 +401,6 @@ HTTPBindingClient.getHTTPRequest = function() {
};
/**
- * DOM parser wrapper.
- */
-if (typeof DOMParser == "undefined") {
- DOMParser = function() {}
-
- DOMParser.prototype.parseFromString = function (str, contentType) {
- if (typeof ActiveXObject != "undefined") {
- var d = new ActiveXObject("MSXML.DomDocument");
- d.loadXML(str);
- return d;
- } else if (typeof XMLHttpRequest != "undefined") {
- var req = new XMLHttpRequest;
- req.open("GET", "data:" + (contentType || "application/xml") +
- ";charset=utf-8," + encodeURIComponent(str), false);
- if (req.overrideMimeType) {
- req.overrideMimeType(contentType);
- }
- req.send(null);
- return req.responseXML;
- }
- }
-}
-
-/**
* Public API.
*/
diff --git a/sca-cpp/trunk/modules/js/htdocs/util.js b/sca-cpp/trunk/modules/js/htdocs/util.js
index 336248d34c..20af741c6d 100644
--- a/sca-cpp/trunk/modules/js/htdocs/util.js
+++ b/sca-cpp/trunk/modules/js/htdocs/util.js
@@ -52,14 +52,14 @@ function cddr(l) {
return cdr(cdr(l));
}
-function cdddr(l) {
- return cdr(cdr(cdr(l)));
-}
-
function caddr(l) {
return car(cddr(l));
}
+function cdddr(l) {
+ return cdr(cdr(cdr(l)));
+}
+
function cadddr(l) {
return car(cdddr(l));
}
@@ -164,13 +164,22 @@ function tokens(path) {
var rconsole;
function log(v) {
- if (rconsole) {
+ try {
+ var s = '';
+ for (i = 0; i < arguments.length; i++) {
+ s = s + writeValue(arguments[i]);
+ if (i < arguments.length)
+ s = s + ' ';
+ }
+
+ if (rconsole) {
+ try {
+ rconsole.log(s);
+ } catch (e) {}
+ }
try {
- rconsole.log(v);
+ console.log(s);
} catch (e) {}
- }
- try {
- console.log(v);
} catch (e) {}
return true;
}