home *** CD-ROM | disk | FTP | other *** search
/ Chip 2003 January / 01_03.iso / software / ghostzilla_hit / files / ghostzilla-1.0-plus-install.exe / chrome / help.jar / content / help / help.js < prev    next >
Encoding:
JavaScript  |  2002-05-21  |  21.5 KB  |  673 lines

  1. /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  * The contents of this file are subject to the Netscape Public
  3.  * License Version 1.1 (the "License"); you may not use this file
  4.  * except in compliance with the License. You may obtain a copy of
  5.  * the License at http://www.mozilla.org/NPL/
  6.  * 
  7.  * Software distributed under the License is distributed on an "AS
  8.  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  9.  * implied. See the License for the specific language governing
  10.  * rights and limitations under the License.
  11.  * 
  12.  * The Original Code is Mozilla Communicator client code, released
  13.  * March 31, 1998.
  14.  * 
  15.  * The Initial Developer of the Original Code is Netscape
  16.  * Communications Corporation. Portions created by Netscape are
  17.  * Copyright (C) 1998-1999 Netscape Communications Corporation. All
  18.  * Rights Reserved.
  19.  * Contributor(s): 
  20.  *    Original author: oeschger@netscape.com 
  21.  *    amended by: Peter Wilson (added sidebar tabs) */
  22.  
  23. //-------- global variables
  24. var helpBrowser;
  25. var helpWindow;
  26. var helpSearchPanel;
  27. var helpTocPanel;
  28. var helpIndexPanel;
  29. var helpGlossaryPanel;
  30.  
  31. // Namespaces
  32. const NC = "http://home.netscape.com/NC-rdf#";
  33. const SN = "rdf:http://www.w3.org/1999/02/22-rdf-syntax-ns#";
  34. const XML = "http://www.w3.org/XML/1998/namespace#"
  35. const MAX_LEVEL = 40; // maximum depth of recursion in search datasources.
  36.  
  37. // Resources
  38. var RDF = Components.classes["@mozilla.org/rdf/rdf-service;1"].getService(Components.interfaces.nsIRDFService);
  39. var RDF_ROOT = RDF.GetResource("urn:root");
  40. var NC_PANELLIST = RDF.GetResource(NC + "panellist");
  41. var NC_PANELID = RDF.GetResource(NC + "panelid");
  42. var NC_DATASOURCES = RDF.GetResource(NC + "datasources");
  43. var NC_SUBHEADINGS = RDF.GetResource(NC + "subheadings");
  44. var NC_NAME = RDF.GetResource(NC + "name");
  45. var NC_LINK = RDF.GetResource(NC + "link");
  46. var NC_TITLE = RDF.GetResource(NC + "title");
  47. var NC_BASE = RDF.GetResource(NC + "base"); 
  48. var NC_DEFAULTTOPIC = RDF.GetResource(NC + "defaulttopic"); 
  49.  
  50. var RDFCUtils = Components.classes["@mozilla.org/rdf/container-utils;1"].getService().
  51.    QueryInterface(Components.interfaces.nsIRDFContainerUtils);
  52. var RDFContainer = Components.classes["@mozilla.org/rdf/container;1"].getService(Components.interfaces.nsIRDFContainer);
  53. var CONSOLE_SERVICE = Components.classes['@mozilla.org/consoleservice;1'].getService(Components.interfaces.nsIConsoleService);
  54.             
  55. var urnID = 0;
  56. var RE;
  57.  
  58. var helpFileURI;
  59. var helpFileDS;
  60. // Set from nc:base attribute on help rdf file. It may be used for prefix reduction on all links within
  61. // the current help set.
  62. var helpBaseURI;
  63.  
  64. const defaultHelpFile = "chrome://help/locale/mozillahelp.rdf";
  65. // Set from nc:defaulttopic. It is used when the requested uri has no topic specified. 
  66. var defaultTopic = "welcome"; 
  67. var searchDatasources = "rdf:null";
  68. var searchDS = null;
  69.  
  70. const NSRESULT_RDF_SYNTAX_ERROR = 0x804e03f7; 
  71.  
  72. // This function is called by dialogs/windows that want to display context-sensitive help
  73. // These dialogs/windows should include the script chrome://help/content/contextHelp.js
  74. function displayTopic(topic) {
  75.   if (!topic)
  76.     topic = defaultTopic;
  77.   var uri = getLink(topic);
  78.   loadURI(uri);
  79. }
  80.  
  81. // Initialize the Help window
  82. function init() {
  83.   //cache panel references.
  84.   helpWindow = document.getElementById("help");
  85.   helpSearchPanel = document.getElementById("help-search-panel");
  86.   helpTocPanel = document.getElementById("help-toc-tree");
  87.   helpIndexPanel = document.getElementById("help-index-tree");
  88.   helpGlossaryPanel = document.getElementById("help-glossary-tree");
  89.   helpBrowser = document.getElementById("help-content");
  90.  
  91.   var URI = normalizeURI(decodeURIComponent(window.location.search));
  92.   helpFileURI = URI.helpFileURI;
  93.   var helpTopic = URI.topic;
  94.   helpBaseURI = helpFileURI.substring(0, helpFileURI.lastIndexOf("/")+1); // trailing "/" included.
  95.  
  96.   loadHelpRDF();
  97.  
  98.   displayTopic(helpTopic);  
  99.  
  100.   // move to right end of screen
  101.   var width = document.documentElement.getAttribute("width");
  102.   var height = document.documentElement.getAttribute("height");
  103.   window.moveTo(screen.availWidth-width, (screen.availHeight-height)/2);
  104.  
  105.   var sessionHistory =  Components.classes["@mozilla.org/browser/shistory;1"]
  106.                   .createInstance(Components.interfaces.nsISHistory);
  107.  
  108.   getWebNavigation().sessionHistory = sessionHistory;
  109.   window.XULBrowserWindow = new nsHelpStatusHandler();
  110.   // hook up UI through progress listener
  111.   var interfaceRequestor = helpBrowser.docShell.QueryInterface(Components.interfaces.nsIInterfaceRequestor);
  112.   var webProgress = interfaceRequestor.getInterface(Components.interfaces.nsIWebProgress);
  113.   webProgress.addProgressListener(window.XULBrowserWindow, Components.interfaces.nsIWebProgress.NOTIFY_ALL);
  114. }
  115.  
  116. function normalizeURI(uri) {
  117.   // uri in format [uri of help rdf file][?initial topic]
  118.   // if the whole uri or help file uri is omitted then the default help is assumed.
  119.   // unpack uri
  120.   var URI = {};
  121.   URI.helpFileURI = defaultHelpFile;
  122.   URI.topic = null;
  123.   // Case: No help uri at all.
  124.   if (uri) {
  125.     // remove leading ?
  126.     if (uri.substr(0,1) == "?") 
  127.       uri = uri.substr(1);
  128.     var i = uri.indexOf("?");
  129.     // Case: Full uri with topic.
  130.     if ( i != -1) {
  131.         URI.helpFileURI = uri.substr(0,i);
  132.         URI.topic = uri.substr(i+1);
  133.     }
  134.     else {
  135.       // Case: uri with no topic.
  136.       if (uri.substr(0,7) == "chrome:") 
  137.         URI.helpFileURI = uri;
  138.       else {
  139.         // Case: uri with topic only.
  140.         URI.topic = uri;
  141.       }  
  142.     }
  143.   }  
  144.   URI.uri = URI.helpFileURI + ((URI.topic)? "?" + URI.topic : "");
  145.   return URI;
  146. }
  147.  
  148. function loadHelpRDF() {
  149.   if (!helpFileDS) {
  150.     try {
  151.       helpFileDS = RDF.GetDataSourceBlocking(helpFileURI);
  152.     }
  153.     catch (e if (e.result == NSRESULT_RDF_SYNTAX_ERROR)) {
  154.       log("Help file: " + helpFileURI + " contains a syntax error.");
  155.     }
  156.     catch (e) {
  157.       log("Help file: " + helpFileURI + " was not found.");
  158.     }
  159.     try {
  160.       helpWindow.setAttribute("title", getAttribute(helpFileDS, RDF_ROOT, NC_TITLE, ""));
  161.       helpBaseURI = getAttribute(helpFileDS, RDF_ROOT, NC_BASE, helpBaseURI);
  162.       defaultTopic = getAttribute(helpFileDS, RDF_ROOT, NC_DEFAULTTOPIC, "welcome");
  163.  
  164.       var panelDefs = helpFileDS.GetTarget(RDF_ROOT, NC_PANELLIST, true);      
  165.       RDFContainer.Init(helpFileDS, panelDefs);
  166.       var iterator = RDFContainer.GetElements();
  167.         while (iterator.hasMoreElements()) {
  168.         var panelDef = iterator.getNext();
  169.         var panelID = getAttribute(helpFileDS, panelDef, NC_PANELID, null);        
  170.  
  171.         var datasources = getAttribute(helpFileDS, panelDef, NC_DATASOURCES, "rdf:none");
  172.         datasources = normalizeLinks(helpBaseURI, datasources);
  173.         // cache additional datsources to augment search datasources.
  174.         if (panelID == "search") {
  175.           searchDatasources = datasources;
  176.           datasources = "rdf:null"; // but don't try to display them yet!
  177.         }  
  178.  
  179.         // cache toc datasources for use by ID lookup.
  180.         var tree = document.getElementById("help-" + panelID + "-tree");
  181.         tree.setAttribute("datasources", datasources);
  182.         //if (panelID == "toc") {
  183.           if (tree.database) {
  184.             loadDatabases(tree.database, datasources);
  185.             tree.builder.rebuild();
  186.           }
  187.         //}
  188.       }  
  189.     }
  190.     catch (e) {
  191.       log(e + "");      
  192.     }
  193.   }
  194. }
  195. function loadDatabases(compositeDatabase, datasources) {
  196.   var ds = datasources.split(/\s+/);
  197.   for (var i=0; i < ds.length; ++i) {
  198.     if (ds[i] == "rdf:null" || ds[i] == "")
  199.       continue;
  200.     try {  
  201.       // we need blocking here to ensure the database is loaded so getLink(topic) works.
  202.       var datasource = RDF.GetDataSourceBlocking(ds[i]);
  203.       if (datasource)  
  204.         compositeDatabase.AddDataSource(datasource);
  205.     }
  206.     catch (e) {
  207.       log("Datasource: " + ds[i] + " was not found.");
  208.     }
  209.   }
  210. }
  211.  
  212. // prepend helpBaseURI to list of space separated links if the don't start with "chrome:"
  213. function normalizeLinks(helpBaseURI, links) {
  214.   if (!helpBaseURI)
  215.     return links;
  216.   var ls = links.split(/\s+/);
  217.   if (ls.length == 0)
  218.     return links;
  219.   for (var i=0; i < ls.length; ++i) {
  220.     if (ls[i] == "")
  221.       continue;
  222.     if (ls[i].substr(0,7) != "chrome:" && ls[i].substr(0,4) != "rdf:") 
  223.       ls[i] = helpBaseURI + ls[i];
  224.   }
  225.   return ls.join(" ");  
  226. }
  227.  
  228. function getLink(ID) {
  229.   if (!ID)
  230.     return null;
  231.   // Note resources are stored in fileURL#ID format.
  232.   // We have one possible source for an ID for each datasource in the composite datasource.
  233.   // The first ID which matches is returned.
  234.   var tocTree = document.getElementById("help-toc-tree");
  235.     tocDS = tocTree.database;
  236.     if (tocDS == null)
  237.       return null;
  238.     var tocDatasources = tocTree.getAttribute("datasources");
  239.   var ds = tocDatasources.split(/\s+/);
  240.   for (var i=0; i < ds.length; ++i) {
  241.     if (ds[i] == "rdf:null" || ds[i] == "")
  242.       continue;
  243.     try {
  244.       var rdfID = ds[i] + "#" + ID;
  245.       var resource = RDF.GetResource(rdfID);
  246.       if (resource) {
  247.         var link = tocDS.GetTarget(resource, NC_LINK, true);
  248.         if (link) {
  249.           link = link.QueryInterface(Components.interfaces.nsIRDFLiteral);
  250.           if (link) 
  251.             return link.Value;
  252.           else  
  253.             return null;
  254.         }  
  255.       }
  256.     }
  257.     catch (e) { log(rdfID + " " + e);}
  258.   }
  259.   return null;
  260. }
  261.  
  262. // Called by contextHelp.js to determine if this window is displaying the requested help file.
  263. function getHelpFileURI() {
  264.   return helpFileURI;
  265. }
  266.  
  267.  
  268. function getWebNavigation()
  269. {
  270.   return helpBrowser.webNavigation;
  271. }
  272.  
  273. function loadURI(uri)
  274. {
  275.   if (uri.substr(0,7) != "chrome:")
  276.     uri = helpBaseURI + uri;
  277.   const nsIWebNavigation = Components.interfaces.nsIWebNavigation;
  278.   getWebNavigation().loadURI(uri, nsIWebNavigation.LOAD_FLAGS_NONE, null, null, null);
  279. }
  280.  
  281. function goBack()
  282. {
  283.   var webNavigation = getWebNavigation();
  284.   if (webNavigation.canGoBack)
  285.     webNavigation.goBack();
  286. }
  287.  
  288. function goForward()
  289. {
  290.   var webNavigation = getWebNavigation();
  291.   if (webNavigation.canGoForward)
  292.     webNavigation.goForward();
  293. }
  294.  
  295. function goHome() {
  296.   // load "Welcome" page
  297.   displayTopic(defaultTopic);
  298. }
  299.  
  300. function print()
  301. {
  302.   try {
  303.     _content.print();
  304.   } catch (e) {
  305.   }
  306. }
  307.  
  308. function createBackMenu(event)
  309. {
  310.   return FillHistoryMenu(event.target, "back");
  311. }
  312.  
  313. function createForwardMenu(event)
  314. {
  315.   return FillHistoryMenu(event.target, "forward");
  316. }
  317.  
  318. function gotoHistoryIndex(aEvent)
  319. {
  320.   var index = aEvent.target.getAttribute("index");
  321.   if (!index)
  322.     return false;
  323.   try {
  324.     getWebNavigation().gotoIndex(index);
  325.   }
  326.   catch(ex) {
  327.     return false;
  328.   }
  329.   return true;
  330. }
  331.  
  332. function BrowserBack()
  333. {
  334.   try {
  335.     getWebNavigation().goBack();
  336.   }
  337.   catch(ex) {
  338.   }
  339.   UpdateBackForwardButtons();
  340. }
  341.  
  342. function BrowserForward()
  343. {
  344.   try {
  345.     getWebNavigation().goForward();
  346.   }
  347.   catch(ex) {
  348.   }
  349.   UpdateBackForwardButtons();
  350. }
  351.  
  352. function nsHelpStatusHandler()
  353. {
  354. }
  355.  
  356. nsHelpStatusHandler.prototype =
  357. {
  358.   onStateChange : function(aWebProgress, aRequest, aStateFlags, aStatus) {},
  359.   onProgressChange : function(aWebProgress, aRequest, aCurSelfProgress,
  360.                               aMaxSelfProgress, aCurTotalProgress, aMaxTotalProgress) {},
  361.   onSecurityChange : function(aWebProgress, aRequest, state) {},
  362.   onLocationChange : function(aWebProgress, aRequest, aLocation)
  363.   {
  364.     UpdateBackForwardButtons();
  365.   },
  366.   QueryInterface : function(aIID)
  367.   {
  368.     if (aIID.equals(Components.interfaces.nsIWebProgressListener) ||
  369.       aIID.equals(Components.interfaces.nsISupportsWeakReference) ||
  370.       aIID.equals(Components.interfaces.nsIXULBrowserWindow) ||
  371.       aIID.equals(Components.interfaces.nsISupports))
  372.       return this;
  373.     throw Components.results.NS_NOINTERFACE;
  374.   },
  375.   setJSStatus : function(status) {},
  376.   setJSDefaultStatus : function(status) {},
  377.   setOverLink : function(link) {}
  378. }
  379.  
  380. function UpdateBackForwardButtons()
  381. {
  382.   var backBroadcaster = document.getElementById("canGoBack");
  383.   var forwardBroadcaster = document.getElementById("canGoForward");
  384.   var webNavigation = getWebNavigation();
  385.  
  386.   // Avoid setting attributes on broadcasters if the value hasn't changed!
  387.   // Remember, guys, setting attributes on elements is expensive!  They
  388.   // get inherited into anonymous content, broadcast to other widgets, etc.!
  389.   // Don't do it if the value hasn't changed! - dwh
  390.  
  391.   var backDisabled = (backBroadcaster.getAttribute("disabled") == "true");
  392.   var forwardDisabled = (forwardBroadcaster.getAttribute("disabled") == "true");
  393.  
  394.   if (backDisabled == webNavigation.canGoBack)
  395.     backBroadcaster.setAttribute("disabled", !backDisabled);
  396.   
  397.   if (forwardDisabled == webNavigation.canGoForward)
  398.     forwardBroadcaster.setAttribute("disabled", !forwardDisabled);
  399. }
  400.  
  401. function find(again)
  402. {
  403.   var focusedWindow = document.commandDispatcher.focusedWindow;
  404.   if (!focusedWindow || focusedWindow == window)
  405.     focusedWindow = window._content;
  406.   if (again)
  407.     findAgainInPage(helpBrowser, window._content, focusedWindow);
  408.   else
  409.     findInPage(browser, window._content, focusedWindow)
  410. }
  411.  
  412. function getMarkupDocumentViewer()
  413. {
  414.   return helpBrowser.markupDocumentViewer;
  415. }
  416.  
  417. function BrowserReload()
  418. {
  419.   const reloadFlags = Components.interfaces.nsIWebNavigation.LOAD_FLAGS_NONE;
  420.   return BrowserReloadWithFlags(reloadFlags);
  421. }
  422.  
  423. function BrowserReloadWithFlags(reloadFlags)
  424. {
  425.    try {
  426.      /* Need to get SessionHistory from docshell so that
  427.       * reload on framed pages will work right. This 
  428.       * method should not be used for the context menu item "Reload frame".
  429.       * "Reload frame" should directly call into docshell as it does right now
  430.       */
  431.      var sh = getWebNavigation().sessionHistory;
  432.      var webNav = sh.QueryInterface(Components.interfaces.nsIWebNavigation);      
  433.      webNav.reload(reloadFlags);
  434.    }
  435.    catch(ex) {
  436.    }
  437.  }
  438.  
  439.  // doc=null for regular page info, doc=owner document for frame info 
  440.  function BrowserPageInfo(doc)
  441.  {
  442.    window.openDialog("chrome://navigator/content/pageInfo.xul",
  443.                      "_blank",
  444.                      "chrome,dialog=no",
  445.                      doc);
  446. }
  447.  
  448. function BrowserViewSource()
  449. {
  450.   var focusedWindow = document.commandDispatcher.focusedWindow;
  451.   if (focusedWindow == window)
  452.     focusedWindow = _content;
  453.  
  454.   if (focusedWindow)
  455.     var docCharset = "charset=" + focusedWindow.document.characterSet;
  456.  
  457.   BrowserViewSourceOfURL(_content.location, docCharset);
  458. }
  459.  
  460. function BrowserViewSourceOfURL(url, charset)
  461. {
  462.   // try to open a view-source window while inheriting the charset (if any)
  463.   openDialog("chrome://navigator/content/viewSource.xul",
  464.              "_blank",
  465.              "scrollbars,resizable,chrome,dialog=no",
  466.              url, charset);
  467. }
  468.  
  469. //Show the selected sidebar panel
  470. function showPanel(panelId) {
  471.   helpSearchPanel.setAttribute("hidden", "true");
  472.   helpTocPanel.setAttribute("hidden", "true");
  473.   helpIndexPanel.setAttribute("hidden", "true");
  474.   helpGlossaryPanel.setAttribute("hidden", "true");
  475.   var thePanel = document.getElementById(panelId);
  476.   thePanel.setAttribute("hidden","false");
  477. }
  478.  
  479. function onselect_loadURI(tree, columnName) {
  480.   try {
  481.     var row = tree.treeBoxObject.view.selection.currentIndex;
  482.     var properties = Components.classes["@mozilla.org/supports-array;1"].createInstance(Components.interfaces.nsISupportsArray);
  483.     tree.treeBoxObject.view.getCellProperties(row, columnName, properties);
  484.     if (!properties) return;
  485.     var uri = getPropertyValue(properties, "link-");
  486.     if (uri)
  487.       loadURI(uri);
  488.   }
  489.   catch (e) {}// when switching between tabs a spurious row number is returned.
  490. }
  491.  
  492. /** Search properties nsISupportsArray for an nsIAtom which starts with the given property name. **/
  493. function getPropertyValue(properties, propName) {
  494.   for (var i=0; i< properties.Count(); ++i) {
  495.     var atom = properties.GetElementAt(i).QueryInterface(Components.interfaces.nsIAtom);
  496.     var atomValue = atom.GetUnicode();
  497.     if (atomValue.substr(0, propName.length) == propName)
  498.       return atomValue.substr(propName.length);
  499.   }
  500.   return null;
  501. }
  502.  
  503. function doFind() {
  504.   var searchTree = document.getElementById("help-search-tree");
  505.   var findText = document.getElementById("findText");
  506.  
  507.   // clear any previous results.
  508.   clearDatabases(searchTree.database);
  509.  
  510.   // split search string into separate terms and compile into regexp's
  511.   RE = findText.value.split(/\s+/);
  512.   for (var i=0; i < RE.length; ++i) {
  513.     if (RE[i] == "")
  514.       continue;
  515.     RE[i] = new RegExp(RE[i].substring(0, RE[i].length-1) +"\w?", "i");
  516.   }
  517.  
  518.   // search TOC
  519.   var resultsDS =  Components.classes["@mozilla.org/rdf/datasource;1?name=in-memory-datasource"].createInstance(Components.interfaces.nsIRDFDataSource);
  520.   var tree = document.getElementById("help-toc-tree");
  521.   var sourceDS = tree.database;
  522.   doFindOnDatasource(resultsDS, sourceDS, RDF_ROOT, 0);
  523.  
  524.   // search additional search datasources                                       
  525.   if (searchDatasources != "rdf:null") {
  526.     if (!searchDS)
  527.       searchDS = loadCompositeDS(searchDatasources);
  528.     doFindOnDatasource(resultsDS, searchDS, RDF_ROOT, 0);
  529.   }
  530.  
  531.   // search glossary.
  532.   tree = document.getElementById("help-glossary-tree");
  533.   sourceDS = tree.database;
  534.   if (!sourceDS) // If the glossary has never been displayed this will be null (sigh!).
  535.     sourceDS = loadCompositeDS(tree.datasources);
  536.   doFindOnDatasource(resultsDS, sourceDS, RDF_ROOT, 0);
  537.  
  538.   // Add the datasource to the search tree
  539.   searchTree.database.AddDataSource(resultsDS);
  540.   searchTree.builder.rebuild();
  541. }
  542.  
  543. function clearDatabases(compositeDataSource) {
  544.   var enumDS = compositeDataSource.GetDataSources()
  545.   while (enumDS.hasMoreElements()) {
  546.     var ds = enumDS.getNext();
  547.         compositeDataSource.RemoveDataSource(ds);
  548.   }
  549. }
  550.  
  551. function doFindOnDatasource(resultsDS, sourceDS, resource, level) {
  552.   if (level > MAX_LEVEL) {
  553.     try {
  554.       log("Recursive reference to resource: " + resource.Value + ".");
  555.     }
  556.     catch (e) {
  557.       log("Recursive reference to unknown resource.");
  558.     }
  559.     return;
  560.   }
  561.   // find all SUBHEADING children of current resource.
  562.   var targets = sourceDS.GetTargets(resource, NC_SUBHEADINGS, true);
  563.   while (targets.hasMoreElements()) {
  564.       var target = targets.getNext();
  565.       target = target.QueryInterface(Components.interfaces.nsIRDFResource);
  566.         // The first child of a rdf:subheading should (must) be a rdf:seq.
  567.         // Should we test for a SEQ here?
  568.     doFindOnSeq(resultsDS, sourceDS, target, level+1);       
  569.   }  
  570. }
  571.  
  572. function doFindOnSeq(resultsDS, sourceDS, resource, level) {
  573.   // load up an RDFContainer so we can access the contents of the current rdf:seq.    
  574.     RDFContainer.Init(sourceDS, resource);
  575.     var targets = RDFContainer.GetElements();
  576.     while (targets.hasMoreElements()) {
  577.     var target = targets.getNext();
  578.         target = target.QueryInterface(Components.interfaces.nsIRDFResource);
  579.         var name = sourceDS.GetTarget(target, NC_NAME, true);
  580.         name = name.QueryInterface(Components.interfaces.nsIRDFLiteral);
  581.         
  582.         if (isMatch(name.Value)) {
  583.           // we have found a search entry - add it to the results datasource.
  584.           
  585.           // Get URL of html for this entry.
  586.       var link = sourceDS.GetTarget(target, NC_LINK, true);
  587.       link = link.QueryInterface(Components.interfaces.nsIRDFLiteral);        
  588.  
  589.       urnID++;
  590.       resultsDS.Assert(RDF_ROOT,
  591.              RDF.GetResource("http://home.netscape.com/NC-rdf#child"),
  592.              RDF.GetResource("urn:" + urnID),
  593.              true);
  594.       resultsDS.Assert(RDF.GetResource("urn:" + urnID),
  595.              RDF.GetResource("http://home.netscape.com/NC-rdf#name"),
  596.              name,
  597.              true);
  598.       resultsDS.Assert(RDF.GetResource("urn:" + urnID),
  599.              RDF.GetResource("http://home.netscape.com/NC-rdf#link"),
  600.              link,
  601.              true);
  602.     }
  603.     // process any nested rdf:seq elements.
  604.     doFindOnDatasource(resultsDS, sourceDS, target, level+1);       
  605.     }  
  606. }
  607.  
  608. function isMatch(text) {
  609.   for (var i=0; i < RE.length; ++i ) {
  610.     if (!RE[i].test(text))
  611.       return false;
  612.   }
  613.   return true;
  614. }
  615. function loadCompositeDS(datasources) {
  616.   // We can't search on each individual datasource's - only the aggregate (for each sidebar tab)
  617.   // has the appropriate structure.
  618.   var compositeDS =  Components.classes["@mozilla.org/rdf/datasource;1?name=composite-datasource"]
  619.       .createInstance(Components.interfaces.nsIRDFCompositeDataSource);
  620.   
  621.   var ds = datasources.split(/\s+/);
  622.   for (var i=0; i < ds.length; ++i) {
  623.     if (ds[i] == "rdf:null" || ds[i] == "")
  624.       continue;
  625.     try {  
  626.       // we need blocking here to ensure the database is loaded.
  627.       var sourceDS = RDF.GetDataSourceBlocking(ds[i]);
  628.       compositeDS.AddDataSource(sourceDS);
  629.     }
  630.     catch (e) {
  631.       log("Datasource: " + ds[i] + " was not found.");
  632.     }
  633.   }
  634.   return compositeDS;
  635. }
  636.  
  637. function getAttribute(datasource, resource, attributeResourceName, defaultValue) {
  638.   var literal = datasource.GetTarget(resource, attributeResourceName, true);
  639.   if (!literal)
  640.     return defaultValue;
  641.   return getLiteralValue(literal, defaultValue);  
  642. }
  643.  
  644. function getLiteralValue(literal, defaultValue) {
  645.   if (literal) {
  646.       literal = literal.QueryInterface(Components.interfaces.nsIRDFLiteral);
  647.       if (literal)
  648.         return literal.Value;
  649.   }
  650.   if (defaultValue)
  651.     return defaultValue;
  652.   return null;
  653. }
  654. // Write debug string to javascript console.
  655. function log(aText) {
  656.   CONSOLE_SERVICE.logStringMessage(aText);
  657. }
  658.  
  659.  
  660. //INDEX OPENING FUNCTION -- called in oncommand for index pane
  661. // iterate over all the items in the outliner;
  662. // open the ones at the top-level (i.e., expose the headings underneath
  663. // the letters in the list.
  664. function displayIndex() {
  665.     var outliner = document.getElementById("help-index-outliner");
  666.     var oview = outliner.outlinerBoxObject.view;    
  667.     for ( i = 0; i < 500; ++i ) {
  668.       if ( !oview.isContainerOpen(i) && oview.getLevel(i) == 0 ) {
  669.         oview.toggleOpenState(i);
  670.       }
  671.     }
  672. }
  673.