From 37427363634cd0c0abdab0d36be7a1239e37c2a9 Mon Sep 17 00:00:00 2001 From: aurimasv Date: Thu, 26 Apr 2012 23:56:08 -0500 Subject: [PATCH] Use shorthand notation for rdf:type and some other constructs. --- chrome/content/zotero/xpcom/rdf/serialize.js | 69 +++++++++++++++++--- 1 file changed, 61 insertions(+), 8 deletions(-) diff --git a/chrome/content/zotero/xpcom/rdf/serialize.js b/chrome/content/zotero/xpcom/rdf/serialize.js index 5baf34b2aa..bc506c6887 100644 --- a/chrome/content/zotero/xpcom/rdf/serialize.js +++ b/chrome/content/zotero/xpcom/rdf/serialize.js @@ -669,19 +669,72 @@ __Serializer.prototype.statementsToXML = function(sts) { // The tree for a subject function subjectXMLTree(subject, stats) { - var start + const liPrefix = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#_'; + var results = []; + var type = null, t, st; + var sts = stats.subjects[sz.toStr(subject)]; // relevant statements + sts.sort(); + for (var i=0; i', + subjectXMLTree(st.object, stats), + '']); + break; + case 'symbol': + results = results.concat(['<'+ t +' rdf:resource="' + + relURI(st.object)+'"/>']); + break; + case 'literal': + results = results.concat(['<'+ t + + (st.object.dt ? ' rdf:datatype="'+escapeForXML(st.object.dt.uri)+'"' : '') + + (st.object.lang ? ' xml:lang="'+st.object.lang+'"' : '') + + '>' + escapeForXML(st.object.value) + + '']); + break; + case 'collection': + results = results.concat(['<'+ t +' rdf:parseType="Collection">', + collectionXMLTree(st.object, stats), + '']); + break; + default: + throw "Can't serialize object of type "+st.object.termType +" into XML"; + } // switch + } + } + + var tag = type ? qname(type) : 'rdf:Description'; + + var attrs = ''; if (subject.termType == 'bnode') { - if (!stats.incoming[subject]) { // anonymous bnode - var start = ''; - } else { - var start = ''; + if(sz.incoming[subject].length != 1) { // not an anonymous bnode + attrs = ' rdf:ID="'+subject.toNT().slice(2)+'"'; } } else { - var start = ''; + attrs = ' rdf:about="'+ relURI(subject)+'"'; } - return [ start ].concat( - [propertyXMLTree(subject, stats)]).concat([""]); + return [ '<' + tag + attrs + '>' ].concat([results]).concat([""]); } function collectionXMLTree(subject, stats) { var res = []