[Zope-CVS] CVS: Packages/Moztop/moztop/content/lib - datasourcemanager.js:1.6 logmanager.js:1.2
Stephan Richter
srichter@cbu.edu
Fri, 21 Mar 2003 15:27:24 -0500
Update of /cvs-repository/Packages/Moztop/moztop/content/lib
In directory cvs.zope.org:/tmp/cvs-serv12663/moztop/content/lib
Modified Files:
datasourcemanager.js logmanager.js
Log Message:
Yeah, got the new DataSourceManager working with the LogManager. As far
as I can tell LogManager is fully functional again.
A couple things I have done:
- After reviewing the API, I agree with Paul that we do not need
add|update|removeResource in DataSourceManager.
- Implemented addDataSource(rdfurl). If no rdfurl is passed, an in-memory
datasource will be created.
- Implemented removeDataSource(rdfurl). If no rdfurl is passed, the first
found in-memory datasource will be deleted. (We might want to change
that behavior.)
- Implemented getDataSource(rdfurl). If no rdfurl was passed, it returns
the first in-memory data source.
- saveDataSource(rdfurl) should work, but was not tested.
- getSelectedResource actually returns a rdfds RDFNode object.
- Dumping the data sources using dumpDataSources() shoudl work.
- openSelectedResource() is a NotImplemented function that needs to be
filled by DataSourceManager children.
Note: In every tree.database CompositeRDFDataSource the first element is
neglected, since it is always a Mozilla-internal data source.
PLEASE LET ME KNOW IF I MISS DOCUMENTATION SOMEWHERE OR YOU DISAGREE WITH
SOMETHING/ANYTHING!
=== Packages/Moztop/moztop/content/lib/datasourcemanager.js 1.5 => 1.6 ===
--- Packages/Moztop/moztop/content/lib/datasourcemanager.js:1.5 Fri Mar 21 10:23:10 2003
+++ Packages/Moztop/moztop/content/lib/datasourcemanager.js Fri Mar 21 15:27:24 2003
@@ -58,88 +58,141 @@
var moztopurl = getProfileDirURL() + 'moztop';
- // debug message
- dump("\nfinished add datasources and rebuilding tree");
}
-DataSourceManager.prototype.addDataSource = function(rdfurl) {
+DataSourceManager2.prototype.addDataSource = function(rdfurl) {
/* Add a new datasource to the tree. */
- // XXX: Get the RDF from the specified URL and creata a RDFDataSource
-
- // XXX: Append RDFDataSource to the tree and rebuild
-
+ // Get the RDF from the specified URL and creata a RDFDataSource
+ if (rdfurl == null)
+ ds = new RDFDataSource();
+ else
+ ds = new RDFDataSource(rdfurl);
+
+ // Append RDFDataSource to the tree and rebuild
+ tree = document.getElementById(this.treeId);
+ tree.database.AddDataSource(ds.getRawDataSource());
+ tree.builder.rebuild();
return true;
}
-DataSourceManager.prototype.removeDataSource = function(rdfurl) {
+DataSourceManager2.prototype.removeDataSource = function(rdfurl) {
/* Delete a data source from the tree database. */
- return true;
+
+ // Get the tree as usual
+ var tree = document.getElementById(this.treeId);
+
+ // Get all the sources
+ sources = tree.database.GetDataSources();
+ // the first source is always Mozilla internal
+ sources.getNext();
+ // Find the datasource with the matching url and delete it
+ while (sources.hasMoreElements()) {
+ ds = sources.getNext();
+ if (ds.uri == rdfurl) {
+ // Remove the datasource and rebuild tree
+ tree.database.RemoveDataSource(ds);
+ tree.builder.rebuild();
+ return true;
+ }
+ }
+ return false;
}
-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 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;
+
+DataSourceManager2.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();
+ while (sources.hasMoreElements()) {
+ source = sources.getNext();
+ if (source.uri == rdfurl) {
+ var ds = new RDFDataSource();
+ ds.Init(source);
+ return ds;
+ }
+ }
+ return false;
}
-DataSourceManager.prototype.saveDataSource = function(rdfurl) {
+DataSourceManager2.prototype.saveDataSource = function(rdfurl) {
/* Only for local datasources, should fail for remote */
+
+ // Check whether this is a local datasource; if not return false
+ profileDir = getProfileDirURL();
+ if (rdfurl.slice(0, profileDir.length) != profileDir)
+ return false;
+
+ // Get the dataaource.
+ ds = this.getDataSource(rdfurl);
+ ds.save();
+
return true;
}
-DataSourceManager.prototype.dumpDataSources = function() {
+DataSourceManager2.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();
+ while (sources.hasMoreElements()) {
+ ds = new RDFDataSource(sources.getNext());
+ dump(ds.serializeToString());
+ }
return true;
}
-DataSourceManager.prototype.getSelectedResource = function() {
+DataSourceManager2.prototype.getSelectedResource = function() {
/* Return the resource that is currently selected in the tree. */
- return true;
-}
-
-DataSourceManager.prototype.openSelectedResource = function() {
- /* This function "opens
-
- Note: This should be overridden by
- */
+ // get index of tree
+ var tree = document.getElementById(this.treeId);
+ var index = tree.view.selection.currentIndex;
- return true;
-}
-
-
-DataSourceManager.prototype.addResource = function(parenturn, resourceurn) {
- /* */
- return true;
+ // get the selected resource
+ if (index == -1)
+ return false;
+ var res = tree.view.getItemAtIndex(index).resource;
+
+ sources = tree.database.GetDataSources();
+ // the first source is always Mozilla internal
+ sources.getNext();
+ // we need to create the RDFDataSource object only once
+ var ds = new RDFDataSource();
+ // Go through all registered datasources
+ while (sources.hasMoreElements()) {
+ // Create a rdfds RDFNode and see whether it exists in the datasource
+ source = sources.getNext();
+ ds.Init(source);
+ node = ds.getNode(res.Value);
+ if (node.propertyExists(this.titleprop))
+ return node;
+ }
+ return false;
}
-DataSourceManager.prototype.updateResource = function(resourceurn,
- property, value) {
- /* A quick way to grab the right RDF */
- return true;
-}
-
+DataSourceManager2.prototype.openSelectedResource = function() {
+ /* This function "opens" the selected Tree resource.
-DataSourceManager.prototype.deleteResource = function() {
- /* */
+ Note: This should be overridden by the implmenting class.
+ */
+
return true;
}
-
function SitesManager2() {
// Overridden DataSource Manager variables
@@ -157,11 +210,13 @@
}
-// SitesManager subclasses from DataSourceManager
-SitesManager.prototype = new DataSourceManager();
+// SitesManager2 subclasses from DataSourceManager
+SitesManager2.prototype = new DataSourceManager2();
+SitesManager2.prototype.constructor = SitesManager2;
+SitesManager2.superclass = DataSourceManager2;
-SitesManager.prototype.initializeProfileDir = function() {
+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. */
@@ -172,7 +227,7 @@
}
-DataSourceManager.prototype.initializeSites = function() {
+SitesManager2.prototype.initializeSites = function() {
/* Called during startup to find needed sites, fetch RDF, and build
tree */
tree = document.getElementById(this.treeid);
@@ -182,7 +237,7 @@
}
-SitesManager.prototype.addSite = function(title, rsdurl, rsddom) {
+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
@@ -195,7 +250,7 @@
}
-SitesManager.prototype.removeSite = function(rsdurl) {
+SitesManager2.prototype.removeSite = function(rsdurl) {
/* Remove a site from the RDF data source.
Note: No remote action has to be taken.*/
@@ -209,8 +264,7 @@
/* ------------ Utility functions below ------------- */
-function getProfileDirURL ()
-{
+function getProfileDirURL() {
// First get the directory service and query interface it to
// nsIProperties
=== Packages/Moztop/moztop/content/lib/logmanager.js 1.1 => 1.2 ===
--- Packages/Moztop/moztop/content/lib/logmanager.js:1.1 Thu Mar 20 10:11:22 2003
+++ Packages/Moztop/moztop/content/lib/logmanager.js Fri Mar 21 15:27:24 2003
@@ -18,9 +18,9 @@
******************************************************************************/
/* Now subclass, then add methods */
-LogManager.prototype = new DataSourceManager();
+LogManager.prototype = new DataSourceManager2();
LogManager.prototype.constructor = LogManager;
-LogManager.superclass = DataSourceManager;
+LogManager.superclass = DataSourceManager2;
function LogManager () {
@@ -34,46 +34,27 @@
// Initialization preocess
if( !(this instanceof LogManager) )
return new LogManager( );
- DataSourceManager.call(this);
-
- // Grep the right resource URL for storing it at the right place
- this.profileurl = this.getProfileDirURL();
+ DataSourceManager2.call(this);
// Initialize RDF data source
- this.elementid = "logmessages-tree";
- this.ds = new RDFDataSource();
+ this.treeId = "logmessages-tree";
this.urn = "urn:moztop:logmessages";
// Define namespaces required for this RDF graph
- this.dcns = "http://www.purl.org/dc/1.1#";
this.zoperdfns = "http://www.zope.org/rdf#";
- this.ncns ="http://home.netscape.com/NC-rdf#";
// Setup log message property names
- this.titleprop = this.dcns + "title";
- this.descriptionprop = this.dcns + "description";
this.timeprop = this.zoperdfns + "time";
this.messageprop = this.zoperdfns + "message";
}
-
-LogManager.prototype.attachDataSource = function() {
- /* Called once when log is first loaded */
- var lms=this.ds.getNode(this.urn);
- lms.makeSeq();
-
- // Now attach the datasource
- var logmessages=document.getElementById(this.elementid);
- logmessages.database.AddDataSource(this.ds.getRawDataSource());
- logmessages.builder.rebuild();
-
- // Create a log message on startup
- this.addMessage("Init Log Manager","LogManager.attachDataSource",
- "Initializing Log Manager.");
- return;
+LogManager.prototype.initialize = function() {
+ this.addDataSource(null);
+ var ds = this.getDataSource();
+ var rootnode = ds.getNode(this.urn);
+ rootnode.makeSeq();
}
-
LogManager.prototype.addMessage = function(msgtitle, msglocation, msg) {
/* title is the short message, msg is full text displayed on dblclick
@@ -93,8 +74,9 @@
msg = msgtitle;
// Create new RDF message node in graph
- var rootnode = this.ds.getNode(this.urn);
- var thismsg = this.ds.getNode(this.urn + ":" + date.getTime());
+ var ds = this.getDataSource();
+ var rootnode = ds.getNode(this.urn);
+ var thismsg = ds.getNode(this.urn + ":" + date.getTime());
// Add a new log message to the RDF graph.
rootnode.addChild(thismsg);
@@ -105,17 +87,19 @@
}
-LogManager.prototype.viewSelectedMessage = function () {
+LogManager.prototype.viewSelectedMessage = function() {
+ this.openSelectedResource();
+}
+
+LogManager.prototype.openSelectedResource = function() {
/* When a user doubleclicks on a message in the log, this
is called. It finds the selected item in the tree
and pops up a dialog box with the contents of the log message. */
- var tree = document.getElementById(this.elementid);
- var index = tree.view.selection.currentIndex;
- var rdf = tree.view.getItemAtIndex(index).resource;
-
- // Grab the RDF value and popup a dialog window
- var node = this.ds.getNode(rdf.Value);
+ // Get the selected resource
+ var node = this.getSelectedResource();
+
+ // Popup a dialog window
var msg = node.getTarget(this.messageprop);
window.openDialog("chrome://moztop/content/lib/logmessagedialog.xul",
"viewlogmessage", "chrome", msg.getValue());
@@ -138,6 +122,6 @@
function initLogManager() {
// Remember that logmanager was defined globally, but not initialized.
logmanager = LogManager();
- logmanager.attachDataSource();
+ logmanager.initialize();
}