[Zope-CVS] CVS: Packages/Moztop/moztop/content/lib - ioutils.js:1.1 jsdav.js:1.1 rdfds.js:1.1 datasourcemanager.js:1.7 sitesmanager.js:1.5

Paul Everitt paul@zope.com
Sat, 22 Mar 2003 09:27:33 -0500


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

Modified Files:
	datasourcemanager.js sitesmanager.js 
Added Files:
	ioutils.js jsdav.js rdfds.js 
Log Message:
Added beginnings of an RDF browser, minor cleanups in data source managers

=== Added File Packages/Moztop/moztop/content/lib/ioutils.js ===
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */





/*  ------------    Utility functions below   ------------- */

function getProfileDirURL ()
{

  // First get the directory service and query interface it to
  // nsIProperties
  var dirService = Components.
      classes['@mozilla.org/file/directory_service;1'].
      getService(Components.interfaces.nsIProperties);

  // Next get the "ProfD" property of type nsIFile from the directory
  // service, FYI this constant is defined in
  // mozilla/xpcom/io/nsAppDirectoryServiceDefs.h

  const NS_APP_USER_PROFILE_50_DIR = "ProfD";
  profileDir = dirService.get(NS_APP_USER_PROFILE_50_DIR,
	Components.interfaces.nsIFile);

  // Now that we have it we can show it's path. See nsIFile for the
  // other things you that can be done with profileDir

	var io_service =
	Components.classes["@mozilla.org/network/io-service;1"].
	getService(Components.interfaces.nsIIOService);
   
  var url = io_service.newFileURI(profileDir)
     .QueryInterface(Components.interfaces.nsIFileURL);
   
  return url.spec;
}


=== Added File Packages/Moztop/moztop/content/lib/jsdav.js ===
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */

SitesManager.prototype.DELETE = function(puturl, putcontent) {
    /* Deleting a resource on the server */
    var req = new XMLHttpRequest();

    function myfunc(e) {
	if (req.responseXML) {

	    var serializer = new XMLSerializer();
	    var resp = req.responseXML;
	    var str = serializer.serializeToString(d);

	    dump("\nmade it in PUT\n" + str + "\n");
	}
    }

    req.onload = myfunc;
    req.open("DELETE", puturl);
    req.setRequestHeader("Content-type", "text/plain");
    req.setRequestHeader("Host", "localhost");
    req.send(putcontent);

    return;
}    


SitesManager.prototype.PUT = function () {
    var puturl = "http://localhost:9700/fooboy3";
    var putcontent = "";

    var p = new XMLHttpRequest();
    var typeheader = "X-Zope-Type-Name"

    function myfunc (e) {
	if (p.responseXML) {

	    var s = new XMLSerializer();
	    var d = p.responseXML;
	    var str = s.serializeToString(d);

	    dump("\nmade it in PUT\n" + str + "\n");
	}
    }

    var x = document.implementation.createDocument("", "test", null);
    x.documentElement.appendChild(document.createElement("Foo"));
    x.documentElement.appendChild(document.createElement("Bar"));
    x.documentElement.firstChild.appendChild(
	document.createTextNode("My Stuff\nYeah"));

    var s = new XMLSerializer();
    str = s.serializeToString(x);

    p.onload = myfunc;
    p.open("PUT",puturl);
    p.setRequestHeader("Content-type", "text/xml");
    p.setRequestHeader("Host","localhost");
    p.setRequestHeader(typeheader, "PageTemplate");
    p.send(x);

    return;
}    



=== Added File Packages/Moztop/moztop/content/lib/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/lib/datasourcemanager.js 1.6 => 1.7 ===
--- Packages/Moztop/moztop/content/lib/datasourcemanager.js:1.6	Fri Mar 21 15:27:24 2003
+++ Packages/Moztop/moztop/content/lib/datasourcemanager.js	Sat Mar 22 09:27:01 2003
@@ -1,3 +1,5 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+
 /*****************************************************************************
 *
 * Copyright (c) 2002, 2003 Zope Corporation and Contributors.


=== Packages/Moztop/moztop/content/lib/sitesmanager.js 1.4 => 1.5 ===
--- Packages/Moztop/moztop/content/lib/sitesmanager.js:1.4	Thu Mar 20 17:39:37 2003
+++ Packages/Moztop/moztop/content/lib/sitesmanager.js	Sat Mar 22 09:27:01 2003
@@ -39,13 +39,8 @@
 function SitesManager () {
     /* A prototype to manage the sites database and datasources */
 
