Mercurial > snowl
annotate modules/opml.js @ 358:c00b3db58dcf
add 'snowl' to all observer topics to avoid conflicts with other extensions/core code; use the Observers component everywhere
author | Myk Melez <myk@mozilla.org> |
---|---|
date | Tue, 04 Nov 2008 12:11:07 -0800 |
parents | ae23e6f323db |
children | 57bbbcb76b0b |
rev | line source |
---|---|
274
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
1 /* ***** BEGIN LICENSE BLOCK ***** |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
3 * |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
4 * The contents of this file are subject to the Mozilla Public License Version |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
5 * 1.1 (the "License"); you may not use this file except in compliance with |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
6 * the License. You may obtain a copy of the License at |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
7 * http://www.mozilla.org/MPL/ |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
8 * |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
9 * Software distributed under the License is distributed on an "AS IS" basis, |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
11 * for the specific language governing rights and limitations under the |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
12 * License. |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
13 * |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
14 * The Original Code is Snowl. |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
15 * |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
16 * The Initial Developer of the Original Code is Mozilla. |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
17 * Portions created by the Initial Developer are Copyright (C) 2008 |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
18 * the Initial Developer. All Rights Reserved. |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
19 * |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
20 * Contributor(s): |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
21 * Myk Melez <myk@mozilla.org> |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
22 * |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
23 * Alternatively, the contents of this file may be used under the terms of |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
24 * either the GNU General Public License Version 2 or later (the "GPL"), or |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
25 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
26 * in which case the provisions of the GPL or the LGPL are applicable instead |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
27 * of those above. If you wish to allow use of your version of this file only |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
28 * under the terms of either the GPL or the LGPL, and not to allow others to |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
29 * use your version of this file under the terms of the MPL, indicate your |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
30 * decision by deleting the provisions above and replace them with the notice |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
31 * and other provisions required by the GPL or the LGPL. If you do not delete |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
32 * the provisions above, a recipient may use your version of this file under |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
33 * the terms of any one of the MPL, the GPL or the LGPL. |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
34 * |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
35 * ***** END LICENSE BLOCK ***** */ |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
36 |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
37 const Cc = Components.classes; |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
38 const Ci = Components.interfaces; |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
39 const Cr = Components.results; |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
40 const Cu = Components.utils; |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
41 |
283
ae23e6f323db
refresh twitter every three minutes
Myk Melez <myk@mozilla.org>
parents:
275
diff
changeset
|
42 Cu.import("resource://snowl/modules/service.js"); |
274
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
43 |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
44 let EXPORTED_SYMBOLS = ["SnowlOPML"]; |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
45 |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
46 let SnowlOPML = { |
275
5982695f4890
factor out OPML export code from the collections view
Myk Melez <myk@mozilla.org>
parents:
274
diff
changeset
|
47 //**************************************************************************// |
5982695f4890
factor out OPML export code from the collections view
Myk Melez <myk@mozilla.org>
parents:
274
diff
changeset
|
48 // OPML Export |
5982695f4890
factor out OPML export code from the collections view
Myk Melez <myk@mozilla.org>
parents:
274
diff
changeset
|
49 // Based on code in Thunderbird's feed-subscriptions.js. |
5982695f4890
factor out OPML export code from the collections view
Myk Melez <myk@mozilla.org>
parents:
274
diff
changeset
|
50 |
274
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
51 export: function(window) { |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
52 let fp = Cc["@mozilla.org/filepicker;1"].createInstance(Ci.nsIFilePicker); |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
53 // FIXME: make this string localizable. |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
54 fp.init(window, "Export sources as an OPML file", Ci.nsIFilePicker.modeSave); |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
55 fp.appendFilter("OPML Files", "*.opml"); |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
56 fp.appendFilters(Ci.nsIFilePicker.filterXML | Ci.nsIFilePicker.filterAll); |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
57 fp.defaultString = "sources.opml"; |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
58 fp.defaultExtension = "opml"; |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
59 |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
60 let rv = fp.show(); |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
61 |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
62 if (rv == Ci.nsIFilePicker.returnCancel) |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
63 return; |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
64 |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
65 let doc = this._createOPMLDocument(window.document); |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
66 |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
67 // Format the document with newlines and indentation so it's easier |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
68 // for humans to read. |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
69 this._prettifyNode(doc.documentElement, 0); |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
70 |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
71 let serializer = Cc["@mozilla.org/xmlextras/xmlserializer;1"]. |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
72 createInstance(Ci.nsIDOMSerializer); |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
73 let foStream = Cc["@mozilla.org/network/file-output-stream;1"]. |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
74 createInstance(Ci.nsIFileOutputStream); |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
75 // default mode: write | create | truncate |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
76 let mode = 0x02 | 0x08 | 0x20; |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
77 foStream.init(fp.file, mode, 0666, 0); |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
78 serializer.serializeToStream(doc, foStream, "utf-8"); |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
79 }, |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
80 |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
81 _createOPMLDocument: function(document) { |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
82 let doc = document.implementation.createDocument("", "opml", null); |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
83 let root = doc.documentElement; |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
84 root.setAttribute("version", "1.0"); |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
85 |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
86 // Create the <head> element. |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
87 let head = doc.createElement("head"); |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
88 root.appendChild(head); |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
89 |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
90 let title = doc.createElement("title"); |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
91 head.appendChild(title); |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
92 title.appendChild(doc.createTextNode("Snowl OPML Export")); |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
93 |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
94 let dt = doc.createElement("dateCreated"); |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
95 head.appendChild(dt); |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
96 dt.appendChild(doc.createTextNode((new Date()).toGMTString())); |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
97 |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
98 // Create the <body> element. |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
99 let body = doc.createElement("body"); |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
100 root.appendChild(body); |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
101 |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
102 // Populate the <body> element with <outline> elements. |
283
ae23e6f323db
refresh twitter every three minutes
Myk Melez <myk@mozilla.org>
parents:
275
diff
changeset
|
103 let sources = SnowlService.getSources(); |
274
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
104 for each (let source in sources) { |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
105 let outline = doc.createElement("outline"); |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
106 // XXX Should we specify the |type| attribute, and should we specify |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
107 // type="atom" for Atom feeds or just type="rss" for all feeds? |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
108 // This document says the latter but is three years old: |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
109 // http://www.therssweblog.com/?guid=20051003145153 |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
110 //outline.setAttribute("type", "rss"); |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
111 outline.setAttribute("text", source.name); |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
112 outline.setAttribute("url", source.humanURI.spec); |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
113 outline.setAttribute("xmlUrl", source.machineURI.spec); |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
114 body.appendChild(outline); |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
115 } |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
116 |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
117 return doc; |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
118 }, |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
119 |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
120 _prettifyNode: function(node, level) { |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
121 let doc = node.ownerDocument; |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
122 |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
123 // Create a string containing two spaces for every level deep we are. |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
124 let indentString = new Array(level + 1).join(" "); |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
125 |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
126 // Indent the tag. |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
127 if (level > 0) |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
128 node.parentNode.insertBefore(doc.createTextNode(indentString), node); |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
129 |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
130 // Grab the list of nodes to format. We can't just use node.childNodes |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
131 // because it'd change under us as we insert formatting nodes. |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
132 let childNodesToFormat = []; |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
133 for (let i = 0; i < node.childNodes.length; i++) |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
134 if (node.childNodes[i].nodeType == node.ELEMENT_NODE) |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
135 childNodesToFormat.push(node.childNodes[i]); |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
136 |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
137 if (childNodesToFormat.length > 0) { |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
138 for each (let childNode in childNodesToFormat) |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
139 this._prettifyNode(childNode, level + 1); |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
140 |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
141 // Insert a newline after the opening tag. |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
142 node.insertBefore(doc.createTextNode("\n"), node.firstChild); |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
143 |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
144 // Indent the closing tag. |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
145 node.appendChild(doc.createTextNode(indentString)); |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
146 } |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
147 |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
148 // Insert a newline after the tag. |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
149 if (level > 0) { |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
150 if (node.nextSibling) |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
151 node.parentNode.insertBefore(doc.createTextNode("\n"), |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
152 node.nextSibling); |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
153 else |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
154 node.parentNode.appendChild(doc.createTextNode("\n")); |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
155 } |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
156 } |
5f5cd84d29ef
add check for new messages, subscribe, import OPML, and export OPML commands to the Snowl menu
Myk Melez <myk@mozilla.org>
parents:
diff
changeset
|
157 }; |