bug 320869: remove unused calendar files. r=jminta

This commit is contained in:
mvl%exedo.nl 2006-02-12 21:55:26 +00:00
Родитель 8792a10a40
Коммит abf17043d3
12 изменённых файлов: 0 добавлений и 4417 удалений

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

@ -1,249 +0,0 @@
/* -*- Mode: Javascript; tab-width: 2; */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Collabnet code.
*
* The Initial Developer of the Original Code is
* Collabnet.
* Portions created by the Initial Developer are Copyright (C) 2000
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Pete Collins, Doug Turner, Brendan Eich, Warren Harris,
* Eric Plaster, Martin Kutschker
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/*
JS Directory Class API
dir.js
Function List
create(aPermissions); // permissions are optional
files(); // returns an array listing all files of a dirs contents
dirs(); // returns an array listing all dirs of a dirs contents
list(aDirPath); // returns an array listing of a dirs contents
// help!
help(); // currently dumps a list of available functions
Instructions:
*/
if (typeof(JS_LIB_LOADED)=='boolean') {
/************* INCLUDE FILESYSTEM *****************/
if(typeof(JS_FILESYSTEM_LOADED)!='boolean')
include(jslib_filesystem);
/************* INCLUDE FILESYSTEM *****************/
/****************** Globals **********************/
const JS_DIR_FILE = "dir.js";
const JS_DIR_LOADED = true;
const JS_DIR_LOCAL_CID = "@mozilla.org/file/local;1";
const JS_DIR_LOCATOR_PROGID = '@mozilla.org/filelocator;1';
const JS_DIR_CID = "@mozilla.org/file/directory_service;1";
const JS_DIR_I_LOCAL_FILE = "nsILocalFile";
const JS_DIR_INIT_W_PATH = "initWithPath";
const JS_DIR_PREFS_DIR = 65539;
const JS_DIR_DIRECTORY = 0x01; // 1
const JS_DIR_OK = true;
const JS_DIR_DEFAULT_PERMS = 0766;
const JS_DIR_FilePath = new C.Constructor(JS_DIR_LOCAL_CID,
JS_DIR_I_LOCAL_FILE,
JS_DIR_INIT_W_PATH);
/****************** Globals **********************/
/****************** Dir Object Class *********************/
// constructor
function Dir(aPath) {
if(!aPath) {
jslibError(null,
"Please enter a local file path to initialize",
"NS_ERROR_XPC_NOT_ENOUGH_ARGS", JS_DIR_FILE);
throw C.results.NS_ERROR_XPC_NOT_ENOUGH_ARGS;
}
return this.initPath(arguments);
} // end constructor
Dir.prototype = new FileSystem;
Dir.prototype.fileInst = null;
/********************* CREATE ****************************/
Dir.prototype.create = function(aPermissions)
{
if(!this.mPath) {
jslibError(null, "create (no file path defined)", "NS_ERROR_NOT_INITIALIZED");
return C.results.NS_ERROR_NOT_INITIALIZED;
}
if(this.exists()) {
jslibError(null, "(Dir already exists", "NS_ERROR_FAILURE", JS_DIR_FILE+":create");
return null;
}
if (typeof(aPermissions) == "number") {
var checkPerms = this.validatePermissions(aPermissions);
if(!checkPerms) {
jslibError(null, "create (invalid permissions)",
"NS_ERROR_INVALID_ARG", JS_DIR_FILE+":create");
return C.results.NS_ERROR_INVALID_ARG;
}
} else {
checkPerms = this.mFileInst.parent.permissions;
}
var rv = null;
try {
rv=this.mFileInst.create(JS_DIR_DIRECTORY, checkPerms);
} catch (e) {
jslibError(e, "(unable to create)", "NS_ERROR_FAILURE", JS_DIR_FILE+":create");
rv=null;
}
return rv;
};
/********************* READDIR **************************/
Dir.prototype.readDir = function ()
{
if(!this.exists()) {
jslibError(null, "(Dir already exists", "NS_ERROR_FAILURE", JS_DIR_FILE+":readDir");
return null;
}
var rv=null;
try {
if(!this.isDir()) {
jslibError(null, "(file is not a directory)", "NS_ERROR_FAILURE", JS_DIR_FILE+":readDir");
return null;
}
var files = this.mFileInst.directoryEntries;
var listings = new Array();
var file;
if(typeof(JS_FILE_LOADED)!='boolean')
include(JS_LIB_PATH+'io/file.js');
while(files.hasMoreElements()) {
file = files.getNext().QueryInterface(C.interfaces.nsILocalFile);
if(file.isFile())
listings.push(new File(file.path));
if(file.isDirectory())
listings.push(new Dir(file.path));
}
rv=listings;
} catch(e) {
jslibError(e, "(unexpected error)", "NS_ERROR_UNEXPECTED", JS_FILE_FILE+":readDir");
rv=null;
}
return rv;
};
/********************* REMOVE *******************************/
Dir.prototype.remove = function (aRecursive)
{
if(typeof(aRecursive)!='boolean')
aRecursive=false;
if(!this.checkInst())
throw C.results.NS_ERROR_NOT_INITIALIZED;
if(!this.mPath)
{
jslibError(null, "remove (no path defined)",
"NS_ERROR_INVALID_ARG", JS_DIR_FILE+":remove");
return null;
}
var rv=null
try {
if(!this.exists()) {
jslibError(null, "(directory doesn't exist)", "NS_ERROR_FAILURE", JS_DIR_FILE+":remove");
return null;
}
if(!this.isDir()) {
jslibError(null, "(file is not a directory)", "NS_ERROR_FAILURE", JS_DIR_FILE+":remove");
return null;
}
rv=this.mFileInst.remove(aRecursive);
} catch (e) {
jslibError(e, "(dir not empty, use 'remove(true)' for recursion)", "NS_ERROR_UNEXPECTED",
JS_DIR_FILE+":remove");
rv=null;
}
return rv;
};
/********************* HELP *****************************/
Dir.prototype.super_help = FileSystem.prototype.help;
Dir.prototype.__defineGetter__('help',
function() {
var help = this.super_help() +
" create(aPermissions);\n" +
" remove(aRecursive);\n" +
" readDir(aDirPath);\n";
return help;
});
jslibDebug('*** load: '+JS_DIR_FILE+' OK');
} else {
dump("JSLIB library not loaded:\n" +
" \tTo load use: chrome://jslib/content/jslib.js\n" +
" \tThen: include(jslib_dir);\n\n");
}

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

@ -1,204 +0,0 @@
/* -*- Mode: Javascript; tab-width: 2; */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Collabnet code.
*
* The Initial Developer of the Original Code is
* Collabnet.
* Portions created by the Initial Developer are Copyright (C) 2000
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Pete Collins, Doug Turner, Brendan Eich, Warren Harris,
* Eric Plaster, Martin Kutschker
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/*
JS Directory Class API
dirUtils.js
Function List
Instructions:
*/
if(typeof(JS_LIB_LOADED)=='boolean') {
const JS_DIRUTILS_FILE = "dirUtils.js";
const JS_DIRUTILS_LOADED = true;
const JS_DIRUTILS_FILE_LOCAL_CID = "@mozilla.org/file/local;1";
const JS_DIRUTILS_FILE_DIR_CID = "@mozilla.org/file/directory_service;1";
const JS_DIRUTILS_FILE_I_LOCAL_FILE = "nsILocalFile";
const JS_DIRUTILS_INIT_W_PATH = "initWithPath";
const JS_DIRUTILS_I_PROPS = "nsIProperties";
const JS_DIRUTILS_NSIFILE = C.interfaces.nsIFile;
const NS_APP_PREFS_50_DIR = "PrefD"; // /root/.mozilla/Default User/k1m30xaf.slt
const NS_APP_CHROME_DIR = "AChrom"; // /usr/src/mozilla/dist/bin/chrome
const NS_APP_USER_PROFILES_ROOT_DIR = "DefProfRt"; // /root/.mozilla
const NS_APP_USER_PROFILE_50_DIR = "ProfD"; // /root/.mozilla/Default User/k1m30xaf.slt
const NS_APP_APPLICATION_REGISTRY_DIR = "AppRegD"; // /root/.mozilla
const NS_APP_APPLICATION_REGISTRY_FILE = "AppRegF"; // /root/.mozilla/appreg
const NS_APP_DEFAULTS_50_DIR = "DefRt"; // /usr/src/mozilla/dist/bin/defaults
const NS_APP_PREF_DEFAULTS_50_DIR = "PrfDef"; // /usr/src/mozilla/dist/bin/defaults/pref
const NS_APP_PROFILE_DEFAULTS_50_DIR = "profDef"; // /usr/src/mozilla/dist/bin/defaults/profile/US
const NS_APP_PROFILE_DEFAULTS_NLOC_50_DIR = "ProfDefNoLoc"; // /usr/src/mozilla/dist/bin/defaults/profile
const NS_APP_RES_DIR = "ARes"; // /usr/src/mozilla/dist/bin/res
const NS_APP_PLUGINS_DIR = "APlugns"; // /usr/src/mozilla/dist/bin/plugins
const NS_APP_SEARCH_DIR = "SrchPlugns"; // /usr/src/mozilla/dist/bin/searchplugins
const NS_APP_PREFS_50_FILE = "PrefF"; // /root/.mozilla/Default User/k1m30xaf.slt/prefs.js
const NS_APP_USER_CHROME_DIR = "UChrm"; // /root/.mozilla/Default User/k1m30xaf.slt/chrome
const NS_APP_LOCALSTORE_50_FILE = "LclSt"; // /root/.mozilla/Default User/k1m30xaf.slt/localstore.rdf
const NS_APP_HISTORY_50_FILE = "UHist"; // /root/.mozilla/Default User/k1m30xaf.slt/history.dat
const NS_APP_USER_PANELS_50_FILE = "UPnls"; // /root/.mozilla/Default User/k1m30xaf.slt/panels.rdf
const NS_APP_USER_MIMETYPES_50_FILE = "UMimTyp"; // /root/.mozilla/Default User/k1m30xaf.slt/mimeTypes.rdf
const NS_APP_BOOKMARKS_50_FILE = "BMarks"; // /root/.mozilla/Default User/k1m30xaf.slt/bookmarks.html
const NS_APP_SEARCH_50_FILE = "SrchF"; // /root/.mozilla/Default User/k1m30xaf.slt/search.rdf
const NS_APP_MAIL_50_DIR = "MailD"; // /root/.mozilla/Default User/k1m30xaf.slt/Mail
const NS_APP_IMAP_MAIL_50_DIR = "IMapMD"; // /root/.mozilla/Default User/k1m30xaf.slt/ImapMail
const NS_APP_NEWS_50_DIR = "NewsD"; // /root/.mozilla/Default User/k1m30xaf.slt/News
const NS_APP_MESSENGER_FOLDER_CACHE_50_DIR = "MFCaD"; // /root/.mozilla/Default User/k1m30xaf.slt/panacea.dat
// Useful OS System Dirs
const NS_OS_CURRENT_PROCESS_DIR = "CurProcD"; // /usr/src/mozilla/dist/bin
const NS_OS_HOME_DIR = "Home"; // /root
const NS_OS_TEMP_DIR = "TmpD"; // /tmp
const NS_XPCOM_COMPONENT_DIR = "ComsD"; // /usr/src/mozilla/dist/bin/components
const JS_DIRUTILS_FilePath = new C.Constructor(JS_DIRUTILS_FILE_LOCAL_CID,
JS_DIRUTILS_FILE_I_LOCAL_FILE,
JS_DIRUTILS_INIT_W_PATH);
const JS_DIRUTILS_DIR = new C.Constructor(JS_DIRUTILS_FILE_DIR_CID,
JS_DIRUTILS_I_PROPS);
// constructor
function DirUtils(){}
DirUtils.prototype = {
getPath : function (aAppID) {
if(!aAppID) {
jslibError(null, "(no arg defined)", "NS_ERROR_INVALID_ARG", JS_FILE_FILE+":getPath");
return null;
}
var rv;
try {
rv=(new JS_DIRUTILS_DIR()).get(aAppID, JS_DIRUTILS_NSIFILE).path;
} catch (e) {
jslibError(e, "(unexpected error)", "NS_ERROR_FAILURE", JS_DIRUTILS_FILE+":getPath");
rv=null;
}
return rv;
},
getPrefsDir : function () { return this.getPath(NS_APP_PREFS_50_DIR); },
getChromeDir : function () { return this.getPath(NS_APP_CHROME_DIR); },
getMozHomeDir : function () { return this.getPath(NS_APP_USER_PROFILES_ROOT_DIR); },
getMozUserHomeDir : function () { return this.getPath(NS_APP_USER_PROFILE_50_DIR); },
getAppRegDir : function () { return this.getPath(NS_APP_APPLICATION_REGISTRY_FILE); },
getAppDefaultDir : function () { return this.getPath(NS_APP_DEFAULTS_50_DIR); },
getAppDefaultPrefDir : function () { return this.getPath(NS_APP_PREF_DEFAULTS_50_DIR); },
getProfileDefaultsLocDir : function () { return this.getPath(NS_APP_PROFILE_DEFAULTS_50_DIR); },
getProfileDefaultsDir : function () { return this.getPath(NS_APP_PROFILE_DEFAULTS_NLOC_50_DIR); },
getAppResDir : function () { return this.getPath(NS_APP_RES_DIR); },
getAppPluginsDir : function () { return this.getPath(NS_APP_PLUGINS_DIR); },
getSearchPluginsDir : function () { return this.getPath(NS_APP_SEARCH_DIR); },
getPrefsFile : function () { return this.getPath(NS_APP_PREFS_50_FILE); },
getUserChromeDir : function () { return this.getPath(NS_APP_USER_CHROME_DIR); },
getLocalStore : function () { return this.getPath(NS_APP_LOCALSTORE_50_FILE); },
getHistoryFile : function () { return this.getPath(NS_APP_HISTORY_50_FILE); },
getPanelsFile : function () { return this.getPath(NS_APP_USER_PANELS_50_FILE); },
getMimeTypes : function () { return this.getPath(NS_APP_USER_MIMETYPES_50_FILE); },
getBookmarks : function () { return this.getPath(NS_APP_BOOKMARKS_50_FILE); },
getSearchFile : function () { return this.getPath(NS_APP_SEARCH_50_FILE); },
getUserMailDir : function () { return this.getPath(NS_APP_MAIL_50_DIR); },
getUserImapDir : function () { return this.getPath(NS_APP_IMAP_MAIL_50_DIR); },
getUserNewsDir : function () { return this.getPath(NS_APP_NEWS_50_DIR); },
getMessengerFolderCache : function () { return this.getPath(NS_APP_MESSENGER_FOLDER_CACHE_50_DIR); },
getCurProcDir : function () { return this.getPath(NS_OS_CURRENT_PROCESS_DIR); },
getHomeDir : function () { return this.getPath(NS_OS_HOME_DIR); },
getTmpDir : function () { return this.getPath(NS_OS_TEMP_DIR); },
getComponentsDir : function () { return this.getPath(NS_XPCOM_COMPONENT_DIR); },
get help() {
const help =
"\n\nFunction and Attribute List:\n" +
"\n" +
" getPrefsDir()\n" +
" getChromeDir()\n" +
" getMozHomeDir()\n" +
" getMozUserHomeDir()\n" +
" getAppRegDir()\n" +
" getAppDefaultDir()\n" +
" getAppDefaultPrefDir()\n" +
" getProfileDefaultsLocDir()\n" +
" getProfileDefaultsDir()\n" +
" getAppResDir()\n" +
" getAppPluginsDir()\n" +
" getSearchPluginsDir()\n" +
" getPrefsFile()\n" +
" getUserChromeDir()\n" +
" getLocalStore()\n" +
" getHistoryFile()\n" +
" getPanelsFile()\n" +
" getMimeTypes()\n" +
" getBookmarks()\n" +
" getSearchFile()\n" +
" getUserMailDir()\n" +
" getUserImapDir()\n" +
" getUserNewsDir()\n" +
" getMessengerFolderCache()\n\n";
return help;
}
}; //END CLASS
jslibDebug('*** load: '+JS_DIRUTILS_FILE+' OK');
} // END BLOCK JS_LIB_LOADED CHECK
else {
dump("JSLIB library not loaded:\n" +
" \tTo load use: chrome://jslib/content/jslib.js\n" +
" \tThen: include(jslib_dirutils);\n\n");
}

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

