[Zope-CVS] CVS: Packages/Moztop/moztop/content/lib - datasourcemanager.js:1.8 logmanager.js:1.3 sitesmanager.js:1.6

Stephan Richter srichter@cbu.edu
Sat, 22 Mar 2003 10:02:37 -0500


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

Modified Files:
	datasourcemanager.js logmanager.js sitesmanager.js 
Log Message:
Okay, here lands a major rewrite Paul and I were working on:

- Implemented DataSourceManager and refactored SitesManager.

- Datasources are now managed only from the tree directly, no private 
  copy is kept. 

- SitesManager makes now full use of the information found in rsd.xml.


Note: Not everything is working yet, so we need to keep digging:

- Gets wrong datasources for SitesManager

- Cannot add sites due to the problem above

- For some reason the content in Content and Packages is not displayed
  correctly. Some inspection of the RDF is necessary. On the other hand,
  fixing the above problems could fix this one too.


=== Packages/Moztop/moztop/content/lib/datasourcemanager.js 1.7 => 1.8 ===
--- Packages/Moztop/moztop/content/lib/datasourcemanager.js:1.7	Sat Mar 22 09:27:01 2003
+++ Packages/Moztop/moztop/content/lib/datasourcemanager.js	Sat Mar 22 10:02:06 2003
@@ -20,7 +20,7 @@
 
 ******************************************************************************/
 
