clerezza-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject [2/7] 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:26 GMT
http://git-wip-us.apache.org/repos/asf/clerezza/blob/8d34e62b/platform.editor/src/main/scala/org/apache/clerezza/platform/editor/renderlets/DiscobitsContentEtch.scala
----------------------------------------------------------------------
diff --git a/platform.editor/src/main/scala/org/apache/clerezza/platform/editor/renderlets/DiscobitsContentEtch.scala
b/platform.editor/src/main/scala/org/apache/clerezza/platform/editor/renderlets/DiscobitsContentEtch.scala
index 302834d..36c5d15 100644
--- a/platform.editor/src/main/scala/org/apache/clerezza/platform/editor/renderlets/DiscobitsContentEtch.scala
+++ b/platform.editor/src/main/scala/org/apache/clerezza/platform/editor/renderlets/DiscobitsContentEtch.scala
@@ -23,103 +23,139 @@ abstract class DiscobitsContentEtch extends SRenderlet {
     new XmlResult(arguments) {
       override def content = {
         val initScript = """
-                       var discoBitsCollection = new Backbone.Collection();
+            var discoBitsCollection = new Backbone.Collection();
             $(function() {
-              
-                var gp = new GraphRDFaProcessor();
-                gp.target.graph = new RDFaGraph();
-                gp.process(document);
-                var origTurtle = gp.target.graph.toString();
-                //alert(origTurtle);
-                function saveAllModified() {
-                    /*var modifiedModels = discoBitsCollection.filter(function(model) {return
model.hasChanged()})
-                    var modified = new Backbone.Collection(modifiedModels);
-                    alert("could save: " +modifiedModels+" models "+ JSON.stringify(modified.toJSON()))
-                    var gp = new GraphRDFaProcessor();*/
-                    gp.target.graph = new RDFaGraph();
-                    gp.process(document);
-                    var newTurtle = gp.target.graph.toString()
-                    $.post( "/tools/editor/post", { assert: newTurtle, revoke: origTurtle,
rdfFormat: 'text/turtle' }, function( data ) {
-                      alert("saved");
-                      origTurtle = newTurtle;
-                    }) .fail(function( data) {
-                      errdata = data
-                      alert( "error: " + data.statusText);
-                    });
-                }
                 
-                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"
+                GreenRdfStore.getGraph(document, function(origGraph) {
+                    //now that we have the orig graph we no longer need the content atr
+                    $("span[property='disco:infoBit']").removeAttr("content");
+                    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());
+                            $.post( "/tools/editor/post", { assert: newGraph.toNT(), revoke:
origGraph.toNT(), rdfFormat: 'text/turtle' }, function( data ) {
+                                alert("saved");
+                                origTurtle = newTurtle;
+                              }) .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();
                     }
+                    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")
-                $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)
+                    //$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")
+                    $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);
             });
@@ -161,7 +197,7 @@ abstract class DiscobitsContentEtch extends SRenderlet {
               false
             );*/
             """
-        val html = <html xmlns:disco="http://discobits.org/ontology#"> 
+        val html = <html xmlns:disco="http://discobits.org/ontology#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">

           
             <head>
                 <link type="text/css" href="/style/style.css" rel="stylesheet" />
@@ -178,6 +214,8 @@ abstract class DiscobitsContentEtch extends SRenderlet {
             <script src="/tools/editor/scripts/backbone-min.js"></script>
             <script src="/tools/editor/scripts/etch.js"></script>
             <script src="/tools/editor/scripts/backbone.stickit.js"></script>
+            <script src="/tools/editor/scripts/rdfstore.js" type="text/javascript"></script>
+            <script src="/tools/editor/scripts/greenrdfstore.js"></script>
             <script>
               {Unparsed(initScript)}
             </script>

http://git-wip-us.apache.org/repos/asf/clerezza/blob/8d34e62b/platform.editor/src/main/scala/org/apache/clerezza/platform/editor/renderlets/HtmlInfoDicobitRDFaNaked.scala
----------------------------------------------------------------------
diff --git a/platform.editor/src/main/scala/org/apache/clerezza/platform/editor/renderlets/HtmlInfoDicobitRDFaNaked.scala
b/platform.editor/src/main/scala/org/apache/clerezza/platform/editor/renderlets/HtmlInfoDicobitRDFaNaked.scala
index 8a297d8..5e64b41 100644
--- a/platform.editor/src/main/scala/org/apache/clerezza/platform/editor/renderlets/HtmlInfoDicobitRDFaNaked.scala
+++ b/platform.editor/src/main/scala/org/apache/clerezza/platform/editor/renderlets/HtmlInfoDicobitRDFaNaked.scala
@@ -25,7 +25,7 @@ class HtmlInfoDicobitRDFaNaked extends SRenderlet {
     new XmlResult(arguments) {
       override def content = {
               <div typeof="disco:XHTMLInfoDiscoBit" about={res*}>
-                <span property="disco:infoBit"  datatype="rdf:XMLLiteral">{Unparsed(res/DISCOBITS.infoBit*)}</span>
+                <span property="disco:infoBit" content={(res/DISCOBITS.infoBit*).replace("\n","\\n")}
datatype="rdf:XMLLiteral">{Unparsed(res/DISCOBITS.infoBit*)}</span>
               </div>
       }
     }


Mime
View raw message