@ -1,945 +0,0 @@
/* -*- Mode: Javascript; tab-width: 2; */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is jslib code.
*
* The Initial Developer of the Original Code is
* jslib team.
* Portions created by the Initial Developer are Copyright (C) 2000
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Pete Collins, Doug Turner, Brendan Eich, Warren Harris,
* Eric Plaster, Martin Kutschker
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/*
The purpose of this file is to make it a little easier to use
xpcom nsIFile file IO library from js
File API
file.js
Base Class:
FileSystem
filesystem.js
Function List:
// Constructor
File(aPath) creates the File object and sets the file path
// file stream methods
open(aMode, aPermissions); open a file handle for reading,
writing or appending. permissions are optional.
read(); returns the contents of a file
readline(); returns the next line in the file.
EOF; boolean check 'end of file' status
write(aContents); writes the contents out to file.
copy(aDest); copy the current file to a aDest
close(); closes a file handle
create(); creates a new file if one doesn't already exist
exists(); check to see if a file exists
// file attributes
size; read only attribute gets the file size
ext; read only attribute gets a file extension if there is one
permissions; attribute gets or sets the files permissions
dateModified; read only attribute gets last modified date in locale string
// file path attributes
leaf; read only attribute gets the file leaf
path; read only attribute gets the path
parent; read only attribute gets parent dir part of a path
// direct manipulation
nsIFile returns an nsIFile obj
// utils
remove(); removes the current file
append(aLeaf); appends a leaf name to the current file
appendRelativePath(aRelPath); appends a relitave path the the current file
// help!
help; currently dumps a list of available functions
Instructions:
First include this js file in your xul file.
Next, create an File object:
var file = new File("/path/file.ext");
To see if the file exists, call the exists() member.
This is a good check before going into some
deep code to try and extract information from a non-existant file.
To open a file for reading<"r">, writing<"w"> or appending<"a">,
just call:
file.open("w", 0644);
where in this case you will be creating a new file called '/path/file.ext',
with a mode of "w" which means you want to write a new file.
If you want to read from a file, just call:
file.open(); or
file.open("r");
var theFilesContents = file.read();
---- or ----
while(!file.EOF) {
var theFileContentsLine = file.readline();
dump("line: "+theFileContentsLine+"\n");
}
The file contents will be returned to the caller so you can do something useful with it.
file.close();
Calling 'close()' destroys any created objects. If you forget to use file.close() no probs
all objects are discarded anyway.
Warning: these API's are not for religious types
************/
// insure jslib base is loaded
if (typeof(JS_LIB_LOADED)=='boolean') {
// test to make sure filesystem base class is loaded
if (typeof(JS_FILESYSTEM_LOADED)!='boolean')
include(jslib_filesystem);
/****************** Globals **********************/
const JS_FILE_LOADED = true;
const JS_FILE_FILE = "file.js";
const JS_FILE_IOSERVICE_CID = "@mozilla.org/network/io-service;1";
const JS_FILE_I_STREAM_CID = "@mozilla.org/scriptableinputstream;1";
const JS_FILE_OUTSTREAM_CID = "@mozilla.org/network/file-output-stream;1";
const JS_FILE_F_TRANSPORT_SERVICE_CID = "@mozilla.org/network/file-transport-service;1";
const JS_FILE_I_IOSERVICE = C.interfaces.nsIIOService;
const JS_FILE_I_SCRIPTABLE_IN_STREAM = "nsIScriptableInputStream";
const JS_FILE_I_FILE_OUT_STREAM = C.interfaces.nsIFileOutputStream;
const JS_FILE_READ = 0x01; // 1
const JS_FILE_WRITE = 0x08; // 8
const JS_FILE_APPEND = 0x10; // 16
const JS_FILE_READ_MODE = "r";
const JS_FILE_WRITE_MODE = "w";
const JS_FILE_APPEND_MODE = "a";
const JS_FILE_FILE_TYPE = 0x00; // 0
const JS_FILE_CHUNK = 1024; // buffer for readline => set to 1k
const JS_FILE_DEFAULT_PERMS = 0644;
const JS_FILE_OK = true;
try {
const JS_FILE_InputStream = new C.Constructor
(JS_FILE_I_STREAM_CID, JS_FILE_I_SCRIPTABLE_IN_STREAM);
const JS_FILE_IOSERVICE = C.classes[JS_FILE_IOSERVICE_CID].
getService(JS_FILE_I_IOSERVICE);
} catch (e) {
jslibError (e, "open("+this.mMode+") (unable to get nsIFileChannel)",
"NS_ERROR_FAILURE",
JS_FILE_FILE);
}
/***
* Possible values for the ioFlags parameter
* From:
* http://lxr.mozilla.org/seamonkey/source/nsprpub/pr/include/prio.h#601
*/
// #define PR_RDONLY 0x01
// #define PR_WRONLY 0x02
// #define PR_RDWR 0x04
// #define PR_CREATE_FILE 0x08
// #define PR_APPEND 0x10
// #define PR_TRUNCATE 0x20
// #define PR_SYNC 0x40
// #define PR_EXCL 0x80
const JS_FILE_NS_RDONLY = 0x01;
const JS_FILE_NS_WRONLY = 0x02;
const JS_FILE_NS_RDWR = 0x04;
const JS_FILE_NS_CREATE_FILE = 0x08;
const JS_FILE_NS_APPEND = 0x10;
const JS_FILE_NS_TRUNCATE = 0x20;
const JS_FILE_NS_SYNC = 0x40;
const JS_FILE_NS_EXCL = 0x80;
/****************** Globals **********************/
/****************************************************************
* void File(aPath) *
* *
* class constructor *
* aPath is an argument of string local file path *
* returns NS_OK on success, exception upon failure *
* Ex: *
* var p = '/tmp/foo.dat'; *
* var f = new File(p); *
* *
* outputs: void(null) *
****************************************************************/
function File(aPath) {
if (!aPath) {
jslibError(null,
"Please enter a local file path to initialize",
"NS_ERROR_XPC_NOT_ENOUGH_ARGS", JS_FILE_FILE);
throw - C.results.NS_ERROR_XPC_NOT_ENOUGH_ARGS;
}
return this.initPath(arguments);
} // constructor
File.prototype = new FileSystem();
// member vars
File.prototype.mMode = null;
File.prototype.mFileChannel = null;
File.prototype.mTransport = null;
File.prototype.mURI = null;
File.prototype.mOutStream = null;
File.prototype.mInputStream = null;
File.prototype.mLineBuffer = null;
File.prototype.mPosition = 0;
/********************* OPEN *************************************
* bool open(aMode, aPerms) *
* *
* opens a file handle to read, write or append *
* aMode is an argument of string 'w', 'a', 'r' *
* returns true on success, null on failure *
* Ex: *
* var p='/tmp/foo.dat'; *
* var f=new File(p); *
* *
* outputs: void(null) *
****************************************************************/
File.prototype.open = function(aMode, aPerms)
{
if (!this.checkInst())
throw C.results.NS_ERROR_NOT_INITIALIZED;
if (!this.mPath) {
jslibError(null, "open("+this.mMode+") (no file path defined)",
"NS_ERROR_NOT_INITIALIZED",
JS_FILE_FILE+":open");
return null;
}
if (this.exists() && this.mFileInst.isDirectory()) {
jslibError(null, "open("+this.mMode+") (cannot open directory)",
"NS_ERROR_FAILURE",
JS_FILE_FILE+":open");
return null;
}
if (this.mMode) {
jslibError(null, "open("+this.mMode+") (already open)",
"NS_ERROR_NOT_INITIALIZED",
JS_FILE_FILE+":open");
this.close();
return null;
}
this.close();
if (!this.mURI) {
if (!this.exists())
this.create();
this.mURI = JS_FILE_IOSERVICE.newFileURI(this.mFileInst);
}
if (!aMode)
aMode=JS_FILE_READ_MODE;
this.resetCache();
var rv;
switch(aMode) {
case JS_FILE_WRITE_MODE:
case JS_FILE_APPEND_MODE: {
try {
if (!this.mFileChannel)
this.mFileChannel = JS_FILE_IOSERVICE.newChannelFromURI(this.mURI);
} catch(e) {
jslibError(e, "open("+this.mMode+") (unable to get nsIFileChannel)",
"NS_ERROR_FAILURE",
JS_FILE_FILE+":open");
return null;
}
if (aPerms) {
if (!this.validatePermissions(aPerms)) {
jslibError(null, "open("+this.mMode+") (invalid permissions)",
"NS_ERROR_INVALID_ARG",
JS_FILE_FILE+":open");
return null;
}
}
if (!aPerms)
aPerms=JS_FILE_DEFAULT_PERMS;
// removing, i don't think we need this --pete
//this.permissions = aPerms;
try {
var offSet=0;
if (aMode == JS_FILE_WRITE_MODE) {
this.mMode=JS_FILE_WRITE_MODE;
// create a filestream
var fs = C.classes[JS_FILE_OUTSTREAM_CID].
createInstance(JS_FILE_I_FILE_OUT_STREAM);
fs.init(this.mFileInst, JS_FILE_NS_TRUNCATE |
JS_FILE_NS_WRONLY, 00004, null);
this.mOutStream = fs;
} else {
this.mMode=JS_FILE_APPEND_MODE;
// create a filestream
var fs = C.classes[JS_FILE_OUTSTREAM_CID].
createInstance(JS_FILE_I_FILE_OUT_STREAM);
fs.init(this.mFileInst, JS_FILE_NS_RDWR |
JS_FILE_NS_APPEND, 00004, null);
this.mOutStream = fs;
}
} catch(e) {
jslibError(e, "open("+this.mMode+") (unable to get file stream)",
"NS_ERROR_FAILURE",
JS_FILE_FILE+":open");
return null;
}
try {
// Use the previously created file transport to open an output
// stream for writing to the file
if (!this.mOutStream) {
// this.mOutStream = this.mTransport.openOutputStream(offSet, -1, 0);
// this.mOutStream =
}
} catch(e) {
jslibError(e, "open("+this.mMode+") (unable to get outputstream)",
"NS_ERROR_FAILURE",
JS_FILE_FILE+":open");
this.close();
return null;
}
rv = true;
break;
}
case JS_FILE_READ_MODE: {
if (!this.exists()) {
jslibError(null, "open(r) (file doesn't exist)",
"NS_ERROR_FAILURE",
JS_FILE_FILE+":open");
return null;
}
this.mMode=JS_FILE_READ_MODE;
try {
jslibPrint('****** '+this.mURI);
this.mFileChannel = JS_FILE_IOSERVICE.newChannelFromURI(this.mURI);
this.mInputStream = new JS_FILE_InputStream();
this.mInputStream.init(this.mFileChannel.open());
this.mLineBuffer = new Array();
rv=true;
} catch (e) {
jslibError(e, "open(r) (error setting permissions)",
"NS_ERROR_FAILURE",
JS_FILE_FILE+":open");
return null;
}
break;
}
default:
jslibError(null, "open (must supply either w,r, or a)",
"NS_ERROR_INVALID_ARG",
JS_FILE_FILE+":open");
return null;
}
return rv;
}
/********************* READ *************************************
* string read() *
* *
* reads a file if the file is binary it will *
* return type ex: ELF *
* takes no arguments needs an open read mode filehandle *
* returns string on success, null on failure *
* Ex: *
* var p='/tmp/foo.dat'; *
* var f=new File(p); *
* f.open(p); *
* f.read(); *
* *
* outputs: <string contents of foo.dat> *
****************************************************************/
File.prototype.read = function(aSize)
{
if (!this.checkInst())
throw C.results.NS_ERROR_NOT_INITIALIZED;
if (this.mMode != JS_FILE_READ_MODE) {
jslibError(null, "(mode is write/append)",
"NS_ERROR_FAILURE",
JS_FILE_FILE+":read");
this.close();
return null;
}
var rv = null;
try {
if (!this.mFileInst || !this.mInputStream) {
jslibError(null, "(no file instance or input stream) ",
"NS_ERROR_NOT_INITIALIZED",
JS_FILE_FILE+":read");
return null;
}
rv = this.mInputStream.read(aSize != undefined ? aSize : this.mFileInst.fileSize);
this.mInputStream.close();
} catch (e) {
jslibError(e, "read (input stream read)",
"NS_ERROR_FAILURE",
JS_FILE_FILE+":read");
return null;
}
return rv;
}
/********************* READLINE**********************************
* string readline() *
* *
* reads a file if the file is binary it will *
* return type string *
* takes no arguments needs an open read mode filehandle *
* returns string on success, null on failure *
* Ex: *
* var p='/tmp/foo.dat'; *
* var f=new File(p); *
* f.open(); *
* while(!f.EOF) *
* dump("line: "+f.readline()+"\n"); *
* *
* outputs: <string line of foo.dat> *
****************************************************************/
File.prototype.readline = function()
{
if (!this.checkInst())
throw C.results.NS_ERROR_NOT_INITIALIZED;
if (!this.mInputStream) {
jslibError(null, "(no input stream)",
"NS_ERROR_NOT_INITIALIZED",
JS_FILE_FILE+":readline");
return null;
}
var rv = null;
var buf = null;
var tmp = null;
try {
if (this.mLineBuffer.length < 2) {
buf = this.mInputStream.read(JS_FILE_CHUNK);
this.mPosition = this.mPosition + JS_FILE_CHUNK;
if (this.mPosition > this.mFileInst.fileSize)
this.mPosition = this.mFileInst.fileSize;
if (buf) {
if (this.mLineBuffer.length == 1) {
tmp = this.mLineBuffer.shift();
buf = tmp+buf;
}
this.mLineBuffer = buf.split(/[\n\r]/);
}
}
rv = this.mLineBuffer.shift();
} catch (e) {
jslibError(e, "(problems reading from file)",
"NS_ERROR_NOT_INITIALIZED",
JS_FILE_FILE+":readline");
rv = null;
}
return rv;
}
/********************* EOF **************************************
* bool getter EOF() *
* *
* boolean check 'end of file' status *
* return type boolean *
* takes no arguments needs an open read mode filehandle *
* returns true on eof, false when not at eof *
* Ex: *
* var p='/tmp/foo.dat'; *
* var f=new File(p); *
* f.open(); *
* while(!f.EOF) *
* dump("line: "+f.readline()+"\n"); *
* *
* outputs: true or false *
****************************************************************/
File.prototype.__defineGetter__('EOF',
function()
{
if (!this.checkInst())
throw C.results.NS_ERROR_NOT_INITIALIZED;
if (!this.mInputStream) {
jslibError(null, "(no input stream)",
"NS_ERROR_NOT_INITIALIZED",
JS_FILE_FILE+":EOF");
throw C.results.NS_ERROR_NOT_INITIALIZED;
}
if ((this.mLineBuffer.length > 0) || (this.mInputStream.available() > 0))
return false;
else
return true;
})
/********************* WRITE ************************************
* bool write() *
* *
* reads a file if the file is binary it will *
* return type ex: ELF *
* takes no arguments needs an open read mode filehandle *
* returns string on success, null on failure *
* Ex: *
* var p='/tmp/foo.dat'; *
* var f=new File(p); *
* f.open(p); *
* f.read(); *
* *
* outputs: <string contents of foo.dat> *
****************************************************************/
File.prototype.write = function(aBuffer, aPerms)
{
if (!this.checkInst())
throw C.results.NS_ERROR_NOT_INITIALIZED;
if (this.mMode == JS_FILE_READ_MODE) {
jslibError(null, "(in read mode)",
"NS_ERROR_FAILURE",
JS_FILE_FILE+":write");
this.close();
return null;
}
if (!this.mFileInst) {
jslibError(null, "(no file instance)",
"NS_ERROR_NOT_INITIALIZED",
JS_FILE_FILE+":write");
return null;
}
if (!aBuffer)
throw(JS_FILE_FILE+":write:ERROR: must have a buffer to write!\n");
var rv=null;
try {
this.mOutStream.write(aBuffer, aBuffer.length);
this.mOutStream.flush();
//this.mOutStream.close();
rv=true;
} catch (e) {
jslibError(e, "write (nsIOutputStream write/flush)",
"NS_ERROR_UNEXPECTED",
JS_FILE_FILE+":write");
rv=false;
}
return rv;
}
/********************* COPY *************************************
* void copy(aDest) *
* *
* void file close *
* return type void(null) *
* takes no arguments closes an open file stream and *
* deletes member var instances of objects *
* Ex: *
* var p='/tmp/foo.dat'; *
* var f=new File(p); *
* fopen(); *
* f.close(); *
* *
* outputs: void(null) *
****************************************************************/
File.prototype.copy = function (aDest)
{
if (!this.checkInst())
throw C.results.NS_ERROR_NOT_INITIALIZED;
if (!aDest) {
jslibError(null, "(no dest defined)",
"NS_ERROR_INVALID_ARG",
JS_FILE_FILE+":copy");
throw -C.results.NS_ERROR_INVALID_ARG;
}
if (!this.exists()) {
jslibError(null, "(file doesn't exist)",
"NS_ERROR_FAILURE",
JS_FILE_FILE+":copy");
throw -C.results.NS_ERROR_FAILURE;
}
var rv;
try {
var dest = new JS_FS_File_Path(aDest);
jslibDebug(dest);
var copyName = null;
var dir = null;
if (dest.equals(this.mFileInst)) {
jslibError(null, "(can't copy file to itself)",
"NS_ERROR_FAILURE",
JS_FILE_FILE+":copy");
throw -C.results.NS_ERROR_FAILURE;
}
if (dest.exists()) {
jslibError(null, "(dest "+dest.path+" already exists)",
"NS_ERROR_FAILURE",
JS_FILE_FILE+":copy");
throw -C.results.NS_ERROR_FAILURE;
}
if (this.mFileInst.isDirectory()) {
jslibError(null, "(cannot copy directory)",
"NS_ERROR_FAILURE",
JS_FILE_FILE+":copy");
throw -C.results.NS_ERROR_FAILURE;
}
if (!dest.exists()) {
copyName = dest.leafName;
dir = dest.parent;
if (!dir.exists()) {
jslibError(null, "(dest "+dir.path+" doesn't exist)",
"NS_ERROR_FAILURE",
JS_FILE_FILE+":copy");
throw -C.results.NS_ERROR_FAILURE;
}
if (!dir.isDirectory()) {
jslibError(null, "(dest "+dir.path+" is not a valid path)",
"NS_ERROR_FAILURE",
JS_FILE_FILE+":copy");
throw -C.results.NS_ERROR_FAILURE;
}
}
if (!dir) {
dir = dest;
if (dest.equals(this.mFileInst)) {
jslibError(null, "(can't copy file to itself)", "NS_ERROR_FAILURE", JS_FILE_FILE+":copy");
throw -C.results.NS_ERROR_FAILURE;
}
}
this.mFileInst.copyTo(dir, copyName);
jslibDebug(JS_FILE_FILE+":copy successful!");
} catch (e) {
jslibError(e, "(unexpected error)", "NS_ERROR_UNEXPECTED", JS_FILE_FILE+":copy");
}
return;
}
/********************* CLOSE ************************************
* void close() *
* *
* void file close *
* return type void(null) *
* takes no arguments closes an open file stream and *
* deletes member var instances of objects *
* Ex: *
* var p='/tmp/foo.dat'; *
* var f=new File(p); *
* fopen(); *
* f.close(); *
* *
* outputs: void(null) *
****************************************************************/
File.prototype.close = function()
{
/***************** Destroy Instances *********************/
if (this.mFileChannel) delete this.mFileChannel;
if (this.mInputStream) delete this.mInputStream;
if (this.mTransport) delete this.mTransport;
if (this.mMode) this.mMode=null;
if (this.mOutStream) {
this.mOutStream.close();
delete this.mOutStream;
}
if (this.mLineBuffer) this.mLineBuffer=null;
this.mPosition = 0;
/***************** Destroy Instances *********************/
return void(null);
}
/********************* CREATE *****************************/
File.prototype.create = function()
{
// We can probably implement this so that it can create a
// file or dir if a long non-existent mPath is present
if (!this.checkInst())
throw C.results.NS_ERROR_NOT_INITIALIZED;
if (this.exists()) {
jslibError(null, "(file already exists)",
"NS_ERROR_FAILURE",
JS_FILE_FILE+":create");
return null
}
if (!this.mFileInst.parent.exists() && this.mFileInst.parent.isDirectory()) {
jslibError(null, "(no such file or dir: '"+this.path+"' )",
"NS_ERROR_INVALID_ARG",
JS_FILE_FILE+":create");
return null
}
var rv=null;
try {
rv = this.mFileInst.create(JS_FILE_FILE_TYPE, JS_FILE_DEFAULT_PERMS);
} catch (e) {
jslibError(e, "(unexpected)",
"NS_ERROR_UNEXPECTED",
JS_FILE_FILE+":create");
rv=null;
}
return rv;
}
/********************* REMOVE *******************************/
File.prototype.remove = function ()
{
if (!this.checkInst())
throw C.results.NS_ERROR_NOT_INITIALIZED;
if (!this.mPath) {
jslibError(null, "(no path defined)",
"NS_ERROR_INVALID_ARG",
JS_FILE_FILE+":remove");
return null;
}
this.close();
var rv;
try {
// this is a non recursive remove because we are only dealing w/ files.
rv = this.mFileInst.remove(false);
} catch (e) {
jslibError(e, "(unexpected)",
"NS_ERROR_UNEXPECTED",
JS_FILE_FILE+":remove");
rv=null;
}
return rv;
}
/********************* POS **************************************
* int getter POS() *
* *
* int file position *
* return type int *
* takes no arguments needs an open read mode filehandle *
* returns current position, default is 0 set when *
* close is called *
* Ex: *
* var p='/tmp/foo.dat'; *
* var f=new File(p); *
* f.open(); *
* while(!f.EOF){ *
* dump("pos: "+f.pos+"\n"); *
* dump("line: "+f.readline()+"\n"); *
* } *
* *
* outputs: int pos *
****************************************************************/
File.prototype.__defineGetter__('pos', function(){ return this.mPosition; })
/********************* SIZE *************************************
* int getter size() *
* *
* int file size *
* return type int *
* takes no arguments a getter only *
* Ex: *
* var p='/tmp/foo.dat'; *
* var f=new File(p); *
* f.size; *
* *
* outputs: int 16 *
****************************************************************/
File.prototype.__defineGetter__('size',
function()
{
if (!this.checkInst())
throw C.results.NS_ERROR_NOT_INITIALIZED;
if (!this.mPath) {
jslibError(null, "size (no path defined)",
"NS_ERROR_INVALID_ARG",
JS_FILE_FILE);
return null;
}
if (!this.exists()) {
jslibError(null, "size (file doesn't exist)", "NS_ERROR_FAILURE", JS_FILE_FILE);
return null;
}
var rv=null;
this.resetCache();
try {
rv=this.mFileInst.fileSize;
} catch(e) {
jslibError(e, "(problem getting file instance)", "NS_ERROR_UNEXPECTED", JS_FILE_FILE+":size");
rv=null;
}
return rv;
}) //END size Getter
/********************* EXTENSION ********************************
* string getter ext() *
* *
* string file extension *
* return type string *
* takes no arguments a getter only *
* Ex: *
* var p='/tmp/foo.dat'; *
* var f=new File(p); *
* f.ext; *
* *
* outputs: dat *
****************************************************************/
File.prototype.__defineGetter__('ext',
function()
{
if (!this.checkInst())
throw C.results.NS_ERROR_NOT_INITIALIZED;
if (!this.exists()) {
jslibError(null, "(file doesn't exist)",
"NS_ERROR_FAILURE",
JS_FILE_FILE+":ext");
return null;
}
if (!this.mPath) {
jslibError(null, "(no path defined)",
"NS_ERROR_INVALID_ARG",
JS_FILE_FILE+":ext");
return null;
}
var rv=null;
try {
var leafName = this.mFileInst.leafName;
var dotIndex = leafName.lastIndexOf('.');
rv=(dotIndex >= 0) ? leafName.substring(dotIndex+1) : "";
} catch(e) {
jslibError(e, "(problem getting file instance)",
"NS_ERROR_UNEXPECTED",
JS_FILE_FILE+":ext");
rv=null;
}
return rv;
})// END ext Getter
File.prototype.super_help = FileSystem.prototype.help;
/********************* HELP *****************************/
File.prototype.__defineGetter__('help',
function()
{
const help = this.super_help() +
" open(aMode);\n" +
" read();\n" +
" readline();\n" +
" EOF;\n" +
" write(aContents, aPermissions);\n" +
" copy(aDest);\n" +
" close();\n" +
" create();\n" +
" remove();\n" +
" size;\n" +
" ext;\n" +
" help;\n";
return help;
})
jslibDebug('*** load: '+JS_FILE_FILE+' OK');
} // END BLOCK JS_LIB_LOADED CHECK
// If jslib base library is not loaded, dump this error.
else
{
dump("JS_FILE library not loaded:\n" +
" \tTo load use: chrome://jslib/content/jslib.js\n" +
" \tThen: include('chrome://jslib/content/io/file.js');\n\n");
}

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