-    // Initialization
-    if( !(this instanceof SitesManager) ) 
-	return new SitesManager( );
-    DataSourceManager.call(this);
-    
     // Grab appropriate Content Tree RDF datasource
-    this.ds = new RDFDataSource(this.profileurl + "/moztop.rdf",null);
+    this.sitesds = new RDFDataSource(this.profileurl + "/moztop.rdf",null);
     
     // Define Content Type RDF datasource
     this.commontypesds = new RDFDataSource();
@@ -62,7 +57,7 @@
     
     /* Attach these (potentially empty) datasources */
     var tree = document.getElementById(this.elementid);
-    tree.database.AddDataSource(this.ds.getRawDataSource());
+    tree.database.AddDataSource(this.sitesds.getRawDataSource());
     tree.database.AddDataSource(this.commontypesds.getRawDataSource());
     tree.builder.rebuild();		
 }
@@ -70,28 +65,29 @@
 /* Now subclass, then add methods */
 SitesManager.prototype = new DataSourceManager();
 
+
 /* Detect if this is an initial install.  If so, initialize. */
 SitesManager.prototype.initializeProfileDatabases = function() {
 
     /* Are there databases in profile dir?  If so, log a message and return */
-    var allres = this.ds.getAllResources();
+    var allres = this.sitesds.getAllResources();
     if (allres.hasMoreElements()) {
 	logmanager.addMessage('Found existing moztop databases', 
 			      'navigation.js, initNavigation', 
-			      this.ds.serializeToString());
+			      this.sitesds.serializeToString());
 	return;
     }
 
     /* If we make it here, it means we need to create moztop databases */
-    var rootnode = this.ds.getNode("urn:moztop:sites");
-    var subitems = this.ds.getNode("urn:moztop:sites:subitems");
+    var rootnode = this.sitesds.getNode("urn:moztop:sites");
+    var subitems = this.sitesds.getNode("urn:moztop:sites:subitems");
     subitems.makeSeq();
     rootnode.addTarget(this.subitemsprop,subitems);
 
-    this.ds.save();
+    this.sitesds.save();
     logmanager.addMessage("Initialized moztop.rdf",
 			  "navigation.js, initNavigation",
-			  this.ds.serializeToString());
+			  this.sitesds.serializeToString());
 
     return;
 }
@@ -143,13 +139,13 @@
 	/* Local anonymous function for handling the async data */
 	if (p.statusText) {
 	    
-	    /* If p.ds is empty, we'll have to attach and rebuild */
+	    /* If p.sitesds is empty, we'll have to attach and rebuild */
 	    var needsReload = false;
-	    if (! p.ds.getAllResources()) {
+	    if (! p.sitesds.getAllResources()) {
 		var needsReload = false;
 	    }
 	    
-	    p.ds.refresh(true);
+	    p.sitesds.refresh(true);
 	    
 	    var newrdf = p.responseText;
 	    var newrdf = newrdf.replace(fixer1,"rdf:RDF");
@@ -157,20 +153,20 @@
 	    var newrdf = newrdf.replace(fixer3,"rdf:Seq");
 	    dump("\ngoober is " + newrdf);
 	    
-	    p.ds.parseFromString(newrdf,siteurl);
+	    p.sitesds.parseFromString(newrdf,siteurl);
 	    logmanager.addMessage("Retrieved remote contents.rdf",
 				  "navigation.js, retrieveSiteContents",
-				  p.ds.serializeToString());
+				  p.sitesds.serializeToString());
 	    
 	    /* XXX: don't rebuild tree if you don't have to */
 	    var tree = document.getElementById("navigationtree");
-	    tree.database.AddDataSource(p.ds.getRawDataSource());
+	    tree.database.AddDataSource(p.sitesds.getRawDataSource());
 	    tree.builder.rebuild();
 	}
     }
 	
     var p = new XMLHttpRequest();
-    p.ds = ds;
+    p.sitesds = ds;
     // p.onreadystatechange = handleError;
     p.onload = serializeResponse;
     p.open("GET", siteurl + "/contents.rdf", false);
