29 Components.utils.import(
"resource://app/jsmodules/sbProperties.jsm");
48 var
istream =
Cc[
"@mozilla.org/network/file-input-stream;1"]
49 .createInstance(
Ci.nsIFileInputStream);
51 istream.QueryInterface(
Ci.nsILineInputStream);
53 var line = {}, hasmore;
55 hasmore = istream.readLine(line);
56 aCallback.apply(aThis, [line.value]);
74 var
istream =
Cc[
"@mozilla.org/network/file-input-stream;1"]
75 .createInstance(
Ci.nsIFileInputStream);
77 istream.QueryInterface(
Ci.nsILineInputStream);
79 var detector =
Cc[
"@songbirdnest.com/Songbird/CharsetDetector;1"]
80 .createInstance(
Ci.sbICharsetDetector);
81 var line = {}, hasmore,
charset;
86 hasmore = istream.readLine(line);
94 detector.detect(value);
96 length += value.length;
98 !detector.isCharsetFound &&
100 charset = detector.finish();
103 dump(
"charset detection error in SB_DetectCharsetAndProcessFile: " +
109 var fstream =
Cc[
"@mozilla.org/network/file-input-stream;1"]
110 .createInstance(
Ci.nsIFileInputStream);
112 fstream.QueryInterface(
Ci.nsILineInputStream);
113 var unicodeConverter =
Cc[
"@mozilla.org/intl/scriptableunicodeconverter"]
114 .createInstance(
Ci.nsIScriptableUnicodeConverter);
117 hasmore = fstream.readLine(line);
125 unicodeConverter.charset = charset ? charset :
"ISO-8859-1";
126 value = unicodeConverter.ConvertToUnicode(value);
129 dump(
"Unicode conversion error in SB_DetectCharsetAndProcessFile: " +
133 aCallback.apply(aThis, [value]);
141 if (aItems.length == 0)
144 function removeItemsByUri(items,
uri) {
145 for (var
i = items.length - 1;
i >= 0;
i--) {
154 if (aAddDistinctOnly) {
157 for (var
i = 0;
i < aItems.length - 1;
i++) {
158 var
uri = aItems[
i].uri;
159 for (var j =
i + 1; j < aItems.length; j++)
160 if (aItems[j].uri.equals(uri))
166 var propertyArray = SBProperties.createArray();
167 aItems.forEach(
function(e) {
168 propertyArray.appendProperty(SBProperties.contentURL, e.uri.spec);
173 onEnumerationBegin:
function() {
175 onEnumeratedItem:
function(list, item) {
176 removeItemsByUri(aItems, item.contentSrc.spec);
178 onEnumerationEnd:
function() {
182 aMediaList.enumerateItemsByProperties(propertyArray,
187 if (aItems.length > 0) {
188 propertyArray.clear();
189 aItems.forEach(
function(e) {
190 propertyArray.appendProperty(SBProperties.originURL, e.uri.spec);
195 onEnumerationBegin:
function() {
197 onEnumeratedItem:
function(list, item) {
198 removeItemsByUri(aItems, item.getProperty(SBProperties.originURL));
200 onEnumerationEnd:
function() {
204 aMediaList.enumerateItemsByProperties(propertyArray,
211 if (aItems.length > 0) {
214 var
uris =
Cc[
"@songbirdnest.com/moz/xpcom/threadsafe-array;1"]
215 .createInstance(
Ci.nsIMutableArray);
216 var libraryUtils =
Cc[
"@songbirdnest.com/Songbird/library/Manager;1"]
217 .getService(
Ci.sbILibraryUtils);
218 aItems.forEach(
function(e) {
219 uris.appendElement(libraryUtils.getContentURI(e.uri),
false);
223 var resultItems = {};
224 var created = aMediaList.library.batchCreateMediaItemsIfNotExist
228 resultItems = resultItems.value;
230 for (var
i = 0;
i < aItems.length;
i++) {
231 aItems[
i].item = resultItems.queryElementAt(
i,
Ci.sbIMediaItem);
232 if (created.queryElementAt(
i,
Ci.nsIVariant))
233 aItems[
i].created =
true;
238 aMediaList.runInBatchMode(
function() {
239 aItems.forEach(
function(e) {
241 for (var prop in e.properties) {
243 e.item.setProperty(prop, e.properties[prop]);
246 Components.utils.reportError(e);
259 return this._index < this._array.length;
261 getNext:
function() {
262 var item = this._array[this._index].item;
268 aMediaList.addSome(enumerator);
275 var
ios =
Cc[
"@mozilla.org/network/io-service;1"]
276 .getService(
Ci.nsIIOService);
280 if (aBaseURI ==
null || aBaseURI.scheme ==
"file") {
282 var
file =
Cc[
"@mozilla.org/file/local;1"]
283 .createInstance(
Ci.nsILocalFile);
284 file.initWithPath(aStringURL);
286 var
uri = ios.newFileURI(file);
314 var
uri = ios.newURI(aStringURL,
null, aBaseURI);
315 if ( uri instanceof
Ci.nsIFileURL && !uri.file.exists() ) {
for(let i=0;i< aHistory.count;i++)
function SB_DetectCharsetAndProcessFile(aFile, aCallback, aThis)
Detect the charset of the file aFile, convert the file encode to the detected one, and process the file line by line with the callback function aCallback.
SimpleArrayEnumerator prototype hasMoreElements
function SB_AddItems(aItems, aMediaList, aAddDistinctOnly)
const GUESS_CHARSET_MIN_CHAR_COUNT
function SB_ResolveURI(aStringURL, aBaseURI)
function SB_ProcessFile(aFile, aCallback, aThis)
Process the file aFile line by line with the callback function aCallback.
_getSelectedPageStyle s i