@ -1,666 +0,0 @@
/* -*- Mode: Javascript; tab-width: 2; */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Collabnet code.
*
* The Initial Developer of the Original Code is
* Collabnet.
* Portions created by the Initial Developer are Copyright (C) 2000
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Pete Collins, Doug Turner, Brendan Eich, Warren Harris,
* Eric Plaster, Martin Kutschker, Philip Lindsay
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/*
JS FileUtils IO API (The purpose of this file is to make it a little easier to do file IO from js)
fileUtils.js
Function List
chromeToPath(aPath) // Converts a chrome://bob/content uri to a path.
// NOTE: although this gives you the
// path to a file in the chrome directory, you will
// most likely not have permisions
// to create or write to files there.
urlToPath(aPath) // Converts a file:// url to a path
exists(aPath); // check to see if a file exists
append(aDirPath, aFileName); // append is for abstracting platform specific file paths
remove(aPath); // remove a file
copy(aSource, aDest); // copy a file from source to destination
leaf(aPath); // leaf is the endmost file string
// eg: foo.html in /myDir/foo.html
permissions(aPath); // returns the files permissions
dateModified(aPath); // returns the last modified date in locale string
size(aPath); // returns the file size
ext(aPath); // returns a file extension if there is one
parent(aPath) // returns the dir part of a path
dirPath(aPath) // *Depriciated* use parent
spawn(aPath, aArgs) // spawns another program
nsIFile(aPath) // returns an nsIFile obj
help; // currently returns a list of available functions
Deprecated
chrome_to_path(aPath); // synonym for chromeToPath
URL_to_path(aPath) // synonym for use urlToPath
rm(aPath); // synonym for remove
extension(aPath); // synonym for ext
Instructions:
First include this js file
var file = new FileUtils();
Examples:
var path='/usr/X11R6/bin/Eterm';
file.spawn(path, ['-e/usr/bin/vi']);
*note* all args passed to spawn must be in the form of an array
// to list help
dump(file.help);
Warning: these API's are not for religious types
*/
// Make sure jslib is loaded
if (typeof(JS_LIB_LOADED)=='boolean')
{
/****************** Globals **********************/
const JS_FILEUTILS_FILE = "fileUtils.js";
const JS_FILEUTILS_LOADED = true;
const JS_FILEUTILS_LOCAL_CID = "@mozilla.org/file/local;1";
const JS_FILEUTILS_FILESPEC_PROGID = '@mozilla.org/filespec;1';
const JS_FILEUTILS_NETWORK_STD_CID = '@mozilla.org/network/standard-url;1';
const JS_FILEUTILS_SIMPLEURI_PROGID = "@mozilla.org/network/simple-uri;1";
const JS_FILEUTILS_CHROME_REG_PROGID = '@mozilla.org/chrome/chrome-registry;1';
const JS_FILEUTILS_DR_PROGID = "@mozilla.org/file/directory_service;1";
const JS_FILEUTILS_PROCESS_CID = "@mozilla.org/process/util;1";
const JS_FILEUTILS_I_LOCAL_FILE = "nsILocalFile";
const JS_FILEUTILS_INIT_W_PATH = "initWithPath";
const JS_FILEUTILS_I_PROPS = "nsIProperties";
const JS_FILEUTILS_CHROME_DIR = "AChrom";
const JS_FILEUTILS_OK = true;
const JS_FILEUTILS_FilePath = new
C.Constructor(JS_FILEUTILS_LOCAL_CID, JS_FILEUTILS_I_LOCAL_FILE, JS_FILEUTILS_INIT_W_PATH);
const JS_FILEUTILS_I_URI = C.interfaces.nsIURI;
const JS_FILEUTILS_I_FILEURL = C.interfaces.nsIFileURL;
const JS_FILEUTILS_I_PROCESS = C.interfaces.nsIProcess;
/****************** FileUtils Object Class *********************/
function FileUtils() {
include (jslib_dirutils);
this.mDirUtils = new DirUtils();
} // constructor
FileUtils.prototype = {
mFileInst : null,
mDirUtils : null,
/********************* CHROME_TO_PATH ***************************/
// this is here for backward compatability but is deprecated --pete
chrome_to_path : function (aPath) { return this.chromeToPath(aPath); },
chromeToPath : function (aPath)
{
if (!aPath) {
jslibError(null, "(no path defined)", "NS_ERROR_INVALID_ARG", JS_FILEUTILS_FILE+":chromeToPath");
return null;
}
var uri = C.classes[JS_FILEUTILS_SIMPLEURI_PROGID].createInstance(JS_FILEUTILS_I_URI);
var rv;
if (/^chrome:/.test(aPath)) {
try {
var cr = C.classes[JS_FILEUTILS_CHROME_REG_PROGID].getService();
if (cr) {
cr = cr.QueryInterface(C.interfaces.nsIChromeRegistry);
uri.spec = aPath;
uri.spec = cr.convertChromeURL(uri);
rv = uri.path;
}
} catch(e) {}
if (/^\/|\\|:chrome/.test(rv)) {
try {
// prepend the system path to this process dir
rv = "file://"+this.mDirUtils.getCurProcDir()+rv;
} catch (e) {
jslibError(e, "(problem getting file instance)", "NS_ERROR_UNEXPECTED",
JS_FILEUTILS_FILE+":chromeToPath");
rv = "";
}
}
}
else if (/^file:/.test(aPath)) {
rv = this.urlToPath(aPath);
} else
rv = "";
return rv;
},
/********************* URL_TO_PATH ***************************/
URL_to_path : function (aPath){ return this.urlToPath(aPath); },
urlToPath : function (aPath)
{
if (!aPath) {
jslibError(null, "(no path defined)", "NS_ERROR_INVALID_ARG", JS_FILEUTILS_FILE+":urlToPath");
return null;
}
var rv;
if (aPath.search(/^file:/) == 0) {
try {
var uri = C.classes[JS_FILEUTILS_NETWORK_STD_CID].createInstance(JS_FILEUTILS_I_FILEURL);
uri.spec = aPath;
rv = uri.file.path;
} catch (e) {
jslibError(e, "(problem getting file instance)", "NS_ERROR_UNEXPECTED", JS_FILEUTILS_FILE+":urlToPath");
rv=null;
}
}
return rv;
},
/********************* EXISTS ***************************/
exists : function (aPath)
{
if (!aPath) {
jslibError(null, "(no path defined)", "NS_ERROR_INVALID_ARG", JS_FILEUTILS_FILE+":exists");
return null;
}
var rv;
try {
var file = new JS_FILEUTILS_FilePath(aPath);
rv=file.exists();
} catch(e) {
jslibError(e, "(problem getting file instance)", "NS_ERROR_UNEXPECTED", JS_FILEUTILS_FILE+":exists");
rv=null;
}
return rv;
},
/********************* RM *******************************/
rm : function (aPath) { return this.remove(aPath); },
remove : function (aPath)
{
if (!aPath) {
jslibError(null, "(no path defined)", "NS_ERROR_INVALID_ARG", JS_FILEUTILS_FILE+":remove");
return null;
}
if (!this.exists(aPath)) {
jslibError(null, "(file doesn't exist)", "NS_ERROR_UNEXPECTED", JS_FILEUTILS_FILE+":remove");
return null;
}
var rv;
try {
var fileInst = new JS_FILEUTILS_FilePath(aPath);
if (fileInst.isDirectory()) {
jslibError(null, "path is a dir. use rmdir()", "NS_ERROR_INVALID_ARG", JS_FILEUTILS_FILE+":remove");
return null;
}
fileInst.remove(false);
rv = C.results.NS_OK;
} catch (e) {
jslibError(e, "(unexpected)", "NS_ERROR_UNEXPECTED", JS_FILEUTILS_FILE+":urlToPath");
rv=null;
}
return rv;
},
/********************* COPY *****************************/
copy : function (aSource, aDest)
{
if (!aSource || !aDest) {
jslibError(null, "(no path defined)", "NS_ERROR_INVALID_ARG", JS_FILEUTILS_FILE+":copy");
return null;
}
if (!this.exists(aSource)) {
jslibError(null, "(file doesn't exist)", "NS_ERROR_UNEXPECTED", JS_FILEUTILS_FILE+":copy");
return null;
}
var rv;
try {
var fileInst = new JS_FILEUTILS_FilePath(aSource);
var dir = new JS_FILEUTILS_FilePath(aDest);
var copyName = fileInst.leafName;
if (fileInst.isDirectory()) {
jslibError(null, "(cannot copy directory)", "NS_ERROR_FAILURE", JS_FILEUTILS_FILE+":copy");
return null;
}
if (!this.exists(aDest) || !dir.isDirectory()) {
copyName = dir.leafName;
dir = new JS_FILEUTILS_FilePath(dir.path.replace(copyName,''));
if (!this.exists(dir.path)) {
jslibError(null, "(dest "+dir.path+" doesn't exist)", "NS_ERROR_FAILURE", JS_FILEUTILS_FILE+":copy");
return null;
}
if (!dir.isDirectory()) {
jslibError(null, "(dest "+dir.path+" is not a valid path)", "NS_ERROR_FAILURE", JS_FILEUTILS_FILE+":copy");
return null;
}
}
if (this.exists(this.append(dir.path, copyName))) {
jslibError(null, "(dest "+this.append(dir.path, copyName)+" already exists)", "NS_ERROR_FAILURE", JS_FILEUTILS_FILE+":copy");
return null;
}
rv=fileInst.copyTo(dir, copyName);
rv = C.results.NS_OK;
} catch (e) {
jslibError(e, "(unexpected error)", "NS_ERROR_UNEXPECTED", JS_FILEUTILS_FILE+":copy");
rv=null;
}
return rv;
},
/********************* LEAF *****************************/
leaf : function (aPath)
{
if (!aPath) {
jslibError(null, "(no path defined)", "NS_ERROR_INVALID_ARG", JS_FILEUTILS_FILE+":leaf");
return null;
}
if (!this.exists(aPath)) {
jslibError(null, "(file doesn't exist)", "NS_ERROR_UNEXPECTED", JS_FILEUTILS_FILE+":leaf");
return null;
}
var rv;
try {
var fileInst = new JS_FILEUTILS_FilePath(aPath);
rv=fileInst.leafName;
}
catch(e) {
jslibError(e, "(unexpected error)", "NS_ERROR_UNEXPECTED", JS_FILEUTILS_FILE+":leaf");
rv=null;
}
return rv;
},
/********************* APPEND ***************************/
append : function (aDirPath, aFileName)
{
if (!aDirPath || !aFileName) {
jslibError(null, "(no path defined)", "NS_ERROR_INVALID_ARG", JS_FILEUTILS_FILE+":append");
return null;
}
if (!this.exists(aDirPath)) {
jslibError(null, "(file doesn't exist)", "NS_ERROR_UNEXPECTED", JS_FILEUTILS_FILE+":append");
return null;
}
var rv;
try {
var fileInst = new JS_FILEUTILS_FilePath(aDirPath);
if (fileInst.exists() && !fileInst.isDirectory()) {
jslibError(null, aDirPath+" is not a dir", "NS_ERROR_INVALID_ARG", JS_FILEUTILS_FILE+":append");
return null;
}
fileInst.append(aFileName);
rv=fileInst.path;
delete fileInst;
} catch(e) {
jslibError(e?e:null, "(unexpected error)", "NS_ERROR_UNEXPECTED", JS_FILEUTILS_FILE+":append");
rv=null;
}
return rv;
},
/********************* VALIDATE PERMISSIONS *************/
validatePermissions : function(aNum)
{
if ( parseInt(aNum.toString(10).length) < 3 )
return false;
return JS_FILEUTILS_OK;
},
/********************* PERMISSIONS **********************/
permissions : function (aPath)
{
if (!aPath) {
jslibError(null, "(no path defined)", "NS_ERROR_INVALID_ARG", JS_FILEUTILS_FILE+":permissions");
return null;
}
if (!this.exists(aPath)) {
jslibError(null, "(file doesn't exist)", "NS_ERROR_UNEXPECTED", JS_FILEUTILS_FILE+":permissions");
return null;
}
var rv;
try {
rv=(new JS_FILEUTILS_FilePath(aPath)).permissions.toString(8);
} catch(e) {
jslibError(e, "(unexpected error)", "NS_ERROR_UNEXPECTED", JS_FILEUTILS_FILE+":permissions");
rv=null;
}
return rv;
},
/********************* MODIFIED *************************/
dateModified : function (aPath)
{
if (!aPath) {
jslibError(null, "(no path defined)", "NS_ERROR_INVALID_ARG", JS_FILEUTILS_FILE+":dateModified");
return null;
}
if (!this.exists(aPath)) {
jslibError(null, "(file doesn't exist)", "NS_ERROR_UNEXPECTED", JS_FILEUTILS_FILE+":dateModified");
return null;
}
var rv;
try {
var date = new Date((new JS_FILEUTILS_FilePath(aPath)).lastModificationDate).toLocaleString();
rv=date;
} catch(e) {
jslibError(e, "(unexpected error)", "NS_ERROR_UNEXPECTED", JS_FILEUTILS_FILE+":dateModified");
rv=null;
}
return rv;
},
/********************* SIZE *****************************/
size : function (aPath)
{
if (!aPath) {
jslibError(null, "(no path defined)", "NS_ERROR_INVALID_ARG", JS_FILEUTILS_FILE+":size");
return null;
}
if (!this.exists(aPath)) {
jslibError(null, "(file doesn't exist)", "NS_ERROR_UNEXPECTED", JS_FILEUTILS_FILE+":size");
return null;
}
var rv;
try {
rv = (new JS_FILEUTILS_FilePath(aPath)).fileSize;
} catch(e) {
jslibError(e, "(unexpected error)", "NS_ERROR_UNEXPECTED", JS_FILEUTILS_FILE+":size");
rv=0;
}
return rv;
},
/********************* EXTENSION ************************/
extension : function (aPath){ return this.ext(aPath); },
ext : function (aPath)
{
if (!aPath) {
jslibError(null, "(no path defined)", "NS_ERROR_INVALID_ARG", JS_FILEUTILS_FILE+":ext");
return null;
}
if (!this.exists(aPath)) {
jslibError(null, "(file doesn't exist)", "NS_ERROR_UNEXPECTED", JS_FILEUTILS_FILE+":ext");
return null;
}
var rv;
try {
var leafName = (new JS_FILEUTILS_FilePath(aPath)).leafName;
var dotIndex = leafName.lastIndexOf('.');
rv=(dotIndex >= 0) ? leafName.substring(dotIndex+1) : "";
} catch(e) {
jslibError(e, "(unexpected error)", "NS_ERROR_UNEXPECTED", JS_FILEUTILS_FILE+":ext");
rv=null;
}
return rv;
},
/********************* DIRPATH **************************/
dirPath : function (aPath){ return this.parent(aPath); },
parent : function (aPath)
{
if (!aPath) {
jslibError(null, "(no path defined)", "NS_ERROR_INVALID_ARG", JS_FILEUTILS_FILE+":parent");
return null;
}
var rv;
try {
var fileInst = new JS_FILEUTILS_FilePath(aPath);
if (!fileInst.exists()) {
jslibError(null, "(file doesn't exist)", "NS_ERROR_FAILURE", JS_FILEUTILS_FILE+":parent");
return null;
}
if (fileInst.isFile())
rv=fileInst.parent.path;
else if (fileInst.isDirectory())
rv=fileInst.path;
else
rv=null;
}
catch (e) {
jslibError(e, "(problem getting file instance)", "NS_ERROR_UNEXPECTED", JS_FILEUTILS_FILE+":parent");
rv=null;
}
return rv;
},
/********************* SPAWN ****************************/
run : function (aPath, aArgs) { this.spawn(aPath, aArgs); },
spawn : function (aPath, aArgs)
/*
* Trys to execute the requested file as a separate *non-blocking* process.
*
* Passes the supplied *array* of arguments on the command line if
* the OS supports it.
*
*/
{
if (!aPath) {
jslibError(null, "(no path defined)", "NS_ERROR_INVALID_ARG",
JS_FILEUTILS_FILE+":spawn");
return null;
}
if (!this.exists(aPath)) {
jslibError(null, "(file doesn't exist)", "NS_ERROR_UNEXPECTED",
JS_FILEUTILS_FILE+":spawn");
return null;
}
var len=0;
if (aArgs)
len = aArgs.length;
else
aArgs=null;
var rv;
try {
var fileInst = new JS_FILEUTILS_FilePath(aPath);
if (!fileInst.isExecutable()) {
jslibError(null, "(File is not executable)", "NS_ERROR_INVALID_ARG",
JS_FILEUTILS_FILE+":spawn");
return null;
}
if (fileInst.isDirectory()) {
jslibError(null, "(File is not a program)", "NS_ERROR_UNEXPECTED",
JS_FILEUTILS_FILE+":spawn");
return null;
} else {
// Create and execute the process...
/*
* NOTE: The first argument of the process instance's 'run' method
* below specifies the blocking state (false = non-blocking).
* The last argument, in theory, contains the process ID (PID)
* on return if a variable is supplied--not sure how to implement
* this with JavaScript though.
*/
try {
var theProcess = C.classes[JS_FILEUTILS_PROCESS_CID].
createInstance(JS_FILEUTILS_I_PROCESS);
theProcess.init(fileInst);
rv = theProcess.run(false, aArgs, len);
jslib_debug("rv="+rv);
} catch (e) {
jslibError(e, "(problem spawing process)", "NS_ERROR_UNEXPECTED",
JS_FILEUTILS_FILE+":spawn");
rv=null;
}
}
} catch (e) {
jslibError(e, "(problem getting file instance)", "NS_ERROR_UNEXPECTED",
JS_FILEUTILS_FILE+":spawn");
rv=null;
}
return rv;
},
/********************* nsIFILE **************************/
nsIFile : function (aPath)
{
if (!aPath) {
jslibError(null, "(no path defined)", "NS_ERROR_INVALID_ARG", JS_FILEUTILS_FILE+":nsIFile");
return null;
}
var rv;
try {
rv = new JS_FILEUTILS_FilePath(aPath);
} catch (e) {
jslibError(e, "(problem getting file instance)", "NS_ERROR_UNEXPECTED", JS_FILEUTILS_FILE+":nsIFile");
rv = null;
}
return rv;
},
/********************* HELP *****************************/
get help()
{
var help =
"\n\nFunction List:\n" +
"\n" +
" exists(aPath);\n" +
" chromeToPath(aPath);\n" +
" urlToPath(aPath);\n" +
" append(aDirPath, aFileName);\n" +
" remove(aPath);\n" +
" copy(aSource, aDest);\n" +
" leaf(aPath);\n" +
" permissions(aPath);\n" +
" dateModified(aPath);\n" +
" size(aPath);\n" +
" ext(aPath);\n" +
" parent(aPath);\n" +
" run(aPath, aArgs);\n" +
" nsIFile(aPath);\n" +
" help;\n";
return help;
}
};
jslibDebug('*** load: '+JS_FILEUTILS_FILE+' OK');
} // END BLOCK JS_LIB_LOADED CHECK
// If jslib base library is not loaded, dump this error.
else
{
dump("JS_FILE library not loaded:\n" +
" \tTo load use: chrome://jslib/content/jslib.js\n" +
" \tThen: include('chrome://jslib/content/io/fileUtils.js');\n\n");
}

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

