125
|
1 include ('chrome://jslib/content/io/dir.js');
|
|
2 include ('chrome://jslib/content/io/file.js');
|
|
3 include ('chrome://jslib/content/io/rdfBase.js');
|
|
4 include ('chrome://jslib/content/io/rdfResource.js');
|
|
5 include ('chrome://jslib/content/io/rdfContainer.js');
|
|
6 include ('chrome://jslib/content/io/rdf.js');
|
|
7 include ('chrome://jslib/content/io/rdfFile.js');
|
|
8 include('chrome://jslib/content/io/fileUtils.js');
|
|
9
|
|
10 var slash='/';
|
|
11 if (navigator.platform=="Win32"){
|
|
12 slash='\\';
|
|
13 }
|
|
14
|
|
15 var directory=slash;
|
|
16 var digilib_path=slash;
|
|
17
|
|
18 getProfile();
|
|
19
|
|
20 function makePathCompatible(path){
|
|
21 if (navigator.platform=="Win32"){
|
|
22 // slash durch backslash ersetzten
|
|
23 path=path.replace(/\//g,"\\");
|
|
24 // nur 2 backslashs am anfang
|
|
25 path=path.replace(/^\\{3}/,"\\\\");
|
|
26 // vor Laufwerkbuchstaben kein Backslash
|
|
27 if (path.indexOf(":")>0){
|
|
28 path=path.replace(/^\\/g,"");
|
|
29 }
|
|
30 // nur ein Slash gibt Absturz
|
|
31 path=path.replace(/^\\$/,"c:\\");
|
|
32 //alert(path);
|
|
33 }
|
|
34 return path;
|
|
35 }
|
|
36
|
|
37 function file_open(){
|
|
38 var nsIFilePicker = Components.interfaces.nsIFilePicker;
|
|
39 var fp = Components.classes["@mozilla.org/filepicker;1"]
|
|
40 .createInstance(nsIFilePicker);
|
|
41 fp.init(window, "Select a Directory", nsIFilePicker.modeGetFolder);
|
|
42
|
|
43 // set default direcotry
|
|
44 var aLocalFile = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
|
|
45 directory=makePathCompatible(directory);
|
|
46 aLocalFile.initWithPath(directory);
|
|
47 fp.displayDirectory=aLocalFile;
|
|
48
|
|
49 var res=fp.show();
|
|
50 if (res==nsIFilePicker.returnOK){
|
|
51 directory=fp.fileURL.path;
|
|
52 directory=makePathCompatible(directory);
|
|
53 setTreeDirectory();
|
|
54 }
|
|
55 }
|
|
56
|
|
57 function setTreeDirectory(){
|
|
58 var t=document.getElementById("file_tree");
|
|
59 t.setAttribute("ref","file://"+directory);
|
|
60 }
|
|
61
|
|
62 function refreshTree(){
|
|
63 var t=document.getElementById("file_tree");
|
|
64 t.builder.rebuild();
|
|
65 }
|
|
66
|
|
67 function file_save(){
|
|
68
|
|
69 // get Digilib-Parameter form Browser
|
|
70 // alert(window.content.location.href);
|
|
71
|
|
72 var documentpath='';
|
|
73 try{
|
|
74 documentpath=window.content.getParameter('fn');
|
|
75 }catch (e){
|
|
76 documentpath='';
|
|
77 }
|
|
78 if (documentpath != ''){
|
|
79 var docPath='urn:echo:'+documentpath;
|
|
80
|
|
81 var rdfString='<?xml version="1.0"?>' +
|
|
82 '<RDF:RDF xmlns:NS1="http://echo.unibe.ch/digilib/rdf#"' +
|
|
83 ' xmlns:RDF="http://www.w3.org/1999/02/22-rdf-syntax-ns#"' +
|
|
84 ' xmlns:d="http://purl.org/dc/elements/1.0/"' +
|
|
85 ' xmlns:a="http://www.w3.org/2000/10/annotation-ns#">' +
|
|
86 ' <RDF:Seq RDF:about="urn:echo">' +
|
|
87 ' <RDF:li RDF:resource="'+docPath+'"/>' +
|
|
88 ' </RDF:Seq>' +
|
|
89 ' <RDF:Description RDF:about="'+docPath+'" NS1:page=0"/>'+
|
|
90 '</RDF:RDF>';
|
|
91
|
|
92 var ds=new RDFDataSource();
|
|
93 ds.parseFromString(rdfString,"http://echo.unibe.ch/digilib/rdf/digilib.rdf");
|
|
94 var node=ds.getNode(docPath);
|
|
95 var arrayParams=window.content.listParameters();
|
|
96 for (i=0; i< arrayParams.length; i++){
|
|
97 var value=window.content.getParameter(arrayParams[i]);
|
|
98 //alert(arrayParams[i]+":"+value);
|
|
99 node.addTarget("http://echo.unibe.ch/digilib/rdf#"+arrayParams[i],value);
|
|
100 }
|
|
101 node.addTarget("http://echo.unibe.ch/digilib/rdf#lv","1");
|
|
102 //alert(ds.serializeToString());
|
|
103 var nsIFilePicker = Components.interfaces.nsIFilePicker;
|
|
104 var fp = Components.classes["@mozilla.org/filepicker;1"]
|
|
105 .createInstance(nsIFilePicker);
|
|
106 fp.init(window, "Select a File", nsIFilePicker.modeSave);
|
|
107
|
|
108 // set default direcotry
|
|
109 var aLocalFile = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
|
|
110 directory=makePathCompatible(directory);
|
|
111 aLocalFile.initWithPath(directory);
|
|
112 fp.displayDirectory=aLocalFile;
|
|
113
|
|
114 fp.appendFilter("Annotations","*.rdf; *.RDF");
|
|
115 var res=fp.show();
|
|
116 if (res==nsIFilePicker.returnOK){
|
|
117 var thefile=fp.file;
|
|
118 // --- do something with the file here ---
|
|
119 //alert(fp.file);
|
|
120 //alert(fp.fileURL.path);
|
|
121
|
|
122 var strFilePath=fp.file.path;
|
|
123 strFilePath=strFilePath.toLowerCase();
|
|
124 if (strFilePath.indexOf('.rdf')<0){
|
|
125 strFilePath=fp.fileURL.path+".rdf";
|
|
126 }else{
|
|
127 strFilePath=fp.fileURL.path;
|
|
128 }
|
|
129 strFilePath=makePathCompatible(strFilePath);
|
|
130 var f=new File(strFilePath);
|
|
131 //var boolFileExists=f.exists();
|
|
132 //alert(boolFileExists);
|
|
133 f.create();
|
|
134 f.open('w');
|
|
135 f.write(ds.serializeToString());
|
|
136 f.close();
|
|
137 refreshTree();
|
|
138 }
|
|
139 }else{
|
|
140 alert("Error: no alcatraz component. can't create an annotation.");
|
|
141 }
|
|
142 }
|
|
143
|
|
144 function file_local(){
|
|
145 // noch nicht programmiert
|
|
146 }
|
|
147
|
|
148 function file_annotaDB(){
|
|
149 alert("At the moment it is not possible to use the annota DB! This feature is not yet programmed.");
|
|
150 var menu_item=document.getElementById('local');
|
|
151 menu_item.setAttribute('checked','true');
|
|
152 }
|
|
153
|
|
154 function tree_click(){
|
|
155 var t=document.getElementById("file_tree"); //tree element
|
|
156 var l=t.view.getItemAtIndex(t.currentIndex); //aus baum treeitem herausholen mit dem selected index (currentIndex)
|
|
157 //l.firstChild ist treeitem
|
|
158 var d=l.firstChild.firstChild; //treecell
|
|
159 var firstLabel=d.getAttribute("label");
|
|
160 var cols=document.getElementById("cols");
|
|
161 var col=cols.childNodes;
|
|
162 var nodes=l.firstChild.childNodes;
|
|
163 var rdf_file="";
|
|
164 for (var i=0;i<nodes.length;i++){
|
|
165 if (col[i].getAttribute("label")=="URL"){
|
|
166 rdf_file=nodes[i].getAttribute("label");
|
|
167 }
|
|
168 }
|
|
169 if (rdf_file!=""){
|
|
170 send_annotation(rdf_file);
|
|
171 }
|
|
172 return rdf_file;
|
|
173 }
|
|
174
|
|
175
|
|
176 /***
|
|
177 * Diese Funktion wird gebraucht um im Dialog den Pfad zu digilib zu setzen
|
|
178 *
|
|
179 ***/
|
|
180 function setDigilibPath(digilibPathValue){
|
|
181 digilib_path=digilibPathValue;
|
|
182 }
|
|
183
|
|
184 /***
|
|
185 * Dialog tools momentan kann man nur den Pfad zu digilib setzen
|
|
186 *
|
|
187 ***/
|
|
188 function show_dialog(dialog){
|
|
189 if (dialog=="tool path"){
|
|
190 window.openDialog("tools_dialog.xul","funny dialog",
|
|
191 "chrome",digilib_path,setDigilibPath);
|
|
192 }
|
|
193 }
|
|
194
|
|
195
|
|
196 /***
|
|
197 * Gibt den Inhalt eines Files als String zurueck
|
|
198 *
|
|
199 ***/
|
|
200 function readFile(str_Filename){
|
|
201 var f=new File(str_Filename);
|
|
202 var str="";
|
|
203 if (f.isFile()){
|
|
204 f.open();
|
|
205 str=f.read();
|
|
206 f.close();
|
|
207 }
|
|
208 return str;
|
|
209 }
|
|
210
|
|
211
|
|
212
|
|
213 function send_annotation(rdf_file){
|
|
214 rdf_file=rdf_file.replace(/^file:\/\//,"");
|
|
215 rdf_file=makePathCompatible(rdf_file);
|
|
216 strRdfFile=readFile(rdf_file);
|
|
217 if (strRdfFile!=""){
|
|
218 var formid='mainform';
|
|
219 var form = createForm(formid, digilib_path+"/digilib.jsp", "post", "_content");
|
|
220 //var form = createForm(formid, "http://sophia.unibe.ch:8080/examples/servlet/RequestRDF", "post", "_content");
|
|
221 //var form = createForm(formid, "http://hera.unibe.ch:8080/examples/servlet/RequestRDF", "post", "_content");
|
|
222 setFormData(form, formid, strRdfFile);
|
|
223 form.submit();
|
|
224 }
|
|
225 }
|
|
226
|
|
227 function createForm(formid, action, method, target)
|
|
228 {
|
|
229 var form = document.getElementById(formid);
|
|
230 if(form != null)
|
|
231 document.documentElement.removeChild(form);
|
|
232
|
|
233 var form = document.createElementNS("http://www.w3.org/1999/xhtml", "form");
|
|
234 form.setAttribute("id", formid);
|
|
235 form.setAttribute("action", action);
|
|
236 form.setAttribute("method", method);
|
|
237 form.setAttribute("target", target);
|
|
238 document.documentElement.appendChild(form);
|
|
239 return form;
|
|
240 }
|
|
241
|
|
242 function setFormData(form, formid, rdf)
|
|
243 {
|
|
244 var val1 = document.createElementNS("http://www.w3.org/1999/xhtml", "input");
|
|
245 val1.setAttribute('type', 'hidden');
|
|
246 val1.setAttribute('name', 'rdf');
|
|
247 val1.setAttribute('value', rdf);
|
|
248 form.appendChild(val1);
|
|
249 }
|
|
250
|
|
251
|
|
252 function getProfileDirectory(){
|
|
253 // First get the directory service and query interface it to
|
|
254 // nsIProperties
|
|
255 var dirService = Components.
|
|
256 classes['@mozilla.org/file/directory_service;1'].
|
|
257 getService(Components.interfaces.nsIProperties);
|
|
258
|
|
259 // Next get the "ProfD" property of type nsIFile from the directory
|
|
260 // service, FYI this constant is defined in
|
|
261 // mozilla/xpcom/io/nsAppDirectoryServiceDefs.h
|
|
262
|
|
263 const NS_APP_USER_PROFILE_50_DIR = "ProfD";
|
|
264 profileDir = dirService.get(NS_APP_USER_PROFILE_50_DIR,
|
|
265 Components.interfaces.nsIFile);
|
|
266
|
|
267 // Now that we have it we can show it's path. See nsIFile for the
|
|
268 // other things you that can be done with profileDir
|
|
269 //alert(profileDir.path);
|
|
270 return profileDir.path;
|
|
271 }
|
|
272
|
|
273 function getProfile(){
|
|
274 var strProfile=readFile(getProfileDirectory()+slash+"annota.dat");
|
|
275 if (strProfile==""){
|
|
276 directory=slash;
|
|
277 digilib_path="http://hera.unibe.ch:8080/alcatraz";
|
|
278 setProfile();
|
|
279 }else{
|
|
280 var params=strProfile.split("\n");
|
|
281 for (var i=0;i<params.length;i++){
|
|
282 var key_value=params[i].split("|");
|
|
283 if (key_value[0]=='directory'){
|
|
284 directory=key_value[1];
|
|
285 }
|
|
286 if (key_value[0]=='tool path'){
|
|
287 digilib_path=key_value[1];
|
|
288 }
|
|
289 }
|
|
290 }
|
|
291 }
|
|
292
|
|
293 function setProfile(){
|
|
294 var f=new File(getProfileDirectory()+slash+'annota.dat');
|
|
295 f.create();
|
|
296 f.open('w');
|
|
297 f.write('directory|'+directory+'\n'+'tool path|'+digilib_path+'\n');
|
|
298 f.close();
|
|
299 }
|
|
300
|
|
301 function traverse(node){
|
|
302 if (node.hasChildNodes){
|
|
303 var arr_nodes=node.childNodes;
|
|
304 for (var i=0;i<arr_nodes.length;i++){
|
|
305 if (arr_nodes[i].getAttribute("open")){
|
|
306 //alert(arr_nodes[i].getAttribute("open"));
|
|
307 if (arr_nodes[i].hasChildNodes && arr_nodes[i].firstChild.hasChildNodes){
|
|
308 alert(arr_nodes[i].firstChild.firstChild.getAttribute("label"));
|
|
309 }
|
|
310 }
|
|
311 traverse(arr_nodes[i]);
|
|
312 }
|
|
313 }
|
|
314 }
|
|
315
|
|
316 function traverseTree(){
|
|
317 var t=document.getElementById("file_tree");
|
|
318 traverse(t);
|
|
319 }
|