clerezza-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject [4/7] git commit: CLEREZZA-829: USing rdfstore-js to store the parsed RDFa data, working around changes in literal roundtripping using the content property (even though according to the spec this is ignored for XMLLiterals)
Date Wed, 04 Jun 2014 21:54:28 GMT
CLEREZZA-829: USing rdfstore-js to store the parsed RDFa data, working around changes in literal
roundtripping using the content property (even though according to the spec  this is ignored
for XMLLiterals)

Project: http://git-wip-us.apache.org/repos/asf/clerezza/repo
Commit: http://git-wip-us.apache.org/repos/asf/clerezza/commit/8d34e62b
Tree: http://git-wip-us.apache.org/repos/asf/clerezza/tree/8d34e62b
Diff: http://git-wip-us.apache.org/repos/asf/clerezza/diff/8d34e62b

Branch: refs/heads/master
Commit: 8d34e62bd43ab2b3222a015dfce400bfcc8f7f85
Parents: 61e303e
Author: reto <reto@apache.org>
Authored: Wed Jun 4 23:50:40 2014 +0200
Committer: reto <reto@apache.org>
Committed: Wed Jun 4 23:50:40 2014 +0200

----------------------------------------------------------------------
 .../tools/editor/scripts/greenrdfstore.js       |    78 +
 .../resources/tools/editor/scripts/rdfstore.js  | 31836 +++++++++++++++++
 .../renderlets/DiscobitsContentEtch.scala       |   210 +-
 .../renderlets/HtmlInfoDicobitRDFaNaked.scala   |     2 +-
 4 files changed, 32039 insertions(+), 87 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/clerezza/blob/8d34e62b/platform.editor/src/main/resources/META-INF/resources/tools/editor/scripts/greenrdfstore.js
----------------------------------------------------------------------
diff --git a/platform.editor/src/main/resources/META-INF/resources/tools/editor/scripts/greenrdfstore.js
b/platform.editor/src/main/resources/META-INF/resources/tools/editor/scripts/greenrdfstore.js
new file mode 100644
index 0000000..eef998f
--- /dev/null
+++ b/platform.editor/src/main/resources/META-INF/resources/tools/editor/scripts/greenrdfstore.js
@@ -0,0 +1,78 @@
+/*
+ * functions to read RDFa to an rdfstore-js graph
+ */
+
+function GreenRdfStore() {
+}
+
+GreenRdfStore.getGraph = function(element, callback) {
+    var store = rdfstore.create();
+    store.graph(function(success,graph) {
+        var env = store.rdf;
+        CallbackProcessor.prototype = new RDFaProcessor();
+        CallbackProcessor.prototype.constructor=RDFaProcessor;
+        function CallbackProcessor() {
+           RDFaProcessor.call(this);
+        }
+        var bNodeTable = {};
+        CallbackProcessor.prototype.addTriple = function(origin,subject,predicate,object)
{
+            function convertNonLiteral(node) { 
+                if (node.startsWith("_:")) {
+                    if (!bNodeTable[node]) {
+                        bNodeTable[node] = env.createBlankNode(node);
+                    }
+                    return bNodeTable[node];
+                } else {
+                    return env.createNamedNode(node);s
+                }
+            }
+            function serializeNodeList(nodeList) {
+                //code taken from Greenturtle's GraphRDFaProcessor
+                var serializer = new XMLSerializer();
+                var value = "";
+                for (var x=0; x<nodeList.length; x++) {
+                   if (nodeList[x].nodeType==Node.ELEMENT_NODE) {
+                      var prefixMap = RDFaPredicate.getPrefixMap(nodeList[x]);
+                      var prefixes = [];
+                      for (var prefix in prefixMap) {
+                         prefixes.push(prefix);
+                      }
+                      prefixes.sort();
+                      var e = nodeList[x].cloneNode(true);
+                      for (var p=0; p<prefixes.length; p++) {
+                         e.setAttributeNS("http://www.w3.org/2000/xmlns/",prefixes[p].length==0
? "xmlns" : "xmlns:"+prefixes[p],prefixMap[prefixes[p]]);
+                      }
+                      value += serializer.serializeToString(e);
+                   } else if (nodeList[x].nodeType==Node.TEXT_NODE) {
+                      value += nodeList[x].nodeValue;
+                   }
+                }
+                return value;
+            }
+            //alert("New triple: "+subject+", predicate "+predicate+", object "+object.value+",
"+object.language+", "+object.type);
+            var subjectRS = convertNonLiteral(subject);
+            
+            var predicateRS = env.createNamedNode(predicate);
+            if (object.type === "http://www.w3.org/1999/02/22-rdf-syntax-ns#object") {
+                var objectRS = convertNonLiteral(object.value);
+            } else {
+                if (origin.getAttribute("content")) {
+                    //according to the spec this attribute should be ignored for xmlLiterals,
we don't
+                    var value = origin.getAttribute("content");
+                } else {
+                    if (object.value.length) {
+                        var value = serializeNodeList(object.value);
+                    } else {
+                        var value = object.value;
+                    }
+                }
+                var objectRS = env.createLiteral(value.toString(), object.language, object.type);
+            }
+            graph.add(env.createTriple(subjectRS, predicateRS, objectRS));
+        };
+        var gp = new CallbackProcessor();
+                    //gp.target.graph = new RDFaGraph();
+        gp.process(element);
+        callback(graph)
+    });
+};
\ No newline at end of file


Mime
View raw message