[Zope-CVS] CVS: Packages/Moztop/moztop/content/lib - datasourcemanager.js:1.4

Stephan Richter srichter@cbu.edu
Fri, 21 Mar 2003 08:58:21 -0500


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

Modified Files:
	datasourcemanager.js 
Log Message:
This file is not used yet, so there is nothing we can break. Here is my 
progress so far.


=== Packages/Moztop/moztop/content/lib/datasourcemanager.js 1.3 => 1.4 ===
--- Packages/Moztop/moztop/content/lib/datasourcemanager.js:1.3	Thu Mar 20 14:30:50 2003
+++ Packages/Moztop/moztop/content/lib/datasourcemanager.js	Fri Mar 21 08:58:20 2003
@@ -20,23 +20,43 @@
 ******************************************************************************/
 
 function DataSourceManager() {
-    /* A prototype to manage the sites database and datasources
+    /* 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
+       to create a higher-level prototype when dealing data sources.
+
+       In the case of Moztop we noticed that we often want our data sources
+       information to be displayed in a tree. We then want to select an item
+       and perform an action on it. Therefore it became desirable to write a
+       prototype that tightly binds a tree with a set of data sources. The
+       reason we are supporting multiple data sources per tree is that the
+       information is often coming from many different locations so that
+       multiple data sources become necessary.
+
+       Some common objects that subclass DataSourceManager include
+       SitesManager (responsible for the navigation tree), LogManager and
+       TasksManager.
+
     
-       The constructor is responsible for ....  */
+       This constructor defines some commonly used property URNs and other
+       handy variables.
+    */
 
+
+    // Properties that must be overridden by the implmenting class
+    this.treeid = null;
+
+    // Common RDF namespaces
     this.dcns = "http://www.purl.org/dc/1.1#";
     this.oscomrdfns = "http://www.oscom.org/rdf#";
     this.ncns ="http://home.netscape.com/NC-rdf#";
     
     this.titleprop = this.dcns + "title";
     this.descriptionprop = this.dcns + "description";
-    this.resourcetypeprop = this.oscomrdfns + "resourcetypes";
     this.urlprop = this.oscomrdfns + "url";
-    this.contentsurlprop = this.oscomrdfns + "contentsurl";
-    this.sitetypeprop = this.oscomrdfns + "sitetype";
-    this.styleidprop = this.oscomrdfns + "styleid";
     this.subitemsprop = this.ncns + "subitems";
-    this.elementid = 'navigation-tree';
+
+    // XXX: So we really need this?
     this.sourceurlprop = this.oscomrdfns + "sourceurl";
     this.saveurlprop = this.oscomrdfns + "saveurl";  
     this.previewurlprop = this.oscomrdfns + "previewurl"; 
@@ -44,21 +64,10 @@
     var moztopurl = getProfileDirURL() + 'moztop';
 
     // Create some default datasources
+    // XXX: Do we still need this?
     this.datasources = new Array();
     
-    /* These next lines will go away after switching to the array */
-    this.sitesds = new RDFDataSource(twingleurl + "/sites.rdf",null);
-    this.oscomtypesds = new RDFDataSource(twingleurl + "/oscomtypes.rdf",null);
-    this.localsiteds = new RDFDataSource(twingleurl + "/localsite.rdf",null);
-    
-    
-    /* Attach these (potentially empty) datasources */
-    var tree=document.getElementById(this.elementid);
-    tree.database.AddDataSource(this.sitesds.getRawDataSource());
-    tree.database.AddDataSource(this.oscomtypesds.getRawDataSource());
-    tree.database.AddDataSource(this.localsiteds.getRawDataSource());
-    tree.builder.rebuild();
-    
+    // debug message
     dump("\nfinished add datasources and rebuilding tree");
 }
 
@@ -66,27 +75,36 @@
 DataSourceManager.prototype.initializeProfileDir = function() {
     /* If this is a first-time install, setup a directory in the 
        Mozilla profile directory with the right RDF files, etc. */
-    return true;
-}
 
+    // XXX: Create moztop sub-directory
 
+    // XXX: Move initial locale RDF files into directory
+    return true;
+}
 
 
 DataSourceManager.prototype.initializeDataSources = function() {
     /* Called during startup to find needed datasources, fetch RDF, and build
      tree */
+    tree = document.getElementById(this.treeid);
+    for (name in this.datasources) {
+	tree.database.AddDataSource(this.datasources[name].getRawDataSource());
+    }
+    tree.builder.rebuild();
     return true;
 }
 
 
