home *** CD-ROM | disk | FTP | other *** search
/ SVM Mac 58 / CD-ROM N°58.iso / navigateurs / Netscape Folder / chrome / RegViewer / content / default / regviewer.js next >
Encoding:
JavaScript  |  2000-04-19  |  3.7 KB  |  120 lines  |  [TEXT/MOSS]

  1. /* -*- Mode: Java; tab-width: 4; c-basic-offset: 4; -*-
  2.  * 
  3.  * The contents of this file are subject to the Netscape Public
  4.  * License Version 1.1 (the "License"); you may not use this file
  5.  * except in compliance with the License. You may obtain a copy of
  6.  * the License at http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the License is distributed on an "AS
  9.  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  10.  * implied. See the License for the specific language governing
  11.  * rights and limitations under the License.
  12.  *
  13.  * The Original Code is mozilla.org code.
  14.  *
  15.  * The Initial Developer of the Original Code is Netscape
  16.  * Communications Corporation.  Portions created by Netscape are
  17.  * Copyright (C) 1998 Netscape Communications Corporation. All
  18.  * Rights Reserved.
  19.  *
  20.  * Contributor(s): 
  21.  */
  22.  
  23. /*
  24.  
  25.    Script for the registry viewer window
  26.  
  27. */
  28.  
  29. var RDF = Components.classes['component://netscape/rdf/rdf-service'].getService();
  30. RDF = RDF.QueryInterface(Components.interfaces.nsIRDFService);
  31.  
  32. var Registry;
  33. var REGISTRY_NAMESPACE_URI = 'urn:mozilla-registry:'
  34. var REGISTRY_VALUE_PREFIX = REGISTRY_NAMESPACE_URI + 'value:';
  35. var kRegistry_Subkeys = RDF.GetResource(REGISTRY_NAMESPACE_URI + 'subkeys');
  36.  
  37. function debug(msg)
  38. {
  39.     //dump(msg + '\n');
  40. }
  41.  
  42. function OnLoad()
  43. {
  44.     Registry = Components.classes['component://netscape/registry-viewer'].createInstance();
  45.     Registry = Registry.QueryInterface(Components.interfaces.nsIRegistryDataSource);
  46.  
  47.     Registry.openWellKnownRegistry(Registry.ApplicationComponentRegistry);
  48.  
  49.     Registry = Registry.QueryInterface(Components.interfaces.nsIRDFDataSource);
  50.  
  51.     var tree = document.getElementById('tree');
  52.     tree.database.AddDataSource(Registry);
  53.  
  54.     tree.setAttribute('ref', 'urn:mozilla-registry:key:/');
  55. }  
  56.  
  57. function OnSelect(event)
  58. {
  59.   var tree = event.target;
  60.   var items = tree.selectedItems;
  61.  
  62.   var properties = document.getElementById('properties');
  63.   if (properties.firstChild) {
  64.       properties.removeChild(properties.firstChild);
  65.   }
  66.  
  67.   if (items.length == 1) {
  68.       // Exactly one item is selected. Show as much information as we
  69.       // can about it.
  70.       var table = document.createElement('html:table');
  71.  
  72.       debug('selected item = ' + items[0].getAttribute('id'));
  73.       var uri = items[0].getAttribute('id');
  74.  
  75.       var source = RDF.GetResource(uri);
  76.       var arcs = Registry.ArcLabelsOut(source);
  77.       while (arcs.HasMoreElements()) {
  78.           var property = arcs.GetNext().QueryInterface(Components.interfaces.nsIRDFResource);
  79.           if (property == kRegistry_Subkeys)
  80.               continue;
  81.  
  82.           var propstr = property.Value.substr(REGISTRY_VALUE_PREFIX.length);
  83.           debug('propstr = ' + propstr);
  84.  
  85.           var target = Registry.GetTarget(source, property, true);
  86.           var targetstr;
  87.  
  88.           var literal;
  89.       literal = target.QueryInterface(Components.interfaces.nsIRDFLiteral);
  90.       if (literal) {
  91.               targetstr = literal.Value;
  92.           }
  93.           else {
  94.         literal = target.QueryInterface(Components.interfaces.nsIRDFInt)
  95.         if (literal) {
  96.                       targetstr = literal.Value;
  97.         }
  98.         else {
  99.             // Hmm. Not sure!
  100.         }
  101.           }
  102.           
  103.           debug('targetstr = ' + targetstr);
  104.  
  105.           var tr = document.createElement('html:tr');
  106.           table.appendChild(tr);
  107.  
  108.           var td1 = document.createElement('html:td');
  109.           td1.appendChild(document.createTextNode(propstr));
  110.           tr.appendChild(td1);
  111.  
  112.           var td2 = document.createElement('html:td');
  113.           td2.appendChild(document.createTextNode(targetstr));
  114.           tr.appendChild(td2);
  115.       }
  116.  
  117.       properties.appendChild(table);
  118.   }
  119. }
  120.