[Zope-CVS] CVS: Packages/Moztop/moztop/content/Inspector - rdfds.js:1.1 Sites.js:1.5 SitesOverlay.xul:1.3

Paul Everitt paul@zope.com
Tue, 14 Jan 2003 10:18:39 -0500


Update of /cvs-repository/Packages/Moztop/moztop/content/Inspector
In directory cvs.zope.org:/tmp/cvs-serv21023

Modified Files:
	Sites.js SitesOverlay.xul 
Added Files:
	rdfds.js 
Log Message:
Switched to rdfds, welcome to heaven.  This is far easier.

=== Added File Packages/Moztop/moztop/content/Inspector/rdfds.js === (660/760 lines abridged)
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
 * The contents of this file are subject to the Mozilla Public
 * License Version 1.1 (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.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS
 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
 * implied. See the License for the specific language governing
 * rights and limitations under the License.
 *
 * The Original Code is rdfds
 *
 * The Initial Developer of the Original Code is Neil Deakin
 * Portions created by Neil Deakin are Copyright (C) 2002 Neil Deakin.
 * All Rights Reserved.
 *
 * Contributor(s):
 */

/* This is a library for easier access to RDF datasources and resources.
 * It contains four objects, RDFDataSource, RDFNode, RDFLiteral. and
 * RDFEnumerator.
 *
 * An RDF DataSource is a graph of nodes and literals. The constructor
 * for RDFDataSource takes one argument, a URI of an RDF file to use.
 * If the URI exists, the contents of the RDF file are loaded. If it
 * does not exist, resources can be added to it and then written using
 * this save method. If the URL argument is null, a blank datasource
 * is created.
 *
 * This library is designed for convenience not for efficiency.
 *
 * The API is documented at:
 *   http://www.xulplanet.com/tutorials/xultu/rdfds/
 *
 * Example:
 *
 * var ds=new RDFDataSource("file:///main/mozilla/mimtest.rdf");
 * var node=ds.getNode("urn:xpimaker:packlist");
 * var child=ds.getNode("urn:xpimaker:packlist:appinfo");
 * child=node.addChild(child);
 * child.addTarget("http://www.xulplanet.com/rdf/xpimaker#appname","Find Files");
 * ds.save();
 *
 */

var RDFService = "@mozilla.org/rdf/rdf-service;1";
RDFService = Components.classes[RDFService].getService();
RDFService = RDFService.QueryInterface(Components.interfaces.nsIRDFService);

[-=- -=- -=- 660 lines omitted -=- -=- -=-]

}

RDFLiteral.prototype.getSources=
  function (prop)
{
  prop=this.makeres(prop);
  return new RDFEnumerator(
    this.datasource.GetSources(prop,this.source,true),this.datasource);
}

RDFLiteral.prototype.type="Literal";


function RDFEnumerator(enumeration,dsource)
{
  this.enumeration=enumeration;
  this.datasource=dsource;
}

RDFEnumerator.prototype.hasMoreElements=
  function ()
{
  return this.enumeration.hasMoreElements();
}

RDFEnumerator.prototype.getNext=
  function ()
{
  var res=null;
  var val=this.enumeration.getNext();

  if (val!=null){
    try {
      val=val.QueryInterface(Components.interfaces.nsIRDFResource);
      res=new RDFNode();
      res.Init(val,this.datasource);
    }
    catch (ex){
      try {
        val=val.QueryInterface(Components.interfaces.nsIRDFLiteral);
        res=new RDFLiteral();
        res.Init(val,this.datasource);
      }
      catch (ex2){
      }
    }
  }
  return res;
}



