mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-10 20:05:49 +00:00
Upgraded jslib code to recent code on 16th Dec 2003 ( version 0.1.123 )
See bug 228626
This commit is contained in:
parent
633925b48a
commit
ad31f8ed11
@ -64,7 +64,7 @@ const JS_DIR_PREFS_DIR = 65539;
|
||||
const JS_DIR_DIRECTORY = 0x01; // 1
|
||||
const JS_DIR_OK = true;
|
||||
|
||||
const JS_DIR_DEFAULT_PERMS = 0755;
|
||||
const JS_DIR_DEFAULT_PERMS = 0766;
|
||||
|
||||
const JS_DIR_FilePath = new C.Constructor(JS_DIR_LOCAL_CID,
|
||||
JS_DIR_I_LOCAL_FILE,
|
||||
@ -101,7 +101,7 @@ Dir.prototype.create = function(aPermissions)
|
||||
return null;
|
||||
}
|
||||
|
||||
if(aPermissions) {
|
||||
if (typeof(aPermissions) == "number") {
|
||||
var checkPerms = this.validatePermissions(aPermissions);
|
||||
|
||||
if(!checkPerms) {
|
||||
@ -109,18 +109,14 @@ Dir.prototype.create = function(aPermissions)
|
||||
"NS_ERROR_INVALID_ARG", JS_DIR_FILE+":create");
|
||||
return C.results.NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
|
||||
//var baseTen = permissions.toString(10);
|
||||
//if(baseTen.substring(0,1) != 0)
|
||||
//aPermissions = 0+baseTen;
|
||||
} else {
|
||||
checkPerms = JS_DIR_DEFAULT_PERMS;
|
||||
checkPerms = this.mFileInst.parent.permissions;
|
||||
}
|
||||
|
||||
var rv = null;
|
||||
|
||||
try {
|
||||
rv=this.mFileInst.create(JS_DIR_DIRECTORY, parseInt(aPermissions) );
|
||||
rv=this.mFileInst.create(JS_DIR_DIRECTORY, checkPerms);
|
||||
} catch (e) {
|
||||
jslibError(e, "(unable to create)", "NS_ERROR_FAILURE", JS_DIR_FILE+":create");
|
||||
rv=null;
|
||||
|
@ -72,6 +72,12 @@ const NS_APP_IMAP_MAIL_50_DIR = "IMapMD"; // /root/.mozilla/Default
|
||||
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);
|
||||
@ -127,6 +133,10 @@ 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 =
|
||||
|
@ -61,7 +61,7 @@ xpcom nsIFile file IO library from js
|
||||
parent; read only attribute gets parent dir part of a path
|
||||
|
||||
// direct manipulation
|
||||
nsIFIle returns an nsIFile obj
|
||||
nsIFile returns an nsIFile obj
|
||||
|
||||
// utils
|
||||
remove(); removes the current file
|
||||
@ -361,10 +361,11 @@ File.prototype.open = function(aMode, aPerms)
|
||||
}
|
||||
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 = new JS_FILE_InputStream();
|
||||
this.mInputStream.init(this.mFileChannel.open());
|
||||
this.mLineBuffer = new Array();
|
||||
this.mLineBuffer = new Array();
|
||||
rv=true;
|
||||
} catch (e) {
|
||||
jslibError(e, "open(r) (error setting permissions)",
|
||||
@ -754,7 +755,6 @@ File.prototype.create = function()
|
||||
/********************* REMOVE *******************************/
|
||||
File.prototype.remove = function ()
|
||||
{
|
||||
|
||||
if (!this.checkInst())
|
||||
throw C.results.NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
@ -767,27 +767,8 @@ File.prototype.remove = function ()
|
||||
this.close();
|
||||
var rv;
|
||||
try {
|
||||
if (!this.exists()) {
|
||||
jslibError(null, "(file doesn't exist)",
|
||||
"NS_ERROR_FAILURE",
|
||||
JS_FILE_FILE+":remove");
|
||||
return null;
|
||||
}
|
||||
|
||||
// I think we should remove whatever is there, sym link, file, dir etc . .
|
||||
if (this.mFileInst.isSpecial()) {
|
||||
jslibError(null, "(file is not a regular file)",
|
||||
"NS_ERROR_FAILURE",
|
||||
JS_FILE_FILE+":remove");
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!this.isFile()) {
|
||||
jslibError(null, "(not a file)", "NS_ERROR_FAILURE", JS_FILE_FILE+":remove");
|
||||
return null;
|
||||
}
|
||||
// this is a recursive remove.
|
||||
this.isFile() ? rv = this.mFileInst.remove(true) : rv = null;
|
||||
// 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",
|
||||
|
@ -80,7 +80,7 @@ Instructions:
|
||||
*/
|
||||
|
||||
// Make sure jslib is loaded
|
||||
if(typeof(JS_LIB_LOADED)=='boolean')
|
||||
if (typeof(JS_LIB_LOADED)=='boolean')
|
||||
{
|
||||
|
||||
/****************** Globals **********************/
|
||||
@ -112,11 +112,14 @@ 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
|
||||
@ -124,41 +127,41 @@ chrome_to_path : function (aPath) { return this.chromeToPath(aPath); },
|
||||
|
||||
chromeToPath : function (aPath)
|
||||
{
|
||||
if(!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 path;
|
||||
var rv;
|
||||
|
||||
if(aPath.search(/^chrome:/) == 0) {
|
||||
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);
|
||||
path = uri.path;
|
||||
rv = uri.path;
|
||||
}
|
||||
} catch(e) {}
|
||||
|
||||
var rv;
|
||||
|
||||
try {
|
||||
var dir = new C.Constructor(JS_FILEUTILS_DR_PROGID, JS_FILEUTILS_I_PROPS);
|
||||
rv = (new dir()).get(JS_FILEUTILS_CHROME_DIR, C.interfaces.nsIFile).path;
|
||||
rv = path.replace(/\/chrome/, rv);
|
||||
} catch (e) {
|
||||
jslibError(e, "(problem getting file instance)", "NS_ERROR_UNEXPECTED", JS_FILEUTILS_FILE+":chromeToPath");
|
||||
rv = null;
|
||||
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(aPath.search(/^file:/) == 0) {
|
||||
rv=this.urlToPath(aPath);
|
||||
else if (/^file:/.test(aPath)) {
|
||||
rv = this.urlToPath(aPath);
|
||||
} else
|
||||
rv=null;
|
||||
rv = "";
|
||||
|
||||
return rv;
|
||||
},
|
||||
@ -168,13 +171,13 @@ URL_to_path : function (aPath){ return this.urlToPath(aPath); },
|
||||
|
||||
urlToPath : function (aPath)
|
||||
{
|
||||
if(!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) {
|
||||
if (aPath.search(/^file:/) == 0) {
|
||||
try {
|
||||
var uri = C.classes[JS_FILEUTILS_NETWORK_STD_CID].createInstance(JS_FILEUTILS_I_FILEURL);
|
||||
uri.spec = aPath;
|
||||
@ -191,7 +194,7 @@ urlToPath : function (aPath)
|
||||
/********************* EXISTS ***************************/
|
||||
exists : function (aPath)
|
||||
{
|
||||
if(!aPath) {
|
||||
if (!aPath) {
|
||||
jslibError(null, "(no path defined)", "NS_ERROR_INVALID_ARG", JS_FILEUTILS_FILE+":exists");
|
||||
return null;
|
||||
}
|
||||
@ -213,12 +216,12 @@ rm : function (aPath) { return this.remove(aPath); },
|
||||
|
||||
remove : function (aPath)
|
||||
{
|
||||
if(!aPath) {
|
||||
if (!aPath) {
|
||||
jslibError(null, "(no path defined)", "NS_ERROR_INVALID_ARG", JS_FILEUTILS_FILE+":remove");
|
||||
return null;
|
||||
}
|
||||
|
||||
if(!this.exists(aPath)) {
|
||||
if (!this.exists(aPath)) {
|
||||
jslibError(null, "(file doesn't exist)", "NS_ERROR_UNEXPECTED", JS_FILEUTILS_FILE+":remove");
|
||||
return null;
|
||||
}
|
||||
@ -227,7 +230,7 @@ remove : function (aPath)
|
||||
|
||||
try {
|
||||
var fileInst = new JS_FILEUTILS_FilePath(aPath);
|
||||
if(fileInst.isDirectory()) {
|
||||
if (fileInst.isDirectory()) {
|
||||
jslibError(null, "path is a dir. use rmdir()", "NS_ERROR_INVALID_ARG", JS_FILEUTILS_FILE+":remove");
|
||||
return null;
|
||||
}
|
||||
@ -245,12 +248,12 @@ remove : function (aPath)
|
||||
/********************* COPY *****************************/
|
||||
copy : function (aSource, aDest)
|
||||
{
|
||||
if(!aSource || !aDest) {
|
||||
if (!aSource || !aDest) {
|
||||
jslibError(null, "(no path defined)", "NS_ERROR_INVALID_ARG", JS_FILEUTILS_FILE+":copy");
|
||||
return null;
|
||||
}
|
||||
|
||||
if(!this.exists(aSource)) {
|
||||
if (!this.exists(aSource)) {
|
||||
jslibError(null, "(file doesn't exist)", "NS_ERROR_UNEXPECTED", JS_FILEUTILS_FILE+":copy");
|
||||
return null;
|
||||
}
|
||||
@ -262,27 +265,27 @@ copy : function (aSource, aDest)
|
||||
var dir = new JS_FILEUTILS_FilePath(aDest);
|
||||
var copyName = fileInst.leafName;
|
||||
|
||||
if(fileInst.isDirectory()) {
|
||||
if (fileInst.isDirectory()) {
|
||||
jslibError(null, "(cannot copy directory)", "NS_ERROR_FAILURE", JS_FILEUTILS_FILE+":copy");
|
||||
return null;
|
||||
}
|
||||
|
||||
if(!this.exists(aDest) || !dir.isDirectory()) {
|
||||
if (!this.exists(aDest) || !dir.isDirectory()) {
|
||||
copyName = dir.leafName;
|
||||
dir = new JS_FILEUTILS_FilePath(dir.path.replace(copyName,''));
|
||||
|
||||
if(!this.exists(dir.path)) {
|
||||
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()) {
|
||||
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))) {
|
||||
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;
|
||||
}
|
||||
@ -300,12 +303,12 @@ copy : function (aSource, aDest)
|
||||
/********************* LEAF *****************************/
|
||||
leaf : function (aPath)
|
||||
{
|
||||
if(!aPath) {
|
||||
if (!aPath) {
|
||||
jslibError(null, "(no path defined)", "NS_ERROR_INVALID_ARG", JS_FILEUTILS_FILE+":leaf");
|
||||
return null;
|
||||
}
|
||||
|
||||
if(!this.exists(aPath)) {
|
||||
if (!this.exists(aPath)) {
|
||||
jslibError(null, "(file doesn't exist)", "NS_ERROR_UNEXPECTED", JS_FILEUTILS_FILE+":leaf");
|
||||
return null;
|
||||
}
|
||||
@ -328,12 +331,12 @@ leaf : function (aPath)
|
||||
/********************* APPEND ***************************/
|
||||
append : function (aDirPath, aFileName)
|
||||
{
|
||||
if(!aDirPath || !aFileName) {
|
||||
if (!aDirPath || !aFileName) {
|
||||
jslibError(null, "(no path defined)", "NS_ERROR_INVALID_ARG", JS_FILEUTILS_FILE+":append");
|
||||
return null;
|
||||
}
|
||||
|
||||
if(!this.exists(aDirPath)) {
|
||||
if (!this.exists(aDirPath)) {
|
||||
jslibError(null, "(file doesn't exist)", "NS_ERROR_UNEXPECTED", JS_FILEUTILS_FILE+":append");
|
||||
return null;
|
||||
}
|
||||
@ -342,7 +345,7 @@ append : function (aDirPath, aFileName)
|
||||
|
||||
try {
|
||||
var fileInst = new JS_FILEUTILS_FilePath(aDirPath);
|
||||
if(fileInst.exists() && !fileInst.isDirectory()) {
|
||||
if (fileInst.exists() && !fileInst.isDirectory()) {
|
||||
jslibError(null, aDirPath+" is not a dir", "NS_ERROR_INVALID_ARG", JS_FILEUTILS_FILE+":append");
|
||||
return null;
|
||||
}
|
||||
@ -370,12 +373,12 @@ validatePermissions : function(aNum)
|
||||
/********************* PERMISSIONS **********************/
|
||||
permissions : function (aPath)
|
||||
{
|
||||
if(!aPath) {
|
||||
if (!aPath) {
|
||||
jslibError(null, "(no path defined)", "NS_ERROR_INVALID_ARG", JS_FILEUTILS_FILE+":permissions");
|
||||
return null;
|
||||
}
|
||||
|
||||
if(!this.exists(aPath)) {
|
||||
if (!this.exists(aPath)) {
|
||||
jslibError(null, "(file doesn't exist)", "NS_ERROR_UNEXPECTED", JS_FILEUTILS_FILE+":permissions");
|
||||
return null;
|
||||
}
|
||||
@ -395,12 +398,12 @@ permissions : function (aPath)
|
||||
/********************* MODIFIED *************************/
|
||||
dateModified : function (aPath)
|
||||
{
|
||||
if(!aPath) {
|
||||
if (!aPath) {
|
||||
jslibError(null, "(no path defined)", "NS_ERROR_INVALID_ARG", JS_FILEUTILS_FILE+":dateModified");
|
||||
return null;
|
||||
}
|
||||
|
||||
if(!this.exists(aPath)) {
|
||||
if (!this.exists(aPath)) {
|
||||
jslibError(null, "(file doesn't exist)", "NS_ERROR_UNEXPECTED", JS_FILEUTILS_FILE+":dateModified");
|
||||
return null;
|
||||
}
|
||||
@ -421,12 +424,12 @@ dateModified : function (aPath)
|
||||
/********************* SIZE *****************************/
|
||||
size : function (aPath)
|
||||
{
|
||||
if(!aPath) {
|
||||
if (!aPath) {
|
||||
jslibError(null, "(no path defined)", "NS_ERROR_INVALID_ARG", JS_FILEUTILS_FILE+":size");
|
||||
return null;
|
||||
}
|
||||
|
||||
if(!this.exists(aPath)) {
|
||||
if (!this.exists(aPath)) {
|
||||
jslibError(null, "(file doesn't exist)", "NS_ERROR_UNEXPECTED", JS_FILEUTILS_FILE+":size");
|
||||
return null;
|
||||
}
|
||||
@ -448,12 +451,12 @@ extension : function (aPath){ return this.ext(aPath); },
|
||||
|
||||
ext : function (aPath)
|
||||
{
|
||||
if(!aPath) {
|
||||
if (!aPath) {
|
||||
jslibError(null, "(no path defined)", "NS_ERROR_INVALID_ARG", JS_FILEUTILS_FILE+":ext");
|
||||
return null;
|
||||
}
|
||||
|
||||
if(!this.exists(aPath)) {
|
||||
if (!this.exists(aPath)) {
|
||||
jslibError(null, "(file doesn't exist)", "NS_ERROR_UNEXPECTED", JS_FILEUTILS_FILE+":ext");
|
||||
return null;
|
||||
}
|
||||
@ -477,7 +480,7 @@ dirPath : function (aPath){ return this.parent(aPath); },
|
||||
|
||||
parent : function (aPath)
|
||||
{
|
||||
if(!aPath) {
|
||||
if (!aPath) {
|
||||
jslibError(null, "(no path defined)", "NS_ERROR_INVALID_ARG", JS_FILEUTILS_FILE+":parent");
|
||||
return null;
|
||||
}
|
||||
@ -487,15 +490,15 @@ parent : function (aPath)
|
||||
try {
|
||||
var fileInst = new JS_FILEUTILS_FilePath(aPath);
|
||||
|
||||
if(!fileInst.exists()) {
|
||||
if (!fileInst.exists()) {
|
||||
jslibError(null, "(file doesn't exist)", "NS_ERROR_FAILURE", JS_FILEUTILS_FILE+":parent");
|
||||
return null;
|
||||
}
|
||||
|
||||
if(fileInst.isFile())
|
||||
if (fileInst.isFile())
|
||||
rv=fileInst.parent.path;
|
||||
|
||||
else if(fileInst.isDirectory())
|
||||
else if (fileInst.isDirectory())
|
||||
rv=fileInst.path;
|
||||
|
||||
else
|
||||
@ -521,13 +524,13 @@ spawn : function (aPath, aArgs)
|
||||
*
|
||||
*/
|
||||
{
|
||||
if(!aPath) {
|
||||
if (!aPath) {
|
||||
jslibError(null, "(no path defined)", "NS_ERROR_INVALID_ARG",
|
||||
JS_FILEUTILS_FILE+":spawn");
|
||||
return null;
|
||||
}
|
||||
|
||||
if(!this.exists(aPath)) {
|
||||
if (!this.exists(aPath)) {
|
||||
jslibError(null, "(file doesn't exist)", "NS_ERROR_UNEXPECTED",
|
||||
JS_FILEUTILS_FILE+":spawn");
|
||||
return null;
|
||||
@ -535,7 +538,7 @@ spawn : function (aPath, aArgs)
|
||||
|
||||
var len=0;
|
||||
|
||||
if(aArgs)
|
||||
if (aArgs)
|
||||
len = aArgs.length;
|
||||
else
|
||||
aArgs=null;
|
||||
@ -545,13 +548,13 @@ spawn : function (aPath, aArgs)
|
||||
try {
|
||||
var fileInst = new JS_FILEUTILS_FilePath(aPath);
|
||||
|
||||
if(!fileInst.isExecutable()) {
|
||||
if (!fileInst.isExecutable()) {
|
||||
jslibError(null, "(File is not executable)", "NS_ERROR_INVALID_ARG",
|
||||
JS_FILEUTILS_FILE+":spawn");
|
||||
return null;
|
||||
}
|
||||
|
||||
if(fileInst.isDirectory()) {
|
||||
if (fileInst.isDirectory()) {
|
||||
jslibError(null, "(File is not a program)", "NS_ERROR_UNEXPECTED",
|
||||
JS_FILEUTILS_FILE+":spawn");
|
||||
return null;
|
||||
@ -590,7 +593,7 @@ spawn : function (aPath, aArgs)
|
||||
/********************* nsIFILE **************************/
|
||||
nsIFile : function (aPath)
|
||||
{
|
||||
if(!aPath) {
|
||||
if (!aPath) {
|
||||
jslibError(null, "(no path defined)", "NS_ERROR_INVALID_ARG", JS_FILEUTILS_FILE+":nsIFile");
|
||||
return null;
|
||||
}
|
||||
|
@ -578,15 +578,12 @@ get URL()
|
||||
***************************/
|
||||
isDir : function()
|
||||
{
|
||||
|
||||
if (!this.exists()) {
|
||||
jslibError(null,
|
||||
"(file doesn't exist)",
|
||||
"NS_ERROR_FAILURE",
|
||||
JS_FILESYSTEM_FILE+":isDir");
|
||||
return false;
|
||||
}
|
||||
return this.mFileInst.isDirectory();
|
||||
var rv = false;
|
||||
try {
|
||||
rv = this.mFileInst.isDirectory();
|
||||
} catch (e) { rv = false; }
|
||||
|
||||
return rv;
|
||||
},
|
||||
|
||||
/***************************
|
||||
@ -594,15 +591,12 @@ isDir : function()
|
||||
***************************/
|
||||
isFile : function()
|
||||
{
|
||||
|
||||
if (!this.exists()) {
|
||||
jslibError(null,
|
||||
"(file doesn't exist)",
|
||||
"NS_ERROR_FAILURE",
|
||||
JS_FILESYSTEM_FILE+":isDir");
|
||||
return false;
|
||||
}
|
||||
return this.mFileInst.isFile();
|
||||
var rv = false;
|
||||
try {
|
||||
rv = this.mFileInst.isFile();
|
||||
} catch (e) { rv = false; }
|
||||
|
||||
return rv;
|
||||
},
|
||||
|
||||
/***************************
|
||||
@ -610,15 +604,12 @@ isFile : function()
|
||||
***************************/
|
||||
isExec : function()
|
||||
{
|
||||
|
||||
if (!this.exists()) {
|
||||
jslibError(null,
|
||||
"(file doesn't exist)",
|
||||
"NS_ERROR_FAILURE",
|
||||
JS_FILESYSTEM_FILE+":isDir");
|
||||
return false;
|
||||
}
|
||||
return this.mFileInst.isExecutable();
|
||||
var rv = false;
|
||||
try {
|
||||
rv = this.mFileInst.isExecutable();
|
||||
} catch (e) { rv = false; }
|
||||
|
||||
return rv;
|
||||
},
|
||||
|
||||
/***************************
|
||||
@ -627,14 +618,12 @@ isExec : function()
|
||||
isSymlink : function()
|
||||
{
|
||||
|
||||
if (!this.exists()) {
|
||||
jslibError(null,
|
||||
"(file doesn't exist)",
|
||||
"NS_ERROR_FAILURE",
|
||||
JS_FILESYSTEM_FILE+":isDir");
|
||||
return false;
|
||||
}
|
||||
return this.mFileInst.isSymlink();
|
||||
var rv = false;
|
||||
try {
|
||||
rv = this.mFileInst.isSymlink();
|
||||
} catch (e) { rv = false; }
|
||||
|
||||
return rv;
|
||||
},
|
||||
|
||||
/***************************
|
||||
|
@ -34,14 +34,14 @@ 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.8";
|
||||
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 = "0.9.5";
|
||||
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" +
|
||||
"\tfor mozilla package authors to use " +
|
||||
"in their applications\n";
|
||||
const JS_LIB_HOME = "http://jslib.mozdev.org/";
|
||||
|
||||
@ -49,8 +49,10 @@ const JS_LIB_HOME = "http://jslib.mozdev.org/";
|
||||
const ON = true;
|
||||
const OFF = false;
|
||||
const C = Components;
|
||||
const jslib_results = C.results;
|
||||
|
||||
var JS_LIB_DEBUG = ON;
|
||||
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;
|
||||
@ -81,9 +83,51 @@ 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 ***************************/
|
||||
|
||||
@ -101,6 +145,7 @@ const jslib_sound = JS_LIB_PATH+'sound/sound.js';
|
||||
|
||||
function include(aScriptPath) {
|
||||
|
||||
jslibPrint(aScriptPath);
|
||||
if (!aScriptPath) {
|
||||
jslibError(null, "Missing file path argument\n",
|
||||
"NS_ERROR_XPC_NOT_ENOUGH_ARGS",
|
||||
@ -118,19 +163,19 @@ function include(aScriptPath) {
|
||||
var end = aScriptPath.lastIndexOf('.');
|
||||
var slice = aScriptPath.length - end;
|
||||
var loadID = aScriptPath.substring(start, (aScriptPath.length - slice));
|
||||
try {
|
||||
if (typeof(eval('JS_'+loadID.toUpperCase()+'_LOADED')) == 'boolean')
|
||||
return 1;
|
||||
} catch (e) {}
|
||||
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";
|
||||
const Inc = new C.Constructor(PROG_ID, INTERFACE);
|
||||
(new Inc()).loadSubScript(aScriptPath);
|
||||
jslibGetService(PROG_ID, INTERFACE).loadSubScript(aScriptPath);
|
||||
rv = C.results.NS_OK;
|
||||
} catch(e) {
|
||||
} 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;
|
||||
@ -155,14 +200,17 @@ function jslib_debug(aOutString) { return jslibDebug(aOutString); }
|
||||
function jslibDebug(aOutString) {
|
||||
|
||||
if (!JS_LIB_DEBUG)
|
||||
return void(null);
|
||||
|
||||
if (!aOutString)
|
||||
aOutString="\n";
|
||||
return;
|
||||
|
||||
if (JS_LIB_DEBUG_ALERT)
|
||||
alert(aOutString);
|
||||
|
||||
dump(aOutString+'\n');
|
||||
return;
|
||||
}
|
||||
|
||||
// print to stdout
|
||||
function jslibPrint(aOutString) {
|
||||
return (dump(aOutString+'\n'));
|
||||
}
|
||||
|
||||
@ -201,15 +249,20 @@ function jslibError(e, aType, aResults, aCaller) {
|
||||
return (dump("JS_LIB_ERROR=ON\n"));
|
||||
|
||||
var errMsg="ERROR: "+(aCaller?"in "+aCaller:"")+" "+aType+"\n";
|
||||
var e = null;
|
||||
if (e) {
|
||||
var m = (e.message?e.message:e);
|
||||
var r = (typeof(e.result)!='undefined'?'0x'+e.result.toString(16):'');
|
||||
var l = (typeof(e.location)!='undefined'?e.location:'');
|
||||
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" +
|
||||
"Message: "+m+"\n" +
|
||||
"Result: "+r+"\n" +
|
||||
"Location: "+l+"\n";
|
||||
"Message: "+m+"\n" +
|
||||
"FileName: "+fn+"\n" +
|
||||
"LineNumber: "+ln+"\n";
|
||||
}
|
||||
if (aResults)
|
||||
errMsg+="NS_ERROR_NUMBER: "+aResults+"\n";
|
||||
@ -222,6 +275,102 @@ function jslibError(e, aType, aResults, aCaller) {
|
||||
|
||||
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
|
||||
|
@ -54,17 +54,18 @@ RDF.prototype._rdf_init = function(src, flags) {
|
||||
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 = Components
|
||||
this.dsource = C
|
||||
.classes[JS_RDFBASE_RDF_DS_PROGID]
|
||||
.createInstance(Components.interfaces.nsIRDFDataSource);
|
||||
.createInstance(C.interfaces.nsIRDFDataSource);
|
||||
|
||||
// The nsIRDFRemoteDataSource interface has the interfaces
|
||||
// that we need to setup the datasource.
|
||||
var remote = this.dsource.QueryInterface(Components.interfaces.nsIRDFRemoteDataSource);
|
||||
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) {
|
||||
@ -76,6 +77,7 @@ RDF.prototype._rdf_init = function(src, flags) {
|
||||
|
||||
if (load) {
|
||||
try {
|
||||
jslibPrint("* RDFFile: refresh remote \n");
|
||||
remote.Refresh((flags & JS_RDF_FLAG_SYNC) ? true: false);
|
||||
}
|
||||
catch(err) {
|
||||
@ -88,8 +90,9 @@ RDF.prototype._rdf_init = function(src, flags) {
|
||||
}
|
||||
else {
|
||||
try {
|
||||
jslibPrint("* RDFFile: getting ds \n");
|
||||
this.dsource = this.RDF.GetDataSource(src);
|
||||
remote = this.dsource.QueryInterface(Components.interfaces.nsIRDFRemoteDataSource);
|
||||
remote = this.dsource.QueryInterface(C.interfaces.nsIRDFRemoteDataSource);
|
||||
}
|
||||
catch(err) {
|
||||
this.dsource = null;
|
||||
@ -127,13 +130,13 @@ RDF.prototype._rdf_init = function(src, flags) {
|
||||
|
||||
onError: function(aSink, aStatus, aErrorMsg)
|
||||
{
|
||||
jslibError(null,"Error loading datasource: "+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(Components.interfaces.nsIRDFXMLSink);
|
||||
var sink = this.dsource.QueryInterface(C.interfaces.nsIRDFXMLSink);
|
||||
|
||||
// Attach the observer to the datasource-as-sink
|
||||
sink.addXMLSinkObserver(obs);
|
||||
@ -153,6 +156,7 @@ RDF.prototype.getSource = function()
|
||||
|
||||
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);
|
||||
@ -261,7 +265,7 @@ RDF.prototype.getRootContainers = function(aType)
|
||||
var elems = this.dsource.GetAllResources();
|
||||
while(elems.hasMoreElements()) {
|
||||
var elem = elems.getNext();
|
||||
elem = elem.QueryInterface(Components.interfaces.nsIRDFResource);
|
||||
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));
|
||||
@ -294,11 +298,15 @@ RDF.prototype.getRootContainers = function(aType)
|
||||
|
||||
RDF.prototype.flush = function()
|
||||
{
|
||||
if(this.isValid()) {
|
||||
this.dsource.QueryInterface(Components.interfaces.nsIRDFRemoteDataSource).Flush();
|
||||
}
|
||||
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');
|
||||
|
||||
|
@ -60,7 +60,7 @@ RDFBase.prototype = {
|
||||
this.dsource = aDatasource;
|
||||
},
|
||||
|
||||
getDatasource : function()
|
||||
getDatasource : function()
|
||||
{
|
||||
return this.dsource;
|
||||
},
|
||||
@ -83,12 +83,46 @@ RDFBase.prototype = {
|
||||
flush : function()
|
||||
{
|
||||
if(this.isValid()) {
|
||||
this.dsource.QueryInterface(Components.interfaces.nsIRDFRemoteDataSource).Flush();
|
||||
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');
|
||||
|
||||
@ -96,7 +130,7 @@ jslibDebug('*** load: '+JS_RDFBASE_FILE+' OK');
|
||||
|
||||
else
|
||||
{
|
||||
dump("JS_RDFBase library not loaded:\n" +
|
||||
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");
|
||||
}
|
||||
|
@ -86,30 +86,42 @@ RDFContainer.prototype.addContainer = function(aContainer, aType)
|
||||
};
|
||||
|
||||
RDFContainer.prototype.getNode = function(aNode) {
|
||||
var rv = null;
|
||||
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 {
|
||||
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;
|
||||
}
|
||||
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 {
|
||||
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;
|
||||
}
|
||||
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");
|
||||
@ -141,118 +153,118 @@ RDFContainer.prototype.getSubNodes = function()
|
||||
|
||||
RDFContainer.prototype.getSubResources = function(aType)
|
||||
{
|
||||
if(this.isValid()) {
|
||||
var list = new Array;
|
||||
if(this.isValid()) {
|
||||
var list = new Array;
|
||||
|
||||
this.RDFC.Init(this.dsource, this.resource);
|
||||
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 {
|
||||
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;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
RDFContainer.prototype.remove_recursive = function(aPath)
|
||||
RDFContainer.prototype.remove_recursive = function(aPath)
|
||||
{
|
||||
if(this.isValid()) {
|
||||
var res = this.RDF.GetResource(aPath);
|
||||
this.RDFC.Init(this.dsource, res);
|
||||
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 {
|
||||
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;
|
||||
}
|
||||
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(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);
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
if(this.parent != null) {
|
||||
this.RDFC.RemoveElement(this.resource, false);
|
||||
}
|
||||
this.setValid(false);
|
||||
} else {
|
||||
} else {
|
||||
jslibError(null, "RDFContainer is no longer valid!\n", "NS_ERROR_UNEXPECTED",
|
||||
JS_RDFCONTAINER_FILE+":remove");
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
jslib_debug('*** load: '+JS_RDFCONTAINER_FILE+' OK');
|
||||
jslibDebug('*** load: '+JS_RDFCONTAINER_FILE+' OK');
|
||||
|
||||
} // END BLOCK JS_LIB_LOADED CHECK
|
||||
|
||||
else
|
||||
{
|
||||
dump("JS_RDF library not loaded:\n" +
|
||||
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");
|
||||
}
|
||||
|
@ -38,12 +38,12 @@ 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) {
|
||||
function RDFFile(aPath, aFlags, aNameSpace, aID)
|
||||
{
|
||||
this.created = false;
|
||||
|
||||
if(aPath) {
|
||||
this._file_init(aPath, aFlags);
|
||||
}
|
||||
if(aPath)
|
||||
this._file_init(aPath, aFlags, aNameSpace, aID);
|
||||
}
|
||||
RDFFile.prototype = new RDF;
|
||||
|
||||
@ -56,23 +56,22 @@ RDFFile.prototype._file_init = function (aPath, aFlags, aNameSpace, aID) {
|
||||
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)) {
|
||||
dump("here!\n");
|
||||
|
||||
if (rdf_file.open("w") != JS_FILE_OK) {
|
||||
return;
|
||||
}
|
||||
|
||||
var filestr =
|
||||
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;
|
||||
@ -92,14 +91,14 @@ RDFFile.prototype._file_init = function (aPath, aFlags, aNameSpace, aID) {
|
||||
this._rdf_init(uri.spec, aFlags);
|
||||
};
|
||||
|
||||
jslib_debug('*** load: '+JS_RDFFILE_FILE+' OK');
|
||||
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" +
|
||||
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");
|
||||
}
|
||||
|
@ -24,27 +24,27 @@ Martin Kutschker <martin.t.kutschker@blackbox.net> (polishing)
|
||||
|
||||
if(typeof(JS_LIB_LOADED)=='boolean')
|
||||
{
|
||||
// test to make sure rdfBase base class is loaded
|
||||
if(typeof(JS_RDFBASE_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";
|
||||
const JS_RDFRESOURCE_LOADED = true;
|
||||
const JS_RDFRESOURCE_FILE = "rdfResource.js";
|
||||
|
||||
function RDFResource(aType, aPath, aParentPath, aDatasource) {
|
||||
function RDFResource(aType, aPath, aParentPath, aDatasource) {
|
||||
if(aDatasource) {
|
||||
this._resource_init(aType, aPath, aParentPath, aDatasource);
|
||||
this._resource_init(aType, aPath, aParentPath, aDatasource);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
RDFResource.prototype = new RDFBase;
|
||||
RDFResource.prototype = new RDFBase;
|
||||
|
||||
RDFResource.prototype.type = null;
|
||||
RDFResource.prototype.parent = null;
|
||||
RDFResource.prototype.resource = null;
|
||||
RDFResource.prototype.subject = null;
|
||||
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) {
|
||||
RDFResource.prototype._resource_init = function(aType, aPath, aParentPath, aDatasource) {
|
||||
this.type = aType;
|
||||
this.parent = aParentPath;
|
||||
this.subject = aPath;
|
||||
@ -52,108 +52,173 @@ if(typeof(JS_LIB_LOADED)=='boolean')
|
||||
|
||||
this._base_init(aDatasource);
|
||||
if(this.resource) {
|
||||
this.setValid(true);
|
||||
this.setValid(true);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
RDFResource.prototype.getResource = function() {
|
||||
RDFResource.prototype.getResource = function() {
|
||||
return this.resource;
|
||||
};
|
||||
};
|
||||
|
||||
RDFResource.prototype.getSubject = function() {
|
||||
RDFResource.prototype.getSubject = function() {
|
||||
return this.subject;
|
||||
};
|
||||
};
|
||||
|
||||
RDFResource.prototype.makeSeq = function(aSeq) {
|
||||
RDFResource.prototype.makeSeq = function(aSeq) {
|
||||
return this.makeContainer("seq");
|
||||
};
|
||||
};
|
||||
|
||||
RDFResource.prototype.makeBag = function(aBag) {
|
||||
RDFResource.prototype.makeBag = function(aBag) {
|
||||
return this.makeContainer("bag");
|
||||
};
|
||||
};
|
||||
|
||||
RDFResource.prototype.makeAlt = function(aAlt) {
|
||||
RDFResource.prototype.makeAlt = function(aAlt) {
|
||||
return this.makeContainer("alt");
|
||||
};
|
||||
};
|
||||
|
||||
RDFResource.prototype.makeContainer = function(aType) {
|
||||
RDFResource.prototype.makeContainer = function(aType) {
|
||||
this.RDFC.Init(this.dsource, this.resource );
|
||||
|
||||
if(aType == "bag") {
|
||||
this.RDFCUtils.MakeBag(this.dsource, this.resource);
|
||||
this.RDFCUtils.MakeBag(this.dsource, this.resource);
|
||||
} else if(aType == "alt") {
|
||||
this.RDFCUtils.MakeAlt(this.dsource, this.resource);
|
||||
this.RDFCUtils.MakeAlt(this.dsource, this.resource);
|
||||
} else {
|
||||
this.RDFCUtils.MakeSeq(this.dsource, this.resource);
|
||||
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)
|
||||
{
|
||||
RDFResource.prototype.setAttribute = function(aName, aValue)
|
||||
{
|
||||
if(this.isValid()) {
|
||||
var oldvalue = this.getAttribute(aName);
|
||||
var oldvalue = this.getAttribute(aName);
|
||||
|
||||
if(oldvalue) {
|
||||
if(oldvalue) {
|
||||
this.dsource.Change(this.resource,
|
||||
this.RDF.GetResource(aName),
|
||||
this.RDF.GetLiteral(oldvalue),
|
||||
this.RDF.GetLiteral(aValue) );
|
||||
} else {
|
||||
jslibPrint("\n Changing old value in "+this.subject+"\n");
|
||||
} else {
|
||||
this.dsource.Assert(this.resource,
|
||||
this.RDF.GetResource(aName),
|
||||
this.RDF.GetLiteral(aValue),
|
||||
true );
|
||||
}
|
||||
return true;
|
||||
jslibPrint("\n Adding a new value in "+this.subject+"\n");
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
RDFResource.prototype.getAttribute = function(aName)
|
||||
{
|
||||
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;
|
||||
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;
|
||||
jslibError(null, "RDFResource is no longer valid!\n", "NS_ERROR_UNEXPECTED",
|
||||
JS_RDFRESOURCE_FILE+":getAttribute");
|
||||
return null;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
RDFResource.prototype.removeAttribute = function(aName)
|
||||
{
|
||||
RDFResource.prototype.getContainer = function(aName,aType)
|
||||
{
|
||||
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);
|
||||
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+":removeAttribute");
|
||||
return null;
|
||||
jslibError(null, "RDFResource is no longer valid!\n", "NS_ERROR_UNEXPECTED",
|
||||
JS_RDFRESOURCE_FILE+":getAttribute");
|
||||
return null;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
RDFResource.prototype.setAllAttributes = function(aList)
|
||||
{
|
||||
var length = 0;
|
||||
try {
|
||||
length = aList.length;
|
||||
} catch(e) {
|
||||
return false;
|
||||
}
|
||||
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 arcs = this.dsource.ArcLabelsOut(this.resource);
|
||||
while(arcs.hasMoreElements()) {
|
||||
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;
|
||||
@ -161,22 +226,22 @@ if(typeof(JS_LIB_LOADED)=='boolean')
|
||||
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);
|
||||
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);
|
||||
}
|
||||
}
|
||||
for(var i=0; i<length; i++) {
|
||||
this.setAttribute(aList[i].name, aList[i].value);
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
RDFResource.prototype.getAllAttributes = function()
|
||||
{
|
||||
RDFResource.prototype.getAllAttributes = function()
|
||||
{
|
||||
var list = new Array;
|
||||
if(this.isValid()) {
|
||||
var arcs = this.dsource.ArcLabelsOut(this.resource);
|
||||
while(arcs.hasMoreElements()) {
|
||||
var arcs = this.dsource.ArcLabelsOut(this.resource);
|
||||
while(arcs.hasMoreElements()) {
|
||||
var arc = arcs.getNext();
|
||||
arc = arc.QueryInterface(Components.interfaces.nsIRDFResource);
|
||||
var obj = new Object;
|
||||
@ -184,55 +249,56 @@ if(typeof(JS_LIB_LOADED)=='boolean')
|
||||
obj.name = l[l.length-1];
|
||||
var targets = this.dsource.GetTargets(this.resource, arc, true);
|
||||
while (targets.hasMoreElements()) {
|
||||
var target = targets.getNext();
|
||||
if(target) {
|
||||
var target = targets.getNext();
|
||||
if(target) {
|
||||
try {
|
||||
target = target.QueryInterface(Components.interfaces.nsIRDFLiteral);
|
||||
target = target.QueryInterface(Components.interfaces.nsIRDFLiteral);
|
||||
}
|
||||
catch(e) {
|
||||
target = target.QueryInterface(Components.interfaces.nsIRDFResource);
|
||||
}
|
||||
jslibPrint('not a literal');
|
||||
target = target.QueryInterface(Components.interfaces.nsIRDFResource);
|
||||
}
|
||||
obj.value = target.Value;
|
||||
list.push(obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
return list;
|
||||
} else {
|
||||
jslibError(null, "RDFResource is no longer valid!\n", "NS_ERROR_UNEXPECTED",
|
||||
JS_RDFRESOURCE_FILE+":getAllAttributes");
|
||||
return null;
|
||||
jslibError(null, "RDFResource is no longer valid!\n", "NS_ERROR_UNEXPECTED",
|
||||
JS_RDFRESOURCE_FILE+":getAllAttributes");
|
||||
return null;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
RDFResource.prototype.remove = function()
|
||||
{
|
||||
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);
|
||||
// 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 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);
|
||||
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);
|
||||
}
|
||||
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;
|
||||
jslibError(null, "RDFResource is no longer valid!\n", "NS_ERROR_UNEXPECTED",
|
||||
JS_RDFRESOURCE_FILE+":remove");
|
||||
return null;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
jslib_debug('*** load: '+JS_RDFRESOURCE_FILE+' OK');
|
||||
jslibDebug('*** load: '+JS_RDFRESOURCE_FILE+' OK');
|
||||
|
||||
} // END BLOCK JS_LIB_LOADED CHECK
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user