clerezza-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject [2/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:54 GMT
http://git-wip-us.apache.org/repos/asf/clerezza/blob/98a83b69/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 36c5d15..f83de2a 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
@@ -1,4 +1,4 @@
-package org.apache.clerezza.platform.editor
+package org.apache.clerezza.platform.editor.renderlets
 
 import org.apache.clerezza.rdf.core._
 import org.apache.clerezza.rdf.scala.utils.Preamble._
@@ -23,183 +23,12 @@ abstract class DiscobitsContentEtch extends SRenderlet {
     new XmlResult(arguments) {
       override def content = {
         val initScript = """
-            var discoBitsCollection = new Backbone.Collection();
-            $(function() {
-                
-                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();
-                        }
-
-                    });
-                    //$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);
-            });
-        
             
-        
-            /*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
-            );*/
             """
         val html = <html xmlns:disco="http://discobits.org/ontology#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">

           
             <head>
+                <meta charset="utf-8"/>
                 <link type="text/css" href="/style/style.css" rel="stylesheet" />
                 <link rel="stylesheet" href="/tools/editor/styles/etch.css" />
                 {for (part <- res/DISCOBITS.contains;  if ((part/DISCOBITS.pos*) == "0"))
yield
@@ -214,8 +43,9 @@ 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/rdf-ext.js" type="text/javascript"></script>
             <script src="/tools/editor/scripts/greenrdfstore.js"></script>
+            <script src="/tools/editor/scripts/editor.js" type="text/javascript"></script>
             <script>
               {Unparsed(initScript)}
             </script>

http://git-wip-us.apache.org/repos/asf/clerezza/blob/98a83b69/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 5e64b41..dc116af 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
@@ -1,32 +1,49 @@
-package org.apache.clerezza.platform.editor
-
+package org.apache.clerezza.platform.editor.renderlets
 
 import org.apache.clerezza.rdf.core._
 import org.apache.clerezza.rdf.scala.utils.Preamble._
+import java.io.ByteArrayOutputStream
 import javax.ws.rs.core.MediaType
+import org.apache.clerezza.commons.rdf.BlankNodeOrIRI
+import org.apache.clerezza.commons.rdf.Graph
+import org.apache.clerezza.commons.rdf.impl.utils.TripleImpl
+import org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph
 import org.apache.clerezza.platform.typerendering.TypeRenderlet
 import org.apache.clerezza.platform.typerendering.scala._
+import org.apache.clerezza.rdf.core.serializedform.Serializer
 import org.apache.clerezza.rdf.ontologies.DISCOBITS
+import org.apache.clerezza.rdf.ontologies.RDF
 import org.apache.felix.scr.annotations.Component;
-import org.apache.felix.scr.annotations.Service;import scala.xml.Unparsed
-
+import org.apache.felix.scr.annotations.Service;
+import org.apache.felix.scr.annotations.Reference;
+import scala.xml.NodeBuffer
+import scala.xml.Unparsed;
 
 @Component
 @Service(Array(classOf[TypeRenderlet]))
 class HtmlInfoDicobitRDFaNaked extends SRenderlet {
 
-  val getRdfType = DISCOBITS.XHTMLInfoDiscoBit 
-    
+  @Reference
+  var serializer: Serializer = null;
+
+  val getRdfType = DISCOBITS.XHTMLInfoDiscoBit
+
   override val getMediaType = MediaType.TEXT_HTML_TYPE
 
   override def getModePattern = "rdfa-naked"
 
   override def renderedPage(arguments: XmlResult.Arguments) = {
-    new XmlResult(arguments) {
-      override def content = {
-              <div typeof="disco:XHTMLInfoDiscoBit" about={res*}>
-                <span property="disco:infoBit" content={(res/DISCOBITS.infoBit*).replace("\n","\\n")}
datatype="rdf:XMLLiteral">{Unparsed(res/DISCOBITS.infoBit*)}</span>
-              </div>
+    new XmlResultWithTurtle(arguments, serializer) {
+
+      override def addTriples(shownGraph : Graph) {
+        shownGraph.add(new TripleImpl((res!).asInstanceOf[BlankNodeOrIRI], RDF.`type`, DISCOBITS.XHTMLInfoDiscoBit));
+        shownGraph.add(new TripleImpl((res!).asInstanceOf[BlankNodeOrIRI], DISCOBITS.infoBit,
res / DISCOBITS.infoBit!));
+      }
+      
+      override def specificContent = {
+        <div typeof="disco:XHTMLInfoDiscoBit" about={ res* }>
+          <span property="disco:infoBit" datatype="rdf:XMLLiteral">{ Unparsed(res /
DISCOBITS.infoBit*) }</span>
+        </div>
       }
     }
   }

http://git-wip-us.apache.org/repos/asf/clerezza/blob/98a83b69/platform/editor/src/main/scala/org/apache/clerezza/platform/editor/renderlets/OrderedContentRDFaNaked.scala
----------------------------------------------------------------------
diff --git a/platform/editor/src/main/scala/org/apache/clerezza/platform/editor/renderlets/OrderedContentRDFaNaked.scala
b/platform/editor/src/main/scala/org/apache/clerezza/platform/editor/renderlets/OrderedContentRDFaNaked.scala
index e8e00f5..fbbba2b 100644
--- a/platform/editor/src/main/scala/org/apache/clerezza/platform/editor/renderlets/OrderedContentRDFaNaked.scala
+++ b/platform/editor/src/main/scala/org/apache/clerezza/platform/editor/renderlets/OrderedContentRDFaNaked.scala
@@ -1,19 +1,29 @@
-package org.apache.clerezza.platform.editor
+package org.apache.clerezza.platform.editor.renderlets
 
 
 import org.apache.clerezza.rdf.core._
 import org.apache.clerezza.rdf.scala.utils.Preamble._
 import javax.ws.rs.core.MediaType
+import org.apache.clerezza.commons.rdf.BlankNode
+import org.apache.clerezza.commons.rdf.BlankNodeOrIRI
+import org.apache.clerezza.commons.rdf.Graph
+import org.apache.clerezza.commons.rdf.impl.utils.TripleImpl
 import org.apache.clerezza.platform.typerendering.TypeRenderlet
 import org.apache.clerezza.platform.typerendering.scala._
+import org.apache.clerezza.rdf.core.serializedform.Serializer
 import org.apache.clerezza.rdf.ontologies.DISCOBITS
+import org.apache.clerezza.rdf.ontologies.RDF
 import org.apache.felix.scr.annotations.Component;
 import org.apache.felix.scr.annotations.Service;
+import org.apache.felix.scr.annotations.Reference;
 
 @Component
 @Service(Array(classOf[TypeRenderlet]))
 class OrderedContentRDFaNaked extends SRenderlet {
 
+  @Reference
+  var serializer: Serializer = null;
+  
   val getRdfType = DISCOBITS.OrderedContent
     
   override val getMediaType = MediaType.TEXT_HTML_TYPE
@@ -21,8 +31,20 @@ class OrderedContentRDFaNaked extends SRenderlet {
   override def getModePattern = "rdfa-naked"
 
   override def renderedPage(arguments: XmlResult.Arguments) = {
-    new XmlResult(arguments) {
-      override def content = {
+    new XmlResultWithTurtle(arguments, serializer) {
+
+      override def addTriples(shownGraph : Graph) {
+        shownGraph.add(new TripleImpl((res!).asInstanceOf[BlankNodeOrIRI], RDF.`type`, DISCOBITS.OrderedContent));
+        for (part <- res/DISCOBITS.contains) {
+          val entry = new BlankNode
+          shownGraph.add(new TripleImpl((res!).asInstanceOf[BlankNodeOrIRI], DISCOBITS.contains,
entry));
+          shownGraph.add(new TripleImpl(entry, RDF.`type`, DISCOBITS.Entry));
+          shownGraph.add(new TripleImpl(entry, DISCOBITS.pos, part/DISCOBITS.pos!));
+          shownGraph.add(new TripleImpl(entry, DISCOBITS.holds, part/DISCOBITS.holds!));
+        }
+      }
+      
+      override def specificContent = {
               <div about={res*} typeof="disco:OrderedContent">
                 {for (part <- (res/DISCOBITS.contains).sortBy(part => (part/DISCOBITS.pos*).toInt))

                   yield <div property="disco:contains" typeof="disco:Entry">

http://git-wip-us.apache.org/repos/asf/clerezza/blob/98a83b69/platform/editor/src/main/scala/org/apache/clerezza/platform/editor/renderlets/TitledContentRDFaNaked.scala
----------------------------------------------------------------------
diff --git a/platform/editor/src/main/scala/org/apache/clerezza/platform/editor/renderlets/TitledContentRDFaNaked.scala
b/platform/editor/src/main/scala/org/apache/clerezza/platform/editor/renderlets/TitledContentRDFaNaked.scala
index 94e29fd..f817350 100644
--- a/platform/editor/src/main/scala/org/apache/clerezza/platform/editor/renderlets/TitledContentRDFaNaked.scala
+++ b/platform/editor/src/main/scala/org/apache/clerezza/platform/editor/renderlets/TitledContentRDFaNaked.scala
@@ -1,19 +1,29 @@
-package org.apache.clerezza.platform.editor
+package org.apache.clerezza.platform.editor.renderlets
 
 
 import org.apache.clerezza.rdf.core._
 import org.apache.clerezza.rdf.scala.utils.Preamble._
 import javax.ws.rs.core.MediaType
+import org.apache.clerezza.commons.rdf.BlankNode
+import org.apache.clerezza.commons.rdf.BlankNodeOrIRI
+import org.apache.clerezza.commons.rdf.Graph
+import org.apache.clerezza.commons.rdf.impl.utils.TripleImpl
 import org.apache.clerezza.platform.typerendering.TypeRenderlet
 import org.apache.clerezza.platform.typerendering.scala._
+import org.apache.clerezza.rdf.core.serializedform.Serializer
 import org.apache.clerezza.rdf.ontologies.DISCOBITS
+import org.apache.clerezza.rdf.ontologies.RDF
 import org.apache.felix.scr.annotations.Component;
 import org.apache.felix.scr.annotations.Service;
+import org.apache.felix.scr.annotations.Reference;
 
 @Component
 @Service(Array(classOf[TypeRenderlet]))
 class TitledContentRDFaNaked extends SRenderlet {
 
+  @Reference
+  var serializer: Serializer = null;
+  
   val getRdfType = DISCOBITS.TitledContent 
     
   override val getMediaType = MediaType.TEXT_HTML_TYPE
@@ -21,22 +31,33 @@ class TitledContentRDFaNaked extends SRenderlet {
   override def getModePattern = "rdfa-naked"
 
   override def renderedPage(arguments: XmlResult.Arguments) = {
-    new XmlResult(arguments) {
-      override def content = {
-              <div typeof="disco:TitledContent" about={res*}>
+    new XmlResultWithTurtle(arguments, serializer) {
+
+      override def addTriples(shownGraph : Graph) {
+        shownGraph.add(new TripleImpl((res!).asInstanceOf[BlankNodeOrIRI], RDF.`type`, DISCOBITS.TitledContent));
+        for (part <- res/DISCOBITS.contains) {
+          val entry = new BlankNode
+          shownGraph.add(new TripleImpl((res!).asInstanceOf[BlankNodeOrIRI], DISCOBITS.contains,
entry));
+          shownGraph.add(new TripleImpl(entry, RDF.`type`, DISCOBITS.Entry));
+          shownGraph.add(new TripleImpl(entry, DISCOBITS.pos, part/DISCOBITS.pos!));
+          shownGraph.add(new TripleImpl(entry, DISCOBITS.holds, part/DISCOBITS.holds!));
+        }
+      }
+      
+      override def specificContent = {
+            <div typeof="disco:TitledContent" about={res*}>
               {for (part <- res/DISCOBITS.contains;  if ((part/DISCOBITS.pos*) == "0"))

                 yield <span property="disco:contains" typeof="disco:Entry">
-                   <span property="disco:pos" style="display: none">0</span>
-                   <h1 resource={part/DISCOBITS.holds*} property="disco:holds">{render(part/DISCOBITS.holds,
"rdfa-naked")}</h1>
-                  </span>}
-              {for (part <- res/DISCOBITS.contains;  if ((part/DISCOBITS.pos*) == "1"))

-                yield <div property="disco:contains" typeof="disco:Entry">
-                       <div property="disco:pos" style="display: none">{part/DISCOBITS.pos*}</div>
-                       <div property="disco:holds" resource={part/DISCOBITS.holds*}>{render(part/DISCOBITS.holds,
"rdfa-naked")}</div>
-                    </div>}
-              </div>
+                    <span property="disco:pos" style="display: none">0</span>
+                    <h1 resource={part/DISCOBITS.holds*} property="disco:holds">{render(part/DISCOBITS.holds,
"rdfa-naked")}</h1>
+                      </span>}
+               {for (part <- res/DISCOBITS.contains;  if ((part/DISCOBITS.pos*) == "1"))

+                 yield <div property="disco:contains" typeof="disco:Entry">
+                      <div property="disco:pos" style="display: none">{part/DISCOBITS.pos*}</div>
+                      <div property="disco:holds" resource={part/DISCOBITS.holds*}>{render(part/DISCOBITS.holds,
"rdfa-naked")}</div>
+                       </div>}
+                </div>
+                }
       }
-    }
   }
-
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/clerezza/blob/98a83b69/platform/editor/src/main/scala/org/apache/clerezza/platform/editor/renderlets/XmlResultWithTurtle.scala
----------------------------------------------------------------------
diff --git a/platform/editor/src/main/scala/org/apache/clerezza/platform/editor/renderlets/XmlResultWithTurtle.scala
b/platform/editor/src/main/scala/org/apache/clerezza/platform/editor/renderlets/XmlResultWithTurtle.scala
new file mode 100644
index 0000000..fcdeba9
--- /dev/null
+++ b/platform/editor/src/main/scala/org/apache/clerezza/platform/editor/renderlets/XmlResultWithTurtle.scala
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2015 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.clerezza.platform.editor.renderlets
+
+import java.io.ByteArrayOutputStream
+import org.apache.clerezza.commons.rdf.Graph
+import org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph
+import org.apache.clerezza.platform.typerendering.scala.XmlResult
+import org.apache.clerezza.rdf.core.serializedform.Serializer
+import org.apache.clerezza.rdf.core.serializedform.SupportedFormat
+import scala.xml.NodeBuffer
+import scala.xml.Unparsed
+
+abstract class XmlResultWithTurtle(arguments: XmlResult.Arguments, serializer: Serializer)
extends XmlResult(arguments) {
+  override def content = {
+    val shownGraph = new SimpleGraph
+    addTriples(shownGraph)
+    val serializedOut = new ByteArrayOutputStream;
+    serializer.serialize(serializedOut, shownGraph, SupportedFormat.TURTLE)
+    val turtle = new String(serializedOut.toByteArray, "UTF-8");
+    new NodeBuffer() &+ <script type="text/turtle">
+                          { Unparsed(turtle) }
+                        </script> &+ specificContent
+
+  }
+  def addTriples(shownGraph: Graph): Unit;
+
+  def specificContent: AnyRef;
+}


Mime
View raw message