clerezza-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject [4/7] clerezza git commit: CLEREZZA-829: using turtle-sections to have the original version without any changes in HTML-literals
Date Sat, 18 Apr 2015 09:48:56 GMT
CLEREZZA-829: using turtle-sections to have the original version without any changes in HTML-literals

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

Branch: refs/heads/master
Commit: 98a83b69676a161ea6e1cb4ac4f64a2b907f5a69
Parents: bd2519d
Author: Reto Gmuer <reto@apache.org>
Authored: Sat Apr 18 09:43:47 2015 +0000
Committer: Reto Gmuer <reto@apache.org>
Committed: Sat Apr 18 09:48:38 2015 +0000

----------------------------------------------------------------------
 .../tools/editor/scripts/RDFa.1.3.0.js          |    40 +-
 .../tools/editor/scripts/RDFaProcessor.1.3.0.js |    17 +-
 .../resources/tools/editor/scripts/editor.js    |   216 +
 .../tools/editor/scripts/greenrdfstore.js       |    11 +-
 .../resources/tools/editor/scripts/rdf-ext.js   | 19324 +++++++++++++++++
 .../renderlets/DiscobitsContentEtch.scala       |   178 +-
 .../renderlets/HtmlInfoDicobitRDFaNaked.scala   |    39 +-
 .../renderlets/OrderedContentRDFaNaked.scala    |    28 +-
 .../renderlets/TitledContentRDFaNaked.scala     |    51 +-
 .../editor/renderlets/XmlResultWithTurtle.scala |    43 +
 10 files changed, 19725 insertions(+), 222 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/clerezza/blob/98a83b69/platform/editor/src/main/resources/META-INF/resources/tools/editor/scripts/RDFa.1.3.0.js