@ -1,681 +0,0 @@
/* -*- Mode: Javascript; tab-width: 2; */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Collabnet code.
*
* The Initial Developer of the Original Code is
* Collabnet.
* Portions created by the Initial Developer are Copyright (C) 2000
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Pete Collins, Doug Turner, Brendan Eich, Warren Harris,
* Eric Plaster, Martin Kutschker
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
if (typeof(JS_LIB_LOADED)=='boolean') {
/***************************
* Globals *
***************************/
const JS_FILESYSTEM_LOADED = true;
const JS_FILESYSTEM_FILE = "filesystem.js";
const JS_FS_LOCAL_CID = "@mozilla.org/file/local;1";
const JS_FS_DIR_CID = "@mozilla.org/file/directory_service;1";
const JS_FS_NETWORK_CID = '@mozilla.org/network/standard-url;1';
const JS_FS_URL_COMP = "nsIURL";
const JS_FS_I_LOCAL_FILE = "nsILocalFile";
const JS_FS_DIR_I_PROPS = "nsIProperties";
const JS_FS_INIT_W_PATH = "initWithPath";
const JS_FS_CHROME_DIR = "AChrom";
const JS_FS_USR_DEFAULT = "DefProfRt";
const JS_FS_PREF_DIR = "PrefD";
const JS_FS_OK = true;
const JS_FS_File_Path = new Components.Constructor
( JS_FS_LOCAL_CID, JS_FS_I_LOCAL_FILE, JS_FS_INIT_W_PATH);
const JS_FS_Dir = new Components.Constructor
(JS_FS_DIR_CID, JS_FS_DIR_I_PROPS);
const JS_FS_URL = new Components.Constructor
(JS_FS_NETWORK_CID, JS_FS_URL_COMP);
/***************************
* Globals *
***************************/
/***************************
* FileSystem Object Class *
***************************/
function FileSystem(aPath) {
return (aPath?this.initPath(arguments):void(null));
} // constructor
/***************************
* FileSystem Prototype *
***************************/
FileSystem.prototype = {
mPath : null,
mFileInst : null,
/***************************
* INIT PATH *
***************************/
initPath : function(args)
{
// check if the argument is a file:// url
if(typeof(args)=='object') {
for (var i=0; i<args.length; i++) {
if(args[i].search(/^file:/) == 0) {
try {
var fileURL= new JS_FS_URL();
fileURL.spec=args[i];
args[i] = fileURL.path;
} catch (e) {
jslibError(e, "(problem getting file instance)",
"NS_ERROR_UNEXPECTED", JS_FILESYSTEM_FILE+":initPath");
rv=null;
}
}
}
} else {
if(args.search(/^file:/) == 0) {
try {
var fileURL= new JS_FS_URL();
fileURL.spec=args;
args = fileURL.path;
} catch (e) {
jslibError(e, "(problem getting file instance)",
"NS_ERROR_UNEXPECTED", JS_FILESYSTEM_FILE+":initPath");
rv=null;
}
}
}
/**
* If you are wondering what all this extra cruft is, well
* this is here so you can reinitialize 'this' with a new path
*/
var rv = null;
try {
if (typeof(args)=='object') {
this.mFileInst = new JS_FS_File_Path(args[0]?args[0]:this.mPath);
if (args.length>1)
for (i=1; i<args.length; i++)
this.mFileInst.append(args[i]);
(args[0] || this.mPath)?rv=this.mPath = this.mFileInst.path:rv=null;
} else {
this.mFileInst = new JS_FS_File_Path(args?args:this.mPath);
this.mFileInst.path?rv=this.mPath = this.mFileInst.path:rv=null;
}
} catch(e) {
jslibError(e?e:null,
"initPath (nsILocalFile problem)",
"NS_ERROR_UNEXPECTED",
JS_FILESYSTEM_FILE+":initPath");
rv = null;
}
return rv;
},
/***************************
* CHECK INST *
***************************/
checkInst : function ()
{
if (!this.mFileInst) {
jslibError(null,
"(no path defined)",
"NS_ERROR_NOT_INITIALIZED",
JS_FILESYSTEM_FILE+":checkInstance");
return false;
}
return true;
},
/***************************
* PATH *
***************************/
get path()
{
if (!this.checkInst())
throw Components.results.NS_ERROR_NOT_INITIALIZED;
return this.mFileInst.path;
},
/***************************
* EXISTS *
***************************/
exists : function ()
{
if (!this.checkInst())
throw Components.results.NS_ERROR_NOT_INITIALIZED;
var rv = false;
try {
rv = this.mFileInst.exists();
} catch(e) {
jslibError(e,
"exists (nsILocalFile problem)",
"NS_ERROR_UNEXPECTED",
JS_FILESYSTEM_FILE+":exists");
rv = false;
}
return rv;
},
/***************************
* GET LEAF *
***************************/
get leaf()
{
if (!this.checkInst())
throw Components.results.NS_ERROR_NOT_INITIALIZED;
var rv = null;
try {
rv = this.mFileInst.leafName;
} catch(e) {
jslibError(e,
"(problem getting file instance)",
"NS_ERROR_FAILURE",
JS_FILESYSTEM_FILE+":leaf");
rv = null;
}
return rv;
},
/***************************
* SET LEAF *
***************************/
set leaf(aLeaf)
{
if (!aLeaf) {
jslibError(null,
"(missing argument)",
"NS_ERROR_INVALID_ARG",
JS_FILESYSTEM_FILE+":leaf");
return null;
}
if (!this.checkInst())
throw Components.results.NS_ERROR_NOT_INITIALIZED;
var rv = null;
try {
rv = (this.mFileInst.leafName=aLeaf);
} catch(e) {
jslibError(e,
"(problem getting file instance)",
"NS_ERROR_FAILURE",
JS_FILESYSTEM_FILE+":leaf");
rv = null;
}
return rv;
},
/***************************
* PARENT *
***************************/
get parent()
{
if (!this.checkInst())
throw Components.results.NS_ERROR_NOT_INITIALIZED;
var rv = null;
try {
if (this.mFileInst.parent.isDirectory()) {
if (typeof(JS_DIR_LOADED)!='boolean')
include(JS_LIB_PATH+'io/dir.js');
rv = new Dir(this.mFileInst.parent.path);
}
} catch (e) {
jslibError(e,
"(problem getting file parent)",
"NS_ERROR_UNEXPECTED",
JS_FILESYSTEM_FILE+":parent");
rv = null;
}
return rv;
},
/***************************
* GET PERMISSIONS *
***************************/
get permissions()
{
if (!this.checkInst())
throw Components.results.NS_ERROR_NOT_INITIALIZED;
if (!this.exists()) {
jslibError(null,
"(file doesn't exist)",
"NS_ERROR_FAILURE",
JS_FILESYSTEM_FILE+":permisions");
return null;
}
var rv = null;
try {
rv = this.mFileInst.permissions.toString(8);
} catch(e) {
jslibError(e,
"(problem getting file instance)",
"NS_ERROR_UNEXPECTED",
JS_FILESYSTEM_FILE+":permissions");
rv = null;
}
return rv;
},
/***************************
* SET PERMISSIONS *
***************************/
set permissions(aPermission)
{
if (!this.checkInst())
throw Components.results.NS_ERROR_NOT_INITIALIZED;
if (!aPermission) {
jslibError(null,
"(no new permission defined)",
"NS_ERROR_INVALID_ARG",
JS_FILESYSTEM_FILE+":permissions");
return null;
}
if (!this.exists()) {
jslibError(null,
"(file doesn't exist)",
"NS_ERROR_FAILURE",
JS_FILESYSTEM_FILE+":permisions");
return null;
}
if (!this.validatePermissions(aPermission)) {
jslibError(null,
"(invalid permission argument)",
"NS_ERROR_INVALID_ARG",
JS_FILESYSTEM_FILE+":permissions");
return null;
}
var rv = null;
try {
rv = this.mFileInst.permissions=aPermission;
} catch(e) {
jslibError(e,
"(problem getting file instance)",
"NS_ERROR_UNEXPECTED",
JS_FILESYSTEM_FILE+":permissions");
rv = null;
}
return rv;
},
/***************************
* VALIDATE PERMISSIONS *
***************************/
validatePermissions : function (aNum)
{
if (typeof(aNum)!='number')
return false;
if (parseInt(aNum.toString(10).length) < 3 )
return false;
return true;
},
/***************************
* MODIFIED *
***************************/
get dateModified()
{
if (!this.checkInst())
throw Components.results.NS_ERROR_NOT_INITIALIZED;
if (!this.exists()) {
jslibError(null,
"(file doesn't exist)",
"NS_ERROR_FAILURE",
JS_FILESYSTEM_FILE+":dateModified");
return null;
}
var rv = null;
try {
rv = (new Date(this.mFileInst.lastModifiedTime));
} catch(e) {
jslibError(e,
"(problem getting file instance)",
"NS_ERROR_UNEXPECTED",
JS_FILESYSTEM_FILE+":dateModified");
rv = null;
}
return rv;
},
/***************************
* RESET CACHE *
***************************/
resetCache : function()
{
if (!this.checkInst())
throw Components.results.NS_ERROR_NOT_INITIALIZED;
var rv = false;
if (this.mPath) {
delete this.mFileInst;
try {
this.mFileInst=new JS_FS_File_Path(this.mPath);
rv = true;
} catch(e) {
jslibError(e,
"(unable to get nsILocalFile)",
"NS_ERROR_UNEXPECTED",
JS_FILESYSTEM_FILE+":resetCache");
rv = false;
}
}
return rv;
},
/***************************
* nsIFILE *
***************************/
get nsIFile()
{
if (!this.checkInst())
throw Components.results.NS_ERROR_NOT_INITIALIZED;
var rv = null;
try {
rv = this.mFileInst.clone();
} catch (e) {
jslibError(e,
"(problem getting file instance)",
"NS_ERROR_UNEXPECTED",
JS_FILESYSTEM_FILE+":nsIFile");
rv = null;
}
return rv;
},
/***************************
* NOTE: after a move *
* successful, 'this' will *
* be reinitialized *
* to the moved file! *
***************************/
move : function (aDest)
{
if (!this.checkInst())
throw Components.results.NS_ERROR_NOT_INITIALIZED;
if (!aDest) {
jslibError(null,
"(no destination path defined)",
"NS_ERROR_INVALID_ARG",
JS_FILESYSTEM_FILE+":move");
return false;
}
if (!this.mPath) {
jslibError(null,
"(no path defined)",
"NS_ERROR_INVALID_ARG",
JS_FILESYSTEM_FILE+":move");
return false;
}
var rv = null;
var newName=null;
try {
var f = new JS_FS_File_Path(aDest);
if (f.exists() && !f.isDirectory()) {
jslibError(null,
"(destination file exists remove it)",
"NS_ERROR_INVALID_ARG",
JS_FILESYSTEM_FILE+":move");
return false;
}
if (f.equals(this.mFileInst)) {
jslibError(null,
"(destination file is this file)",
"NS_ERROR_INVALID_ARG",
JS_FILESYSTEM_FILE+":move");
return false;
}
if (!f.exists() && f.parent.exists())
newName=f.leafName;
if (f.equals(this.mFileInst.parent) && !newName) {
jslibError(null,
"(destination file is this file)",
"NS_ERROR_INVALID_ARG",
JS_FILESYSTEM_FILE+":move");
return false;
}
var dir=f.parent;
if (dir.exists() && dir.isDirectory()) {
jslibDebug(newName);
this.mFileInst.moveTo(dir, newName);
jslibDebug(JS_FILESYSTEM_FILE+':move successful!\n');
this.mPath=f.path;
this.resetCache();
delete dir;
rv = true;
} else {
jslibError(null,
"(destination "+dir.parent.path+" doesn't exists)",
"NS_ERROR_INVALID_ARG",
JS_FILESYSTEM_FILE+":move");
return false;
}
} catch (e) {
jslibError(e,
"(problem getting file instance)",
"NS_ERROR_UNEXPECTED",
JS_FILESYSTEM_FILE+":move");
rv = false;
}
return rv;
},
/***************************
* APPEND *
***************************/
append : function(aLeaf)
{
if (!this.checkInst())
throw Components.results.NS_ERROR_NOT_INITIALIZED;
if (!aLeaf) {
jslibError(null,
"(no argument defined)",
"NS_ERROR_INVALID_ARG",
JS_FILESYSTEM_FILE+":append");
return null;
}
if (!this.mPath) {
jslibError(null,
"(no path defined)",
"NS_ERROR_INVALID_ARG",
JS_FILESYSTEM_FILE+":append");
return null;
}
var rv = null;
try {
this.mFileInst.append(aLeaf);
rv = this.mPath=this.path;
} catch(e) {
jslibError(null,
"(unexpected error)",
"NS_ERROR_UNEXPECTED",
JS_FILESYSTEM_FILE+":append");
rv = null;
}
return rv;
},
/***************************
* APPEND RELATIVE *
***************************/
appendRelativePath : function(aRelPath)
{
if (!this.checkInst())
throw Components.results.NS_ERROR_NOT_INITIALIZED;
if (!aRelPath) {
jslibError(null,
"(no argument defined)",
"NS_ERROR_INVALID_ARG",
JS_FILESYSTEM_FILE+":appendRelativePath");
return null;
}
if (!this.mPath) {
jslibError(null,
"(no path defined)",
"NS_ERROR_INVALID_ARG",
JS_FILESYSTEM_FILE+":appendRelativePath");
return null;
}
var rv = null;
try {
this.mFileInst.appendRelativePath(aRelPath);
rv = this.mPath=this.path;
} catch(e) {
jslibError(null,
"(unexpected error)",
"NS_ERROR_UNEXPECTED",
JS_FILESYSTEM_FILE+":appendRelativePath");
rv = null;
}
return rv;
},
/***************************
* GET URL *
***************************/
get URL()
{
return (this.path?'file://'+this.path.replace(/\ /g, "%20").replace(/\\/g, "\/"):'');
},
/***************************
* ISDIR *
***************************/
isDir : function()
{
var rv = false;
try {
rv = this.mFileInst.isDirectory();
} catch (e) { rv = false; }
return rv;
},
/***************************
* ISFILE *
***************************/
isFile : function()
{
var rv = false;
try {
rv = this.mFileInst.isFile();
} catch (e) { rv = false; }
return rv;
},
/***************************
* ISEXEC *
***************************/
isExec : function()
{
var rv = false;
try {
rv = this.mFileInst.isExecutable();
} catch (e) { rv = false; }
return rv;
},
/***************************
* ISSYMLINK *
***************************/
isSymlink : function()
{
var rv = false;
try {
rv = this.mFileInst.isSymlink();
} catch (e) { rv = false; }
return rv;
},
/***************************
* HELP *
***************************/
help : function()
{
const help =
"\n\nFunction and Attribute List:\n" +
"\n" +
" initPath(aPath);\n" +
" path;\n" +
" exists();\n" +
" leaf;\n" +
" parent;\n" +
" permissions;\n" +
" dateModified;\n" +
" nsIFile;\n" +
" move(aDest);\n" +
" append(aLeaf);\n" +
" appendRelativePath(aRelPath);\n" +
" URL;\n" +
" isDir();\n" +
" isFile();\n" +
" isExec();\n" +
" isSymlink();\n";
return help;
}
}; // END FileSystem Class
jslibDebug('*** load: '+JS_FILESYSTEM_FILE+' OK');
} // END BLOCK JS_LIB_LOADED CHECK
else {
dump("JS_FILE library not loaded:\n" +
" \tTo load use: chrome://jslib/content/jslib.js\n" +
" \tThen: include('chrome://jslib/content/io/filesystem.js');\n\n");
}

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

