1 | ///////////////////////////////////////////////////////////////////// |
---|
2 | // ã¿ã°ä»ãåºåæ©èœé¢é£ |
---|
3 | ///////////////////////////////////////////////////////////////////// |
---|
4 | var bitsTagOutputService = { |
---|
5 | |
---|
6 | _saveinfo : null, |
---|
7 | |
---|
8 | get STRING() { return document.getElementById("MarkingCollectionOverlayString"); }, |
---|
9 | get DataSource() { return bitsObjectMng.DataSource; }, |
---|
10 | get Common() { return bitsObjectMng.Common; }, |
---|
11 | get XPath() { return bitsObjectMng.XPath; }, |
---|
12 | get Database() { return bitsObjectMng.Database; }, |
---|
13 | get gBrowser() { return bitsObjectMng.getBrowser();}, |
---|
14 | |
---|
15 | get BROWSER() { return document.getElementById("bitsTagOutputBrowser"); }, |
---|
16 | |
---|
17 | get SIDEBAR() { return window.top.document.getElementById("sidebar"); }, |
---|
18 | get CONTENT() { return window.top.document.getElementById("content"); }, |
---|
19 | |
---|
20 | get SIDEBAR_DOC() {try{return this.SIDEBAR.contentDocument;}catch(e){return undefined;}}, |
---|
21 | get SIDEBAR_WIN() {try{return this.SIDEBAR.contentWindow;}catch(e){return undefined;}}, |
---|
22 | get mcTreeHandler() {try{return this.SIDEBAR_WIN.mcTreeHandler;}catch(e){return undefined;}}, |
---|
23 | get mcMainService() {try{return this.SIDEBAR_WIN.mcMainService;}catch(e){return undefined;}}, |
---|
24 | get mcController() {try{return this.SIDEBAR_WIN.mcController;}catch(e){return undefined;}}, |
---|
25 | get mcPropertyView() {try{return this.SIDEBAR_WIN.mcPropertyView;}catch(e){return undefined;}}, |
---|
26 | get mcTreeViewModeService() {try{return this.SIDEBAR_WIN.mcTreeViewModeService;}catch(e){return undefined;}}, |
---|
27 | get bitsItemView() {try{return this.SIDEBAR_WIN.bitsItemView;}catch(e){return undefined;}}, |
---|
28 | |
---|
29 | get TREE_POPUP(){try{return this.SIDEBAR_DOC.getElementById("mcPopup");}catch(e){return undefined;}}, |
---|
30 | get TREE_LISTVIEWMENU(){try{return this.SIDEBAR_DOC.getElementById("mcPopupViewMenu");}catch(e){return undefined;}}, |
---|
31 | get TREE_TAGOUTPUTMENU(){try{return this.SIDEBAR_DOC.getElementById("mcPopupTagOutput");}catch(e){return undefined;}}, |
---|
32 | get TREE_TAGOUTPUTMENU_SEP(){try{return this.SIDEBAR_DOC.getElementById("mcPopupTagOutputMenuseparator");}catch(e){return undefined;}}, |
---|
33 | |
---|
34 | get ITEMTREE_POPUP(){try{return this.SIDEBAR_DOC.getElementById("bitsItemTreePopup");}catch(e){return undefined;}}, |
---|
35 | get ITEMTREE_CACHEMENU(){try{return this.SIDEBAR_DOC.getElementById("bitsItemTreePopupCache");}catch(e){return undefined;}}, |
---|
36 | get ITEMTREE_TAGOUTPUTMENU(){try{return this.SIDEBAR_DOC.getElementById("bitsItemTreePopupTagOutput");}catch(e){return undefined;}}, |
---|
37 | get ITEMTREE_TAGOUTPUTMENU_SEP(){try{return this.SIDEBAR_DOC.getElementById("bitsItemTreePopupTagOutputMenuseparator");}catch(e){return undefined;}}, |
---|
38 | |
---|
39 | get _contentAreaContextMenu() { return window.top.document.getElementById("contentAreaContextMenu"); }, |
---|
40 | get CONTEXTMENU() { return window.top.document.getElementById("MarkingCollectionContextMenuTagOutput"); }, |
---|
41 | get CONTEXTMENUSEP() { return window.top.document.getElementById("MarkingCollectionContextMenuTagOutputSeparator"); }, |
---|
42 | |
---|
43 | |
---|
44 | ///////////////////////////////////////////////////////////////////// |
---|
45 | init : function(aEvent){ |
---|
46 | this._contentAreaContextMenu.addEventListener("popupshowing",this.popupshowing_contextmenu,false); |
---|
47 | }, |
---|
48 | |
---|
49 | ///////////////////////////////////////////////////////////////////// |
---|
50 | done : function(aEvent){ |
---|
51 | this._contentAreaContextMenu.removeEventListener("popupshowing",this.popupshowing_contextmenu,false); |
---|
52 | }, |
---|
53 | |
---|
54 | ///////////////////////////////////////////////////////////////////// |
---|
55 | load : function(aEvent){ |
---|
56 | var popup = this.TREE_POPUP; |
---|
57 | if(!popup) return; |
---|
58 | popup.addEventListener("popupshowing",this.popupshowing_tree, false); |
---|
59 | var popup = this.ITEMTREE_POPUP; |
---|
60 | if(!popup) return; |
---|
61 | popup.addEventListener("popupshowing",this.popupshowing_itemview, false); |
---|
62 | // popup.addEventListener("popupshown",this.popupshown_tree, false); |
---|
63 | }, |
---|
64 | |
---|
65 | ///////////////////////////////////////////////////////////////////// |
---|
66 | unload : function(aEvent){ |
---|
67 | var popup = this.TREE_POPUP; |
---|
68 | if(!popup) return; |
---|
69 | popup.removeEventListener("popupshowing",this.popupshowing_tree, false); |
---|
70 | var popup = this.ITEMTREE_POPUP; |
---|
71 | if(!popup) return; |
---|
72 | popup.removeEventListener("popupshowing",this.popupshowing_itemview, false); |
---|
73 | }, |
---|
74 | |
---|
75 | ///////////////////////////////////////////////////////////////////// |
---|
76 | popupshowing_contextmenu : function(aEvent){ |
---|
77 | bitsTagOutputService._popupshowing_contextmenu(aEvent); |
---|
78 | }, |
---|
79 | |
---|
80 | _popupshowing_contextmenu : function(aEvent){ |
---|
81 | this.CONTEXTMENUSEP.setAttribute("hidden","true"); |
---|
82 | this.CONTEXTMENU.setAttribute("hidden","true"); |
---|
83 | var contextmenu_mode = nsPreferences.copyUnicharPref("wiredmarker.contextmenu.mode"); |
---|
84 | var contextmenu_type = nsPreferences.copyUnicharPref("wiredmarker.contextmenu.type",""); |
---|
85 | if(contextmenu_mode == "legacy" && contextmenu_type == "simple") return; |
---|
86 | var popup_elem = false; |
---|
87 | var cm = bitsContextMenu._contextMenuObject; |
---|
88 | if(cm && (cm.isTextSelected || cm.onLink || cm.onImage)) popup_elem = true; |
---|
89 | if(this.isDispContextmenu(this.gBrowser.contentDocument)){ |
---|
90 | this.CONTEXTMENU.removeAttribute("hidden"); |
---|
91 | if(popup_elem) this.CONTEXTMENUSEP.removeAttribute("hidden"); |
---|
92 | } |
---|
93 | }, |
---|
94 | |
---|
95 | ///////////////////////////////////////////////////////////////////// |
---|
96 | popupshowing_tree : function(aEvent){ |
---|
97 | bitsTagOutputService._popupshowing_tree(aEvent); |
---|
98 | }, |
---|
99 | |
---|
100 | _popupshowing_tree : function(aEvent){ |
---|
101 | var contextmenu_mode = nsPreferences.copyUnicharPref("wiredmarker.contextmenu.mode"); |
---|
102 | if(contextmenu_mode == "legacy"){ |
---|
103 | var contextmenu_type = nsPreferences.copyUnicharPref("wiredmarker.contextmenu.type",""); |
---|
104 | if(contextmenu_type == "simple"){ |
---|
105 | this.TREE_TAGOUTPUTMENU.setAttribute("hidden","true"); |
---|
106 | }else{ |
---|
107 | this.TREE_TAGOUTPUTMENU.removeAttribute("hidden"); |
---|
108 | } |
---|
109 | if(contextmenu_type == "simple"){ |
---|
110 | this.TREE_TAGOUTPUTMENU_SEP.setAttribute("hidden","true"); |
---|
111 | }else{ |
---|
112 | this.TREE_TAGOUTPUTMENU_SEP.removeAttribute("hidden"); |
---|
113 | } |
---|
114 | }else{ |
---|
115 | this.TREE_TAGOUTPUTMENU.removeAttribute("hidden"); |
---|
116 | if(this.TREE_LISTVIEWMENU.hasAttribute("hidden")){ |
---|
117 | this.TREE_TAGOUTPUTMENU_SEP.setAttribute("hidden","true"); |
---|
118 | }else{ |
---|
119 | this.TREE_TAGOUTPUTMENU_SEP.removeAttribute("hidden"); |
---|
120 | } |
---|
121 | } |
---|
122 | }, |
---|
123 | |
---|
124 | ///////////////////////////////////////////////////////////////////// |
---|
125 | popupshown_tree : function(aEvent){ |
---|
126 | bitsTagOutputService._popupshown_tree(aEvent); |
---|
127 | }, |
---|
128 | |
---|
129 | _popupshown_tree : function(aEvent){ |
---|
130 | var popup = aEvent.target; |
---|
131 | var elem = popup.firstChild; |
---|
132 | while(elem){ |
---|
133 | if(!elem.hidden) this._dump("elem=["+elem.nodeName+"]["+elem.id+"]["+elem.hidden+"]"); |
---|
134 | elem = elem.nextSibling; |
---|
135 | } |
---|
136 | }, |
---|
137 | |
---|
138 | ///////////////////////////////////////////////////////////////////// |
---|
139 | popupshowing_itemview : function(aEvent){ |
---|
140 | bitsTagOutputService._popupshowing_itemview(aEvent); |
---|
141 | }, |
---|
142 | |
---|
143 | _popupshowing_itemview : function(aEvent){ |
---|
144 | var contextmenu_mode = nsPreferences.copyUnicharPref("wiredmarker.contextmenu.mode"); |
---|
145 | if(contextmenu_mode == "legacy"){ |
---|
146 | var contextmenu_type = nsPreferences.copyUnicharPref("wiredmarker.contextmenu.type",""); |
---|
147 | if(contextmenu_type == "simple"){ |
---|
148 | this.ITEMTREE_TAGOUTPUTMENU.setAttribute("hidden","true"); |
---|
149 | }else{ |
---|
150 | this.ITEMTREE_TAGOUTPUTMENU.removeAttribute("hidden"); |
---|
151 | } |
---|
152 | if(contextmenu_type == "simple"){ |
---|
153 | this.ITEMTREE_TAGOUTPUTMENU_SEP.setAttribute("hidden","true"); |
---|
154 | }else{ |
---|
155 | this.ITEMTREE_TAGOUTPUTMENU_SEP.removeAttribute("hidden"); |
---|
156 | } |
---|
157 | }else{ |
---|
158 | this.ITEMTREE_TAGOUTPUTMENU.removeAttribute("hidden"); |
---|
159 | this.ITEMTREE_TAGOUTPUTMENU_SEP.removeAttribute("hidden"); |
---|
160 | } |
---|
161 | }, |
---|
162 | |
---|
163 | ///////////////////////////////////////////////////////////////////// |
---|
164 | pageshow : function(aEvent){ |
---|
165 | bitsTagOutputService._pageshow(aEvent); |
---|
166 | }, |
---|
167 | |
---|
168 | ///////////////////////////////////////////////////////////////////// |
---|
169 | _pageshow : function(aEvent){ |
---|
170 | var aDoc = aEvent.target; |
---|
171 | var URLString = this.Common.getURLStringFromDocument(aDoc); |
---|
172 | if(URLString.indexOf("chrome:") >= 0 || URLString.indexOf("about:") >= 0){ |
---|
173 | if(this._saveinfo.cb){ |
---|
174 | var self = this; |
---|
175 | setTimeout(function(){ self._saveinfo.cb(aEvent); },0); |
---|
176 | } |
---|
177 | return; |
---|
178 | } |
---|
179 | if(this._saveinfo.uri != URLString || !aDoc.body) return; |
---|
180 | if(!this._saveinfo.file){ |
---|
181 | var aSaveFile = this.getSaveFile(this.getDocomentFilename(aDoc)); |
---|
182 | if(aSaveFile){ |
---|
183 | this._saveinfo.file = aSaveFile.clone(); |
---|
184 | }else{ |
---|
185 | this.BROWSER.removeEventListener("pageshow", this.pageshow, false); |
---|
186 | this._saveinfo.cb = undefined; |
---|
187 | this._saveinfo = undefined; |
---|
188 | return; |
---|
189 | } |
---|
190 | } |
---|
191 | var orgURLString = URLString; |
---|
192 | if(bitsAutocacheService.isCacheURL(orgURLString)) orgURLString = bitsAutocacheService.convertCacheURLToOriginalURL(orgURLString); |
---|
193 | var folderTag = {} |
---|
194 | var rtnObj = this.Database.getAllObjectFormContentURL(orgURLString); |
---|
195 | if(rtnObj && rtnObj.length>0){ |
---|
196 | var cnt; |
---|
197 | for(cnt=0;cnt<rtnObj.length;cnt++){ |
---|
198 | var rObj = rtnObj[cnt]; |
---|
199 | if(rObj.oid_type.match(/^image\/(.+)$/)) continue; |
---|
200 | if(!aDoc.defaultView) return; |
---|
201 | var rtnContent = bitsMarker.xPathMarker( |
---|
202 | aDoc, |
---|
203 | { |
---|
204 | start : rObj.bgn_dom, |
---|
205 | end : rObj.end_dom, |
---|
206 | context : rObj.oid_txt, |
---|
207 | con_url : URLString |
---|
208 | },{ |
---|
209 | id : rObj.oid, |
---|
210 | dbtype : rObj.dbtype, |
---|
211 | pfid : rObj.pfid, |
---|
212 | style : rObj.fid_style |
---|
213 | } |
---|
214 | ); |
---|
215 | if(folderTag[rObj.pfid]) continue; |
---|
216 | folderTag[rObj.pfid] = { |
---|
217 | dbtype : rObj.dbtype, |
---|
218 | style : rObj.fid_style |
---|
219 | }; |
---|
220 | } |
---|
221 | var parser = new DOMParser(); |
---|
222 | for(var fid in folderTag){ |
---|
223 | var rtnFolder = this.Database.getFolder({fid:fid},folderTag[fid].dbtype); |
---|
224 | if(!rtnFolder) continue; |
---|
225 | rtnFolder = rtnFolder[0]; |
---|
226 | folderTag[fid].tag = rtnFolder.fid_title; |
---|
227 | if(rtnFolder.fid_property){ |
---|
228 | var xmldoc = parser.parseFromString(rtnFolder.fid_property, "text/xml"); |
---|
229 | if(xmldoc && xmldoc.documentElement.nodeName == "parsererror") xmldoc = undefined; |
---|
230 | if(xmldoc){ |
---|
231 | var tagNode = xmldoc.getElementsByTagName("TAG")[0]; |
---|
232 | if(tagNode) folderTag[fid].tag = tagNode.textContent; |
---|
233 | tagNode = undefined; |
---|
234 | xmldoc = undefined; |
---|
235 | } |
---|
236 | } |
---|
237 | } |
---|
238 | parser = undefined; |
---|
239 | var nodesSnapshot = this.getMarkerNodes(aDoc); |
---|
240 | for(var i=0;i<nodesSnapshot.snapshotLength;i++){ |
---|
241 | var node = nodesSnapshot.snapshotItem(i); |
---|
242 | var fid = node.getAttribute('pfid'); |
---|
243 | if(!folderTag[fid]) continue; |
---|
244 | if(this._saveinfo.hidden){ |
---|
245 | var range = aDoc.createRange(); |
---|
246 | range.selectNodeContents(node); |
---|
247 | var tagNode = aDoc.createElement(folderTag[fid].tag); |
---|
248 | var docfrag = range.extractContents(); |
---|
249 | tagNode.appendChild(docfrag); |
---|
250 | range.insertNode(tagNode); |
---|
251 | range = undefined; |
---|
252 | }else{ |
---|
253 | var tagNode = aDoc.createTextNode('<'+folderTag[fid].tag+'>'); |
---|
254 | if(node.firstChild){ |
---|
255 | node.insertBefore(tagNode,node.firstChild); |
---|
256 | }else{ |
---|
257 | node.appendChild(tagNode); |
---|
258 | } |
---|
259 | node.appendChild(aDoc.createTextNode('</'+folderTag[fid].tag+'>')); |
---|
260 | } |
---|
261 | if(this._saveinfo.style){ |
---|
262 | var attrs = node.attributes; |
---|
263 | for(var a=attrs.length-1;a>=0;a--){ |
---|
264 | if(attrs[a].name == 'style') continue; |
---|
265 | node.removeAttribute(attrs[a].name); |
---|
266 | } |
---|
267 | }else{ |
---|
268 | var parent = node.parentNode; |
---|
269 | var children = node.childNodes; |
---|
270 | var index; |
---|
271 | for(index = children.length-1;index>=0;index--){ |
---|
272 | parent.insertBefore(children[0],node); |
---|
273 | } |
---|
274 | parent.removeChild(node); |
---|
275 | parent.normalize(); |
---|
276 | } |
---|
277 | } |
---|
278 | if(this._saveinfo.rpath){ |
---|
279 | if(aDoc.images && aDoc.images.length>0){ |
---|
280 | for(var i=0;i<aDoc.images.length;i++){ |
---|
281 | aDoc.images[i].setAttribute("src",aDoc.images[i].src); |
---|
282 | } |
---|
283 | } |
---|
284 | if(aDoc.links && aDoc.links.length>0){ |
---|
285 | for(var i=0;i<aDoc.links.length;i++){ |
---|
286 | aDoc.links[i].setAttribute("href",aDoc.links[i].href); |
---|
287 | } |
---|
288 | } |
---|
289 | var nodesSnapshot = this.XPath.evaluate('//link[@href]',aDoc); |
---|
290 | for(var i=0;i<nodesSnapshot.snapshotLength;i++){ |
---|
291 | var node = nodesSnapshot.snapshotItem(i); |
---|
292 | node.setAttribute("href",node.href); |
---|
293 | } |
---|
294 | var nodesSnapshot = this.XPath.evaluate('//*[@style]',aDoc); |
---|
295 | for(var i=0;i<nodesSnapshot.snapshotLength;i++){ |
---|
296 | var node = nodesSnapshot.snapshotItem(i); |
---|
297 | if(!node.style.backgroundImage) continue; |
---|
298 | if(node.style.backgroundImage.match(/^url\((.+)?\)/)){ |
---|
299 | node.style.backgroundImage = 'url(' + this.Common.resolveURL(aDoc.location.href,RegExp.$1) + ')'; |
---|
300 | } |
---|
301 | } |
---|
302 | } |
---|
303 | var file = null; |
---|
304 | if(!this._saveinfo.file.exists() || this._saveinfo.file.isFile()){ |
---|
305 | file = this._saveinfo.file.clone(); |
---|
306 | }else if(this._saveinfo.file.isDirectory()){ |
---|
307 | var fn = this.getDocomentFilename(aDoc); |
---|
308 | if(fn){ |
---|
309 | file = this._saveinfo.file.clone(); |
---|
310 | file.append(fn); |
---|
311 | if(file.exists()){ |
---|
312 | if(!this.Common.confirm(this.STRING.getString("CONFIRM_FILE_OVERWRITE")+"\n["+file.path+"]")){ |
---|
313 | file = this.getSaveFile(file.path); |
---|
314 | if(!file){ |
---|
315 | if(this._saveinfo.list && this._saveinfo.list.length>0) this._saveinfo.list.length = 0; |
---|
316 | this._saveinfo.cb = undefined; |
---|
317 | } |
---|
318 | } |
---|
319 | } |
---|
320 | } |
---|
321 | } |
---|
322 | if(file){ |
---|
323 | var content = null; |
---|
324 | if(this._saveinfo.style || this._saveinfo.hidden || aDoc.contentType != 'text/plain'){ |
---|
325 | content = '<html>' + aDoc.documentElement.innerHTML + '</html>'; |
---|
326 | }else{ |
---|
327 | var nodesSnapshot = this.XPath.evaluate('/html/body/pre[1]',aDoc); |
---|
328 | if(nodesSnapshot && nodesSnapshot.snapshotLength>0) content = nodesSnapshot.snapshotItem(0).textContent; |
---|
329 | } |
---|
330 | if(content) this.writeFile(file,content,aDoc.characterSet); |
---|
331 | } |
---|
332 | } |
---|
333 | if(this._saveinfo.list && this._saveinfo.list.length>0){ |
---|
334 | this._saveinfo.uri = this._saveinfo.list.shift(); |
---|
335 | this.BROWSER.loadURI(this._saveinfo.uri); |
---|
336 | }else if(this._saveinfo.cb){ |
---|
337 | var self = this; |
---|
338 | setTimeout(function(){ self._saveinfo.cb(aEvent); },0); |
---|
339 | }else{ |
---|
340 | this.BROWSER.removeEventListener("pageshow", this.pageshow, false); |
---|
341 | this._saveinfo.cb = undefined; |
---|
342 | this._saveinfo = undefined; |
---|
343 | } |
---|
344 | }, |
---|
345 | |
---|
346 | ///////////////////////////////////////////////////////////////////// |
---|
347 | isDispContextmenu : function(aDoc){ |
---|
348 | var nodesSnapshot = this.getMarkerNodes(aDoc); |
---|
349 | return (nodesSnapshot&&nodesSnapshot.snapshotLength>0?true:false); |
---|
350 | }, |
---|
351 | |
---|
352 | ///////////////////////////////////////////////////////////////////// |
---|
353 | getMarkerNodes : function(aDoc){ |
---|
354 | return this.XPath.evaluate('//*[@id and @dbtype and @pfid]',aDoc); |
---|
355 | }, |
---|
356 | |
---|
357 | ///////////////////////////////////////////////////////////////////// |
---|
358 | getOptions : function(){ |
---|
359 | var result = { |
---|
360 | accept : false, |
---|
361 | uri : null, |
---|
362 | file : null, |
---|
363 | list : null, |
---|
364 | cb : this.outputDone, |
---|
365 | hidden : nsPreferences.getBoolPref("wiredmarker.tagoutput.tag.hidden", false), |
---|
366 | style : nsPreferences.getBoolPref("wiredmarker.tagoutput.tag.style", false), |
---|
367 | rpath : nsPreferences.getBoolPref("wiredmarker.tagoutput.path.change",true) |
---|
368 | }; |
---|
369 | window.openDialog("chrome://markingcollection/content/tagoutputDialog.xul", "", "chrome,centerscreen,modal", result); |
---|
370 | if(result.accept){ |
---|
371 | nsPreferences.setBoolPref("wiredmarker.tagoutput.tag.hidden", result.hidden); |
---|
372 | nsPreferences.setBoolPref("wiredmarker.tagoutput.tag.style", result.style); |
---|
373 | nsPreferences.setBoolPref("wiredmarker.tagoutput.path.change",result.rpath); |
---|
374 | delete result.accept; |
---|
375 | return result; |
---|
376 | }else{ |
---|
377 | return undefined; |
---|
378 | } |
---|
379 | }, |
---|
380 | |
---|
381 | ///////////////////////////////////////////////////////////////////// |
---|
382 | onTagOutputRdfCommand : function(aParam){ |
---|
383 | if(!this.mcTreeHandler) return; |
---|
384 | var aRes = this.mcTreeHandler.resource; |
---|
385 | if(!aRes) return; |
---|
386 | this._saveinfo = this.getOptions(); |
---|
387 | if(!this._saveinfo) return; |
---|
388 | if(this.DataSource.isContainer(aRes)){ |
---|
389 | this._saveinfo.file = this.getSaveFolder(this.DataSource.getProperty(aRes, "title")); |
---|
390 | if(!this._saveinfo.file) return; |
---|
391 | |
---|
392 | this._saveinfo.list = []; |
---|
393 | var hash = {}; |
---|
394 | |
---|
395 | var folderList = this.DataSource.flattenResources(aRes, 1, true); |
---|
396 | // this._dump(folderList.length); |
---|
397 | var f; |
---|
398 | for(f=0;f<folderList.length;f++){ |
---|
399 | var fid = this.DataSource.getProperty(folderList[f], "id"); |
---|
400 | var dbtype = this.DataSource.getProperty(folderList[f], "dbtype"); |
---|
401 | var rtnObjs = this.Database.getObject({pfid:fid},dbtype); |
---|
402 | if(rtnObjs && rtnObjs.length){ |
---|
403 | var i; |
---|
404 | for(i=0;i<rtnObjs.length;i++){ |
---|
405 | if(hash[rtnObjs[i].doc_url] != undefined) continue; |
---|
406 | hash[rtnObjs[i].doc_url] = rtnObjs[i].doc_url; |
---|
407 | this._saveinfo.list.push(rtnObjs[i].doc_url); |
---|
408 | } |
---|
409 | } |
---|
410 | } |
---|
411 | |
---|
412 | // this._dump("this._saveinfo.list.length=["+this._saveinfo.list.length+"]"); |
---|
413 | |
---|
414 | if(this._saveinfo.list.length>0){ |
---|
415 | this._saveinfo.uri = this._saveinfo.list.shift(); |
---|
416 | this.BROWSER.addEventListener("pageshow", this.pageshow, false); |
---|
417 | this.BROWSER.loadURI(this._saveinfo.uri); |
---|
418 | } |
---|
419 | }else{ |
---|
420 | this._saveinfo.uri = this.DataSource.getProperty(aRes, "uri"); |
---|
421 | this.BROWSER.addEventListener("pageshow", this.pageshow, false); |
---|
422 | this.BROWSER.loadURI(this._saveinfo.uri); |
---|
423 | } |
---|
424 | }, |
---|
425 | |
---|
426 | ///////////////////////////////////////////////////////////////////// |
---|
427 | onTagOutputItemviewCommand : function(aParam){ |
---|
428 | var object = this.bitsItemView.object; |
---|
429 | if(!object) return; |
---|
430 | this._saveinfo = this.getOptions(); |
---|
431 | if(!this._saveinfo) return; |
---|
432 | this._saveinfo.uri = object.doc_url; |
---|
433 | this.BROWSER.addEventListener("pageshow", this.pageshow, false); |
---|
434 | this.BROWSER.loadURI(this._saveinfo.uri); |
---|
435 | }, |
---|
436 | |
---|
437 | ///////////////////////////////////////////////////////////////////// |
---|
438 | onTagOutputContextmenuCommand : function(aParam){ |
---|
439 | this._saveinfo = this.getOptions(); |
---|
440 | if(!this._saveinfo) return; |
---|
441 | this._saveinfo.uri = this.Common.getURLStringFromDocument(this.gBrowser.contentDocument); |
---|
442 | this.BROWSER.addEventListener("pageshow", this.pageshow, false); |
---|
443 | this.BROWSER.loadURI(this._saveinfo.uri); |
---|
444 | aParam.event.stopPropagation(); |
---|
445 | }, |
---|
446 | |
---|
447 | ///////////////////////////////////////////////////////////////////// |
---|
448 | outputDone : function(aEvent){ |
---|
449 | bitsTagOutputService._outputDone(aEvent); |
---|
450 | }, |
---|
451 | |
---|
452 | _outputDone : function(aEvent){ |
---|
453 | if(this._saveinfo.uri == this.Common.getURLStringFromDocument(aEvent.target)){ |
---|
454 | this.BROWSER.removeEventListener("pageshow", this.pageshow, false); |
---|
455 | this._saveinfo.cb = undefined; |
---|
456 | this._saveinfo = undefined; |
---|
457 | this.Common.alert('Output documents.'); |
---|
458 | } |
---|
459 | }, |
---|
460 | |
---|
461 | ///////////////////////////////////////////////////////////////////// |
---|
462 | writeFile : function(aFile, aContent, aCharacterSet){ |
---|
463 | try { |
---|
464 | if(aCharacterSet == undefined) aCharacterSet = 'UTF-8'; |
---|
465 | if(!aFile.parent.exists()) aFile.parent.create(aFile.DIRECTORY_TYPE, 0777); |
---|
466 | if(aFile.exists()) aFile.remove(false); |
---|
467 | aFile.create(aFile.NORMAL_FILE_TYPE, 0666); |
---|
468 | var content = this.Common.convertFormUnicode(aContent,aCharacterSet); |
---|
469 | var ostream = Components.classes['@mozilla.org/network/file-output-stream;1'].createInstance(Components.interfaces.nsIFileOutputStream); |
---|
470 | ostream.init(aFile, 2, 0x200, false); |
---|
471 | ostream.write(content, content.length); |
---|
472 | ostream.close(); |
---|
473 | return true; |
---|
474 | }catch(ex){ |
---|
475 | this._dump("bitsTagOutputService ERROR: Failed to write file: " + aFile.path + "["+ ex + "]"); |
---|
476 | return false; |
---|
477 | } |
---|
478 | }, |
---|
479 | |
---|
480 | ///////////////////////////////////////////////////////////////////// |
---|
481 | saveTagDocoment : function (aParam){ |
---|
482 | }, |
---|
483 | |
---|
484 | ///////////////////////////////////////////////////////////////////// |
---|
485 | getDocomentFilename : function (aDoc){ |
---|
486 | var fileBaseName = null; |
---|
487 | var fileExtension = null; |
---|
488 | var fileDefault = null; |
---|
489 | var aURL = Components.classes['@mozilla.org/network/standard-url;1'].createInstance(Components.interfaces.nsIURL); |
---|
490 | aURL.spec = (typeof aDoc == 'string' ? aDoc : aDoc.location.href); |
---|
491 | if(aURL.fileBaseName) fileBaseName = aURL.fileBaseName; |
---|
492 | if(aURL.fileExtension) fileExtension = aURL.fileExtension; |
---|
493 | if(!fileBaseName){ |
---|
494 | var fileName = this.Common.getFileName(aURL.spec); |
---|
495 | var splitFileName = this.Common.splitFileName(fileName); |
---|
496 | if(!splitFileName[0] || splitFileName[0] == ""){ |
---|
497 | fileBaseName = ""; |
---|
498 | var arr = aURL.spec.split("/"); |
---|
499 | while(arr.length){ |
---|
500 | fileBaseName = arr.pop(); |
---|
501 | if(fileBaseName.length>0) break; |
---|
502 | } |
---|
503 | if(fileBaseName.length == 0) fileBaseName = "index"; |
---|
504 | }else{ |
---|
505 | fileBaseName = decodeURIComponent(splitFileName[0]); |
---|
506 | } |
---|
507 | } |
---|
508 | if(!fileExtension && typeof aDoc == 'object'){ |
---|
509 | if(aDoc.contentType=='text/plain'){ |
---|
510 | fileExtension = 'txt'; |
---|
511 | }else{ |
---|
512 | fileExtension = 'html'; |
---|
513 | } |
---|
514 | } |
---|
515 | if(typeof aDoc == 'object' && aDoc.contentType && aDoc.contentType=='text/html') fileExtension = 'html'; |
---|
516 | if(fileExtension){ |
---|
517 | if(this._saveinfo.style || this._saveinfo.hidden) fileExtension = "html"; |
---|
518 | if(fileExtension != 'html') fileExtension = "txt"; |
---|
519 | } |
---|
520 | if(fileBaseName && fileExtension) fileDefault = fileBaseName + "." + fileExtension; |
---|
521 | return fileDefault; |
---|
522 | }, |
---|
523 | |
---|
524 | ///////////////////////////////////////////////////////////////////// |
---|
525 | getSaveFile : function (aFilename){ |
---|
526 | var picker = Components.classes["@mozilla.org/filepicker;1"].createInstance(Components.interfaces.nsIFilePicker); |
---|
527 | var result = null; |
---|
528 | try{ |
---|
529 | var title = "Selected Save File"; |
---|
530 | picker.init(window, title, picker.modeSave); |
---|
531 | if(aFilename) picker.defaultString = aFilename; |
---|
532 | picker.appendFilters(picker.filterAll|picker.filterText|picker.filterHTML); |
---|
533 | var showResult = picker.show(); |
---|
534 | if(showResult == picker.returnOK){ |
---|
535 | result = picker.file; |
---|
536 | }else if(showResult == picker.returnReplace){ |
---|
537 | if(picker.file.exists()) picker.file.remove(false); |
---|
538 | result = picker.file; |
---|
539 | } |
---|
540 | }catch(e){ |
---|
541 | result = null; |
---|
542 | this.Common.alert(e); |
---|
543 | } |
---|
544 | return result; |
---|
545 | }, |
---|
546 | |
---|
547 | ///////////////////////////////////////////////////////////////////// |
---|
548 | getSaveFolder : function (aTitle){ |
---|
549 | var picker = Components.classes["@mozilla.org/filepicker;1"].createInstance(Components.interfaces.nsIFilePicker); |
---|
550 | var result = null; |
---|
551 | try{ |
---|
552 | var title = "Selected Save Folder"; |
---|
553 | if(aTitle) title += " ["+aTitle+"]"; |
---|
554 | picker.init(window, title, picker.modeGetFolder); |
---|
555 | if(aTitle) picker.defaultString = aTitle; |
---|
556 | var showResult = picker.show(); |
---|
557 | if(showResult == picker.returnOK){ |
---|
558 | result = picker.file; |
---|
559 | }else if(showResult == picker.returnReplace){ |
---|
560 | if(picker.file.exists()) picker.file.remove(false); |
---|
561 | result = picker.file; |
---|
562 | } |
---|
563 | }catch(e){ |
---|
564 | result = null; |
---|
565 | this.Common.alert(e); |
---|
566 | } |
---|
567 | return result; |
---|
568 | }, |
---|
569 | |
---|
570 | ///////////////////////////////////////////////////////////////////// |
---|
571 | _dump : function(aString){ |
---|
572 | window.top.bitsMarkingCollection._dump(aString); |
---|
573 | } |
---|
574 | }; |
---|