----------------------------------------------------------------------
diff --git a/platform/editor/src/main/resources/META-INF/resources/tools/editor/scripts/RDFa.1.3.0.js
b/platform/editor/src/main/resources/META-INF/resources/tools/editor/scripts/RDFa.1.3.0.js
index 4cc83b4..7f15ed6 100644
--- a/platform/editor/src/main/resources/META-INF/resources/tools/editor/scripts/RDFa.1.3.0.js
+++ b/platform/editor/src/main/resources/META-INF/resources/tools/editor/scripts/RDFa.1.3.0.js
@@ -1,4 +1,4 @@
-/** @preserve green-turtle version 1.3.0 Copyright (c) 2011-2013, R. Alexander Milowski <alex@milowski.com>
All rights reserved. */
+/** @preserve green-turtle version 1.3.0 Copyright (c) 2011-2014, R. Alexander Milowski <alex@milowski.com>
All rights reserved. */
 /**         
 
 Redistribution and use in source and binary forms, with or without modification, are permitted
provided that the following conditions are met:
@@ -1353,6 +1353,9 @@ RDFaSubject.prototype.toObject = function() {
                }
             } 
             p.objects.push({ type: object.type, value: value, language: object.language });
+         } else if (object.type==RDFaProcessor.HTMLLiteralURI) {
+            var value = object.value.length==0 ? "" : object.value[0].parentNode.innerHTML;
+            p.objects.push({ type: object.type, value: value, language: object.language });
          } else {
             p.objects.push({ type: object.type, value: object.value, language: object.language
});
          }
@@ -1416,7 +1419,6 @@ RDFaPredicate.prototype.toString = function(options) {
       if (i>0) {
          s += ", ";
       }
-      // TODO: handle HTML literal
       if (this.objects[i].type=="http://www.w3.org/1999/02/22-rdf-syntax-ns#object") {
          if (this.objects[i].value.substring(0,2)=="_:") {
             if (options && options.filterBlankNode) {
@@ -1459,13 +1461,20 @@ RDFaPredicate.prototype.toString = function(options) {
                value += this.objects[i].value[x].nodeValue;
             }
          }
-         s += '"""'+value.replace(/"""/,"\\\"\\\"\\\"")+'"""^^<http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral>';
+         s += '"""'+value.replace(/"""/g,"\\\"\\\"\\\"")+'"""^^<http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral>';
+      } else if (this.objects[i].type=="http://www.w3.org/1999/02/22-rdf-syntax-ns#HTML")
{
+         // We can use innerHTML as a shortcut from the parentNode if the list is not empty
+         if (this.objects[i].value.length==0) {
+            s += '""""""^^<http://www.w3.org/1999/02/22-rdf-syntax-ns#HTML>';
+         } else {
+            s += '"""'+this.objects[i].value[0].parentNode.innerHTML.replace(/"""/g,"\\\"\\\"\\\"")+'"""^^<http://www.w3.org/1999/02/22-rdf-syntax-ns#HTML>';
+         }
       } else {
          var l = this.objects[i].value;
          if (l.indexOf("\n")>=0 || l.indexOf("\r")>=0) {
-            s += '"""' + l.replace(/"""/,"\\\"\\\"\\\"") + '"""';
+            s += '"""' + l.replace(/"""/g,"\\\"\\\"\\\"") + '"""';
          } else {
-            s += '"' + l.replace(/"/,"\\\"") + '"';
+            s += '"' + l.replace(/"/g,"\\\"") + '"';
          }
          if (this.objects[i].type!="http://www.w3.org/1999/02/22-rdf-syntax-ns#PlainLiteral")
{
              s += "^^<"+this.objects[i].type+">";
@@ -2065,9 +2074,10 @@ DocumentData.prototype.merge = function(graph,options) {
             }
             return mapSubject ? mapSubject : u;
          };
-      for (var subject in graph) {
+      var subjects = typeof graph.subjects != "undefined" ? graph.subjects : graph;
+      for (var subject in subjects) {
          var mapSubject = subjectMap(subject);
-         var snode = graph[subject];
+         var snode = subjects[subject];
          subject = mapSubject ? mapSubject : subject;
          var target = this._data_.graph.subjects[subject];
          if (target) {
@@ -2079,7 +2089,7 @@ DocumentData.prototype.merge = function(graph,options) {
                      var object = pnode.objects[i];
                      var toAdd = [];
                      for (var j=0; j<targetPredicate.objects.length; j++) {
-                        if (object.type==RDFaProcessor.XMLLiteralURI && (targetPredicate.objects[j].type!=object.type
|| targetPredicate.objects[j].value!==object.value)) {
+                        if ((object.type==RDFaProcessor.XMLLiteralURI || object.type==RDFaProcessor.HTMLLiteralURI)
&& (targetPredicate.objects[j].type!=object.type || targetPredicate.objects[j].value!==object.value))
{
                            toAdd.push(object);
                         } else if (targetPredicate.objects[j].type!=object.type || targetPredicate.objects[j].value==object.value)
{
                            toAdd.push(object);
@@ -2664,7 +2674,19 @@ TurtleParser.prototype.parseObject = function(subject,predicate,text)
{
    }
    var match = this.parseLiteral(text);
    if (match) {
-      this.addTriple(subject,predicate,{ type: match.type ? match.type : TurtleParser.plainLiteralURI,
value: match.literal, language: match.language});
+      var value = match.literal;
+      if (match.type=="http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral") {
+         var xml = "<root>"+match.literal+"</root>";
+         var parser = new DOMParser();
+         var doc = parser.parseFromString(xml,"application/xml");
+         value = doc.documentElement.childNodes;
+      } else if (match.type=="http://www.w3.org/1999/02/22-rdf-syntax-ns#HTML") {
+         var xml = "<html><head/><body>"+match.literal+"</body></html>";
+         var parser = new DOMParser();
+         var doc = parser.parseFromString(xml,"text/html");
+         value = doc.body.childNodes;
+      }
+      this.addTriple(subject,predicate,{ type: match.type ? match.type : TurtleParser.plainLiteralURI,
value: value, language: match.language});
       return match.remaining;
    }
    this.reportError("Terminating: Cannot parse literal at "+text.substring(0,20));

http://git-wip-us.apache.org/repos/asf/clerezza/blob/98a83b69/platform/editor/src/main/resources/META-INF/resources/tools/editor/scripts/RDFaProcessor.1.3.0.js
----------------------------------------------------------------------
diff --git a/platform/editor/src/main/resources/META-INF/resources/tools/editor/scripts/RDFaProcessor.1.3.0.js
b/platform/editor/src/main/resources/META-INF/resources/tools/editor/scripts/RDFaProcessor.1.3.0.js
index 1dc3f47..1e90cc3 100644
--- a/platform/editor/src/main/resources/META-INF/resources/tools/editor/scripts/RDFaProcessor.1.3.0.js
+++ b/platform/editor/src/main/resources/META-INF/resources/tools/editor/scripts/RDFaProcessor.1.3.0.js
@@ -1345,6 +1345,9 @@ RDFaSubject.prototype.toObject = function() {
                }
             } 
             p.objects.push({ type: object.type, value: value, language: object.language });
+         } else if (object.type==RDFaProcessor.HTMLLiteralURI) {
+            var value = object.value.length==0 ? "" : object.value[0].parentNode.innerHTML;
+            p.objects.push({ type: object.type, value: value, language: object.language });
          } else {
             p.objects.push({ type: object.type, value: object.value, language: object.language
});
          }
@@ -1408,7 +1411,6 @@ RDFaPredicate.prototype.toString = function(options) {
       if (i>0) {
          s += ", ";
       }
-      // TODO: handle HTML literal
       if (this.objects[i].type=="http://www.w3.org/1999/02/22-rdf-syntax-ns#object") {
          if (this.objects[i].value.substring(0,2)=="_:") {
             if (options && options.filterBlankNode) {
@@ -1451,13 +1453,20 @@ RDFaPredicate.prototype.toString = function(options) {
                value += this.objects[i].value[x].nodeValue;
             }
          }
-         s += '"""'+value.replace(/"""/,"\\\"\\\"\\\"")+'"""^^<http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral>';
+         s += '"""'+value.replace(/"""/g,"\\\"\\\"\\\"")+'"""^^<http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral>';
+      } else if (this.objects[i].type=="http://www.w3.org/1999/02/22-rdf-syntax-ns#HTML")
{
+         // We can use innerHTML as a shortcut from the parentNode if the list is not empty
+         if (this.objects[i].value.length==0) {
+            s += '""""""^^<http://www.w3.org/1999/02/22-rdf-syntax-ns#HTML>';
+         } else {
+            s += '"""'+this.objects[i].value[0].parentNode.innerHTML.replace(/"""/g,"\\\"\\\"\\\"")+'"""^^<http://www.w3.org/1999/02/22-rdf-syntax-ns#HTML>';
+         }
       } else {
          var l = this.objects[i].value;
          if (l.indexOf("\n")>=0 || l.indexOf("\r")>=0) {
-            s += '"""' + l.replace(/"""/,"\\\"\\\"\\\"") + '"""';
+            s += '"""' + l.replace(/"""/g,"\\\"\\\"\\\"") + '"""';
          } else {
-            s += '"' + l.replace(/"/,"\\\"") + '"';
+            s += '"' + l.replace(/"/g,"\\\"") + '"';
          }
          if (this.objects[i].type!="http://www.w3.org/1999/02/22-rdf-syntax-ns#PlainLiteral")
{
              s += "^^<"+this.objects[i].type+">";

http://git-wip-us.apache.org/repos/asf/clerezza/blob/98a83b69/platform/editor/src/main/resources/META-INF/resources/tools/editor/scripts/editor.js
----------------------------------------------------------------------
diff --git a/platform/editor/src/main/resources/META-INF/resources/tools/editor/scripts/editor.js
b/platform/editor/src/main/resources/META-INF/resources/tools/editor/scripts/editor.js
new file mode 100644
index 0000000..1f18595
--- /dev/null
+++ b/platform/editor/src/main/resources/META-INF/resources/tools/editor/scripts/editor.js
@@ -0,0 +1,216 @@
+function getGraphFromTurtle(callback) {
+    function getTurtleSections() {
+        var result = [];
+        var i = -1;
+        var scripts = document.getElementsByTagNameNS("http://www.w3.org/1999/xhtml", "script");
+        for (var i = 0; i < scripts.length; i++) {
+            if (scripts[i] && (scripts[i].getAttribute("type") === "text/turtle"))
{
+                result.push(scripts[i].text.toString());
+            }
+        }
+        return result;
+    }
+
+    function parseMultiple(turtleStrings, callback) {
+        var graph = rdf.createGraph();
+        var i = -1;
+        function processScript() {
+            i++;
+            if (i === turtleStrings.length) {
+                callback(graph);
+            }
+            var currentTurtle = turtleStrings[i];
+            //console.log('parsing ' + currentTurtle);
+            rdf.parseTurtle(currentTurtle, function (g) {
+                //console.log('parsed ' + g.toString());
+                graph.addAll(g);
+                processScript();
+            });
+        }
+        processScript();
+    }
+    var turtleSections = getTurtleSections();
+    parseMultiple(turtleSections, callback);
+
+}
+
+var discoBitsCollection = new Backbone.Collection();
+$(function () {
+
+    getGraphFromTurtle(function (origGraph) {
+        var InfoBit = Backbone.Model.extend({
+            defaults: {
+                "@type": 'disco:XHTMLInfoDiscoBit',
+                "disco:infoBit": 'Some content'
+            },
+            initialize: function () {
+                console.log('This model has been initialized.');
+                var m = this;
+                this.on('change', function (msg) {
+                    console.log('A value for this model has changed: ');
+                    console.log(m.changed);
+                    console.log(m.get("@id"));
+                    console.log('A value for this model has changed: ' + m.hasChanged(null));
+                    m.foo = "bar"
+                });
+            }
+        });
+        function saveAllModified() {
+            GreenRdfStore.getGraph(document, function (newGraph) {
+                //alert("orig: "+origGraph.toNT());
+                //alert("new: "+ newGraph.toNT());
+                rdf.serializeTurtle(origGraph, function (origTurtle) {
+                    rdf.serializeTurtle(newGraph, function (newTurtle) {
+                        $.post("/tools/editor/post", {assert: newTurtle, revoke: origTurtle,
rdfFormat: 'text/turtle'}, function (data) {
+                            alert("saved");
+                            origGraph = newGraph;
+                        }).fail(function (data) {
+                            errdata = data
+                            alert("error: " + data.statusText);
+                        });
+                    });
+                });
+
+            });
+
+        }
+        var InfoBitView = Backbone.View.extend({
+            initialize: function () {
+                _.bindAll(this, 'save')
+                this.model.bind('save', this.save);
+                var infoBit = $(this.el).find('[property="disco:infoBit"]').html()
+                console.log(this.model.hasChanged(null))
+                //this.model.set("disco:infoBit", infoBit)
+                console.log(this.model.hasChanged(null))
+                this.stickit();
+            },
+            events: {
+                'mousedown .editable': 'editableClick'
+            },
+            bindings: {
+                '[property="disco:infoBit"]': 'disco:infoBit'
+            },
+            editableClick: etch.editableInit,
+            save: function () {
+
+                // normally you would call model.save() here but this is a demo
+                // $(this.el).find('.editable').effect('highlight', {color: 'yellow'});
+                // $('.save-event').fadeIn('fast', function() {
+                //     setTimeout($(this).fadeOut('slow'), 10000);
+                // });
+                console.log("this modified: ");
+                console.log(this.model.get("@id"));
+                console.log(this.model.changed);
+                console.log("this is modified: " + this.model.hasChanged(null));
+                saveAllModified();
+            }
+
+        });
+        //$article = $('[property="disco:infoBit"]');
+        $('[property="disco:infoBit"]').addClass("editable")
+        $('[property="disco:infoBit"]').attr("data-button-class", "all")
+        //this ensure two way binding with stickit
+        $('[property="disco:infoBit"]').attr("contenteditable", "true")
+        $('[property="disco:infoBit"]').children().attr("contenteditable", "true")
+        $article = $('[typeof="disco:XHTMLInfoDiscoBit"]');
+        _.forEach($article, function (art) {
+            console.log(art);
+            var infoBit = $(art).find('[property="disco:infoBit"]').html()
+            var about = $(art).attr('about')
+            var model = new InfoBit({
+                "@id": about,
+                "disco:infoBit": infoBit
+            });
+            new InfoBitView({model: model, el: art, tagName: art.tagName});
+            discoBitsCollection.add(model)
+        });
+
+
+
+    });
+    /*var store = rdfstore.create();
+     
+     CallbackProcessor.prototype = new RDFaProcessor();
+     CallbackProcessor.prototype.constructor=RDFaProcessor;
+     function CallbackProcessor() {
+     RDFaProcessor.call(this);
+     }
+     
+     CallbackProcessor.prototype.addTriple = function(origin,subject,predicate,object) {
+     alert("New triple: "+subject+", predicate "+predicate+", object "+object.value+", "+object.language+",
"+object.type);
+     //RDFaProcessor.prototype.addTriple.call(this, origin, subject, predicate, object);
+     //graph.add(env.createTriple())
+     }*/
+    //var gp = new GraphRDFaProcessor();
+    /*function WrappedGraphProcessor() {
+     GraphRDFaProcessor.call(this)
+     }
+     WrappedGraphProcessor.prototype = new GraphRDFaProcessor();
+     WrappedGraphProcessor.prototype.addTriple= function(origin,subject,predicate,object)
{
+     alert("uff "+origin+","+subject+","+predicate+","+object);
+     if (origin.getAttribute("content")) {
+     object.value = origin.getAttribute("content");
+     }
+     GraphRDFaProcessor.prototype.addTriple.call(this, origin, subject, predicate, object);
+     }
+     var gp = new WrappedGraphProcessor();
+     //var gp = new CallbackProcessor();
+     gp.target.graph = new RDFaGraph();
+     gp.process(document);
+     var origTurtle = gp.target.graph.toString();
+     alert(origTurtle);*/
+
+
+    //});
+
+
+
+
+
+    //var view = new articleView({model: model, el: $article[0], tagName: $article[0].tagName});
+
+});
+
+Backbone.on('all', function (s) {
+    console.log('Handling all: ' + s);
+});
+
+
+
+/*document.addEventListener(
+ "rdfa.loaded",
+ function() {
+ _.forEach(document.getElementsByType("http://discobits.org/ontology#Entry"), function(e)
{
+ $(e).css('background-color', 'blue');
+ });
+ console.log('all colored');
+ //console.log('activating: '+RDFaProcessor);
+ CallbackProcessor.prototype = new RDFaProcessor();
+ CallbackProcessor.prototype.constructor=RDFaProcessor;
+ function CallbackProcessor() {
+ RDFaProcessor.call(this);
+ }
+ 
+ CallbackProcessor.prototype.newSubjectOrigin = function(origin,subject) {
+ console.log("New origin for "+subject);
+ }
+ 
+ CallbackProcessor.prototype.addTriple = function(origin,subject,predicate,object) {
+ console.log("New triple: "+subject+", predicate "+predicate+
+ ", object "+object.value+", "+object.language+", "+object.type);
+ }
+ console.log('activated: '+CallbackProcessor);
+ processor = new CallbackProcessor();
+ processor.finishedHandlers.push(
+ function(node) {
+ alert("Done!");
+ }
+ );
+ processor.process(document);
+ console.log('done');
+ },
+ false
+ );*/
+
+
+ 
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/clerezza/blob/98a83b69/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
index eef998f..5b9fe16 100644
--- 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
@@ -6,9 +6,9 @@ function GreenRdfStore() {
 }
 
 GreenRdfStore.getGraph = function(element, callback) {
-    var store = rdfstore.create();
-    store.graph(function(success,graph) {
-        var env = store.rdf;
+    var graph = rdf.createGraph();
+
+        var env = rdf;
         CallbackProcessor.prototype = new RDFaProcessor();
         CallbackProcessor.prototype.constructor=RDFaProcessor;
         function CallbackProcessor() {
@@ -60,13 +60,13 @@ GreenRdfStore.getGraph = function(element, callback) {
                     //according to the spec this attribute should be ignored for xmlLiterals,
we don't
                     var value = origin.getAttribute("content");
                 } else {
-                    if (object.value.length) {
+                    if (object.value instanceof NodeList) {
                         var value = serializeNodeList(object.value);
                     } else {
                         var value = object.value;
                     }
                 }
-                var objectRS = env.createLiteral(value.toString(), object.language, object.type);
+                var objectRS = env.createLiteral(value.toString(), object.language, env.createNamedNode(object.type));
             }
             graph.add(env.createTriple(subjectRS, predicateRS, objectRS));
         };
@@ -74,5 +74,4 @@ GreenRdfStore.getGraph = function(element, callback) {
                     //gp.target.graph = new RDFaGraph();
         gp.process(element);
         callback(graph)
-    });
 };
\ No newline at end of file


Mime
View raw message