@ -1,57 +0,0 @@
/* -*- Mode: Javascript; tab-width: 2; */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Collabnet code.
*
* The Initial Developer of the Original Code is
* Collabnet.
* Portions created by the Initial Developer are Copyright (C) 2000
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Pete Collins, Doug Turner, Brendan Eich, Warren Harris
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
if(typeof(JS_LIB_LOADED)=='boolean')
{
/********************* INCLUDED FILES **************/
include(JS_LIB_PATH+'io/filesystem.js');
include(JS_LIB_PATH+'io/file.js');
include(JS_LIB_PATH+'io/dir.js');
include(JS_LIB_PATH+'io/fileUtils.js');
include(JS_LIB_PATH+'io/dirUtils.js');
/********************* INCLUDED FILES **************/
}
else
{
dump("JSLIB library not loaded:\n" +
" \tTo load use: chrome://jslib/content/jslib.js\n" +
" \tThen: include('chrome://jslib/content/io/io.js');\n\n");
}

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

@ -1,391 +0,0 @@
/*** -*- Mode: Javascript; tab-width: 2;
***** BEGIN LICENSE BLOCK *****
Version: MPL 1.1/GPL 2.0/LGPL 2.1
The contents of this file are subject to the Mozilla Public License Version
1.1 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
for the specific language governing rights and limitations under the
License.
The Original Code is jslib team code.
The Initial Developer of the Original Code is
jslib team.
Portions created by the Initial Developer are Copyright (C) 2000
the Initial Developer. All Rights Reserved.
Contributor(s):
Martin Kutschker <Martin.T.Kutschker@blackbox.net>
Alternatively, the contents of this file may be used under the terms of
either the GNU General Public License Version 2 or later (the "GPL"), or
the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
in which case the provisions of the GPL or the LGPL are applicable instead
of those above. If you wish to allow use of your version of this file only
under the terms of either the GPL or the LGPL, and not to allow others to
use your version of this file under the terms of the MPL, indicate your
decision by deleting the provisions above and replace them with the notice
and other provisions required by the GPL or the LGPL. If you do not delete
the provisions above, a recipient may use your version of this file under
the terms of any one of the MPL, the GPL or the LGPL.
***** END LICENSE BLOCK ***** */
/**
* insure jslib base is not already loaded
*/
if (typeof(JS_LIB_LOADED)!='boolean') {
try {
/*************************** GLOBALS ***************************/
const JS_LIB_LOADED = true;
const JS_LIBRARY = "jslib";
const JS_LIB_FILE = "jslib.js"
const JS_LIB_PATH = "chrome://calendar/content/jslib/";
const JS_LIB_VERSION = "0.1.123";
const JS_LIB_AUTHORS = "\tPete Collins <petejc@mozdevgroup.com>\n" +
"\tEric Plaster <plaster@urbanrage.com>\n" +
"\tMartin.T.Kutschker <Martin.T.Kutschker@blackbox.net>\n";
const JS_LIB_BUILD = "mozilla 1.3+";
const JS_LIB_ABOUT = "\tThis is an effort to provide a fully " +
"functional js library\n" +
"\tfor mozilla package authors to use " +
"in their applications\n";
const JS_LIB_HOME = "http://jslib.mozdev.org/";
// Hopefully there won't be any global namespace collisions here
const ON = true;
const OFF = false;
const C = Components;
const jslib_results = C.results;
if (typeof(JS_LIB_DEBUG)!='boolean')
var JS_LIB_DEBUG = ON;
var JS_LIB_DEBUG_ALERT = OFF;
var JS_LIB_ERROR = ON;
var JS_LIB_ERROR_ALERT = OFF;
const JS_LIB_HELP = "\n\nWelcome to jslib version "+JS_LIB_VERSION+"\n\n"
+ "Global Constants:\n\n"
+ "JS_LIBRARY \n\t"+JS_LIBRARY +"\n"
+ "JS_LIB_FILE \n\t"+JS_LIB_FILE +"\n"
+ "JS_LIB_PATH \n\t"+JS_LIB_PATH +"\n"
+ "JS_LIB_VERSION \n\t"+JS_LIB_VERSION +"\n"
+ "JS_LIB_AUTHORS \n" +JS_LIB_AUTHORS
+ "JS_LIB_BUILD \n\t"+JS_LIB_BUILD +"\n"
+ "JS_LIB_ABOUT \n" +JS_LIB_ABOUT
+ "JS_LIB_HOME \n\t"+JS_LIB_HOME +"\n\n"
+ "Global Variables:\n\n"
+ " JS_LIB_DEBUG\n JS_LIB_ERROR\n\n";
// help identifier
const jslib_help = "need to write some global help docs here\n";
// Library Identifiers
// io library modules
const jslib_io = JS_LIB_PATH+'io/io.js';
const jslib_filesystem = JS_LIB_PATH+'io/filesystem.js'
const jslib_file = JS_LIB_PATH+'io/file.js';
const jslib_fileutils = JS_LIB_PATH+'io/fileUtils.js';
const jslib_dir = JS_LIB_PATH+'io/dir.js';
const jslib_dirutils = JS_LIB_PATH+'io/dirUtils.js';
// data structures
const jslib_dictionary = JS_LIB_PATH+'ds/dictionary.js';
const jslib_chaindictionary = JS_LIB_PATH+'ds/chainDictionary.js';
// RDF library modules
const jslib_rdf = JS_LIB_PATH+'rdf/rdf.js';
const jslib_rdffile = JS_LIB_PATH+'rdf/rdfFile.js';
const jslib_rdfcontainer = JS_LIB_PATH+'rdf/rdfContainer.js';
const jslib_rdfresource = JS_LIB_PATH+'rdf/rdfResource.js';
// network library modules
const jslib_remotefile = JS_LIB_PATH+'network/remoteFile.js';
const jslib_socket = JS_LIB_PATH+'network/socket.js';
// network - http
const jslib_http = JS_LIB_PATH+'network/http.js';
const jslib_getrequest = JS_LIB_PATH+'network/getRequest.js';
const jslib_postrequest = JS_LIB_PATH+'network/postRequest.js';
const jslib_multipartrequest = JS_LIB_PATH+'network/multipartRequest.js';
const jslib_filepart = JS_LIB_PATH+'network/parts/filePart.js';
const jslib_textpart = JS_LIB_PATH+'network/parts/textPart.js';
const jslib_urlparameterspart = JS_LIB_PATH+'network/parts/urlParametersPart.js';
const jslib_bodyparameterspart = JS_LIB_PATH+'network/parts/bodyParametersPart.js';
// xul dom library modules
const jslib_dialog = JS_LIB_PATH+'xul/commonDialog.js';
const jslib_filepicker = JS_LIB_PATH+'xul/commonFilePicker.js';
const jslib_window = JS_LIB_PATH+'xul/commonWindow.js';
const jslib_routines = JS_LIB_PATH+'xul/appRoutines.js';
// sound library modules
const jslib_sound = JS_LIB_PATH+'sound/sound.js';
// utils library modules
const jslib_date = JS_LIB_PATH+'utils/date.js';
const jslib_prefs = JS_LIB_PATH+'utils/prefs.js';
const jslib_validate = JS_LIB_PATH+'utils/validate.js';
// zip
const jslib_zip = JS_LIB_PATH+'zip/zip.js';
// install/uninstall
const jslib_install = JS_LIB_PATH+'install/install.js';
const jslib_uninstall = JS_LIB_PATH+'install/uninstall.js';
/*************************** GLOBALS ***************************/
/****************************************************************
* void include(aScriptPath) *
* aScriptPath is an argument of string lib chrome path *
* returns NS_OK on success, 1 if file is already loaded and *
* - errorno or throws exception on failure *
* Ex: *
* var path='chrome://jslib/content/io/file.js'; *
* include(path); *
* *
* outputs: void(null) *
****************************************************************/
function include(aScriptPath) {
jslibPrint(aScriptPath);
if (!aScriptPath) {
jslibError(null, "Missing file path argument\n",
"NS_ERROR_XPC_NOT_ENOUGH_ARGS",
JS_LIB_FILE+": include");
throw - C.results.NS_ERROR_XPC_NOT_ENOUGH_ARGS;
}
if (aScriptPath==JS_LIB_PATH+JS_LIB_FILE) {
jslibError(null, aScriptPath+" is already loaded!",
"NS_ERROR_INVALID_ARG", JS_LIB_FILE+": include");
throw - C.results.NS_ERROR_INVALID_ARG;
}
var start = aScriptPath.lastIndexOf('/') + 1;
var end = aScriptPath.lastIndexOf('.');
var slice = aScriptPath.length - end;
var loadID = aScriptPath.substring(start, (aScriptPath.length - slice));
if (typeof(this['JS_'+loadID.toUpperCase()+'_LOADED']) == 'boolean') {
jslibPrint (loadID+" library already loaded");
return 1;
}
var rv;
try {
const PROG_ID = "@mozilla.org/moz/jssubscript-loader;1";
const INTERFACE = "mozIJSSubScriptLoader";
jslibGetService(PROG_ID, INTERFACE).loadSubScript(aScriptPath);
rv = C.results.NS_OK;
} catch (e) {
jslibDebug(e);
const msg = aScriptPath+" is not a valid path or is already loaded";
jslibError(e, msg, "NS_ERROR_INVALID_ARG", JS_LIB_FILE+": include");
rv = - C.results.NS_ERROR_INVALID_ARG;
}
return rv;
}
/****************************************************************
* void jslibDebug(aOutString) *
* aOutString is an argument of string debug message *
* returns void *
* Ex: *
* var msg='Testing function'; *
* jslibDebug(msg); *
* *
* outputs: Testing function *
****************************************************************/
// this is here for backward compatability but is deprecated --masi
function jslib_debug(aOutString) { return jslibDebug(aOutString); }
function jslibDebug(aOutString) {
if (!JS_LIB_DEBUG)
return;
if (JS_LIB_DEBUG_ALERT)
alert(aOutString);
dump(aOutString+'\n');
return;
}
// print to stdout
function jslibPrint(aOutString) {
return (dump(aOutString+'\n'));
}
// Welcome message
jslibDebug(JS_LIB_HELP);
jslibDebug("\n\n*********************\nJS_LIB DEBUG IS ON\n*********************\n\n");
/****************************************************************
* void jslibError(e, aType, aResults, aCaller) *
* e - argument of results exception *
* aType - argument of string error type message *
* aResults - argument of string Components.results name *
* aCaller - argument of string caller filename and func name *
* returns void *
* Ex: *
* jslibError(null, "Missing file path argument\n", *
* "NS_ERROR_XPC_NOT_ENOUGH_ARGS", *
* JS_LIB_FILE+": include"); *
* *
* outputs: *
* -----======[ ERROR ]=====----- *
* Error in jslib.js: include: Missing file path argument *
* *
* NS_ERROR_NUMBER: NS_ERROR_XPC_NOT_ENOUGH_ARGS *
* ------------------------------ *
* *
****************************************************************/
function jslibError(e, aType, aResults, aCaller) {
if (!JS_LIB_ERROR)
return void(null);
if (arguments.length==0)
return (dump("JS_LIB_ERROR=ON\n"));
var errMsg="ERROR: "+(aCaller?"in "+aCaller:"")+" "+aType+"\n";
if (e && typeof(e)=='object') {
var m, n, r, l, ln, fn = "";
try {
r = e.result;
m = e.message;
fn = e.filename;
l = e.location;
ln = l.lineNumber;
} catch (e) {}
errMsg+="Name: "+e.name+"\n" +
"Result: "+r+"\n" +
"Message: "+m+"\n" +
"FileName: "+fn+"\n" +
"LineNumber: "+ln+"\n";
}
if (aResults)
errMsg+="NS_ERROR_NUMBER: "+aResults+"\n";
if (JS_LIB_ERROR_ALERT)
alert(errMsg);
errMsg = "\n-----======[ ERROR ]=====-----\n" + errMsg;
errMsg += "------------------------------\n\n";
return (dump(errMsg));
}
function jslibGetService (aURL, aInterface) {
var rv;
try {
rv = C.classes[aURL].getService(C.interfaces[aInterface]);
} catch (e) {
jslibDebug("Error getting service: " + aURL + ", " + aInterface + "\n" + e);
rv = -1;
}
return rv;
}
function jslibCreateInstance (aURL, aInterface) {
var rv;
try {
rv = C.classes[aURL].createInstance(C.interfaces[aInterface]);
} catch (e) {
jslibDebug("Error creating instance: " + aURL + ", " + aInterface + "\n" + e);
rv = -1;
}
return rv;
}
function jslibGetInterface (aInterface) {
var rv;
try {
rv = C.interfaces[aInterface];
} catch (e) {
jslibDebug("Error getting interface: [" + aInterface + "]\n" + e);
rv = -1;
}
return rv;
}
/************
QI: function(aEl, aIName)
{
try {
return aEl.QueryInterface(Components.interfaces[aIName]);
} catch (ex) {
throw("Unable to QI " + aEl + " to " + aIName);
}
}
************/
function jslibUninstall (aPackage, aCallback)
{
if (!aPackage || typeof(aPackage) != "string")
throw jslib_results.NS_ERROR_INVALID_ARG;
include (jslib_window);
var win = new CommonWindow(null, 400, 400);
win.position = JS_MIDDLE_CENTER;
win.openUninstallWindow(aPackage, aCallback);
}
/*********** Launch JSLIB Splash ***************/
function jslibLaunchSplash ()
{
include (jslib_window);
const url = "chrome://jslib/content/splash.xul";
var win = new CommonWindow(url, 400, 220);
win.position = JS_MIDDLE_CENTER;
win.openSplash();
}
function jslib_turnDumpOn () {
include (jslib_prefs);
// turn on dump
var pref = new Prefs();
const prefStr = "browser.dom.window.dump.enabled"
// turn dump on if not enabled
if (!pref.getBool(prefStr)) {
pref.setBool(prefStr, true);
pref.save();
}
return;
}
function jslib_turnDumpOff () {
include (jslib_prefs);
// turn off dump
var pref = new Prefs();
const prefStr = "browser.dom.window.dump.enabled"
// turn dump off if enabled
if (pref.getBool(prefStr)) {
pref.setBool(prefStr, false);
pref.save();
}
return;
}
} catch (e) {}
} // end jslib load test

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