=== Packages/Moztop/moztop/content/Inspector/Sites.js 1.4 => 1.5 ===
--- Packages/Moztop/moztop/content/Inspector/Sites.js:1.4	Mon Jan 13 21:43:46 2003
+++ Packages/Moztop/moztop/content/Inspector/Sites.js	Tue Jan 14 10:18:37 2003
@@ -1,68 +1,101 @@
-var RDF =
-  Components
-  .classes["@mozilla.org/rdf/rdf-service;1"]
-  .getService(Components.interfaces.nsIRDFService);
-
-var sites_source =
-  Components
-  .classes["@mozilla.org/rdf/datasource;1?name=in-memory-datasource"]
-  .createInstance(Components.interfaces.nsIRDFDataSource);
-
-/* Initialize the Sites datasource */
-function initSites() {
-  var tree = document.getElementById("sites-tree");
-  tree.database.AddDataSource(sites_source);
-  tree.setAttribute("ref", "urn:sites:data");
-  addSite('test.com', '8081', 'srichter', 'bar');
-}
-
-function addSite(servername, serverport, username, password) {
-    var root = "urn:sites:" + servername+"_"+serverport
-
-    sites_source.Assert(RDF.GetResource(root),
-              RDF.GetResource("http://www.zope.org/rdf/site#servername"),
-              RDF.GetLiteral(servername),
-              true);
-
-    sites_source.Assert(RDF.GetResource(root),
-              RDF.GetResource("http://www.zope.org/rdf/site#serverport"),
-              RDF.GetLiteral(serverport),
-              true);
-
-    sites_source.Assert(RDF.GetResource(root),
-              RDF.GetResource("http://www.zope.org/rdf/site#username"),
-              RDF.GetLiteral(username),
-              true);
-    
-    sites_source.Assert(RDF.GetResource(root),
-              RDF.GetResource("http://www.zope.org/rdf/site#password"),
-              RDF.GetLiteral(password),
-              true);
-
-    sites_source.Assert(RDF.GetResource("urn:sites:data"),
-              RDF.GetResource("http://www.zope.org/rdf/site#child"),
-              RDF.GetLiteral(root),
-              true);
-}
-
-
-function deleteSelectedSite() {
-    var tree = document.getElementById("sites-tree");
-    alert(tree.builder);
-    var start = new Object();
-    var end = new Object();
-    var numRanges = tree.view.selection.getRangeCount();
-
-    for (var t=0; t<numRanges; t++){
-        tree.view.selection.getRangeAt(t,start,end);
-        for (var v = start.value; v <= end.value; v++){
-	    var builder = tree.builder.QueryInterface(
-                                  Components.interfaces.nsIXULTreeBuilder)
-            rdf = builder.getResourceAtIndex(v)
-            sites_source.Unassert(RDF.GetResource("urn:sites:data"),
-                        RDF.GetResource("http://www.zope.org/rdf/site#child"),
-                        RDF.GetResource(rdf.Value));
-        }
-    }
-}
-
+var RDF =
+  Components
+  .classes["@mozilla.org/rdf/rdf-service;1"]
+  .getService(Components.interfaces.nsIRDFService);
+
+var ds=null;
+	
+var sites_source =
+  Components
+  .classes["@mozilla.org/rdf/datasource;1?name=in-memory-datasource"]
+  .createInstance(Components.interfaces.nsIRDFDataSource);
+
+function initSites()
+{
+
+  /*
+   * This sample RDF is used by some of the examples. It is serialized into
+   * a new datasource.
+   */
+  var sample='<?xml version="1.0"?>' +
+             '<RDF:RDF xmlns:z="http://www.zope.org/rdf/site#"' +
+             '         xmlns:RDF="http://www.w3.org/1999/02/22-rdf-syntax-ns#">' +
+             '  <RDF:Seq about="urn:sites:data">' +
+             '    <RDF:li resource="urn:sites:data:mysite"/>' +
+             '  </RDF:Seq>' +   
+             '  <RDF:Description about="urn:sites:data:mysite" ' +
+             '                   z:servername="My Site" ' +
+             '                   z:serverport="9000" ' +
+             '                   z:username="Paul"/>' +
+             '</RDF:RDF>';
+
+  ds=new RDFDataSource();
+  ds.parseFromString(sample,"http://192.168.1.3:9080/");
+  var tree = document.getElementById("sites-tree");
+  tree.database.AddDataSource(ds.getRawDataSource());
+  tree.builder.rebuild();
+
+}
+
+
+function addSite (servername, serverport, username) {
+
+  var sites=ds.getNode("urn:sites:data");
+  var newsite=ds.getNode("urn:sites:data:" + servername);
+  sites.addChild(newsite);
+
+  newsite.addTarget("http://www.zope.org/rdf/site#servername",servername);
+  newsite.addTarget("http://www.zope.org/rdf/site#serverport",serverport);
+  newsite.addTarget("http://www.zope.org/rdf/site#username",username);
+	alert(ds.serializeToString());
+}
+
+function oldaddSite(servername, serverport, username, password) {
+    var root = "urn:sites:" + servername+"_"+serverport
+    sites_source.Assert(RDF.GetResource(root),
+              RDF.GetResource("http://www.zope.org/rdf/site#servername"),
+              RDF.GetLiteral(servername),
+              true);
+
+    sites_source.Assert(RDF.GetResource(root),
+              RDF.GetResource("http://www.zope.org/rdf/site#serverport"),
+              RDF.GetLiteral(serverport),
+              true);
+
+    sites_source.Assert(RDF.GetResource(root),
+              RDF.GetResource("http://www.zope.org/rdf/site#username"),
+              RDF.GetLiteral(username),
+              true);
+    
+    sites_source.Assert(RDF.GetResource(root),
+              RDF.GetResource("http://www.zope.org/rdf/site#password"),
+              RDF.GetLiteral(password),
+              true);
+
+    sites_source.Assert(RDF.GetResource("urn:sites:data"),
+              RDF.GetResource("http://www.zope.org/rdf/site#child"),
+              RDF.GetLiteral(root),
+              true);
+}
+
+
+function deleteSelectedSite() {
+    var tree = document.getElementById("sites-tree");
+    alert(tree.builder);
+    var start = new Object();
+    var end = new Object();
+    var numRanges = tree.view.selection.getRangeCount();
+
+    for (var t=0; t<numRanges; t++){
+        tree.view.selection.getRangeAt(t,start,end);
+        for (var v = start.value; v <= end.value; v++){
+	    var builder = tree.builder.QueryInterface(
+                                  Components.interfaces.nsIXULTreeBuilder)
+            rdf = builder.getResourceAtIndex(v)
+            sites_source.Unassert(RDF.GetResource("urn:sites:data"),
+                        RDF.GetResource("http://www.zope.org/rdf/site#child"),
+                        RDF.GetResource(rdf.Value));
+        }
+    }
+}
+


=== Packages/Moztop/moztop/content/Inspector/SitesOverlay.xul 1.2 => 1.3 ===
--- Packages/Moztop/moztop/content/Inspector/SitesOverlay.xul:1.2	Mon Jan 13 21:43:46 2003
+++ Packages/Moztop/moztop/content/Inspector/SitesOverlay.xul	Tue Jan 14 10:18:37 2003
@@ -4,17 +4,19 @@
          xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
 
 <script type="application/x-javascript" 
+        src="chrome://moztop/content/Inspector/rdfds.js"/>
+<script type="application/x-javascript" 
         src="chrome://moztop/content/Inspector/Sites.js"/>
 
 <tabpanel id="sites-panel">
 
-<button onclick="addSite('test5.com', '8081', 'test', 'test');" 
+<button onclick="addSite('test5.com', '8081', 'stephan');" 
         label="Add Site" />
 <button onclick="deleteSelectedSite();" label="Delete Site" />
 
 <tree id="sites-tree" flex="1" 
       datasources="rdf:null"
-      flags="dont-build-content"
+      flags="dont-build-content" ref="urn:sites:data"
       containment="http://www.zope.org/rdf/site#child">
   <treecols>
     <treecol id="servername" label="Server Name" primary="true" flex="10"/>