home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / mozil06.zip / bin / chrome / chatzilla.jar / content / chatzilla / rdf.js < prev    next >
Text File  |  2000-09-13  |  6KB  |  215 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  2.  *
  3.  * The contents of this file are subject to the Mozilla 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/MPL/
  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 Chatzilla
  14.  *
  15.  * The Initial Developer of the Original Code is New Dimensions Consulting,
  16.  * Inc. Portions created by New Dimensions Consulting, Inc. are
  17.  * Copyright (C) 1999 New Dimenstions Consulting, Inc. All
  18.  * Rights Reserved.
  19.  *
  20.  * Contributor(s):
  21.  *  Robert Ginda, rginda@ndcico.com, original author
  22.  */
  23.  
  24. const RES_PFX = "http://home.netscape.com/NC-irc#";
  25.  
  26. const nsIRDFResource = Components.interfaces.nsIRDFResource;
  27. const nsIRDFNode = Components.interfaces.nsIRDFNode;
  28.  
  29. function RDFHelper()
  30. {
  31.     const RDF_MEMORYDS_CONTRACTID =
  32.         "@mozilla.org/rdf/datasource;1?name=in-memory-datasource";
  33.     const RDF_DS_IID = Components.interfaces.nsIRDFDataSource;
  34.  
  35.     const RDF_DS_CONTRACTID = "@mozilla.org/rdf/rdf-service;1";
  36.     const RDF_SVC_IID = Components.interfaces.nsIRDFService;
  37.  
  38.     this.ds =
  39.         Components.classes[RDF_MEMORYDS_CONTRACTID].createInstance(RDF_DS_IID);
  40.     this.svc = 
  41.         Components.classes[RDF_DS_CONTRACTID].getService(RDF_SVC_IID);    
  42.  
  43.     /* predefined nodes */
  44.     this.resRoot     = this.svc.GetResource ("NC:chatzilla-data");
  45.     this.resNullUser = this.svc.GetResource (RES_PFX + "NUSER");
  46.     this.resNullChan = this.svc.GetResource (RES_PFX + "NCHAN");
  47.  
  48.     /* predefined arcs */
  49.     this.resNetwork  = this.svc.GetResource (RES_PFX + "network");
  50.     this.resServer   = this.svc.GetResource (RES_PFX + "server");
  51.     this.resChannel  = this.svc.GetResource (RES_PFX + "channel");
  52.     this.resChanUser = this.svc.GetResource (RES_PFX + "chanuser");
  53.     this.resOp       = this.svc.GetResource (RES_PFX + "op");
  54.     this.resVoice    = this.svc.GetResource (RES_PFX + "voice");
  55.     this.resNick     = this.svc.GetResource (RES_PFX + "nick");
  56.     this.resUser     = this.svc.GetResource (RES_PFX + "user");
  57.     this.resHost     = this.svc.GetResource (RES_PFX + "host");
  58.  
  59.     /* predefined literals */
  60.     this.litTrue     = this.svc.GetLiteral ("true");
  61.     this.litFalse    = this.svc.GetLiteral ("false");
  62.     this.litUnk      = this.svc.GetLiteral ("----"); 
  63.  
  64.     this.ds.Assert (this.resNullUser, this.resOp, this.litFalse, true);
  65.     this.ds.Assert (this.resNullUser, this.resVoice, this.litFalse, true);
  66.     this.ds.Assert (this.resNullUser, this.resNick, this.litUnk, true);
  67.     this.ds.Assert (this.resNullUser, this.resUser, this.litUnk, true);
  68.     this.ds.Assert (this.resNullUser, this.resHost, this.litUnk, true);
  69.     /*
  70.     this.ds.Assert (this.resNullChan, this.resChanUser, this.resNullUser, true);
  71.     */
  72.     this.ds.Assert (this.resRoot, this.resChannel, this.resNullChan, true);
  73.     
  74. }
  75.  
  76. RDFHelper.prototype.GetResource =
  77. function rdf_getr (s)
  78. {
  79.     return this.svc.GetResource(s);
  80. }
  81.  
  82. RDFHelper.prototype.GetLiteral =
  83. function rdf_getl (s)
  84. {
  85.     return this.svc.GetLiteral(s);
  86. }
  87.  
  88. RDFHelper.prototype.Assert =
  89. function rdf_assert (n1, a, n2, f)
  90. {
  91.  
  92.     if (typeof f == "undefined")
  93.         f = true;
  94.  
  95.     return this.dAssert (n1, a, n2, f);
  96.  
  97.  
  98.     return this.ds.Assert (n1, a, n2, f);
  99. }
  100.  
  101. RDFHelper.prototype.Unassert =
  102. function rdf_uassert (n1, a, n2)
  103. {
  104.     /*return this.dUnassert (n1, a, n2);*/
  105.     return this.ds.Unassert (n1, a, n2);
  106. }
  107.  
  108. RDFHelper.prototype.dAssert =
  109. function rdf_dassert (n1, a, n2, f)
  110. {
  111.     var n1v = n1 ? n1.Value : "!!!";
  112.     var av = a ? a.Value : "!!!";
  113.     var n2v = n2 ? n2.Value : "!!!";
  114.     
  115.     if (!n1 || !a || !n2)
  116.         dd(getStackTrace());
  117.     
  118.     this.ds.Assert (n1, a, n2, f)
  119. }
  120.  
  121. RDFHelper.prototype.dUnassert =
  122. function rdf_duassert (n1, a, n2)
  123. {
  124.  
  125.     var n1v = n1 ? n1.Value : "!!!";
  126.     var av = a ? a.Value : "!!!";
  127.     var n2v = n2 ? n2.Value : "!!!";
  128.     
  129.     if (!n1 || !a || !n2)
  130.         dd(getStackTrace());
  131.     
  132.     this.ds.Unassert (n1, a, n2)
  133.  
  134. }
  135.  
  136. RDFHelper.prototype.Change =
  137. function rdf_duassert (n1, a, n2)
  138. {
  139.  
  140.     var oldN2 = this.ds.GetTarget (n1, a, true);
  141.     if (!oldN2)
  142.     {
  143.         dd ("** Unable to change " + n1.Value + " -[" + a.Value + "]->, " +
  144.             "because old value was not found.");
  145.         return;
  146.     }
  147.     
  148.     return this.ds.Change (n1, a, oldN2, n2);
  149.     
  150. }
  151.  
  152. RDFHelper.prototype.clearTargets =
  153. function rdf_inittree (n1, a, recurse)
  154. {
  155.     if (typeof recurse == "undefined")
  156.         recurse = false;
  157.  
  158.     var targets = this.ds.GetTargets(n1, a, true);
  159.  
  160.     while (targets.hasMoreElements())
  161.     {
  162.         var n2 = targets.getNext().QueryInterface(nsIRDFNode);
  163.  
  164.         if (recurse)
  165.         {
  166.             try
  167.             {
  168.                 var resN2 = n2.QueryInterface(nsIRDFResource);
  169.                 var arcs = this.ds.ArcLabelsOut(resN2);
  170.  
  171.                 while (arcs.hasMoreElements())
  172.                 {
  173.                     arc = arcs.getNext().QueryInterface(nsIRDFNode);
  174.                     this.clearTargets (resN2, arc, true);
  175.                 }
  176.             }
  177.             catch (e)
  178.             {
  179.                 /*
  180.                 dd ("** Caught " + e + " while recursivley clearing " +
  181.                     n2.Value + " **");
  182.                 */
  183.             }
  184.         }
  185.         
  186.         this.Unassert (n1, a, n2);
  187.     }
  188. }        
  189.     
  190.  
  191. RDFHelper.prototype.initTree =
  192. function rdf_inittree (id)
  193. {
  194.     var tree = document.getElementById (id);
  195.     tree.database.AddDataSource (this.ds);
  196. }
  197.  
  198. RDFHelper.prototype.setTreeRoot =
  199. function rdf_settroot (id, root)
  200. {
  201.     var tree = document.getElementById (id);
  202.  
  203.     if (typeof root == "object")
  204.         root = root.Value;
  205.     tree.setAttribute ("ref", root);
  206. }
  207.  
  208. RDFHelper.prototype.getTreeRoot =
  209. function rdf_gettroot (id, root)
  210. {
  211.     var tree = document.getElementById (id);
  212.  
  213.     return tree.getAttribute ("ref");
  214. }
  215.