-function DataSourceManager2() {
+function DataSourceManager() {
     /* The term "data source" has a very specific meaning in Mozilla referring
        to an RDF data container that can be used to display information using
        XUL. However, the functionality is very low-level and it is desirable
@@ -57,30 +57,29 @@
     this.descriptionprop = this.dcns + "description";
     this.urlprop = this.oscomrdfns + "url";
     this.subitemsprop = this.ncns + "subitems";
-
-    var moztopurl = getProfileDirURL() + 'moztop';
-
 }
 
 
-DataSourceManager2.prototype.addDataSource = function(rdfurl) {
+DataSourceManager.prototype.addDataSource = function(rdfurl) {
     /* Add a new datasource to the tree. */
 
     // Get the RDF from the specified URL and creata a RDFDataSource
     if (rdfurl == null) 
-	ds = new RDFDataSource();
+	var ds = new RDFDataSource();
     else
-	ds = new RDFDataSource(rdfurl);
+	// For some reason getDataSourceBlocked is not part of the API
+	// anymore, so that we need to use getDataSource
+	var ds = new RDFDataSource(rdfurl, function(request){});
 
     // Append RDFDataSource to the tree and rebuild
     tree = document.getElementById(this.treeId);
     tree.database.AddDataSource(ds.getRawDataSource());
     tree.builder.rebuild();
-    return true;
+    return ds;
 }
 
 
-DataSourceManager2.prototype.removeDataSource = function(rdfurl) {
+DataSourceManager.prototype.removeDataSource = function(rdfurl) {
     /* Delete a data source from the tree database. */
     
     // Get the tree as usual
@@ -92,8 +91,8 @@
     sources.getNext();
     // Find the datasource with the matching url and delete it
     while (sources.hasMoreElements()) {
-	ds = sources.getNext();
-	if (ds.uri == rdfurl) {
+	var ds = sources.getNext();
+	if (ds.URI == rdfurl) {
 	    // Remove the datasource and rebuild tree
 	    tree.database.RemoveDataSource(ds);
 	    tree.builder.rebuild();
@@ -104,13 +103,13 @@
 }
 
 
-DataSourceManager2.prototype.getDataSource = function(rdfurl) {
+DataSourceManager.prototype.getDataSource = function(rdfurl) {
     /* Get a datasource by the rdfurl. Memomory-based datasources do not 
        have an rdfurl, so just pass simply nothing. */
     var tree = document.getElementById(this.treeId);
     sources = tree.database.GetDataSources();
     // the first source is always Mozilla internal
-    sources.getNext();
+    source = sources.getNext();
     while (sources.hasMoreElements()) {
 	source = sources.getNext();
 	if (source.uri == rdfurl) {
@@ -119,11 +118,11 @@
 	    return ds;
 	}
     }
-    return false;
+    return null;
 }
 
 
-DataSourceManager2.prototype.saveDataSource = function(rdfurl) {
+DataSourceManager.prototype.saveDataSource = function(rdfurl) {
     /* Only for local datasources, should fail for remote  */
 
     // Check whether this is a local datasource; if not return false
@@ -131,7 +130,7 @@
     if (rdfurl.slice(0, profileDir.length) != profileDir)
 	return false;
 
-    // Get the dataaource.
+    // Get the datasource.
     ds = this.getDataSource(rdfurl);
     ds.save();
 
@@ -139,23 +138,26 @@
 }
 
 
-DataSourceManager2.prototype.dumpDataSources = function() {
+DataSourceManager.prototype.dumpDataSources = function() {
     /* Dump a serialized representation of all data sources into a meaningful
        medium, such as the LogManager */
 
     // XXX: Iterate through all datasources in the tree database and dump
     //      their serialized data.
     var tree = document.getElementById(logmanager.treeId);
-    var sources = tree.database.getDataSources();
+    var sources = tree.database.GetDataSources();
     while (sources.hasMoreElements()) {
-	ds = new RDFDataSource(sources.getNext());
-	dump(ds.serializeToString());
+	ds = new RDFDataSource();
+	ds.Init(sources.getNext());
+	logmanager.addMessage('DS: ' + ds.getRawDataSource().URI, 
+			      'Tree: ' + this.treeId + ', dumpDataSources', 
+			      ds.serializeToString());
     }
     return true;
 }
 
 
-DataSourceManager2.prototype.getSelectedResource = function() {
+DataSourceManager.prototype.getSelectedResource = function() {
     /* Return the resource that is currently selected in the tree. */
 
     // get index of tree
@@ -185,7 +187,7 @@
 }
 
 
-DataSourceManager2.prototype.openSelectedResource = function() {
+DataSourceManager.prototype.openSelectedResource = function() {
     /* This function "opens" the selected Tree resource.
 
        Note: This should be overridden by the implmenting class. 
@@ -193,268 +195,3 @@
     
     return true;
 }
-
-
-function SitesManager2() {
-
-    // Overridden DataSource Manager variables
-    this.treeid = 'navigation-tree';
-
-    // Sites-specific RDF properties
-    this.resourcetypeprop = this.oscomrdfns + "resourcetypes";
-    this.contentsurlprop = this.oscomrdfns + "contentsurl";
-    this.sitetypeprop = this.oscomrdfns + "sitetype";
-    this.styleidprop = this.oscomrdfns + "styleid";
-
-    // XXX: I do not know whether this should be here.
-    var tree = document.getElementById(this.elementid);
-    tree.builder.rebuild();
-
-}
-
-// SitesManager2 subclasses from DataSourceManager
-SitesManager2.prototype = new DataSourceManager2();
-SitesManager2.prototype.constructor = SitesManager2;
-SitesManager2.superclass = DataSourceManager2;
-
-
-SitesManager2.prototype.initializeProfileDir = function() {
-    /* If this is a first-time install, setup a directory in the 
-       Mozilla profile directory with the right RDF files, etc. */
-
-    // XXX: If non-existent, create moztop sub-directory
-
-    // XXX: Move initial local RDF files into directory
-    return true;
-}
-
-
-SitesManager2.prototype.initializeSites = function() {
-    /* Called during startup to find needed sites, fetch RDF, and build
-     tree */
-    tree = document.getElementById(this.treeid);
-    // XXX: Iterate over all sites found in sites.rdf
-    tree.builder.rebuild();
-    return true;
-}
-
-
-SitesManager2.prototype.addSite = function(title, rsdurl, rsddom) {
-    /* Create a new site from the information in the DOM passed in  */
-
-    // XXX: Add site to sites.rdf
-
-    // XXX: Get the resource types and content RDF sources URL
-
-    // XXX: Append types and content RDFDataSources to tree.
-
-    return true;
-}
-
-
-SitesManager2.prototype.removeSite = function(rsdurl) {
-    /* Remove a site from the RDF data source. 
-
-       Note: No remote action has to be taken.*/
-
-    return true;
-}
-
-
-
-
-
-/*  ------------    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;
-}
-
-
-/* 
-
-Email with requirements
-
-Clearly we need to write down something and agree to it, before
-jumping into code or doing checkins.  Below is a statement of the
-problem and the beginning of a proposal to solve it.
-
-I haven't gone too far into writing an API yet, as we should agree on
-this part first.
-
---Paul
-
-
-Summary
-
-Moztop needs to manage the RDF datasources associated with each remote
-Zope site.  This proposal covers the responsibilities needed by this
-component and a proposed implementation.
-
-Problem
-
-The data in remote datasites is encoded in RDF and loaded as a
-datasource in Moztop.  To make working with this RDF easier, we use
-the RDFDataSource object from rdfds.js to provide an easier API.
-
-However, Moztop still needs a way grab an RDFDataSource from a list of
-all the datasources, as well as other operations.  Thus we need a
-component that manages all the datasources.
-
-Responsibilities
-
-  Adding a datasource
-
-    When the site developer adds a new Zope site to their Moztop, the
-    component needs to retrieve the RDF, update the sites database,
-    and update the tree.
-
-  Reloading a datasource
-
-    If the server data have been changed by someone other than the
-    current user, then the RDF is out of date.  In this case, Moztop
-    needs to reload the RDF data.  This will involve grabbing the
-    datasource, retrieving the RDF, reloading the data, and
-    reattaching the datasource to the tree.
-
-    Note that this responsibility also applies when Moztop is
-    restarted, thus making this responsibility a common and critical
-    one.
-
-  Removing a datasource
-
-    If a user deletes a site, the datasource manager needs to ensure
-    that the datasource is removed.  Also, when the Moztop is
-    restarted, there shouldn't be a connection to the server to
-    retrieve data that won't be displayed.
-
-  Attaching a datasource to the tree
-
-    This is a simple but common activity.  When a datasource is
-    created, and also (I believe) when data have changed, the tree
-    needs to be rebuilt.
-
-    This is a visually painful process, as the tree collapses.  It
-    would be interesting to find techniques to avoid this.
-
-  Detatching a datasource
-
-    There may be circumstances where a datasource is removed from the
-    tree and removed from memory, but not permanently.  For instance,
-    this might be as part of another sequence, such as reloading.
-
-  Grabbing the appropriate datasource to make a change
-
-    When the site developer makes a change to a resource, the RDF
-    model must be updated.  While read-only operations can be made on
-    the composite datasource, changes require grabbing the correct
-    site datasource.
-
-    Thus, this responsibility requires being given a resource, and
-    giving back the datasource that contains that resource.
-
-    There are other situations that require grabbing the correct
-    datasource.  For instance, when a site developer selects a site
-    and selects reload, the correct datasource for that site must be
-    used.
-
-  Saving a datasource
-
-    For datasources where the RDF comes from a Zope server, there
-    should be *no* circumstances under which the datasource should be
-    saved.  All changes should be sent to the server, which is the
-    authoritative copy of the content.  The datasource contents should
-    be considered volatile.
-
-    However, datasources such as the sites database are managed by
-    Moztop in the local profile directory.  These will need to be
-    flushed to disk as appropriate.
-
-  Dumping a datasource
-
-    When debugging, it is very important to see the contents of a
-    datasource.  This responsibility can be fulfilled in a number of
-    ways (using the dump command, logging something to the log
-    manager, creating a visual inspector, etc.)
-
-  Managing in-mem and remote datasources
-
-    The classic Mozilla technique for remote datasources is to create
-    a pair: a read-only datasource representing the remote content and
-    an in-memory datasource where all local changes are made.  With a
-    model like this, you never have to worry about losing changes when
-    refreshing the remote content.
-
-  Performing operations on all datasources
-
-    Some of these operations will apply not just to one datasource,
-    but to all datasources in the list.  For instance, dumping all
-    datasource contents for debugging purposes is a very common
-    activity.
-
-Scenarios
-
-  Site developer adds site
-
-  Site developer deletes site
-
-  Site developer reloads site contents
-
-  Site developer restarts Moztop
-
-  Site developer choses "Debug->Dump Datsources"
-
-Proposed Architecture
-
-  I propose an architecture where we create a JavaScript prototype
-  called DataSourceManager.  It will be located in its own JavaScript
-  module stored in a top-level "lib" directory.
-
-  An instance of this called "dsm" will be declared as a global in
-  moztop.js and initialized in initMoztop (which is called by
-  moztop.xul as the onload action).  The initialization happens after
-  the initialization of the global logging service, thus allowing dsm
-  to log messages during its initialization.
-
-  The dsm variable will be global to all scripts in the main window.
-  Like the log manager, it will need to be passed explicitly to
-  dialogs and wizards.
-
-  The central architectural idea for dsm is that you "lookup" a
-  datasource via a method, instead of directly accessing it via a
-  property or variable.  This allows dsm to use a datasource attached
-  to tree.database and return an instance of RDFDataSource.
-
-Proposed DataSourceManager API
-
-  constructor() -> return null
-
-    Does this do all the work to open the sites database, retrieve all
-    the remote RDF, create all the datsources, attach to tree, etc.?
-
-*/


=== Packages/Moztop/moztop/content/lib/logmanager.js 1.2 => 1.3 ===
--- Packages/Moztop/moztop/content/lib/logmanager.js:1.2	Fri Mar 21 15:27:24 2003
+++ Packages/Moztop/moztop/content/lib/logmanager.js	Sat Mar 22 10:02:06 2003
@@ -18,9 +18,9 @@
 ******************************************************************************/
 
 /* Now subclass, then add methods */
-LogManager.prototype = new DataSourceManager2();
+LogManager.prototype = new DataSourceManager();
 LogManager.prototype.constructor = LogManager;
-LogManager.superclass = DataSourceManager2;
+LogManager.superclass = DataSourceManager;
 
 function LogManager () {
 
@@ -32,9 +32,7 @@
        a popup text box. */
 
     // Initialization preocess
-    if( !(this instanceof LogManager) )
-	return new LogManager( );
-    DataSourceManager2.call(this);
+    DataSourceManager.call(this);
 
     // Initialize RDF data source
     this.treeId = "logmessages-tree";
@@ -121,7 +119,7 @@
 /* Initialize the data in the tree object. */
 function initLogManager() {
     // Remember that logmanager was defined globally, but not initialized.
-    logmanager = LogManager();
+    logmanager = new LogManager();
     logmanager.initialize();
 }
 


=== Packages/Moztop/moztop/content/lib/sitesmanager.js 1.5 => 1.6 ===
--- Packages/Moztop/moztop/content/lib/sitesmanager.js:1.5	Sat Mar 22 09:27:01 2003
+++ Packages/Moztop/moztop/content/lib/sitesmanager.js	Sat Mar 22 10:02:06 2003
@@ -1,5 +1,3 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-
 /*****************************************************************************
 *
 * Copyright (c) 2002, 2003 Zope Corporation and Contributors.
@@ -31,296 +29,153 @@
 
 ******************************************************************************/
 
-/* Some regular expressions to fix the case-sensitivity of Moz RDF */
-var fixer1 = /rdf:rdf/g;
-var fixer2 = /rdf:description/g;
-var fixer3 = /rdf:seq/g;
-
-function SitesManager () {
-    /* A prototype to manage the sites database and datasources */
-
-    // Grab appropriate Content Tree RDF datasource
-    this.sitesds = new RDFDataSource(this.profileurl + "/moztop.rdf",null);
-    
-    // Define Content Type RDF datasource
-    this.commontypesds = new RDFDataSource();
-    this.commontypesds.parseFromString(commontypes_data,
-				       "http://www.zope.org/rdf");
-
-    dump(this.commontypesds.serializeToString());
-
-    // DOM element id of the Navigation tree
-    this.elementid = 'navigationtree';
-    
-    // An array of all datasources that describe the content of a site.
-    this.sitedatasources = new Array();
-    
-    /* Attach these (potentially empty) datasources */
-    var tree = document.getElementById(this.elementid);
-    tree.database.AddDataSource(this.sitesds.getRawDataSource());
-    tree.database.AddDataSource(this.commontypesds.getRawDataSource());
-    tree.builder.rebuild();		
+function SitesManager() {
+
+    // Initialization
+    DataSourceManager.call(this);
+
+    // Overridden DataSource Manager variables
+    this.treeId = 'navigationtree';
+
+    // Sites-specific RDF properties
+    this.resourcetypeprop = this.oscomrdfns + "resourcetypes";
+    this.contentsurlprop = this.oscomrdfns + "contentsurl";
+    this.sitetypeprop = this.oscomrdfns + "sitetype";
+    this.styleidprop = this.oscomrdfns + "styleid";
+
+    // Local Sites RDF file
+    this.sitesurl = getProfileDirURL() + '/moztop_sites.rdf'; 
+    this.sitesurn = 'urn:moztop:sites'
+
 }
 
-/* Now subclass, then add methods */
+// SitesManager subclasses from DataSourceManager
 SitesManager.prototype = new DataSourceManager();
+SitesManager.prototype.constructor = SitesManager;
+SitesManager.superclass = DataSourceManager;
 
 
-/* Detect if this is an initial install.  If so, initialize. */
 SitesManager.prototype.initializeProfileDatabases = function() {
+    /* If this is a first-time install, setup a directory in the 
+       Mozilla profile directory with the right RDF files, etc. */
+
+    var tree = document.getElementById(this.treeId);
+    sitesds = new RDFDataSource(this.sitesurl);
 
     /* Are there databases in profile dir?  If so, log a message and return */
-    var allres = this.sitesds.getAllResources();
+    var allres = sitesds.getAllResources();
     if (allres.hasMoreElements()) {
 	logmanager.addMessage('Found existing moztop databases', 
 			      'navigation.js, initNavigation', 
-			      this.sitesds.serializeToString());
-	return;
+			      sitesds.serializeToString());
+	return true;
     }
 
     /* If we make it here, it means we need to create moztop databases */
-    var rootnode = this.sitesds.getNode("urn:moztop:sites");
-    var subitems = this.sitesds.getNode("urn:moztop:sites:subitems");
+    sitesds = this.addDataSource(this.sitesurl);
+    var rootnode = sitesds.getNode(this.sitesurn);
+    var subitems = sitesds.getNode(this.sitesurn+":subitems");
     subitems.makeSeq();
-    rootnode.addTarget(this.subitemsprop,subitems);
+    rootnode.addTarget(this.subitemsprop, subitems);
 
-    this.sitesds.save();
+    sitesds.save();
     logmanager.addMessage("Initialized moztop.rdf",
 			  "navigation.js, initNavigation",
-			  this.sitesds.serializeToString());
+			  sitesds.serializeToString());
 
-    return;
-}
+    return true;
 
-SitesManager.prototype.toggleNoSites = function() {
-    return;
+    // XXX: Move initial local RDF files into directory
 }
 
-SitesManager.prototype.connectSelectedSite = function() {
-    var selectedsite = this.getSelectedResource();
-
-    if (! selectedsite) {
-    	alert("Please select a site to connect to.");
-	return;
-    }
 
-    var siteurl = selectedsite.getTarget(this.urlprop).getValue();
+SitesManager.prototype.initializeSites = function() {
+    /* Called during startup to find needed sites, fetch RDF, and build
+     tree */
+    // Get the sites resource from the data source
+    sitesds = this.addDataSource(this.sitesurl);
+    var sites_node = sitesds.getNode(this.sitesurn).getTarget(
+	this.subitemsprop);
+    var sites = sites_node.getChildren();
 
-    /* If the site isn't already in the array, create a ds */
-    id = this.sitedatasources.length
-    var ds = this.sitedatasources[id];
-    if (! ds) {
-	var ds = new RDFDataSource();
-	this.sitedatasources[id] = ds;
+    while (sites.hasMoreElements()) {
+	site = sites.getNext();
+	this.openSite(site.getValue());
     }
-
-    this.retrieveSiteContents(siteurl, ds);
-
-    return;
+    return true;
 }
 
 
-SitesManager.prototype.retrieveSiteContents = function(siteurl, ds) {
-    /* Given a URL, retrieve the RDF and add it to the passed-in datasource */
+SitesManager.prototype.openSite = function(rsdurl) {
+    /* Open a site by grabbing its contents and types. */
 
-    function handleError() {
-	dump("\n in handleError");
-	if (p.readyState == 2) {
-	    if (p.status) {
-		if (p.status== "401") {
-		    alert("Invalid URL");
-		    return;
-		}
-	    }
-	}
-    }
+    // Allowing the Sites Manager namespace to be present in openThisSite()
+    sm = this;
 
-    function serializeResponse(e) {
-	/* Local anonymous function for handling the async data */
-	if (p.statusText) {
-	    
-	    /* If p.sitesds is empty, we'll have to attach and rebuild */
-	    var needsReload = false;
-	    if (! p.sitesds.getAllResources()) {
-		var needsReload = false;
-	    }
+    function openThisSite(error) {
+	if (request.statusText) {
+	    var response = request.responseXML;
 	    
-	    p.sitesds.refresh(true);
+	    // Retrieve site content URL from response (XML)
+	    var holder = response.getElementsByTagNameNS(
+		sm.oscomrdfns, "contentsurl")[0];
+	    var contenturl = holder.firstChild.nodeValue;
 	    
-	    var newrdf = p.responseText;
-	    var newrdf = newrdf.replace(fixer1,"rdf:RDF");
-	    var newrdf = newrdf.replace(fixer2,"rdf:Description");
-	    var newrdf = newrdf.replace(fixer3,"rdf:Seq");
-	    dump("\ngoober is " + newrdf);
+	    // Retrieve site resource types URL from response (XML)
+	    var holder = response.getElementsByTagNameNS(
+		sm.oscomrdfns, "resourcetypesurl")[0];
+	    var typesurl = holder.firstChild.nodeValue;
 	    
-	    p.sitesds.parseFromString(newrdf,siteurl);
-	    logmanager.addMessage("Retrieved remote contents.rdf",
-				  "navigation.js, retrieveSiteContents",
-				  p.sitesds.serializeToString());
+	    // Get the tree
+	    var tree = document.getElementById(sm.treeId);
 	    
-	    /* XXX: don't rebuild tree if you don't have to */
-	    var tree = document.getElementById("navigationtree");
-	    tree.database.AddDataSource(p.sitesds.getRawDataSource());
-	    tree.builder.rebuild();
+	    // Append types and content RDFDataSources to tree.
+	    sm.addDataSource(typesurl);
+	    sm.addDataSource(contenturl);
+	    sm.dumpDataSources();
 	}
-    }
-	
-    var p = new XMLHttpRequest();
-    p.sitesds = ds;
-    // p.onreadystatechange = handleError;
-    p.onload = serializeResponse;
-    p.open("GET", siteurl + "/contents.rdf", false);
-    p.send(null);
-}
-
-
-SitesManager.prototype.addSite = function(site_name, siteurn, contentsurl, 
-					  site_username, site_password) {
-
-    /* The realm is used in URNs while the name is for the display */
-    var sc=this.sitesds.getNode("urn:moztop:sites")
-               .getTarget(this.subitemsprop);
-    var newsite=this.sitesds.getNode(siteurn);
-    var siteres = this.sitesds.getNode("urn:moztop:resourcetypes:site");
-    sc.addChild(newsite);
-
-
-    // Now fill in the data for the new site
-    newsite.addTarget(this.titleprop, site_name);
-    newsite.addTarget(this.urlprop, contentsurl);
-    newsite.addTarget(this.usernameprop, site_username);
-    newsite.addTarget(this.passwordprop, site_password);
-    newsite.addTarget(this.resourcetypeprop, siteres);
-
-    // Prepare the area for pseudo-folders (Configurations, Content, etc.)
+    };
 
-    var subitemsurn = siteurn + ":subitems";
-    var subitems = this.sitesds.getNode(subitemsurn);
-    subitems.makeSeq();
-    newsite.addTarget(this.subitemsprop,subitems);
-
-
-    /* Finally, create a site datasource and load the contents for this site */
-    id = this.sitedatasources.length
-    var ds = this.sitedatasources[id];
-    if (! ds) {
-	var ds = new RDFDataSource();
-	this.sitedatasources[id] = ds;
-    }
-
-    dump("about to retrieve " + contentsurl);
-    this.retrieveSiteContents(contentsurl, ds);
-
-    this.sitesds.save();
-    return;
+    // Trying to get a discovery response from the server
+    var request = new XMLHttpRequest();
+    request.onload = openThisSite;
+    request.open("GET", rsdurl, false);
+    request.send(null);
 }
 
 
-SitesManager.prototype.getSelectedResource = function() {
-    /* Overwriting default implementation, since we need to look into the
-       sitedatasources as well. */
-
-    // get index of tree
-    var tree = document.getElementById(this.elementid);
-    var index = tree.view.selection.currentIndex;
-    
-    // get the selected resource
-    if (index == -1) return false;
-    var res = tree.view.getItemAtIndex(index).resource;
-    
-    // Try to find the node in the standard ds
-    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++) {
- 	node = this.sitedatasources[i].getNode(res.Value);
- 	if (node.propertyExists(this.titleprop)) 
- 	    rdf = node;
-    }    
-    return rdf;
-}
-
+SitesManager.prototype.addSite = function(title, rsdurl) {
+    /* Create a new site from the information in the DOM passed in  */
 
-SitesManager.prototype.openSelectedResource = function() {
-    /* Opens the tab views for the selected resource */
+    // Get the sites resource from the data source
+    sitesds = this.getDataSource(this.sitesurl);
+    var sites = sitesds.getNode(this.sitesurn).getTarget(this.subitemsprop);
 
-    var rdf = this.getSelectedResource();
-
-    // Grab the selected resource and its title
-    var resourcetitle = rdf.getTarget(this.titleprop).getValue();
-    
-    // Find viewer container
-    var outter = document.getElementById("active-contents-tabpanels");
-
-    // Do not open resource if already opened.
-    for (var i = 0; i < outter.childNodes.length; i++) {
-	if (outter.childNodes[i].getAttribute('urn') == rdf.getValue())
-	    return;
-    }
-
-    // Make an appropriate log entry
-    logmanager.addMessage("Opening " + resourcetitle);
-
-    // Retrieving resource type
-    typeURN = rdf.getTarget(this.resourcetypeprop).getValue();
-    type = this.commontypesds.getNode(typeURN);
-    // XXX: The type registry should really have an attribute for this.
-    typeViewerName = type.getTarget(
-	"http://www.zope.org/rdf#styleid").getValue() + "viewer";
-
-    // Creating resource viewer
-    var viewer = document.createElement(typeViewerName);
-    // Setting initialization attributes
-    viewer.id = typeViewerName + "-" + new Date().getTime();
-    viewer.setAttribute("urn", rdf.getValue());
-    viewer.setAttribute("resourcetitle", resourcetitle);
-    
-    // Add new viewer to opened resources tabs
-    outter.appendChild(viewer);
-}
+    // Create a new site and add it to the sites resource
+    var newsite = sitesds.getNode(rsdurl);
+    newsite.addTarget(this.titleprop, title);
+    sites.addChild(newsite);
 
+    // Save the changes
+    this.sitesds.save();
 
-SitesManager.prototype.addResource = function(type, name) {
-    /* Add a resource to the selected container object. */
-    return;
+    // Open the site
+    this.connectSite(rsdurl)
+    return true;
 }
 
-SitesManager.prototype.deleteResource = function() {
-    /* Delete a resource from the server and the RDF graph. */
-    
-    var urn = this.getSelectedResource();
-    
-    if (! urn) {
-    	alert("Please select a resource to delete.");
-	return;
-    }
-    
-    var urn = urn.getValue();
-    var selectedsite = this.sitesds.getNode(urn);
-    var resourcetype = selectedsite.getTarget(
-	this.resourcetypeprop).getValue();
-
-    if (resourcetype != "urn:moztop:resourcetypes:site") {
-	alert("You cannot delete a " + resourcetype);
-	return;
-    }
-
-    /* XXX: Delete object from server */
-    
+SitesManager.prototype.removeSite = function(rsdurl) {
+    /* Remove a site from the RDF data source. 
 
+       Note: No remote action has to be taken.*/
 
-    /* Only delete if you get a valid response back from the server */
-    /* XXX: remove from array */
-    this.sitesds.deleteRecursive(urn);
-    this.sitesds.save();
-
-    return;
+    return true;
 }
 
-
 /* Initialize the Sites Manager */
 function initSitesManager() {
     sitesmanager = new SitesManager();
     sitesmanager.initializeProfileDatabases();
+    sitesmanager.initializeSites();
     return;
 }