# HG changeset patch # User engler # Date 1056548378 -7200 # Node ID bf6d9b7a77d4c30f7925ba3b3c7154c827e43741 # Parent 6d30311f772b9004bc5ba9854653cdfc0d9e6dd6 Annotation Tool to integrate in chrome sidebar diff -r 6d30311f772b -r bf6d9b7a77d4 xul/annota/annota.js --- /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='' + + '' + + ' ' + + ' ' + + ' ' + + ' '+ + ''; + + 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 + + + + + + + +