@ -1,337 +0,0 @@
/* -*- Mode: Javascript; tab-width: 2; */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Urban Rage Software code.
*
* The Initial Developer of the Original Code is
* Eric Plaster.
* Portions created by the Initial Developer are Copyright (C) 2000
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Eric Plaster <plaster@urbanrage.com)> (original author)
* Martin Kutschker <martin.t.kutschker@blackbox.net> (polishing)
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
if(typeof(JS_LIB_LOADED)=='boolean')
{
// test to make sure rdf base classes are loaded
if(typeof(JS_RDFBASE_LOADED)!='boolean')
include(JS_LIB_PATH+'rdf/rdfBase.js');
if(typeof(JS_RDFRESOURCE_LOADED)!='boolean')
include(JS_LIB_PATH+'rdf/rdfResource.js');
if(typeof(JS_RDFCONTAINER_LOADED)!='boolean')
include(JS_LIB_PATH+'rdf/rdfContainer.js');
const JS_RDF_LOADED = true;
const JS_RDF_FILE = "rdf.js";
const JS_RDF_FLAG_SYNC = 1; // load RDF source synchronously
function RDF(src, flags) {
this.loaded = false;
if(src) {
this._rdf_init(src, flags);
}
}
RDF.prototype = new RDFBase;
RDF.prototype.src = null;
RDF.prototype._rdf_init = function(src, flags) {
flags = flags || 0;
this.src = src;
var load = true; // load source
jslibPrint("* RDFFile: Opening file \n");
// Create an RDF/XML datasource using the XPCOM Component Manager
this.dsource = C
.classes[JS_RDFBASE_RDF_DS_PROGID]
.createInstance(C.interfaces.nsIRDFDataSource);
// The nsIRDFRemoteDataSource interface has the interfaces
// that we need to setup the datasource.
var remote = this.dsource.QueryInterface(C.interfaces.nsIRDFRemoteDataSource);
try {
jslibPrint("* RDFFile: doing remote init \n");
remote.Init(src); // throws an exception if URL already in use
}
catch(err) {
// loading already
load = false;
jslibDebug(JS_RDF_FILE+":_rdf_init: Init of "+src+" failed.");
}
if (load) {
try {
jslibPrint("* RDFFile: refresh remote \n");
remote.Refresh((flags & JS_RDF_FLAG_SYNC) ? true: false);
}
catch(err) {
this.dsource = null;
jslibError(err, "Error refreshing remote rdf: "+src, "NS_ERROR_UNEXPECTED",
JS_RDF_FILE+":_rdf_init");
return;
}
}
else {
try {
jslibPrint("* RDFFile: getting ds \n");
this.dsource = this.RDF.GetDataSource(src);
remote = this.dsource.QueryInterface(C.interfaces.nsIRDFRemoteDataSource);
}
catch(err) {
this.dsource = null;
jslibError(err, "Error getting datasource: "+src, "NS_ERROR_UNEXPECTED",
JS_RDF_FILE+":_rdf_init");
return;
}
}
try {
if (remote.loaded) {
this.loaded = true;
this.setValid(true);
}
else {
var obs = {
rdf: this, // backreference to ourselves
onBeginLoad: function(aSink)
{
},
onInterrupt: function(aSink)
{},
onResume: function(aSink)
{},
onEndLoad: function(aSink)
{
this.rdf.loaded = true;
this.rdf.setValid(true);
},
onError: function(aSink, aStatus, aErrorMsg)
{
jslibError(null,"Error loading datasource: "+aErrorMsg,
"NS_ERROR_UNEXPECTED", JS_RDF_FILE+":_rdf_init (observer)");
}
};
// RDF/XML Datasources are all nsIRDFXMLSinks
var sink = this.dsource.QueryInterface(C.interfaces.nsIRDFXMLSink);
// Attach the observer to the datasource-as-sink
sink.addXMLSinkObserver(obs);
}
}
catch(err) {
jslibError(err, "Error loading rdf!\n", "NS_ERROR_UNEXPECTED",
JS_RDF_FILE+":_rdf_init");
return;
}
};
RDF.prototype.getSource = function()
{
return this.src;
};
RDF.prototype.getNode = function(aPath)
{
jslibDebug("entering getNode");
if(this.isValid()) {
var res = this.RDF.GetResource(aPath);
return new RDFResource("node", res.Value, null, this.dsource);
} else {
jslibError(null, "RDF is no longer valid!\n", "NS_ERROR_UNEXPECTED",
JS_RDF_FILE+":getNode");
return null;
}
};
RDF.prototype.addRootSeq = function(aSeq)
{
return this.addRootContainer(aSeq, "seq");
};
RDF.prototype.addRootAlt = function(aAlt)
{
return this.addRootContainer(aAlt, "alt");
};
RDF.prototype.addRootBag = function(aBag)
{
return this.addRootContainer(aBag, "bag");
};
RDF.prototype.addRootContainer = function(aContainer, aType)
{
if(this.isValid()) {
if(!aContainer)
jslibError(null, "Must supply a container path", null, JSRDFCONTAINER+":addRootContainer");
var res = this.RDF.GetResource(aContainer);
// FIXME: should test if exists and is already a container
if(aType == "bag") {
this.RDFCUtils.MakeBag(this.dsource, res);
} else if(aType == "alt") {
this.RDFCUtils.MakeAlt(this.dsource, res);
} else if(aType == "seq") {
this.RDFCUtils.MakeSeq(this.dsource, res);
} else {
// FIXME: this.RDFCUtils.MakeContainer....
}
return new RDFContainer(aType, aContainer, null, this.dsource);
} else {
jslibError(null, "RDF is no longer valid!\n", "NS_ERROR_UNEXPECTED",
JS_RDF_FILE+":addRootContainer");
return null;
}
};
RDF.prototype.getRootSeq = function(aSeq)
{
return this.getContainer(aSeq, "seq");
};
RDF.prototype.getRootAlt = function(aAlt)
{
return this.getContainer(aAlt, "alt");
};
RDF.prototype.getRootBag = function(aBag)
{
return this.getContainer(aBag, "bag");
};
RDF.prototype.getContainer = function(aContainer, aType)
{
var rv = null;
if(this.isValid()) {
var res = this.RDF.GetResource(aContainer);
if(res) {
rv = new RDFContainer(aType, aContainer, null, this.dsource);
}
}
return rv;
};
RDF.prototype.getAllSeqs = function()
{
return this.getRootContainers("seq");
};
RDF.prototype.getAllAlts = function()
{
return this.getRootContainers("alt");
};
RDF.prototype.getAllBags = function()
{
return this.getRootContainers("bag");
};
RDF.prototype.getAllContainers = function()
{
return this.getRootContainers("all");
};
RDF.prototype.getRootContainers = function(aType)
{
var rv = null;
if(this.isValid()) {
var list = new Array;
var elems = this.dsource.GetAllResources();
while(elems.hasMoreElements()) {
var elem = elems.getNext();
elem = elem.QueryInterface(C.interfaces.nsIRDFResource);
if(aType == "bag") {
if(this.RDFCUtils.IsBag(this.dsource, elem)) {
list.push(new RDFContainer(aType, elem.Value, null, this.dsource));
}
} else if(aType == "alt") {
if(this.RDFCUtils.IsAlt(this.dsource, elem)) {
list.push(new RDFContainer(aType, elem.Value, null, this.dsource));
}
} else if(aType == "seq") {
if(this.RDFCUtils.IsSeq(this.dsource, elem)) {
list.push(new RDFContainer(aType, elem.Value, null, this.dsource));
}
} else if(aType == "all") {
if(this.RDFCUtils.IsContainer(this.dsource, elem)) {
list.push(new RDFContainer(aType, elem.Value, null, this.dsource));
}
} else {
if(!this.RDFCUtils.IsContainer(this.dsource, elem)) {
list.push(new RDFResource(aType, elem.Value, null, this.dsource));
}
}
}
return list;
} else {
jslibError(null, "RDF is no longer valid!\n", "NS_ERROR_UNEXPECTED",
JS_RDF_FILE+":getRootContainers");
return null;
}
};
RDF.prototype.flush = function()
{
if(this.isValid())
this.dsource.QueryInterface(C.interfaces.nsIRDFRemoteDataSource).Flush();
};
RDF.prototype.refresh = function(aBlocking)
{
if(this.isValid())
this.dsource.QueryInterface(C.interfaces.nsIRDFRemoteDataSource).Refresh(aBlocking);
};
jslibDebug('*** load: '+JS_RDF_FILE+' OK');
} // END BLOCK JS_LIB_LOADED CHECK
else
{
dump("JS_RDF library not loaded:\n" +
" \tTo load use: chrome://jslib/content/jslib.js\n" +
" \tThen: include('chrome://jslib/content/rdf/rdf.js');\n\n");
}

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

