Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var VHExportProgress =
- {
- onLoad: function()
- {
- var dbConn = VHDatabase.getDbConn();
- if (!dbConn) return;
- // the list contains all rows
- var list = [];
- var statement = dbConn.createStatement("SELECT word,note,htmlnote,matchcase,nothighlight,penname,style,leftboundary,rightboundary,findderivatives FROM vocabulary LEFT JOIN pens ON vocabulary.penid = pens.id");
- statement.executeAsync(
- {
- handleResult: function(aResultSet)
- {
- for (var row = aResultSet.getNextRow(); row; row = aResultSet.getNextRow())
- {
- var theWord = row.getResultByName("word");
- var note = row.getResultByName("note");
- var htmlnote = row.getResultByName("htmlnote");
- var matchCase = row.getResultByName("matchcase");
- var nothighlight = row.getResultByName("nothighlight");
- var penName = row.getResultByName("penname");
- var style = row.getResultByName("style");
- var leftBoundary = row.getResultByName("leftboundary");
- var rightBoundary = row.getResultByName("rightboundary");
- var findDerivatives = row.getResultByName("findderivatives");
- list.push({theWord: theWord, note: note, htmlnote: htmlnote, matchCase: matchCase, nothighlight: nothighlight, penName:penName, style:style, leftBoundary: leftBoundary, rightBoundary: rightBoundary, findDerivatives: findDerivatives});
- }
- },
- handleError: VHDatabase.handleDBError,
- handleCompletion: function(aReason)
- {
- VHDatabase.handleDBCompletion(aReason);
- var file = window.arguments[0].file;
- // saves the directory
- var parentDir = file.parent;
- VHPrefs.setFilePref("exportDirectory", parentDir);
- // file output stream
- var fileOutputStream = Components.classes["@mozilla.org/network/file-output-stream;1"].
- createInstance(Components.interfaces.nsIFileOutputStream);
- // write only, create if not exist, empty file if exist
- fileOutputStream.init(file, 0x02 | 0x08 | 0x20, -1, 0);
- var converter = Components.classes["@mozilla.org/intl/converter-output-stream;1"].
- createInstance(Components.interfaces.nsIConverterOutputStream);
- converter.init(fileOutputStream, "UTF-8", 0, 0);
- VHExportProgress.converter = converter;
- VHExportProgress.writeLine(0, '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>');
- VHExportProgress.writeLine(0, '<' + VHDatabase.databaseFileName + ' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">');
- writtenPens = {};
- var defaultPenName = VH.getString("defaultPen");
- var defaultPenStyle = VHPrefs.getCharPref("defaultpenstyle");
- var defaultPenLeftBoundary = VHPrefs.getBoolPref("defaultpenleftboundary");
- var defaultPenRightBoundary = VHPrefs.getBoolPref("defaultpenrightboundary");
- var defaultPenFindDerivatives = VHPrefs.getBoolPref("defaultpenfindderivatives");
- var penName, style, leftBoundary, rightBoundary, findDerivatives;
- for (var i = 0; i < list.length; i++)
- {
- VHExportProgress.writeLine(1, '<vocabulary>');
- VHExportProgress.writeLine(2, '<word>' + VH.getSearchText(list[i].theWord) + '</word>');
- if (!list[i].htmlnote)
- {
- if (list[i].note)
- VHExportProgress.writeLine(2, '<note>' + VH.getSearchText(list[i].note) + '</note>');
- else
- VHExportProgress.writeLine(2, '<note/>');
- VHExportProgress.writeLine(2, '<htmlnote/>');
- }
- else
- {
- VHExportProgress.writeLine(2, '<note/>');
- VHExportProgress.writeLine(2, '<htmlnote>' + VH.getSearchText(list[i].htmlnote) + '</htmlnote>');
- }
- VHExportProgress.writeLine(2, '<matchcase>' + list[i].matchCase + '</matchcase>');
- VHExportProgress.writeLine(2, '<nothighlight>' + list[i].nothighlight + '</nothighlight>');
- if (list[i].penName)
- {
- penName = VH.getSearchText(list[i].penName);
- style = list[i].style;
- leftBoundary = list[i].leftBoundary;
- rightBoundary = list[i].rightBoundary;
- findDerivatives = list[i].findDerivatives;
- if (writtenPens[penName])
- VHExportProgress.writeLine(2, '<pen penname="' + penName + '"/>');
- else
- VHExportProgress.writeLine(2, '<pen penname="' + penName + '">');
- }
- else // default pen
- {
- penName = defaultPenName;
- style = defaultPenStyle;
- leftBoundary = defaultPenLeftBoundary?1:0;
- rightBoundary = defaultPenRightBoundary?1:0;
- findDerivatives = defaultPenFindDerivatives?1:0;
- if (writtenPens[penName])
- VHExportProgress.writeLine(2, '<pen/>');
- else
- VHExportProgress.writeLine(2, '<pen penname="">');
- }
- if (!writtenPens[penName])
- {
- VHExportProgress.writeLine(3, '<style>' + style + '</style>');
- VHExportProgress.writeLine(3, '<leftboundary>' + leftBoundary + '</leftboundary>');
- VHExportProgress.writeLine(3, '<rightboundary>' + rightBoundary + '</rightboundary>');
- VHExportProgress.writeLine(3, '<findderivatives>' + findDerivatives + '</findderivatives>');
- VHExportProgress.writeLine(2, '</pen>');
- writtenPens[penName] = true;
- }
- VHExportProgress.writeLine(1, '</vocabulary>');
- }
- // makes sure there are always at least two rows
- if (list.length == 0)
- {
- VHExportProgress.writeLine(1, '<vocabulary>');
- VHExportProgress.writeLine(2, '<word/>');
- VHExportProgress.writeLine(2, '<note/>');
- VHExportProgress.writeLine(2, '<htmlnote/>');
- VHExportProgress.writeLine(2, '<matchcase/>');
- VHExportProgress.writeLine(2, '<nothighlight/>');
- VHExportProgress.writeLine(2, '<pen penname="">');
- VHExportProgress.writeLine(3, '<style/>');
- VHExportProgress.writeLine(3, '<leftboundary/>');
- VHExportProgress.writeLine(3, '<rightboundary/>');
- VHExportProgress.writeLine(3, '<findderivatives/>');
- VHExportProgress.writeLine(2, '</pen>');
- VHExportProgress.writeLine(1, '</vocabulary>');
- }
- if (list.length <= 1)
- VHExportProgress.writeLine(1, '<vocabulary/>');
- VHExportProgress.writeLine(0, '</' + VHDatabase.databaseFileName + '>');
- converter.close(); // closes output stream
- // closes the dialog
- document.documentElement.acceptDialog();
- }
- });
- },
- converter: null,
- writeLine: function(tabCount, str)
- {
- var tabStr = "";
- for (var i = 0; i < tabCount; i++)
- tabStr += "\t";
- // uses CRLF for human-reading in Windows
- VHExportProgress.converter.writeString(tabStr + str.replace(/\\/g, "\\") + "\r\n"); // converts '\' to '\\'
- }
- }
Add Comment
Please, Sign In to add comment