-DataSourceManager.prototype.addDataSource = function(title, rdfurl) {
-    /* Create a new   */
+DataSourceManager.prototype.addDataSource = function(rdfurl) {
+    /* Add a new datasource to the set. */
+    this.datasources[rdfurl] = new RDFDataSource(rdfurl);
     return true;
 }
 
 
-DataSourceManager.prototype.openDataSource = function (rdfurl)  {
+DataSourceManager.prototype.openDataSource = function(rdfurl)  {
     /* Used during Moztop launch  */
+    // XXX: What do we need to do here?
     return true;
 }
 
@@ -96,31 +114,12 @@
     return true;
 }
 
-
-DataSourceManager.prototype.addSite = 
-function (title, rsdurl, rsddom) 
-{
-    /* Create a new site from the information in the DOM passed in  */
-
-
-
-    return true;
-}
-
-
-DataSourceManager.prototype.removeSite = function (rsdurl) 
-{
-    /*   */
-    return true;
-}
-
-
-DataSourceManager.prototype.getDataSource = function (resourceurl) 
-{
+DataSourceManager.prototype.getDataSource = function(resourceurl) {
     /* Given a urn, find the datasource containing that resource.  For 
-     sites, the urn is the urn of the root node, whose value is the 
-    URL of the rdf file on the server.  For non-remote datasources, like  
-    the sites.rdf in the profile dir, the root node urn is concocted. */
+       sites, the urn is the urn of the root node, whose value is the 
+       URL of the rsd file on the server.  For non-remote datasources, like  
+       the sites.rdf in the profile dir, the root node urn is concocted.
+    */
     return true;
 }
 
@@ -182,95 +181,79 @@
 }
 
 
-DataSourceManager.prototype. = function () 
-{
-    /*   */
-    return true;
-}
 
+function SitesManager() {
 
-DataSourceManager.prototype. = function () 
-{
-    /*   */
-    return true;
-}
+    // Overridden DataSource Manager variables
+    this.elementid = '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";
 
-DataSourceManager.prototype. = function () 
-{
-    /*   */
-    return true;
-}
 
+    // XXX: I do not know whether this should be here.
+    var tree = document.getElementById(this.elementid);
+    tree.builder.rebuild();
 
-DataSourceManager.prototype. = function () 
-{
-    /*   */
-    return true;
 }
 
+// SitesManager subclasses from DataSourceManager
+SitesManager.prototype = new DataSourceManager();
 
-DataSourceManager.prototype. = function () 
-{
-    /*   */
-    return true;
-}
 
+SitesManager.prototype.addSite = function(title, rsdurl, rsddom) {
+    /* Create a new site from the information in the DOM passed in  */
 
-DataSourceManager.prototype. = function () 
-{
-    /*   */
-    return true;
-}
+    var sc = this.ds.getNode("urn:moztop:sites").getTarget(this.subitemsprop);
+    var newsite=this.ds.getNode(siteurn);
+    var siteres = this.ds.getNode("urn:moztop:resourcetypes:site");
+    sc.addChild(newsite);
 
 
-DataSourceManager.prototype. = function () 
-{
-    /*   */
-    return true;
-}
+    // 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.)
 
-DataSourceManager.prototype. = function () 
-{
-    /*   */
-    return true;
-}
+    var subitemsurn = siteurn + ":subitems";
+    var subitems = this.ds.getNode(subitemsurn);
+    subitems.makeSeq();
+    newsite.addTarget(this.subitemsprop,subitems);
 
 
-DataSourceManager.prototype. = function () 
-{
-    /*   */
-    return true;
-}
+    /* 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.ds.save();
 
-DataSourceManager.prototype. = function () 
-{
-    /*   */
     return true;
 }
 
 
-DataSourceManager.prototype. = function () 
-{
-    /*   */
-    return true;
-}
+SitesManager.prototype.removeSite = function(rsdurl) {
+    /* Remove a site from the RDF data source. 
 
+       Note: No remote action has to be taken.*/
 
-DataSourceManager.prototype. = function () 
-{
-    /*   */
     return true;
 }
 
 
-DataSourceManager.prototype. = function () 
-{
-    /*   */
-    return true;
-}