@ -1,153 +0,0 @@
/* -*- Mode: Javascript; tab-width: 2; */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Urban Rage Software code.
*
* The Initial Developer of the Original Code is
* Eric Plaster.
* Portions created by the Initial Developer are Copyright (C) 2000
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Eric Plaster <plaster@urbanrage.com)> (original author)
* Martin Kutschker <martin.t.kutschker@blackbox.net> (polishing)
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
if(typeof(JS_LIB_LOADED)=='boolean')
{
const JS_RDFBASE_LOADED = true;
const JS_RDFBASE_FILE = "rdfBase.js";
const JS_RDFBASE_CONTAINER_PROGID = '@mozilla.org/rdf/container;1';
const JS_RDFBASE_CONTAINER_UTILS_PROGID = '@mozilla.org/rdf/container-utils;1';
const JS_RDFBASE_LOCATOR_PROGID = '@mozilla.org/filelocator;1';
const JS_RDFBASE_RDF_PROGID = '@mozilla.org/rdf/rdf-service;1';
const JS_RDFBASE_RDF_DS_PROGID = '@mozilla.org/rdf/datasource;1?name=xml-datasource';
/***************************************
* RDFBase is the base class for all RDF classes
*
*/
function RDFBase(aDatasource) {
this.RDF = Components.classes[JS_RDFBASE_RDF_PROGID].getService();
this.RDF = this.RDF.QueryInterface(Components.interfaces.nsIRDFService);
this.RDFC = Components.classes[JS_RDFBASE_CONTAINER_PROGID].getService();
this.RDFC = this.RDFC.QueryInterface(Components.interfaces.nsIRDFContainer);
this.RDFCUtils = Components.classes[JS_RDFBASE_CONTAINER_UTILS_PROGID].getService();
this.RDFCUtils = this.RDFCUtils.QueryInterface(Components.interfaces.nsIRDFContainerUtils);
if(aDatasource) {
this._base_init(aDatasource);
}
}
RDFBase.prototype = {
RDF : null,
RDFC : null,
RDFCUtils : null,
dsource : null,
valid : false,
_base_init : function(aDatasource) {
this.dsource = aDatasource;
},
getDatasource : function()
{
return this.dsource;
},
isValid : function()
{
return this.valid;
},
setValid : function(aTruth)
{
if(typeof(aTruth)=='boolean') {
this.valid = aTruth;
return this.valid;
} else {
return null;
}
},
flush : function()
{
if(this.isValid()) {
this.dsource.QueryInterface(Components.interfaces.nsIRDFRemoteDataSource).Flush();
}
}
};
RDFBase.prototype.getAnonymousResource = function()
{
jslibDebug("entering getAnonymousNode");
if(this.isValid()) {
var res = this.RDF.GetAnonymousResource();
return new RDFResource("node", res.Value, null, this.dsource);
} else {
jslibError(null, "RDF is no longer valid!\n", "NS_ERROR_UNEXPECTED",
JS_RDF_FILE+":getNode");
return null;
}
};
RDFBase.prototype.getAnonymousContainer = function(aType)
{
jslibDebug("entering getAnonymousContainer");
if(this.isValid()) {
var res = this.getAnonymousResource();
jslibDebug("making Container");
if(aType == "bag") {
this.RDFCUtils.MakeBag(this.dsource, res.getResource());
} else if(aType == "alt") {
this.RDFCUtils.MakeAlt(this.dsource, res.getResource());
} else {
this.RDFCUtils.MakeSeq(this.dsource, res.getResource());
}
jslibPrint("* made cont ..."+res.getSubject()+"\n");
return new RDFContainer(aType, res.getSubject(),null, this.dsource);
} else {
jslibError(null, "RDF is no longer valid!\n", "NS_ERROR_UNEXPECTED",
JS_RDF_FILE+":getNode");
return null;
}
};
jslibDebug('*** load: '+JS_RDFBASE_FILE+' OK');
} // END BLOCK JS_LIB_LOADED CHECK
else
{
jslibPrint("JS_RDFBase library not loaded:\n" +
" \tTo load use: chrome://jslib/content/jslib.js\n" +
" \tThen: include('chrome://jslib/content/rdf/rdf.js');\n\n");
}

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

@ -1,287 +0,0 @@
/* -*- Mode: Javascript; tab-width: 2; */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Urban Rage Software code.
*
* The Initial Developer of the Original Code is
* Eric Plaster.
* Portions created by the Initial Developer are Copyright (C) 2000
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Eric Plaster <plaster@urbanrage.com)> (original author)
* Martin Kutschker <martin.t.kutschker@blackbox.net> (polishing)
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
if(typeof(JS_LIB_LOADED)=='boolean')
{
// test to make sure filesystem base class is loaded
if(typeof(JS_RDFRESOURCE_LOADED)!='boolean')
include(JS_LIB_PATH+'rdf/rdfResource.js');
const JS_RDFCONTAINER_LOADED = true;
const JS_RDFCONTAINER_FILE = "rdfContainer.js";
function RDFContainer(aType, aPath, aParent, aDatasource) {
if(aDatasource) {
this._container_init(aType, aPath, aParent, aDatasource);
}
}
RDFContainer.prototype = new RDFResource;
RDFContainer.prototype._container_init = function(aType, aPath, aParent, aDatasource)
{
this._resource_init(aType, aPath, aParent, aDatasource);
};
RDFContainer.prototype.addSeq = function(aSeq) {
return this.addContainer(aSeq, "seq");
};
RDFContainer.prototype.addBag = function(aBag) {
return this.addContainer(aBag, "bag");
};
RDFContainer.prototype.addAlt = function(aAlt) {
return this.addContainer(aAlt, "alt");
};
RDFContainer.prototype.addContainer = function(aContainer, aType)
{
if(this.isValid()) {
if(!aContainer || !aType)
jslibError(null, "Must supply two arguments", null, JS_RDFCONTAINER_FILE+":addContainer");
var res = this.RDF.GetResource(this.subject+":"+aContainer);
if( this.resource ) {
this.RDFC.Init(this.dsource, this.resource );
if(aType == "bag") {
this.RDFCUtils.MakeBag(this.dsource, res);
} else if(aType == "alt") {
this.RDFCUtils.MakeAlt(this.dsource, res);
} else {
this.RDFCUtils.MakeSeq(this.dsource, res);
}
this.RDFC.AppendElement(res);
}
return new RDFContainer(aType, this.subject+":"+aContainer, this.parent, this.dsource);
} else {
jslibError(null, "RDFContainer is no longer valid!\n", "NS_ERROR_UNEXPECTED",
JS_RDFCONTAINER_FILE+":addContainer");
return null;
}
};
RDFContainer.prototype.getNode = function(aNode) {
var rv = null;
if(this.isValid()) {
var res = this.RDF.GetResource(this.subject+":"+aNode);
if(res) {
return new RDFResource("node", this.subject+":"+aNode, this.subject, this.dsource);
}
} else {
jslibError(null, "RDFContainer is no longer valid!\n", "NS_ERROR_UNEXPECTED",
JS_RDFCONTAINER_FILE+":getNode");
return null;
}
};
RDFContainer.prototype.addNode = function(aNode) {
if(this.isValid()) {
var res = this.RDF.GetResource(this.subject+":"+aNode);
this.RDFC.Init(this.dsource, this.resource);
this.RDFC.AppendElement(res);
return new RDFResource("node", this.subject+":"+aNode, this.subject, this.dsource);
} else {
jslibError(null, "RDFContainer is no longer valid!\n", "NS_ERROR_UNEXPECTED",
JS_RDFCONTAINER_FILE+":addNode");
return null;
}
};
RDFContainer.prototype.addResource = function(aResource) {
if(this.isValid()) {
var res = aResource.getResource();
this.RDFC.Init(this.dsource, this.resource);
this.RDFC.AppendElement(res);
} else {
jslibError(null, "RDFContainer is no longer valid!\n", "NS_ERROR_UNEXPECTED",
JS_RDFCONTAINER_FILE+":addNode");
return null;
}
};
// FIXME add a getSeq("relative:path");
//
RDFContainer.prototype.getSubSeqs = function()
{
return this.getSubResources("seq");
};
RDFContainer.prototype.getSubBags = function()
{
return this.getSubResources("bag");
};
RDFContainer.prototype.getSubAlts = function()
{
return this.getSubResources("alt");
};
RDFContainer.prototype.getSubContainers = function()
{
return this.getSubResources("all");
};
RDFContainer.prototype.getSubNodes = function()
{
return this.getSubResources("node");
};
RDFContainer.prototype.getSubResources = function(aType)
{
if(this.isValid()) {
var list = new Array;
this.RDFC.Init(this.dsource, this.resource);
var elems = this.RDFC.GetElements();
while(elems.hasMoreElements()) {
var elem = elems.getNext();
elem = elem.QueryInterface(Components.interfaces.nsIRDFResource);
if(aType == "bag") {
if(this.RDFCUtils.IsBag(this.dsource, elem)) {
list.push(new RDFContainer(aType, elem.Value, this.subject, this.dsource));
}
} else if(aType == "alt") {
if(this.RDFCUtils.IsAlt(this.dsource, elem)) {
list.push(new RDFContainer(aType, elem.Value, this.subject, this.dsource));
}
} else if(aType == "seq") {
if(this.RDFCUtils.IsSeq(this.dsource, elem)) {
list.push(new RDFContainer(aType, elem.Value, this.subject, this.dsource));
}
} else if(aType == "all") {
if(this.RDFCUtils.IsContainer(this.dsource, elem)) {
list.push(new RDFContainer(aType, elem.Value, this.subject, this.dsource));
}
} else {
if(!this.RDFCUtils.IsContainer(this.dsource, elem)) {
list.push(new RDFResource(aType, elem.Value, this.subject, this.dsource));
}
}
}
return list;
} else {
jslibError(null, "RDFContainer is no longer valid!\n", "NS_ERROR_UNEXPECTED",
JS_RDFCONTAINER_FILE+":getSubResources");
return null;
}
};
RDFContainer.prototype.remove_recursive = function(aPath)
{
if(this.isValid()) {
var res = this.RDF.GetResource(aPath);
this.RDFC.Init(this.dsource, res);
var elems = this.RDFC.GetElements();
while(elems.hasMoreElements()) {
var elem = elems.getNext();
if(this.RDFCUtils.IsContainer(this.dsource, elem)) {
this.remove_recursive(elem.QueryInterface(Components.interfaces.nsIRDFResource).Value);
this.RDFC.Init(this.dsource, res);
}
var arcs = this.dsource.ArcLabelsOut(elem);
while(arcs.hasMoreElements()) {
var arc = arcs.getNext();
var targets = this.dsource.GetTargets(elem, arc, true);
while (targets.hasMoreElements()) {
var target = targets.getNext();
this.dsource.Unassert(elem, arc, target, true);
}
}
this.RDFC.RemoveElement(elem, false);
}
this.RDFC.RemoveElement(res, false);
} else {
jslibError(null, "RDFContainer is no longer valid!\n", "NS_ERROR_UNEXPECTED",
JS_RDFCONTAINER_FILE+":remove");
return null;
}
};
RDFContainer.prototype.remove = function(aDeep)
{
if(this.isValid()) {
if(this.parent != null) {
var parentres = this.RDF.GetResource(this.parent);
this.RDFC.Init(this.dsource, parentres);
}
if(aDeep) {
this.remove_recursive(this.subject);
}
var arcs = this.dsource.ArcLabelsOut(this.resource);
while(arcs.hasMoreElements()) {
var arc = arcs.getNext();
var targets = this.dsource.GetTargets(this.resource, arc, true);
while (targets.hasMoreElements()) {
var target = targets.getNext();
this.dsource.Unassert(this.resource, arc, target, true);
}
}
if(this.parent != null) {
this.RDFC.RemoveElement(this.resource, false);
}
this.setValid(false);
} else {
jslibError(null, "RDFContainer is no longer valid!\n", "NS_ERROR_UNEXPECTED",
JS_RDFCONTAINER_FILE+":remove");
return null;
}
};
jslibDebug('*** load: '+JS_RDFCONTAINER_FILE+' OK');
} // END BLOCK JS_LIB_LOADED CHECK
else
{
jslibPrint("JS_RDF library not loaded:\n" +
" \tTo load use: chrome://jslib/content/jslib.js\n" +
" \tThen: include('chrome://jslib/content/rdf/rdf.js');\n\n");
}

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