@@ -182,10 +178,10 @@
 					  site_username, site_password) {
 
     /* The realm is used in URNs while the name is for the display */
-    var sc=this.ds.getNode("urn:moztop:sites")
+    var sc=this.sitesds.getNode("urn:moztop:sites")
                .getTarget(this.subitemsprop);
-    var newsite=this.ds.getNode(siteurn);
-    var siteres = this.ds.getNode("urn:moztop:resourcetypes:site");
+    var newsite=this.sitesds.getNode(siteurn);
+    var siteres = this.sitesds.getNode("urn:moztop:resourcetypes:site");
     sc.addChild(newsite);
 
 
@@ -199,7 +195,7 @@
     // Prepare the area for pseudo-folders (Configurations, Content, etc.)
 
     var subitemsurn = siteurn + ":subitems";
-    var subitems = this.ds.getNode(subitemsurn);
+    var subitems = this.sitesds.getNode(subitemsurn);
     subitems.makeSeq();
     newsite.addTarget(this.subitemsprop,subitems);
 
@@ -215,7 +211,7 @@
     dump("about to retrieve " + contentsurl);
     this.retrieveSiteContents(contentsurl, ds);
 
-    this.ds.save();
+    this.sitesds.save();
     return;
 }
 
@@ -233,7 +229,7 @@
     var res = tree.view.getItemAtIndex(index).resource;
     
     // Try to find the node in the standard ds
-    var rdf = this.ds.getNode(res.Value);
+    var rdf = this.sitesds.getNode(res.Value);
     
     // See whether the node could be possibly in sitedatasources.
     for (var i = 0; i < this.sitedatasources.length; i++) {
@@ -300,7 +296,7 @@
     }
     
     var urn = urn.getValue();
-    var selectedsite = this.ds.getNode(urn);
+    var selectedsite = this.sitesds.getNode(urn);
     var resourcetype = selectedsite.getTarget(
 	this.resourcetypeprop).getValue();
 
@@ -315,78 +311,16 @@
 
     /* Only delete if you get a valid response back from the server */
     /* XXX: remove from array */
-    this.ds.deleteRecursive(urn);
-    this.ds.save();
+    this.sitesds.deleteRecursive(urn);
+    this.sitesds.save();
 
     return;
 }
 
 
-SitesManager.prototype.DELETE = function(puturl, putcontent) {
-    /* Deleting a resource on the server */
-    var req = new XMLHttpRequest();
-
-    function myfunc(e) {
-	if (req.responseXML) {
-
-	    var serializer = new XMLSerializer();
-	    var resp = req.responseXML;
-	    var str = serializer.serializeToString(d);
-
-	    dump("\nmade it in PUT\n" + str + "\n");
-	}
-    }
-
-    req.onload = myfunc;
-    req.open("DELETE", puturl);
-    req.setRequestHeader("Content-type", "text/plain");
-    req.setRequestHeader("Host", "localhost");
-    req.send(putcontent);
-
-    return;
-}    
-
-
-SitesManager.prototype.PUT = function () {
-    var puturl = "http://localhost:9700/fooboy3";
-    var putcontent = "";
-
-    var p = new XMLHttpRequest();
-    var typeheader = "X-Zope-Type-Name"
-
-    function myfunc (e) {
-	if (p.responseXML) {
-
-	    var s = new XMLSerializer();
-	    var d = p.responseXML;
-	    var str = s.serializeToString(d);
-
-	    dump("\nmade it in PUT\n" + str + "\n");
-	}
-    }
-
-    var x = document.implementation.createDocument("", "test", null);
-    x.documentElement.appendChild(document.createElement("Foo"));
-    x.documentElement.appendChild(document.createElement("Bar"));
-    x.documentElement.firstChild.appendChild(
-	document.createTextNode("My Stuff\nYeah"));
-
-    var s = new XMLSerializer();
-    str = s.serializeToString(x);
-
-    p.onload = myfunc;
-    p.open("PUT",puturl);
-    p.setRequestHeader("Content-type", "text/xml");
-    p.setRequestHeader("Host","localhost");
-    p.setRequestHeader(typeheader, "PageTemplate");
-    p.send(x);
-
-    return;
-}    
-
 /* Initialize the Sites Manager */
 function initSitesManager() {
-    sitesmanager = SitesManager();
+    sitesmanager = new SitesManager();
     sitesmanager.initializeProfileDatabases();
     return;
 }