Bug #297804 --> OPML Export should be pretty-printed

patch by robert sayre

sr=me
This commit is contained in:
scott%scott-macgregor.org 2005-06-15 21:32:01 +00:00
Родитель b3bea742b2
Коммит 28018cc54b
1 изменённых файлов: 31 добавлений и 8 удалений

Просмотреть файл

@ -817,22 +817,32 @@ var gFeedSubscriptionsWindow = {
var opmlDoc = document.implementation.createDocument("","opml",null); var opmlDoc = document.implementation.createDocument("","opml",null);
var opmlRoot = opmlDoc.documentElement; var opmlRoot = opmlDoc.documentElement;
opmlRoot.setAttribute("version","1.0"); opmlRoot.setAttribute("version","1.0");
this.generatePPSpace(opmlRoot," ");
// Make the <head> element // Make the <head> element
var head = opmlDoc.createElement("head"); var head = opmlDoc.createElement("head");
this.generatePPSpace(head, " ");
var title = opmlDoc.createElement("title"); var title = opmlDoc.createElement("title");
title.appendChild(opmlDoc.createTextNode(this.mBundle.getString("subscribe-OPMLExportFileTitle"))); title.appendChild(opmlDoc.createTextNode(this.mBundle.getString("subscribe-OPMLExportFileTitle")));
head.appendChild(title); head.appendChild(title);
this.generatePPSpace(head, " ");
var dt = opmlDoc.createElement("dateCreated"); var dt = opmlDoc.createElement("dateCreated");
dt.appendChild(opmlDoc.createTextNode((new Date()).toGMTString())); dt.appendChild(opmlDoc.createTextNode((new Date()).toGMTString()));
head.appendChild(dt); head.appendChild(dt);
this.generatePPSpace(head, " ");
opmlRoot.appendChild(head); opmlRoot.appendChild(head);
this.generatePPSpace(opmlRoot, " ");
//add <outline>s to the <body> //add <outline>s to the <body>
var body = opmlDoc.createElement("body"); var body = opmlDoc.createElement("body");
this.generateOutline(this.mRSSServer.rootFolder, body); this.generateOutline(this.mRSSServer.rootFolder, body, 4);
this.generatePPSpace(body, " ");
opmlRoot.appendChild(body); opmlRoot.appendChild(body);
this.generatePPSpace(opmlRoot, "");
var serial=new XMLSerializer(); var serial=new XMLSerializer();
var rv = pickSaveAs(this.mBundle.getString("subscribe-OPMLExportTitle"),'$all', var rv = pickSaveAs(this.mBundle.getString("subscribe-OPMLExportTitle"),'$all',
this.mBundle.getString("subscribe-OPMLExportFileName")); this.mBundle.getString("subscribe-OPMLExportFileName"));
@ -847,12 +857,23 @@ var gFeedSubscriptionsWindow = {
} }
} }
}, },
generatePPSpace: function(aNode, indentString)
{
aNode.appendChild(aNode.ownerDocument.createTextNode("\n"));
aNode.appendChild(aNode.ownerDocument.createTextNode(indentString));
},
generateOutline: function(baseFolder, parent) generateOutline: function(baseFolder, parent, indentLevel)
{ {
var folderEnumerator = baseFolder.GetSubFolders(); var folderEnumerator = baseFolder.GetSubFolders();
var done = false; var done = false;
// pretty printing
var indentString = "";
for(i = 0; i < indentLevel; i++)
indentString = indentString + " ";
while (!done) while (!done)
{ {
var folder = folderEnumerator.currentItem().QueryInterface(Components.interfaces.nsIMsgFolder); var folder = folderEnumerator.currentItem().QueryInterface(Components.interfaces.nsIMsgFolder);
@ -864,17 +885,19 @@ var gFeedSubscriptionsWindow = {
// Make a mostly empty outline element // Make a mostly empty outline element
outline = parent.ownerDocument.createElement("outline"); outline = parent.ownerDocument.createElement("outline");
outline.setAttribute("text",folder.prettiestName); outline.setAttribute("text",folder.prettiestName);
this.generateOutline(folder, outline); // recurse this.generateOutline(folder, outline, indentLevel+2); // recurse
this.generatePPSpace(parent, indentString);
this.generatePPSpace(outline, indentString);
parent.appendChild(outline); parent.appendChild(outline);
} }
else else
{ {
// Add outline elements with xmlUrls // Add outline elements with xmlUrls
var feeds = this.getFeedsInFolder(folder); var feeds = this.getFeedsInFolder(folder);
for(feed in feeds) for (feed in feeds)
{ {
debug("feed: " + feeds[feed]);
outline = this.opmlFeedToOutline(feeds[feed],parent.ownerDocument); outline = this.opmlFeedToOutline(feeds[feed],parent.ownerDocument);
this.generatePPSpace(parent, indentString);
parent.appendChild(outline); parent.appendChild(outline);
} }
} }