changeset 125:bf6d9b7a77d4

Annotation Tool to integrate in chrome sidebar
author engler
date Wed, 25 Jun 2003 15:39:38 +0200
parents 6d30311f772b
children 08511ef1fa5c
files xul/annota/annota.js xul/annota/annota.xul xul/annota/rdfds.js xul/annota/tools_dialog.xul
diffstat 4 files changed, 1165 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/xul/annota/annota.js	Wed Jun 25 15:39:38 2003 +0200
@@ -0,0 +1,319 @@
+include ('chrome://jslib/content/io/dir.js');
+include ('chrome://jslib/content/io/file.js');
+include ('chrome://jslib/content/io/rdfBase.js');
+include ('chrome://jslib/content/io/rdfResource.js');
+include ('chrome://jslib/content/io/rdfContainer.js');
+include ('chrome://jslib/content/io/rdf.js');
+include ('chrome://jslib/content/io/rdfFile.js');
+include('chrome://jslib/content/io/fileUtils.js');
+
+var slash='/';
+if (navigator.platform=="Win32"){
+   slash='\\';
+}
+
+var directory=slash;
+var digilib_path=slash;
+
+getProfile(); 
+
+function makePathCompatible(path){
+  if (navigator.platform=="Win32"){
+    // slash durch backslash ersetzten
+    path=path.replace(/\//g,"\\");
+    // nur 2 backslashs am anfang
+    path=path.replace(/^\\{3}/,"\\\\");
+    // vor Laufwerkbuchstaben kein Backslash
+    if (path.indexOf(":")>0){
+      path=path.replace(/^\\/g,"");
+    }
+    // nur ein Slash gibt Absturz
+    path=path.replace(/^\\$/,"c:\\");
+    //alert(path);
+  }
+  return path;
+}
+
+function file_open(){
+  var nsIFilePicker = Components.interfaces.nsIFilePicker;
+  var fp = Components.classes["@mozilla.org/filepicker;1"]
+        .createInstance(nsIFilePicker);
+  fp.init(window, "Select a Directory", nsIFilePicker.modeGetFolder);
+
+  // set default direcotry
+  var aLocalFile = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
+  directory=makePathCompatible(directory);
+  aLocalFile.initWithPath(directory);
+  fp.displayDirectory=aLocalFile;
+
+  var res=fp.show();
+  if (res==nsIFilePicker.returnOK){
+    directory=fp.fileURL.path;
+    directory=makePathCompatible(directory);
+    setTreeDirectory();
+  }
+}
+
+function setTreeDirectory(){
+    var t=document.getElementById("file_tree");
+    t.setAttribute("ref","file://"+directory);
+}
+
+function refreshTree(){
+   var t=document.getElementById("file_tree");
+   t.builder.rebuild(); 
+}
+
+function file_save(){
+  
+  // get Digilib-Parameter form Browser
+  // alert(window.content.location.href);
+
+ var documentpath='';
+   try{
+      documentpath=window.content.getParameter('fn'); 
+   }catch (e){
+      documentpath='';
+   }
+   if (documentpath != ''){
+     var docPath='urn:echo:'+documentpath;
+
+      var rdfString='<?xml version="1.0"?>' +
+                  '<RDF:RDF xmlns:NS1="http://echo.unibe.ch/digilib/rdf#"' +
+                  '         xmlns:RDF="http://www.w3.org/1999/02/22-rdf-syntax-ns#"' +
+                  '         xmlns:d="http://purl.org/dc/elements/1.0/"' +
+                  '         xmlns:a="http://www.w3.org/2000/10/annotation-ns#">' +
+                  '         <RDF:Seq RDF:about="urn:echo">' +
+                  '         <RDF:li RDF:resource="'+docPath+'"/>' +
+                  '         </RDF:Seq>' +   
+                  '         <RDF:Description RDF:about="'+docPath+'" NS1:page=0"/>'+
+                  '</RDF:RDF>';
+
+     var ds=new RDFDataSource();
+     ds.parseFromString(rdfString,"http://echo.unibe.ch/digilib/rdf/digilib.rdf");
+     var node=ds.getNode(docPath);
+     var arrayParams=window.content.listParameters();
+     for (i=0; i< arrayParams.length; i++){
+        var value=window.content.getParameter(arrayParams[i]);
+        //alert(arrayParams[i]+":"+value);
+        node.addTarget("http://echo.unibe.ch/digilib/rdf#"+arrayParams[i],value);
+     }
+     node.addTarget("http://echo.unibe.ch/digilib/rdf#lv","1");
+     //alert(ds.serializeToString());
+     var nsIFilePicker = Components.interfaces.nsIFilePicker;
+     var fp = Components.classes["@mozilla.org/filepicker;1"]
+           .createInstance(nsIFilePicker);
+     fp.init(window, "Select a File", nsIFilePicker.modeSave);
+
+     // set default direcotry
+     var aLocalFile = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
+     directory=makePathCompatible(directory);
+     aLocalFile.initWithPath(directory);
+     fp.displayDirectory=aLocalFile;     
+
+     fp.appendFilter("Annotations","*.rdf; *.RDF");
+     var res=fp.show();
+     if (res==nsIFilePicker.returnOK){
+       var thefile=fp.file;
+       // --- do something with the file here ---
+       //alert(fp.file);
+       //alert(fp.fileURL.path);
+       
+       var strFilePath=fp.file.path;
+       strFilePath=strFilePath.toLowerCase();
+       if (strFilePath.indexOf('.rdf')<0){
+          strFilePath=fp.fileURL.path+".rdf";
+       }else{
+          strFilePath=fp.fileURL.path;
+       }
+       strFilePath=makePathCompatible(strFilePath);
+       var f=new File(strFilePath);
+       //var boolFileExists=f.exists();
+       //alert(boolFileExists);
+       f.create();
+       f.open('w');
+       f.write(ds.serializeToString());
+       f.close();
+       refreshTree();
+     }
+  }else{
+     alert("Error: no alcatraz component. can't create an annotation.");
+  }
+}
+
+function file_local(){
+  // noch nicht programmiert
+}
+
+function file_annotaDB(){
+  alert("At the moment it is not possible to use the annota DB! This feature is not yet programmed.");
+  var menu_item=document.getElementById('local');
+  menu_item.setAttribute('checked','true');
+}
+
+function tree_click(){
+   var t=document.getElementById("file_tree");    //tree element
+   var l=t.view.getItemAtIndex(t.currentIndex);   //aus baum treeitem herausholen mit dem selected index (currentIndex)   
+                                                  //l.firstChild ist treeitem
+   var d=l.firstChild.firstChild;                 //treecell
+   var firstLabel=d.getAttribute("label"); 
+   var cols=document.getElementById("cols");
+   var col=cols.childNodes;
+   var nodes=l.firstChild.childNodes;
+   var rdf_file="";
+   for (var i=0;i<nodes.length;i++){
+      if (col[i].getAttribute("label")=="URL"){
+         rdf_file=nodes[i].getAttribute("label");
+      }
+   }
+   if (rdf_file!=""){
+     send_annotation(rdf_file);
+   }
+   return rdf_file;  
+}
+
+
+/***
+* Diese Funktion wird gebraucht um im Dialog den Pfad zu digilib zu setzen
+*
+***/
+function setDigilibPath(digilibPathValue){
+   digilib_path=digilibPathValue;
+}
+
+/***
+* Dialog tools momentan kann man nur den Pfad zu digilib setzen
+*
+***/
+function show_dialog(dialog){
+  if (dialog=="tool path"){
+    window.openDialog("tools_dialog.xul","funny dialog",
+                  "chrome",digilib_path,setDigilibPath);
+  }
+}
+
+
+/***
+* Gibt den Inhalt eines Files als String zurueck
+*
+***/
+function readFile(str_Filename){
+  var f=new File(str_Filename);
+  var str="";
+  if (f.isFile()){
+    f.open();
+    str=f.read();
+    f.close();
+  }
+  return str;
+} 
+
+
+
+function send_annotation(rdf_file){
+   rdf_file=rdf_file.replace(/^file:\/\//,"");
+   rdf_file=makePathCompatible(rdf_file);
+   strRdfFile=readFile(rdf_file);
+   if (strRdfFile!=""){
+     var formid='mainform';   
+     var form = createForm(formid, digilib_path+"/digilib.jsp", "post", "_content");
+     //var form = createForm(formid, "http://sophia.unibe.ch:8080/examples/servlet/RequestRDF", "post", "_content");
+     //var form = createForm(formid, "http://hera.unibe.ch:8080/examples/servlet/RequestRDF", "post", "_content");
+     setFormData(form, formid, strRdfFile);
+     form.submit();
+   }
+}
+
+function createForm(formid, action, method, target)
+{
+     var form = document.getElementById(formid);
+     if(form != null)
+     document.documentElement.removeChild(form);
+
+     var form = document.createElementNS("http://www.w3.org/1999/xhtml", "form");
+     form.setAttribute("id", formid);
+     form.setAttribute("action", action);
+     form.setAttribute("method", method);
+     form.setAttribute("target", target);
+     document.documentElement.appendChild(form);
+     return form;
+}
+
+function setFormData(form, formid, rdf)
+{
+     var val1 = document.createElementNS("http://www.w3.org/1999/xhtml", "input");
+     val1.setAttribute('type', 'hidden');
+     val1.setAttribute('name', 'rdf');
+     val1.setAttribute('value', rdf);
+     form.appendChild(val1); 
+}
+
+
+function getProfileDirectory(){
+ // First get the directory service and query interface it to
+   // nsIProperties
+   var dirService = Components.
+       classes['@mozilla.org/file/directory_service;1'].
+       getService(Components.interfaces.nsIProperties);
+ 
+   // Next get the "ProfD" property of type nsIFile from the directory
+   // service, FYI this constant is defined in
+   // mozilla/xpcom/io/nsAppDirectoryServiceDefs.h
+ 
+   const NS_APP_USER_PROFILE_50_DIR = "ProfD";
+   profileDir = dirService.get(NS_APP_USER_PROFILE_50_DIR,
+        Components.interfaces.nsIFile);
+ 
+   // Now that we have it we can show it's path. See nsIFile for the
+   // other things you that can be done with profileDir
+   //alert(profileDir.path);
+   return profileDir.path;
+}
+
+function getProfile(){
+   var strProfile=readFile(getProfileDirectory()+slash+"annota.dat");
+   if (strProfile==""){
+      directory=slash;
+      digilib_path="http://hera.unibe.ch:8080/alcatraz";
+      setProfile();
+   }else{
+      var params=strProfile.split("\n");
+      for (var i=0;i<params.length;i++){
+         var key_value=params[i].split("|");
+	 if (key_value[0]=='directory'){
+	    directory=key_value[1];
+         }
+	 if (key_value[0]=='tool path'){
+	    digilib_path=key_value[1];
+         }
+      }
+   }
+}
+
+function setProfile(){
+   var f=new File(getProfileDirectory()+slash+'annota.dat');
+   f.create();
+   f.open('w');
+   f.write('directory|'+directory+'\n'+'tool path|'+digilib_path+'\n');
+   f.close();
+}
+
+function traverse(node){
+   if (node.hasChildNodes){   
+      var arr_nodes=node.childNodes;  
+      for (var i=0;i<arr_nodes.length;i++){
+	 if (arr_nodes[i].getAttribute("open")){
+            //alert(arr_nodes[i].getAttribute("open"));
+            if (arr_nodes[i].hasChildNodes && arr_nodes[i].firstChild.hasChildNodes){
+               alert(arr_nodes[i].firstChild.firstChild.getAttribute("label"));
+            }
+         }         
+         traverse(arr_nodes[i]);  
+      }
+   }
+}
+
+function traverseTree(){
+    var t=document.getElementById("file_tree");
+    traverse(t);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/xul/annota/annota.xul	Wed Jun 25 15:39:38 2003 +0200
@@ -0,0 +1,57 @@
+<?xml version="1.0"?>
+
+<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
+
+<window id="example-window" title="Example 5.1.1"
+        xmlns:html="http://www.w3.org/1999/xhtml"
+        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
+        onload="setTreeDirectory()">
+<toolbox flex="1">
+  <script type="application/x-javascript" src="chrome://jslib/content/jslib.js" />
+  <script language="JavaScript" src="annota.js"/>
+  <script language="JavaScript" src="rdfds.js"/>
+  <menubar id="sample-menubar">
+    <menu id="file-menu" label="File">
+      <menupopup id="file-popup">
+        <menuitem label="Save" onclick="file_save()" />
+      </menupopup>
+    </menu>
+    <menu id="edit-menu" label="Options">
+      <menupopup id="edit-popup">
+        <menuitem id="local" label="Local" type="radio" name="location" checked="true" onclick="file_local()" />
+        <menuitem id="annotaDB" label="Annota DB" type="radio" name="location" onclick="file_annotaDB()" />        
+        <menuseparator/>
+        <menuitem id="tool_path" label="Tool URL" onclick="show_dialog('tool path')" />  
+        <menuitem id="annotations_path" label="Path to annotations" onclick="file_open()" />       
+        <menuseparator/>
+        <menuitem id="save_options" label="Save Options" onclick="setProfile()" />   
+      </menupopup>
+    </menu>
+  </menubar>
+</toolbox>
+<vbox flex="100">
+  <tree id="file_tree" flex="1" datasources="rdf:files" ref="file:///" ondblclick="tree_click()">
+
+    <treecols id="cols">
+      <treecol id="name" label="Name" primary="true" flex="1"/>
+      <treecol id="url" label="URL" hidden="true" flex="1"/>
+    </treecols>
+
+    <template>
+
+      <rule>
+        <treechildren flex="1" >
+         <treeitem uri="rdf:*" persist="open">
+           <treerow>
+             <treecell label="rdf:http://home.netscape.com/NC-rdf#Name"/>
+             <treecell label="rdf:http://home.netscape.com/NC-rdf#URL"/>
+           </treerow>
+         </treeitem>
+        </treechildren>
+      </rule>
+      
+    </template>
+  </tree>
+
+</vbox>
+</window>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/xul/annota/rdfds.js	Wed Jun 25 15:39:38 2003 +0200
@@ -0,0 +1,760 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
+ * The contents of this file are subject to the Mozilla Public
+ * License Version 1.1 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS
+ * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
+ * implied. See the License for the specific language governing
+ * rights and limitations under the License.
+ *
+ * The Original Code is rdfds
+ *
+ * The Initial Developer of the Original Code is Neil Deakin
+ * Portions created by Neil Deakin are Copyright (C) 2002 Neil Deakin.
+ * All Rights Reserved.
+ *
+ * Contributor(s):
+ */
+
+/* This is a library for easier access to RDF datasources and resources.
+ * It contains four objects, RDFDataSource, RDFNode, RDFLiteral. and
+ * RDFEnumerator.
+ *
+ * An RDF DataSource is a graph of nodes and literals. The constructor
+ * for RDFDataSource takes one argument, a URI of an RDF file to use.
+ * If the URI exists, the contents of the RDF file are loaded. If it
+ * does not exist, resources can be added to it and then written using
+ * this save method. If the URL argument is null, a blank datasource
+ * is created.
+ *
+ * This library is designed for convenience not for efficiency.
+ *
+ * The API is documented at:
+ *   http://www.xulplanet.com/tutorials/xultu/rdfds/
+ *
+ * Example:
+ *
+ * var ds=new RDFDataSource("file:///main/mozilla/mimtest.rdf");
+ * var node=ds.getNode("urn:xpimaker:packlist");
+ * var child=ds.getNode("urn:xpimaker:packlist:appinfo");
+ * child=node.addChild(child);
+ * child.addTarget("http://www.xulplanet.com/rdf/xpimaker#appname","Find Files");
+ * ds.save();
+ *
+ */
+
+var RDFService = "@mozilla.org/rdf/rdf-service;1";
+RDFService = Components.classes[RDFService].getService();
+RDFService = RDFService.QueryInterface(Components.interfaces.nsIRDFService);
+
+var RDFContainerUtilsService = "@mozilla.org/rdf/container-utils;1";
+RDFContainerUtilsService = Components.classes[RDFContainerUtilsService].getService();
+RDFContainerUtilsService = RDFContainerUtilsService.QueryInterface(Components.interfaces.nsIRDFContainerUtils);
+
+/* RDFLoadObserver
+ *   this object is necessary to listen to RDF files being loaded. The Init
+ *   function should be called to initialize the callback when the RDF file is
+ *   loaded.
+ */
+function RDFLoadObserver(){}
+  
+RDFLoadObserver.prototype =
+{
+  callback: null,
+  callbackDataSource: null,
+
+  Init: function(c,cDS){
+    this.callback=c;
+    this.callbackDataSource=cDS;
+  },
+
+  QueryInterface: function(iid){
+    if (iid.equals(Components.interfaces.nsIRDFXMLSinkObserver)) return this;
+    else throw Components.results.NS_ERROR_NO_INTERFACE;
+  },
+
+  onBeginLoad : function(sink){},
+  onInterrupt : function(sink){},
+  onResume : function(sink){},
+  onError : function(sink,status,msg){},
+ 
+  onEndLoad : function(sink){
+    if (this.callback!=null) this.callback(this.callbackDataSource);
+  }
+};  
+
+function RDFDataSource(uri,callbackFn)
+{
+  if (uri==null) this.datasource=null;
+  else this.load(uri,callbackFn);
+}
+
+RDFDataSource.prototype.load=
+  function(uri,callbackFn)
+{
+  if (uri.indexOf(":") == -1){
+    var docurl=document.location.href;
+    if (document.location.pathname == null) uri=docurl+"/"+uri;
+    else uri=docurl.substring(0,docurl.lastIndexOf("/")+1)+uri;
+  }
+
+  if (callbackFn == null){
+    this.datasource=RDFService.GetDataSourceBlocking(uri);
+  }
+  else {
+    this.datasource=RDFService.GetDataSource(uri);
+    var ds;
+    try {
+      var ds=this.datasource.QueryInterface(Components.interfaces.nsIRDFRemoteDataSource);
+    }
+    catch (ex){
+      callbackFn(this);
+      return;
+    }
+    if (ds.loaded){
+      callbackFn(this);
+      return;
+    }
+
+    var packObserver=new RDFLoadObserver();
+    packObserver.Init(callbackFn,this);
+
+    var rawsource=this.datasource;
+    rawsource=rawsource.QueryInterface(Components.interfaces.nsIRDFXMLSink);
+    rawsource.addXMLSinkObserver(packObserver);
+  }
+}
+
+RDFDataSource.prototype.Init=
+  function (dsource)
+{
+  this.datasource=dsource;
+}
+
+RDFDataSource.prototype.parseFromString=
+  function (str,baseUri)
+{
+  if (this.datasource==null) this.makeemptyds();
+  var ios=Components.classes["@mozilla.org/network/io-service;1"]
+                    .getService(Components.interfaces.nsIIOService);
+  baseUri=ios.newURI(baseUri,null,null);
+  var xmlParser=Components.classes["@mozilla.org/rdf/xml-parser;1"]
+                          .createInstance(Components.interfaces.nsIRDFXMLParser);
+  xmlParser.parseString(this.datasource,baseUri,str);
+}
+
+RDFDataSource.prototype.serializeToString=
+  function ()
+{
+  var outputStream = {
+    data: "",
+    close : function(){},
+    flush : function(){},
+    write : function (buffer,count){
+      this.data += buffer;
+      return count;
+    },
+    writeFrom : function (stream,count){},
+    isNonBlocking: false
+  }
+  this.serializeToStream(outputStream);
+  return outputStream.data;
+}
+
+RDFDataSource.prototype.serializeToStream=
+  function (outputStream)
+{
+  var ser=Components.classes["@mozilla.org/rdf/xml-serializer;1"]
+                    .createInstance(Components.interfaces.nsIRDFXMLSerializer);
+  ser.init(this.datasource);
+  ser.QueryInterface(Components.interfaces.nsIRDFXMLSource).Serialize(outputStream);
+}
+
+RDFDataSource.prototype.makeemptyds=
+  function (uri)
+{
+  this.datasource=Components.classes["@mozilla.org/rdf/datasource;1?name=in-memory-datasource"]
+                            .createInstance(Components.interfaces.nsIRDFDataSource);
+}
+
+RDFDataSource.prototype.getAllResources=
+  function ()
+{
+  if (this.datasource==null) return null;
+  return new RDFEnumerator(this.datasource.GetAllResources(),this.datasource);
+}
+
+RDFDataSource.prototype.getRawDataSource=
+  function ()
+{
+  if (this.datasource==null) this.makeemptyds();
+  return this.datasource;
+}
+
+RDFDataSource.prototype.getNode=
+  function (uri)
+{
+  if (this.datasource==null) this.makeemptyds();
+  var node=new RDFNode(uri,this);
+  return node;
+}
+
+RDFDataSource.prototype.getAnonymousNode=
+  function ()
+{
+  if (this.datasource==null) this.makeemptyds();
+
+  var anon=RDFService.GetAnonymousResource();
+  var node=new RDFNode();
+  node.Init(anon,this.datasource);
+  return node;
+}
+
+RDFDataSource.prototype.getLiteral=
+  function (uri)
+{
+  if (this.datasource==null) this.makeemptyds();
+
+  return new RDFLiteral(uri,this);
+}
+
+RDFDataSource.prototype.refresh=
+  function (sync)
+{
+  try {
+    var ds=this.datasource.QueryInterface(Components.interfaces.nsIRDFRemoteDataSource);
+    ds.Refresh(sync);
+    return true;
+  }
+  catch (ex){
+    return false;
+  }
+}
+
+RDFDataSource.prototype.save=
+  function ()
+{
+  try {
+    var ds=this.datasource.QueryInterface(Components.interfaces.nsIRDFRemoteDataSource);
+    ds.Flush();
+    return true;
+  }
+  catch (ex){
+    return false;
+  }
+}
+
+RDFDataSource.prototype.copyAllToDataSource=
+  function (dsource2)
+{
+  if (this.datasource==null) this.makeemptyds();
+  if (dsource2.datasource==null) dsource2.makeemptyds();
+
+  var dsource1=this.datasource;
+  dsource2=dsource2.datasource;
+
+  var sourcelist=dsource1.GetAllResources();
+  while(sourcelist.hasMoreElements()){
+    var source=sourcelist.getNext();
+    var props=dsource1.ArcLabelsOut(source);
+    while(props.hasMoreElements()){
+      var prop=props.getNext();
+      prop=prop.QueryInterface(Components.interfaces.nsIRDFResource);
+      var target=dsource1.GetTarget(source,prop,true);
+      if (target!=null) dsource2.Assert(source,prop,target,true);
+    }
+  }
+}
+
+RDFDataSource.prototype.deleteRecursive=
+  function (val)
+{
+  var node;
+  var dsource=this.datasource;
+
+  if (dsource==null) return;
+
+  if (typeof val == "string") node=RDFService.GetResource(val);
+  else node=val.source;
+
+  this.deleteRecursiveH(dsource,node); // remove descendants
+
+  // remove the node itself
+  var props=dsource.ArcLabelsIn(node);
+  while(props.hasMoreElements()){
+    var prop=props.getNext();
+    var source=dsource.GetSource(prop,node,true);
+    dsource.Unassert(source,prop,node);
+  }
+}
+
+RDFDataSource.prototype.deleteRecursiveH=
+  function (dsource,node)
+{
+  var props=dsource.ArcLabelsOut(node);
+  while(props.hasMoreElements()){
+    var prop=props.getNext();
+    var target=dsource.GetTarget(node,prop,true);
+    try {
+      target=target.QueryInterface(Components.interfaces.nsIRDFResource);
+      this.deleteRecursiveH(dsource,target);
+    }
+    catch (e){}
+    dsource.Unassert(node,prop,target)
+  }
+}
+
+function RDFNode(uri,dsource)
+{
+  if (uri==null) this.source=null;
+  else this.source=RDFService.GetResource(uri);
+
+  if (dsource==null) this.datasource=null;
+  else this.datasource=dsource.datasource;
+
+  this.container=null;
+}
+
+RDFNode.prototype.Init=
+  function (source,dsource)
+{
+  this.source=source;
+  this.datasource=dsource;
+  this.container=null;
+}
+
+RDFNode.prototype.getValue=
+  function ()
+{
+  return this.source.Value;
+}
+
+RDFNode.prototype.rlify=
+  function (val)
+{
+  var res=null;
+
+  if (val!=null){
+    try {
+      val=val.QueryInterface(Components.interfaces.nsIRDFResource);
+      res=new RDFNode();
+      res.Init(val,this.datasource);
+    }
+    catch (ex){
+      try {
+        val=val.QueryInterface(Components.interfaces.nsIRDFLiteral);
+        res=new RDFLiteral();
+        res.Init(val,this.datasource);
+      }
+      catch (ex2){
+      }
+    }
+  }
+  return res;
+}
+
+RDFNode.prototype.makeres=
+  function (val)
+{
+  if (typeof val == "string") return RDFService.GetResource(val);
+  else return val.source;
+}
+
+RDFNode.prototype.makelit=
+  function (val)
+{
+  if (typeof val == "string") return RDFService.GetLiteral(val);
+  else return val.source;
+}
+
+RDFNode.prototype.makecontain=
+  function ()
+{
+  if (this.container!=null) return true;
+
+  var RDFContainer = '@mozilla.org/rdf/container;1';
+  RDFContainer = Components.classes[RDFContainer].createInstance();
+  RDFContainer = RDFContainer.QueryInterface(Components.interfaces.nsIRDFContainer);
+
+  try {
+    RDFContainer.Init(this.datasource,this.source);
+    this.container=RDFContainer;
+    return true;
+  }
+  catch (ex){
+    return false;
+  }
+}
+
+RDFNode.prototype.addTarget=
+  function (prop,target)
+{
+  prop=this.makeres(prop);
+  target=this.makelit(target);
+  this.datasource.Assert(this.source,prop,target,true);
+}
+
+RDFNode.prototype.addTargetOnce=
+  function (prop,target)
+{
+  prop=this.makeres(prop);
+  target=this.makelit(target);
+
+  var oldtarget=this.datasource.GetTarget(this.source,prop,true);
+  if (oldtarget!=null){
+    this.datasource.Change(this.source,prop,oldtarget,target);
+  }
+  else {
+    this.datasource.Assert(this.source,prop,target,true);
+  }
+}
+
+RDFNode.prototype.modifyTarget=
+  function (prop,oldtarget,newtarget)
+{
+  prop=this.makeres(prop);
+  oldtarget=this.makelit(oldtarget);
+  newtarget=this.makelit(newtarget);
+  this.datasource.Change(this.source,prop,oldtarget,newtarget);
+}
+
+RDFNode.prototype.modifySource=
+  function (prop,oldsource,newsource)
+{
+  prop=this.makeres(prop);
+  oldsource=this.makeres(oldsource);
+  newsource=this.makeres(newsource);
+  this.datasource.Move(oldsource,newsource,prop,this.source);
+}
+
+RDFNode.prototype.targetExists=
+  function (prop,target)
+{
+  prop=this.makeres(prop);
+  target=this.makelit(target);
+  return this.datasource.HasAssertion(this.source,prop,target,true);
+}
+
+RDFNode.prototype.removeTarget=
+  function (prop,target)
+{
+  prop=this.makeres(prop);
+  target=this.makelit(target);
+  this.datasource.Unassert(this.source,prop,target);
+}
+
+RDFNode.prototype.getProperties=
+  function ()
+{
+  return new RDFEnumerator(this.datasource.ArcLabelsOut(this.source),this.datasource);
+}
+
+RDFNode.prototype.getInProperties=
+  function ()
+{
+  return new RDFEnumerator(this.datasource.ArcLabelsIn(this.source),this.datasource);
+}
+
+RDFNode.prototype.propertyExists=
+  function (prop)
+{
+  prop=this.makeres(prop);
+  return this.datasource.hasArcOut(this.source,prop);
+}
+
+RDFNode.prototype.inPropertyExists=
+  function (prop)
+{
+  prop=this.makeres(prop);
+  return this.datasource.hasArcIn(this.source,prop);
+}
+
+RDFNode.prototype.getTarget=
+  function (prop)
+{
+  prop=this.makeres(prop);
+  return this.rlify(this.datasource.GetTarget(this.source,prop,true));
+}
+
+RDFNode.prototype.getSource=
+  function (prop)
+{
+  prop=this.makeres(prop);
+  var src=this.datasource.GetSource(prop,this.source,true);
+  if (src==null) return null;
+  var res=new RDFNode();
+  res.Init(src,this.datasource);
+  return res;
+}
+
+RDFNode.prototype.getTargets=
+  function (prop)
+{
+  prop=this.makeres(prop);
+  return new RDFEnumerator(
+    this.datasource.GetTargets(this.source,prop,true),this.datasource);
+}
+
+RDFNode.prototype.getSources=
+  function (prop)
+{
+  prop=this.makeres(prop);
+  return new RDFEnumerator(
+    this.datasource.GetSources(prop,this.source,true),this.datasource);
+}
+
+RDFNode.prototype.makeBag=
+  function ()
+{
+  this.container=RDFContainerUtilsService.MakeBag(this.datasource,this.source);
+}
+
+RDFNode.prototype.makeSeq=
+  function ()
+{
+  this.container=RDFContainerUtilsService.MakeSeq(this.datasource,this.source);
+}
+
+RDFNode.prototype.makeAlt=
+  function ()
+{
+  this.container=RDFContainerUtilsService.MakeAlt(this.datasource,this.source);
+}
+
+RDFNode.prototype.isBag=
+  function ()
+{
+  return RDFContainerUtilsService.isBag(this.datasource,this.source);
+}
+
+RDFNode.prototype.isSeq=
+  function ()
+{
+  return RDFContainerUtilsService.isSeq(this.datasource,this.source);
+}
+
+RDFNode.prototype.isAlt=
+  function ()
+{
+  return RDFContainerUtilsService.isAlt(dsource,this.source);
+}
+
+RDFNode.prototype.isContainer=
+  function ()
+{
+  return RDFContainerUtilsService.IsContainer(this.datasource,this.source);
+}
+
+RDFNode.prototype.getChildCount=
+  function ()
+{
+  if (this.makecontain()){
+    return this.container.GetCount();
+  }
+  return -1;
+}
+
+RDFNode.prototype.getChildren=
+  function ()
+{
+  if (this.makecontain()){
+    return new RDFEnumerator(this.container.GetElements(),this.datasource);
+  }
+  else return null;
+}
+
+RDFNode.prototype.addChild=
+  function (child,exists)
+{
+  if (this.makecontain()){
+    var childres=null;
+    if (typeof child == "string"){
+      childres=RDFService.GetResource(child);
+      child=new RDFNode();
+      child.Init(childres,this.datasource);
+    }
+    else childres=child.source;
+
+    if (!exists && this.container.IndexOf(childres)>=0) return child;
+
+    this.container.AppendElement(childres);
+    return child;
+  }
+  else return null;
+}
+
+RDFNode.prototype.addChildAt=
+  function (child,idx)
+{
+  if (this.makecontain()){
+    var childres=null;
+    if (typeof child == "string"){
+      childres=RDFService.GetResource(child);
+      child=new RDFNode();
+      child.Init(childres,this.datasource);
+    }
+    else childres=child.source;
+    this.container.InsertElementAt(childres,idx,true);
+    return child;
+  }
+  else return null;
+}
+
+RDFNode.prototype.removeChild=
+  function (child)
+{
+  if (this.makecontain()){
+    var childres=null;
+    if (typeof child == "string"){
+      childres=RDFService.GetResource(child);
+      child=new RDFNode();
+      child.Init(childres,this.datasource);
+    }
+    else childres=child.source;
+    this.container.RemoveElement(childres,true);
+    return child;
+  }
+  else return null;
+}
+
+RDFNode.prototype.removeChildAt=
+  function (idx)
+{
+  if (this.makecontain()){
+    var childres=this.container.RemoveElementAt(idx,true);
+    return this.rlify(childres);
+  }
+  else return null;
+}
+
+RDFNode.prototype.getChildIndex=
+  function (child)
+{
+  if (this.makecontain()){
+    return this.container.IndexOf(child.source);
+  }
+  else return -1;
+}
+
+RDFNode.prototype.type="Node";
+
+
+function RDFLiteral(val,dsource)
+{
+  if (val==null) this.source=null;
+  else this.source=RDFService.GetLiteral(val);
+
+  if (dsource==null) this.datasource=null;
+  else this.datasource=dsource.datasource;
+}
+
+RDFLiteral.prototype.Init=
+  function (source,dsource)
+{
+  this.source=source;
+  this.datasource=dsource;
+}
+
+RDFLiteral.prototype.getValue=
+  function ()
+{
+  return this.source.Value;
+}
+
+RDFLiteral.prototype.makeres=
+  function (val)
+{
+  if (typeof val == "string") return RDFService.GetResource(val);
+  else return val.source;
+}
+
+RDFLiteral.prototype.makelit=
+  function (val)
+{
+  if (typeof val == "string") return RDFService.GetLiteral(val);
+  else return val.source;
+}
+
+RDFLiteral.prototype.modifySource=
+  function (prop,oldsource,newsource)
+{
+  prop=this.makeres(prop);
+  oldsource=this.makeres(oldsource);
+  newsource=this.makeres(newsource);
+  this.datasource.Move(oldsource,newsource,prop,this.source);
+}
+
+RDFLiteral.prototype.getInProperties=
+  function (prop)
+{
+  return new RDFEnumerator(this.datasource.ArcLabelsIn(this.source),this.datasource);
+}
+
+RDFLiteral.prototype.inPropertyExists=
+  function (prop)
+{
+  prop=this.makeres(prop);
+  return this.datasource.hasArcIn(this.source,prop);
+}
+
+RDFLiteral.prototype.getSource=
+  function (prop)
+{
+  prop=this.makeres(prop);
+  var src=this.datasource.GetSource(prop,this.source,true);
+  if (src==null) return null;
+  var res=new RDFNode();
+  res.Init(src,this.datasource);
+  return res;
+}
+
+RDFLiteral.prototype.getSources=
+  function (prop)
+{
+  prop=this.makeres(prop);
+  return new RDFEnumerator(
+    this.datasource.GetSources(prop,this.source,true),this.datasource);
+}
+
+RDFLiteral.prototype.type="Literal";
+
+
+function RDFEnumerator(enumeration,dsource)
+{
+  this.enumeration=enumeration;
+  this.datasource=dsource;
+}
+
+RDFEnumerator.prototype.hasMoreElements=
+  function ()
+{
+  return this.enumeration.hasMoreElements();
+}
+
+RDFEnumerator.prototype.getNext=
+  function ()
+{
+  var res=null;
+  var val=this.enumeration.getNext();
+
+  if (val!=null){
+    try {
+      val=val.QueryInterface(Components.interfaces.nsIRDFResource);
+      res=new RDFNode();
+      res.Init(val,this.datasource);
+    }
+    catch (ex){
+      try {
+        val=val.QueryInterface(Components.interfaces.nsIRDFLiteral);
+        res=new RDFLiteral();
+        res.Init(val,this.datasource);
+      }
+      catch (ex2){
+      }
+    }
+  }
+  return res;
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/xul/annota/tools_dialog.xul	Wed Jun 25 15:39:38 2003 +0200
@@ -0,0 +1,29 @@
+<?xml version="1.0"?>
+
+<?xml-stylesheet href="chrome://global/skin/global.css" type="text/css"?>
+
+<dialog id="donothing" title="tool path"
+        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
+        buttons="accept,cancel"
+        ondialogaccept="return doOK();"
+        ondialogcancel="return doCancel();">
+
+<label control="digilib_path" value="tool path (where you can find digilib.jsp)"/>
+<textbox id="digilib_path"/>
+<script>
+document.getElementById('digilib_path').value=window.arguments[0];
+
+function doOK()
+{
+  window.arguments[1](document.getElementById('digilib_path').value);
+  return true;
+}
+
+function doCancel()
+{
+  return true;
+}
+
+</script>
+
+</dialog>