@ -1,120 +0,0 @@
/* -*- Mode: Javascript; tab-width: 2; */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Urban Rage Software code.
*
* The Initial Developer of the Original Code is
* Eric Plaster.
* Portions created by the Initial Developer are Copyright (C) 2000
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Eric Plaster <plaster@urbanrage.com)> (original author)
* Martin Kutschker <martin.t.kutschker@blackbox.net> (polishing)
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
if(typeof(JS_LIB_LOADED)=='boolean')
{
// test to make sure rdf base class is loaded
if(typeof(JS_RDF_LOADED)!='boolean')
include(JS_LIB_PATH+'rdf/rdf.js');
// test to make sure file class is loaded
if (typeof(JS_FILE_LOADED)!='boolean')
include(JS_LIB_PATH+'io/file.js');
const JS_RDFFILE_FLAG_SYNC = 1; // load RDF source synchronously
const JS_RDFFILE_FLAG_DONT_CREATE = 2; // don't create RDF file (RDFFile only)
const JS_RDFFILE_FILE = "rdfFile.js";
function RDFFile(aPath, aFlags, aNameSpace, aID)
{
this.created = false;
if(aPath)
this._file_init(aPath, aFlags, aNameSpace, aID);
}
RDFFile.prototype = new RDF;
RDFFile.prototype._file_init = function (aPath, aFlags, aNameSpace, aID) {
aFlags = aFlags || JS_RDFFILE_FLAG_SYNC; // default to synchronous loading
if(aNameSpace == null) {
aNameSpace = "http://jslib.mozdev.org/rdf#";
}
if(aID == null) {
aID = "JSLIB";
}
// Ensure we have a base RDF file to work with
var rdf_file = new File(aPath);
if (!rdf_file.exists() && !(aFlags & JS_RDFFILE_FLAG_DONT_CREATE)) {
if (rdf_file.open("w") != JS_FILE_OK) {
return;
}
var filestr =
'<?xml version="1.0" ?>\n' +
'<RDF:RDF\n' +
' xmlns:'+ aID +'="'+ aNameSpace +'"\n' +
' xmlns:RDF="http://www.w3.org/1999/02/22-rdf-syntax-ns#">\n' +
'</RDF:RDF>\n';
jslibPrint("here4!\n");
if (rdf_file.write(filestr) != JS_FILE_OK) {
rdf_file.close();
return;
}
this.created = true;
}
rdf_file.close();
// Get a reference to the available datasources
var serv = Components.classes["@mozilla.org/network/io-service;1"].
getService(Components.interfaces.nsIIOService);
if (!serv) {
throw Components.results.ERR_FAILURE;
}
var uri = serv.newFileURI(rdf_file.nsIFile);
this._rdf_init(uri.spec, aFlags);
};
jslibDebug('*** load: '+JS_RDFFILE_FILE+' OK');
} // END BLOCK JS_LIB_LOADED CHECK
// If jslib base library is not loaded, dump this error.
else
{
dump("JS_RDFFILE library not loaded:\n" +
" \tTo load use: chrome://jslib/content/jslib.js\n" +
" \tThen: include('chrome://jslib/content/rdf/rdfFile.js');\n\n");
}

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

@ -1,327 +0,0 @@
/* -*- Mode: Javascript; tab-width: 2; */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Urban Rage Software code.
*
* The Initial Developer of the Original Code is
* Eric Plaster.
* Portions created by the Initial Developer are Copyright (C) 2000
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Eric Plaster <plaster@urbanrage.com)> (original author)
* Martin Kutschker <martin.t.kutschker@blackbox.net> (polishing)
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
if(typeof(JS_LIB_LOADED)=='boolean')
{
// test to make sure rdfBase base class is loaded
if(typeof(JS_RDFBASE_LOADED)!='boolean')
include(JS_LIB_PATH+'rdf/rdfBase.js');
const JS_RDFRESOURCE_LOADED = true;
const JS_RDFRESOURCE_FILE = "rdfResource.js";
function RDFResource(aType, aPath, aParentPath, aDatasource) {
if(aDatasource) {
this._resource_init(aType, aPath, aParentPath, aDatasource);
}
}
RDFResource.prototype = new RDFBase;
RDFResource.prototype.type = null;
RDFResource.prototype.parent = null;
RDFResource.prototype.resource = null;
RDFResource.prototype.subject = null;
RDFResource.prototype._resource_init = function(aType, aPath, aParentPath, aDatasource) {
this.type = aType;
this.parent = aParentPath;
this.subject = aPath;
this.resource = this.RDF.GetResource(aPath);
this._base_init(aDatasource);
if(this.resource) {
this.setValid(true);
}
};
RDFResource.prototype.getResource = function() {
return this.resource;
};
RDFResource.prototype.getSubject = function() {
return this.subject;
};
RDFResource.prototype.makeSeq = function(aSeq) {
return this.makeContainer("seq");
};
RDFResource.prototype.makeBag = function(aBag) {
return this.makeContainer("bag");
};
RDFResource.prototype.makeAlt = function(aAlt) {
return this.makeContainer("alt");
};
RDFResource.prototype.makeContainer = function(aType) {
this.RDFC.Init(this.dsource, this.resource );
if(aType == "bag") {
this.RDFCUtils.MakeBag(this.dsource, this.resource);
} else if(aType == "alt") {
this.RDFCUtils.MakeAlt(this.dsource, this.resource);
} else {
this.RDFCUtils.MakeSeq(this.dsource, this.resource);
}
jslibPrint("* made cont ...\n");
return new RDFContainer(aType, this.resource_path+":"+aContainer, this.parent, this.dsource);
this.setValid(false);
};
RDFResource.prototype.setAttribute = function(aName, aValue)
{
if(this.isValid()) {
var oldvalue = this.getAttribute(aName);
if(oldvalue) {
this.dsource.Change(this.resource,
this.RDF.GetResource(aName),
this.RDF.GetLiteral(oldvalue),
this.RDF.GetLiteral(aValue) );
jslibPrint("\n Changing old value in "+this.subject+"\n");
} else {
this.dsource.Assert(this.resource,
this.RDF.GetResource(aName),
this.RDF.GetLiteral(aValue),
true );
jslibPrint("\n Adding a new value in "+this.subject+"\n");
}
return true;
} else {
return false;
}
};
RDFResource.prototype.getAttribute = function(aName)
{
if(this.isValid()) {
var itemRes = this.RDF.GetResource(aName);
if (!itemRes) { return null; }
var target = this.dsource.GetTarget(this.resource, itemRes, true);
if (target) target = target.QueryInterface(Components.interfaces.nsIRDFLiteral);
if (!target) { return null; }
return target.Value;
} else {
jslibError(null, "RDFResource is no longer valid!\n", "NS_ERROR_UNEXPECTED",
JS_RDFRESOURCE_FILE+":getAttribute");
return null;
}
};
RDFResource.prototype.getContainer = function(aName,aType)
{
if(this.isValid()) {
var itemRes = this.RDF.GetResource(aName);
if (!itemRes) { return null; }
var target = this.dsource.GetTarget(this.resource, itemRes, true);
if (target) target = target.QueryInterface(Components.interfaces.nsIRDFResource);
if (!target) { return null; }
if(!aType) aType = "bag";
return new RDFContainer(aType, target.Value, null, this.dsource);
} else {
jslibError(null, "RDFResource is no longer valid!\n", "NS_ERROR_UNEXPECTED",
JS_RDFRESOURCE_FILE+":getAttribute");
return null;
}
};
RDFResource.prototype.addContainer = function(aName,aType)
{
if(this.isValid()) {
//var oldvalue = this.getContainer(aName);
var newC = this.getAnonymousContainer(aType);
this.dsource.Assert( this.resource,this.RDF.GetResource(aName), newC.getResource(), true );
jslibPrint("\n Adding a new value in "+this.subject+"\n");
return newC;
} else {
jslibPrint("\n cudnt get anon container\n");
return null;
}
};
RDFResource.prototype.getAssociationContainers = function(aName)
{
if(this.isValid()) {
var list = new Array();
var arcs = this.dsource.ArcLabelsIn(this.resource);
while(arcs.hasMoreElements()) {
var arc = arcs.getNext();
arc = arc.QueryInterface(Components.interfaces.nsIRDFResource);
jslibDebug("Got arc " +arc.Value);
if(!this.RDFCUtils.IsOrdinalProperty(arc)) {
continue;
}
var targets = this.dsource.GetSources(arc, this.resource, true);
var itemRes = this.RDF.GetResource(aName);
while (targets.hasMoreElements()) {
var target = targets.getNext();
target = target.QueryInterface(Components.interfaces.nsIRDFResource);
if(this.RDFCUtils.IsContainer(this.dsource,target)) {
if(this.dsource.hasArcIn( target, itemRes)) {
target = new RDFContainer(null, target.Value, null, this.dsource);
list.push(target);
}
}
}
}
return list;
} else {
jslibError(null, "RDFResource is no longer valid!\n", "NS_ERROR_UNEXPECTED",
JS_RDFRESOURCE_FILE+":getAttribute");
return null;
}
};
RDFResource.prototype.removeAttribute = function(aName)
{
if(this.isValid()) {
var itemRes = this.RDF.GetResource(aName, true);
var target = this.dsource.GetTarget(this.resource, itemRes, true);
this.dsource.Unassert(this.resource, itemRes, target);
} else {
jslibError(null, "RDFResource is no longer valid!\n", "NS_ERROR_UNEXPECTED",
JS_RDFRESOURCE_FILE+":removeAttribute");
return null;
}
};
RDFResource.prototype.setAllAttributes = function(aList)
{
var length = 0;
try {
length = aList.length;
} catch(e) {
return false;
}
if(this.isValid()) {
var arcs = this.dsource.ArcLabelsOut(this.resource);
while(arcs.hasMoreElements()) {
var arc = arcs.getNext();
arc = arc.QueryInterface(Components.interfaces.nsIRDFResource);
var obj = new Object;
var l = arc.Value.split("#");
obj.name = l[l.length-1];
var targets = this.dsource.GetTargets(this.resource, arc, true);
while (targets.hasMoreElements()) {
var target = targets.getNext();
this.dsource.Unassert(this.resource, arc, target, true);
}
}
for(var i=0; i<length; i++) {
this.setAttribute(aList[i].name, aList[i].value);
}
}
};
RDFResource.prototype.getAllAttributes = function()
{
var list = new Array;
if(this.isValid()) {
var arcs = this.dsource.ArcLabelsOut(this.resource);
while(arcs.hasMoreElements()) {
var arc = arcs.getNext();
arc = arc.QueryInterface(Components.interfaces.nsIRDFResource);
var obj = new Object;
var l = arc.Value.split("#");
obj.name = l[l.length-1];
var targets = this.dsource.GetTargets(this.resource, arc, true);
while (targets.hasMoreElements()) {
var target = targets.getNext();
if(target) {
try {
target = target.QueryInterface(Components.interfaces.nsIRDFLiteral);
}
catch(e) {
jslibPrint('not a literal');
target = target.QueryInterface(Components.interfaces.nsIRDFResource);
}
obj.value = target.Value;
list.push(obj);
}
}
}
return list;
} else {
jslibError(null, "RDFResource is no longer valid!\n", "NS_ERROR_UNEXPECTED",
JS_RDFRESOURCE_FILE+":getAllAttributes");
return null;
}
};
RDFResource.prototype.remove = function()
{
if(this.isValid()) {
// FIXME: if we get this node from RDF, it has no parent...
// try just removing all arcs and targets...
// var parentres = this.RDF.GetResource(this.parent);
// this.RDFC.Init(this.dsource, parentres);
var arcs = this.dsource.ArcLabelsOut(this.resource);
while(arcs.hasMoreElements()) {
var arc = arcs.getNext();
var targets = this.dsource.GetTargets(this.resource, arc, true);
while (targets.hasMoreElements()) {
var target = targets.getNext();
this.dsource.Unassert(this.resource, arc, target, true);
}
}
this.RDFC.RemoveElement(this.resource, false); //removes the parent element
this.setValid(false);
} else {
jslibError(null, "RDFResource is no longer valid!\n", "NS_ERROR_UNEXPECTED",
JS_RDFRESOURCE_FILE+":remove");
return null;
}
};
jslibDebug('*** load: '+JS_RDFRESOURCE_FILE+' OK');
} // END BLOCK JS_LIB_LOADED CHECK
else
{
dump("JS_RDFResource library not loaded:\n" +
" \tTo load use: chrome://jslib/content/jslib.js\n" +
" \tThen: include('chrome://jslib/content/rdf/rdf.js');\n\n");
}