1 | // æå®ã¿ã°å蟌 |
---|
2 | var bitsImportTagService = { |
---|
3 | _progressWindow : null, |
---|
4 | |
---|
5 | get STRING() { return document.getElementById("MarkingCollectionOverlayString"); }, |
---|
6 | get DataSource() { return window.top.bitsObjectMng.DataSource; }, |
---|
7 | get Common() { return window.top.bitsObjectMng.Common; }, |
---|
8 | get XPath() { return window.top.bitsObjectMng.XPath; }, |
---|
9 | get Database() { return window.top.bitsObjectMng.Database; }, |
---|
10 | get gBrowser() { return window.top.bitsObjectMng.getBrowser();}, |
---|
11 | |
---|
12 | get SIDEBAR() { return window.top.document.getElementById("sidebar"); }, |
---|
13 | get SIDEBAR_DOC() {try{return this.SIDEBAR.contentDocument;}catch(e){return undefined;}}, |
---|
14 | get SIDEBAR_WIN() {try{return this.SIDEBAR.contentWindow;}catch(e){return undefined;}}, |
---|
15 | get mcTreeHandler() {try{return this.SIDEBAR_WIN.mcTreeHandler;}catch(e){return undefined;}}, |
---|
16 | get mcPropertyView() {try{return this.SIDEBAR_WIN.mcPropertyView;}catch(e){return undefined;}}, |
---|
17 | get bitsItemView() {try{return this.SIDEBAR_WIN.bitsItemView;}catch(e){return undefined;}}, |
---|
18 | get mcItemView() {try{return this.SIDEBAR_WIN.mcItemView;}catch(e){return undefined;}}, |
---|
19 | |
---|
20 | ///////////////////////////////////////////////////////////////////// |
---|
21 | init : function(){ |
---|
22 | |
---|
23 | }, |
---|
24 | |
---|
25 | ///////////////////////////////////////////////////////////////////// |
---|
26 | done : function(){ |
---|
27 | |
---|
28 | }, |
---|
29 | |
---|
30 | ///////////////////////////////////////////////////////////////////// |
---|
31 | dispList : function(aEvent){ |
---|
32 | try{ |
---|
33 | var bitsItemView = null; |
---|
34 | var mcTreeHandler = null; |
---|
35 | var mcPropertyView = null; |
---|
36 | var mcItemView = null; |
---|
37 | |
---|
38 | if(this.bitsItemView) bitsItemView = this.bitsItemView; |
---|
39 | if(this.mcTreeHandler) mcTreeHandler = this.mcTreeHandler; |
---|
40 | if(this.mcPropertyView) mcPropertyView = this.mcPropertyView; |
---|
41 | if(this.mcItemView) mcItemView = this.mcItemView; |
---|
42 | if(!mcTreeHandler) return; |
---|
43 | var aRes = mcTreeHandler.resource; |
---|
44 | if(!aRes) return; |
---|
45 | |
---|
46 | var tags = this._analyzeDocument(); |
---|
47 | var result = {accept : false}; |
---|
48 | window.openDialog("chrome://markingcollection/content/importtagDialog.xul", "", "chrome,centerscreen,modal", tags, result); |
---|
49 | if(result.accept){ |
---|
50 | |
---|
51 | var fid = this.DataSource.getProperty(aRes, "id"); |
---|
52 | var fid_style = this.DataSource.getProperty(aRes, "style"); |
---|
53 | var dbtype = this.DataSource.getProperty(aRes, "dbtype"); |
---|
54 | var param = { |
---|
55 | fid : fid, |
---|
56 | fid_style : fid_style, |
---|
57 | dbtype : dbtype |
---|
58 | }; |
---|
59 | |
---|
60 | if(!this._progressWindow){ |
---|
61 | var x = screen.width; |
---|
62 | var y = screen.height; |
---|
63 | this._progressWindow = window.openDialog( |
---|
64 | "chrome://markingcollection/content/progress.xul", |
---|
65 | "myProgress", "chrome,centerscreen,alwaysRaised,dependent=yes,left="+x+",top="+y, |
---|
66 | {status: this.STRING.getString("MSG_IMPORT_TAG") + "..."}); |
---|
67 | } |
---|
68 | |
---|
69 | if(this._progressWindow && !this._progressWindow.closed){ |
---|
70 | if(result.tags.length>0){ |
---|
71 | if(this._progressWindow.setStatus){ |
---|
72 | var num = 0; |
---|
73 | var i; |
---|
74 | for(i=0;i<result.tags.length;i++){ |
---|
75 | num += (tags[result.type][result.tags[i]]?tags[result.type][result.tags[i]].length:0); |
---|
76 | } |
---|
77 | this._progressWindow.setStatus(this.STRING.getString("MSG_IMPORT_TAG") + "... [ "+ num + " ]"); |
---|
78 | } |
---|
79 | this._progressWindow.focus(); |
---|
80 | var self = this; |
---|
81 | setTimeout(function(){ self._execImport(tags,param,result); },100); |
---|
82 | }else{ |
---|
83 | if(this._progressWindow && !this._progressWindow.closed) this._progressWindow.close(); |
---|
84 | this._progressWindow = null; |
---|
85 | } |
---|
86 | } |
---|
87 | } |
---|
88 | }catch(e){ |
---|
89 | this._dump("bitsImportTagService.dispList():"+e); |
---|
90 | } |
---|
91 | }, |
---|
92 | |
---|
93 | ///////////////////////////////////////////////////////////////////// |
---|
94 | _execImport : function(tags,param,result,arr,options){ |
---|
95 | try{ |
---|
96 | if((!result.tags || result.tags.length == 0) && arr == undefined){ |
---|
97 | if(this._progressWindow && !this._progressWindow.closed) this._progressWindow.close(); |
---|
98 | this._progressWindow = null; |
---|
99 | return; |
---|
100 | } |
---|
101 | if(arr == undefined){ |
---|
102 | var tag = result.tags.shift(); |
---|
103 | arr = tags[result.type][tag]; |
---|
104 | } |
---|
105 | if(arr && arr.length>0){ |
---|
106 | if(this._progressWindow && !this._progressWindow.closed && this._progressWindow.setStatus){ |
---|
107 | var num = 0; |
---|
108 | for(var i=0;i<result.tags.length;i++){ |
---|
109 | num += (tags[result.type][result.tags[i]]?tags[result.type][result.tags[i]].length:0); |
---|
110 | } |
---|
111 | num += arr.length; |
---|
112 | this._progressWindow.setStatus(this.STRING.getString("MSG_IMPORT_TAG") + "... [ "+ num + " ]"); |
---|
113 | } |
---|
114 | for(var i=0;i<10;i++){ |
---|
115 | var node = arr.shift(); |
---|
116 | var doc = node.ownerDocument; |
---|
117 | var win = doc.defaultView; |
---|
118 | if(node.nodeName.toUpperCase() == "IMG" && result.img_opt == "image"){ |
---|
119 | var aXferString = node.src + "\n" + node.alt; |
---|
120 | bitsMarkingCollection.addURLText(param,-1,undefined, aXferString, node, (result.tags.length==0 && arr.length==0 ? true : false),false); |
---|
121 | }else{ |
---|
122 | var selection = win.getSelection(); |
---|
123 | if(selection){ |
---|
124 | selection.removeAllRanges(); |
---|
125 | var range = doc.createRange(); |
---|
126 | range.selectNodeContents(node); |
---|
127 | selection.addRange(range); |
---|
128 | bitsMarkingCollection.addSelectedText(param,-1,undefined,(result.tags.length==0 && arr.length==0 ? true : false),false); |
---|
129 | } |
---|
130 | } |
---|
131 | if(arr.length == 0){ |
---|
132 | arr = undefined; |
---|
133 | break; |
---|
134 | } |
---|
135 | } |
---|
136 | } |
---|
137 | var self = this; |
---|
138 | setTimeout(function(){ self._execImport(tags,param,result,arr,options); },100); |
---|
139 | }catch(e){ |
---|
140 | this._dump("bitsImportTagService._execImport():"+e); |
---|
141 | } |
---|
142 | }, |
---|
143 | |
---|
144 | ///////////////////////////////////////////////////////////////////// |
---|
145 | _getDocument : function(aWin){ |
---|
146 | var docs = []; |
---|
147 | if(!aWin) return docs; |
---|
148 | if(aWin.frames != null){ |
---|
149 | var i; |
---|
150 | for(i=0;i<aWin.frames.length;i++){ |
---|
151 | docs = docs.concat(this._getDocument(aWin.frames[i])); |
---|
152 | } |
---|
153 | } |
---|
154 | if(aWin.document) docs.push(aWin.document); |
---|
155 | return docs; |
---|
156 | }, |
---|
157 | |
---|
158 | ///////////////////////////////////////////////////////////////////// |
---|
159 | _analyzeDocument : function(){ |
---|
160 | var regexp = new RegExp("^"+bitsMarker.id_key); |
---|
161 | var tags = { |
---|
162 | html : {}, |
---|
163 | nohtml : {}, |
---|
164 | }; |
---|
165 | var htmlTags = this._getHtmlTags(); |
---|
166 | var DOCS = this._getDocument(this.gBrowser.contentWindow); |
---|
167 | var i,j; |
---|
168 | for(i=0;i<DOCS.length;i++){ |
---|
169 | if(!DOCS[i].body) continue; |
---|
170 | var nodeWalker = DOCS[i].createTreeWalker(DOCS[i].body,NodeFilter.SHOW_ELEMENT,null,false); |
---|
171 | var node; |
---|
172 | for(node=nodeWalker.nextNode();node;node = nodeWalker.nextNode()){ |
---|
173 | j=0; |
---|
174 | var elms = [node]; |
---|
175 | |
---|
176 | if(elms[j].nodeName.toUpperCase() == "SCRIPT"){ |
---|
177 | continue; |
---|
178 | }else if(elms[j].nodeName.toUpperCase() == "SPAN"){ |
---|
179 | if(elms[j].hasAttribute("id") && regexp.test(elms[j].id)) continue; //Markerãé€å€ |
---|
180 | }else if(elms[j].nodeName.toUpperCase() == "IMG"){ |
---|
181 | if(!elms[j].hasAttribute("src")) continue; |
---|
182 | }else if(elms[j].nodeName.toUpperCase() == "A"){ |
---|
183 | if(!elms[j].hasChildNodes()) continue; |
---|
184 | if(!elms[j].hasAttribute("href")) continue; |
---|
185 | }else{ |
---|
186 | if(!elms[j].hasChildNodes()) continue; |
---|
187 | var textContent = elms[j].textContent.replace(/^\s*/mg,"").replace(/\s*$/mg,""); |
---|
188 | if(textContent.length == 0) continue; |
---|
189 | } |
---|
190 | if(htmlTags[elms[j].nodeName.toUpperCase()] != undefined){ |
---|
191 | if(htmlTags[elms[j].nodeName.toUpperCase()]){ |
---|
192 | if(tags.html[elms[j].nodeName.toLowerCase()] == undefined) tags.html[elms[j].nodeName.toLowerCase()] = []; |
---|
193 | tags.html[elms[j].nodeName.toLowerCase()].push(elms[j]); |
---|
194 | } |
---|
195 | }else{ |
---|
196 | if(tags.nohtml[elms[j].nodeName.toLowerCase()] == undefined) tags.nohtml[elms[j].nodeName.toLowerCase()] = []; |
---|
197 | tags.nohtml[elms[j].nodeName.toLowerCase()].push(elms[j]); |
---|
198 | } |
---|
199 | } |
---|
200 | } |
---|
201 | return tags; |
---|
202 | }, |
---|
203 | |
---|
204 | ///////////////////////////////////////////////////////////////////// |
---|
205 | _getHtmlTags : function(){ |
---|
206 | var htmlTags = { |
---|
207 | "A" : 1, |
---|
208 | "ABBR" : 0, |
---|
209 | "ACRONYM" : 0, |
---|
210 | "ADDRESS" : 0, |
---|
211 | "APPLET" : 0, |
---|
212 | "AREA" : 0, |
---|
213 | "B" : 0, |
---|
214 | "BASE" : 0, |
---|
215 | "BASEFONT" : 0, |
---|
216 | "BDO" : 0, |
---|
217 | "BIG" : 0, |
---|
218 | "BLOCKQUOT" : 0, |
---|
219 | "BLOCKQUOTE" : 0, |
---|
220 | "BODY" : 0, |
---|
221 | "BR" : 0, |
---|
222 | "BUTTON" : 0, |
---|
223 | "CAPTION" : 0, |
---|
224 | "CENTER" : 0, |
---|
225 | "CITE" : 0, |
---|
226 | "CODE" : 0, |
---|
227 | "COL" : 0, |
---|
228 | "COLGROUP" : 0, |
---|
229 | "DD" : 0, |
---|
230 | "DEL" : 0, |
---|
231 | "DFN" : 0, |
---|
232 | "DIR" : 0, |
---|
233 | "DIV" : 0, |
---|
234 | "DL" : 0, |
---|
235 | "DT" : 0, |
---|
236 | "EM" : 0, |
---|
237 | "FIELDSET" : 0, |
---|
238 | "FONT" : 0, |
---|
239 | "FORM" : 0, |
---|
240 | "FRAME" : 0, |
---|
241 | "FRAMESET" : 0, |
---|
242 | "H1" : 0, |
---|
243 | "H2" : 0, |
---|
244 | "H3" : 0, |
---|
245 | "H4" : 0, |
---|
246 | "H5" : 0, |
---|
247 | "H6" : 0, |
---|
248 | "HEAD" : 0, |
---|
249 | "HR" : 0, |
---|
250 | "HTML" : 0, |
---|
251 | "I" : 0, |
---|
252 | "IFRAME" : 0, |
---|
253 | "IMG" : 1, |
---|
254 | "INPUT" : 0, |
---|
255 | "INS" : 0, |
---|
256 | "ISINDEX" : 0, |
---|
257 | "KBD" : 0, |
---|
258 | "LABEL" : 0, |
---|
259 | "LEGEND" : 0, |
---|
260 | "LI" : 0, |
---|
261 | "LINK" : 0, |
---|
262 | "MAP" : 0, |
---|
263 | "MENU" : 0, |
---|
264 | "META" : 0, |
---|
265 | "NOBR" : 0, |
---|
266 | "NOFRAMES" : 0, |
---|
267 | "NOSCRIPT" : 0, |
---|
268 | "OBJECT" : 0, |
---|
269 | "OL" : 0, |
---|
270 | "OPTGROUP" : 0, |
---|
271 | "OPTION" : 0, |
---|
272 | "P" : 0, |
---|
273 | "PARAM" : 0, |
---|
274 | "PRE" : 0, |
---|
275 | "Q" : 0, |
---|
276 | "S" : 0, |
---|
277 | "SAMP" : 0, |
---|
278 | "SCRIPT" : 0, |
---|
279 | "SELECT" : 0, |
---|
280 | "SMALL" : 0, |
---|
281 | "SPAN" : 0, |
---|
282 | "STRIKE" : 0, |
---|
283 | "STRONG" : 0, |
---|
284 | "STYLE" : 0, |
---|
285 | "SUB" : 0, |
---|
286 | "SUP" : 0, |
---|
287 | "TABLE" : 0, |
---|
288 | "TBODY" : 0, |
---|
289 | "TD" : 0, |
---|
290 | "TEXTAREA" : 0, |
---|
291 | "TFOOT" : 0, |
---|
292 | "TH" : 0, |
---|
293 | "THEAD" : 0, |
---|
294 | "TITLE" : 0, |
---|
295 | "TR" : 0, |
---|
296 | "TT" : 0, |
---|
297 | "U" : 0, |
---|
298 | "UL" : 0, |
---|
299 | "VAR" : 0, |
---|
300 | }; |
---|
301 | return htmlTags; |
---|
302 | }, |
---|
303 | |
---|
304 | ///////////////////////////////////////////////////////////////////// |
---|
305 | _dump : function(aString){ |
---|
306 | window.top.bitsMarkingCollection._dump(aString); |
---|
307 | }, |
---|
308 | }; |
---|