Changeset c65ba0


Ignore:
Timestamp:
Oct 4, 2010, 11:32:04 PM (10 years ago)
Author:
rene <just@…>
Branches:
ng_0.6, ng_0.8, ng_0.9
Children:
045bfd
Parents:
c4e569
Message:

major changes to allow importing of data, including changing of namespaces (not required)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • chrome/content/v_identity/vI_rdfDatasource.js

    rc4e569 rc65ba0  
    2323 * ***** END LICENSE BLOCK ***** */
    2424
    25 function vI_rdfDatasource(rdfFileName, dontRegisterObserver) {
     25
     26
     27function vI_rdfDatasource(rdfFileName, dontRegisterObserver, rdfNS) {
    2628    this._rdfFileName = rdfFileName;
     29    this._rdfNS = rdfNS?rdfNS:"http://virtual-id.absorb.it/";
    2730    if (this._rdfFileName) this.init();
    2831    if (!dontRegisterObserver) this.AccountManagerObserver.register();
    2932}
    3033
    31 vI_rdfDatasource.prototype = {         
     34vI_rdfDatasource.prototype = {
     35    _rdfVersion :       "0.0.5",
    3236    _rdfService :       Components.classes["@mozilla.org/rdf/rdf-service;1"]
    3337                            .getService(Components.interfaces.nsIRDFService),
    3438    _rdfDataSource :    null,
    3539    _rdfFileName :      null,
    36     _rdfNS :            "http://virtual-id.absorb.it/",
     40    _rdfNS :            null,           //   defaults to "http://virtual-id.absorb.it/"
    3741    _rdfNSStorage :     "vIStorage",
    3842    _rdfNSEmail :       "vIStorage/email",
     
    7781
    7882    init: function() {
    79         if (vI_notificationBar) vI_notificationBar.dump("## vI_rdfDatasource init.\n");
     83        if (vI_notificationBar) vI_notificationBar.dump("## vI_rdfDatasource init with namespace " + this._rdfNS + ".\n");
    8084
    8185        this._openRdfDataSource();
     
    9296   
    9397    _openRdfDataSource: function() {
    94         if (!this._rdfFileName || this._rdfDataSource);
     98//         if (!this._rdfFileName || this._rdfDataSource);
    9599        var protoHandler = Components.classes["@mozilla.org/network/protocol;1?name=file"]
    96100            .getService(Components.interfaces.nsIFileProtocolHandler)
     
    111115            this._rdfService.GetDataSourceBlocking(fileURI.spec);
    112116           
    113         if (vI_notificationBar) vI_notificationBar.dump("## vI_rdfDatasource read rdf from '" + fileURI.spec + "' done." + this._rdfService + "\n");
     117//         if (vI_notificationBar) vI_notificationBar.dump("## vI_rdfDatasource read rdf from '" + fileURI.spec + "' done." + this._rdfService + "\n");
    114118    },
    115119   
    116120    _initContainers: function() {
     121        if (vI_notificationBar) vI_notificationBar.dump("## vI_rdfDatasource _initContainers with namespace " + this._rdfNS + ".\n");
    117122        try {   // will possibly fail before upgrade
    118123            var storageRes = this._rdfService
     
    169174            case "0.0.4":
    170175            default:
    171                 this._createAccountInfoContainersTP();
     176                this._createAccountInfoContainers();
    172177        }
    173178        this.storeRDFVersion();
     
    178183    _transferAllResources : function () {
    179184        if (vI_notificationBar) vI_notificationBar.dump("upgrade: transferAllResources ");
    180         var enumerator = this.rdfDataSource.GetAllResources();
     185        var enumerator = this._rdfDataSource.GetAllResources();
    181186        while (enumerator && enumerator.hasMoreElements()) {
    182187            var resource = enumerator.getNext();
     
    184189           
    185190            var type; var name;
    186             if (resource.ValueUTF8.match(new RegExp(this.rdfNS + this.rdfNSEmail + "/", "i")))
     191            if (resource.ValueUTF8.match(new RegExp(this._rdfNS + this._rdfNSEmail + "/", "i")))
    187192                { type = "email"; name = RegExp.rightContext }
    188             else if (resource.ValueUTF8.match(new RegExp(this.rdfNS + this.rdfNSNewsgroup + "/", "i")))
     193            else if (resource.ValueUTF8.match(new RegExp(this._rdfNS + this._rdfNSNewsgroup + "/", "i")))
    189194                { type = "newsgroup"; name = RegExp.rightContext }
    190             else if (resource.ValueUTF8.match(new RegExp(this.rdfNS + this.rdfNSMaillist + "/", "i")))
     195            else if (resource.ValueUTF8.match(new RegExp(this._rdfNS + this._rdfNSMaillist + "/", "i")))
    191196                { type = "maillist"; name = RegExp.rightContext }
    192197            else continue;
     
    217222    },
    218223    // **************    RDF UPGRADE CODE    ****************************************************
    219     _createAccountInfoContainersTP: function() {
     224    _createAccountInfoContainers: function() {
    220225        if (vI_notificationBar) vI_notificationBar.dump("upgrade: createAccountInfoContainers \n");
    221226        var rdfContainerUtils = Components.classes["@mozilla.org/rdf/container-utils;1"].
    222227            getService(Components.interfaces.nsIRDFContainerUtils);
    223228       
    224         var accountRes = this.rdfService
    225             .GetResource(this.rdfNS + this.rdfNSAccounts);
    226         var identityRes = this.rdfService
    227             .GetResource(this.rdfNS + this.rdfNSIdentities);
    228         var smtpRes = this.rdfService
    229             .GetResource(this.rdfNS + this.rdfNSSMTPservers);
     229        var accountRes = this._rdfService
     230            .GetResource(this._rdfNS + this._rdfNSAccounts);
     231        var identityRes = this._rdfService
     232            .GetResource(this._rdfNS + this._rdfNSIdentities);
     233        var smtpRes = this._rdfService
     234            .GetResource(this._rdfNS + this._rdfNSSMTPservers);
    230235        this._setRDFValue(accountRes, "name", "Accounts");
    231236        this._setRDFValue(identityRes, "name", "Identities");
    232237        this._setRDFValue(smtpRes, "name", "SMTP-Server");
    233238       
    234         rdfContainerUtils.MakeBag(this.rdfDataSource, accountRes);
    235         rdfContainerUtils.MakeBag(this.rdfDataSource, identityRes);
    236         rdfContainerUtils.MakeBag(this.rdfDataSource, smtpRes);
     239        rdfContainerUtils.MakeBag(this._rdfDataSource, accountRes);
     240        rdfContainerUtils.MakeBag(this._rdfDataSource, identityRes);
     241        rdfContainerUtils.MakeBag(this._rdfDataSource, smtpRes);
    237242
    238243        var accountContainer = Components.classes["@mozilla.org/rdf/container;1"].
     
    240245       
    241246        // initialize container with accountRes
    242         accountContainer.Init(this.rdfDataSource, accountRes);
     247        accountContainer.Init(this._rdfDataSource, accountRes);
    243248        // append all new containers to accountRes
    244249        if (accountContainer.IndexOf(identityRes) == -1) accountContainer.AppendElement(identityRes);
     
    254259            getService(Components.interfaces.nsIRDFContainerUtils);
    255260
    256         var storageRes = this.rdfService
    257             .GetResource(this.rdfNS + this.rdfNSStorage);
    258         var emailRes = this.rdfService
    259             .GetResource(this.rdfNS + this.rdfNSEmail);
    260         var maillistRes = this.rdfService
    261             .GetResource(this.rdfNS + this.rdfNSMaillist);
    262         var newsgroupRes = this.rdfService
    263             .GetResource(this.rdfNS + this.rdfNSNewsgroup);
    264         var filterRes = this.rdfService
    265             .GetResource(this.rdfNS + this.rdfNSFilter);
     261        var storageRes = this._rdfService
     262            .GetResource(this._rdfNS + this._rdfNSStorage);
     263        var emailRes = this._rdfService
     264            .GetResource(this._rdfNS + this._rdfNSEmail);
     265        var maillistRes = this._rdfService
     266            .GetResource(this._rdfNS + this._rdfNSMaillist);
     267        var newsgroupRes = this._rdfService
     268            .GetResource(this._rdfNS + this._rdfNSNewsgroup);
     269        var filterRes = this._rdfService
     270            .GetResource(this._rdfNS + this._rdfNSFilter);
    266271        this._setRDFValue(emailRes, "name", "E-Mail");
    267272        this._setRDFValue(maillistRes, "name", "Mailing-List");
     
    269274        this._setRDFValue(filterRes, "name", "Filter");
    270275
    271         rdfContainerUtils.MakeBag(this.rdfDataSource, storageRes);
    272         rdfContainerUtils.MakeBag(this.rdfDataSource, emailRes);
    273         rdfContainerUtils.MakeBag(this.rdfDataSource, maillistRes);
    274         rdfContainerUtils.MakeBag(this.rdfDataSource, newsgroupRes);
     276        rdfContainerUtils.MakeBag(this._rdfDataSource, storageRes);
     277        rdfContainerUtils.MakeBag(this._rdfDataSource, emailRes);
     278        rdfContainerUtils.MakeBag(this._rdfDataSource, maillistRes);
     279        rdfContainerUtils.MakeBag(this._rdfDataSource, newsgroupRes);
    275280        // use a sequence for the filters, order does matter
    276         rdfContainerUtils.MakeSeq(this.rdfDataSource, filterRes);
     281        rdfContainerUtils.MakeSeq(this._rdfDataSource, filterRes);
    277282       
    278283        var container = Components.classes["@mozilla.org/rdf/container;1"].
     
    280285       
    281286        // initialize container with storageRes
    282         container.Init(this.rdfDataSource, storageRes);
     287        container.Init(this._rdfDataSource, storageRes);
    283288        // append all new containers to storageRes
    284289        if (container.IndexOf(emailRes) == -1) container.AppendElement(emailRes);
     
    307312        this._setRDFValue(
    308313            this._rdfService.GetResource(this._rdfNS + "virtualIdentity"), "rdfVersion",
    309             this.rdfVersion);
     314            this._rdfVersion);
    310315        this._flush();
    311316    },
     
    360365    },
    361366   
    362     searchIdentityMismatch : function() {
    363         if (vI_notificationBar) vI_notificationBar.dump("## vI_rdfDatasource: searchIdentityMismatch\n");
    364 
     367    getRelevantIDs : function() {
    365368        var relevantIDs = new Object();
    366         var mismatchIDs = [];
    367        
    368369        // search relevant Identities
    369370        for each (treeType in Array("email", "maillist", "newsgroup", "filter")) {
     
    378379            }
    379380        }
     381        return relevantIDs;
     382    },
     383   
     384    searchIdentityMismatch : function() {
     385        if (vI_notificationBar) vI_notificationBar.dump("## vI_rdfDatasource: searchIdentityMismatch\n");
     386
     387        var relevantIDs = this.getRelevantIDs();
     388        var mismatchIDs = [];
    380389       
    381390        var AccountManager = Components.classes["@mozilla.org/messenger/account-manager;1"]
     
    426435    },
    427436   
    428     searchSmtpMismatch : function() {
    429         if (vI_notificationBar) vI_notificationBar.dump("## vI_rdfDatasource: searchSmtpMismatch\n");
    430 
     437    getRelevantSMTPs : function() {
    431438        var relevantSMTPs = new Object();
    432         var mismatchSMTPs = [];
    433        
    434439        // search relevant SMTPs
    435440        for each (treeType in Array("email", "maillist", "newsgroup", "filter")) {
     
    444449            }
    445450        }
     451        return relevantSMTPs;
     452    },
     453   
     454    searchSmtpMismatch : function() {
     455        if (vI_notificationBar) vI_notificationBar.dump("## vI_rdfDatasource: searchSmtpMismatch\n");
     456
     457        var relevantSMTPs = this.getRelevantSMTPs();
     458        var mismatchSMTPs = [];
    446459       
    447460        var SmtpService = Components.classes["@mozilla.org/messengercompose/smtp;1"]
     
    493506        function storeSmtp(server, parent) {
    494507//             if (vI_notificationBar) vI_notificationBar.dump("## vI_rdfDatasource: storeAccounts smtp store id " + server.key + "\n");
    495             var resource = parent._rdfService.GetResource(this._rdfNS + this._rdfNSSMTPservers + "/" + server.key);
     508            var resource = parent._rdfService.GetResource(parent._rdfNS + parent._rdfNSSMTPservers + "/" + server.key);
    496509            parent._setRDFValue(resource, "label", (server.description?server.description:server.hostname));
    497510            parent._setRDFValue(resource, "hostname", server.hostname);
     
    534547    },
    535548   
    536     import : function(rdfFileName) {
    537         var filePicker = Components.classes["@mozilla.org/filepicker;1"]
    538             .createInstance(Components.interfaces.nsIFilePicker);
    539 
    540         filePicker.init(window, "", Components.interfaces.nsIFilePicker.modeOpen);
    541         filePicker.appendFilter("RDF Files","*.rdf");
    542         filePicker.appendFilters(Components.interfaces.nsIFilePicker.filterText | Components.interfaces.nsIFilePicker.filterAll );
    543        
    544         if (filePicker.show() == Components.interfaces.nsIFilePicker.returnOK) {
    545             // init local Datasource
    546             this._rdfFileName = rdfFileName; this.init();
    547            
    548             var importRdfDataFile = Components.classes["@mozilla.org/file/local;1"]
    549                 .createInstance(Components.interfaces.nsILocalFile);
    550             var file = Components.classes["@mozilla.org/file/directory_service;1"]
    551                 .getService(Components.interfaces.nsIProperties).get("ProfD", Components.interfaces.nsIFile);
    552             var delimiter = (file.path.match(/\\/))?"\\":"/";
    553             rdfDataFile.initWithPath(file.path + delimiter + this._rdfFileName + "_import");
    554            
    555             filePicker.file.copyTo(importRdfDataFile.parent,importRdfDataFile.leafName);
    556             if (vI_notificationBar) vI_notificationBar.dump("## vI_rdfDatasource import: copied file from " + filePicker.path + " to " + importRdfDataFile.path + "'\n");
    557            
    558             import_rdfDatasource = new vI_rdfDatasource(importRdfDataFile.leafName);
    559             // --- do something with the file here ---
    560         } 
    561     },
    562 
    563549    _getRDFResourceForVIdentity : function (recDescription, recType) {
    564550        if (!this._rdfDataSource) return null;
     
    575561        }
    576562        return this._rdfService.GetResource(this._rdfNS + _rdfNSRecType + "/" + recDescription);
     563       
     564       
    577565    },
    578566   
    579567    removeVIdentityFromRDF : function (resource, recType) {
    580         if (vI_notificationBar) vI_notificationBar.dump("## vI_rdfDatasource: removeVIdentityFromRDF " + resource.ValueUTF8 + ".\n");
     568//      if (vI_notificationBar) vI_notificationBar.dump("## vI_rdfDatasource: removeVIdentityFromRDF " + resource.ValueUTF8 + ".\n");
    581569        this._unsetRDFValue(resource, "email", this._getRDFValue(resource, "email"))
    582570        this._unsetRDFValue(resource, "fullName", this._getRDFValue(resource, "fullName"))
     
    585573        this._unsetRDFValue(resource, "name", this._getRDFValue(resource, "name"))
    586574       
    587         var extras = new vI_storageExtras(this, resource);
    588         extras.loopForRDF(this._unsetRDFValue, resource);
    589         this.getContainer(recType).RemoveElement(resource, true);
     575        var extras = new vI_storageExtras(this, resource);
     576        extras.loopForRDF(this, resource, "unset");
     577        this.getContainer(recType).RemoveElement(resource, true);
    590578    },
    591579   
     
    595583        var name = this._rdfService.GetLiteral(value?value:"");
    596584        var target = this._rdfDataSource.GetTarget(resource, predicate, true);
    597         if (target instanceof Components.interfaces.nsIRDFLiteral)
     585        if (target instanceof Components.interfaces.nsIRDFLiteral) {
    598586            this._rdfDataSource.Unassert(resource, predicate, name, true);
     587            return null;
     588        }
     589        else return value;
    599590    },
    600591   
     
    713704
    714705    updateRDF : function (recDescription, recType, localIdentityData, storeBaseID, storeSMTP, prevRecDescription, prevRecType) {
     706        if (vI_notificationBar) vI_notificationBar.dump("## vI_rdfDatasource (" + this._rdfNS + "): updateRDF recDescription=" + recDescription + " localIdentityData.email=" + localIdentityData.email + ".\n");
     707       
    715708//      if (!localIdentityData.email) {
    716709//          if (vI_notificationBar) vI_notificationBar.dump("## vI_rdfDatasource: updateRDF: no Sender-email for Recipient, aborting.\n");
    717710//          return;
    718711//      }
    719         if (recDescription.length == 0) return;
     712        if (!recDescription || recDescription.length == 0) return;
    720713
    721714        if (!prevRecDescription) prevRecDescription = recDescription;
     
    728721        var position = this.getContainer(recType).IndexOf(resource); // check for index in new recType
    729722        this.removeVIdentityFromRDF(resource, prevRecType);
    730        
    731         resource = this._getRDFResourceForVIdentity(recDescription, recType);
     723       
     724        resource = this._getRDFResourceForVIdentity(recDescription, recType);
    732725
    733726        this._setRDFValue(resource, "email", localIdentityData.email);
     
    739732            this._setRDFValue(resource, "smtp", localIdentityData.smtp.key);
    740733        else    this._unsetRDFValue(resource, "smtp", this._getRDFValue(resource, "smtp"))
    741         this._setRDFValue(resource, "name", recDescription);
    742 
    743         localIdentityData.extras.loopForRDF(this._setRDFValue, resource);
     734        this._setRDFValue(resource, "name", recDescription);
     735 
     736        localIdentityData.extras.loopForRDF(this, resource, "set");
    744737       
    745         if (vI_notificationBar) vI_notificationBar.dump("## vI_rdfDatasource: updateRDF " + resource.ValueUTF8  + " added.\n");
    746         if (position != -1) this.getContainer(recType).InsertElementAt(resource, position, false);
     738        if (vI_notificationBar) vI_notificationBar.dump("## vI_rdfDatasource (" + this._rdfFileName + "): updateRDF add " + resource.ValueUTF8 + " at position " + position + ".\n");
     739        if (position != -1) this.getContainer(recType).InsertElementAt(resource, position, true);
    747740        else this.getContainer(recType).AppendElement(resource);
    748741    },
     
    750743    _setRDFValue : function (resource, field, value) {
    751744//      if (vI_notificationBar) vI_notificationBar.dump("## vI_rdfDatasource: _setRDFValue " + resource.ValueUTF8 + " " + field + " " + value + ".\n");
    752         if (!value) return; // return if some value was not set.
     745        if (!value) return value; // return if some value was not set.
    753746//      if (vI_notificationBar) vI_notificationBar.dump("## vI_rdfDatasource _setRDFValue " + this._rdfService + " " + this._rdfDataSource + "\n");
    754747        var predicate = this._rdfService.GetResource(this._rdfNS + "rdf#" + field);
     
    759752            this._rdfDataSource.Change(resource, predicate, target, name);
    760753        else    this._rdfDataSource.Assert(resource, predicate, name, true);
     754        return value;
    761755    },
    762756   
     
    789783    }
    790784}
     785
     786
     787function vI_rdfDatasourceImporter(rdfFileName) {
     788    this._rdfFileName = rdfFileName;
     789    if (this._rdfFileName) this.import();
     790}
     791
     792vI_rdfDatasourceImporter.prototype = {
     793    _rdfDataSource :    null,
     794    _rdfFileName :      null,
     795    _rdfImportDataSource :    null,
     796
     797    _getMatchingIdentity : function(name, email, fullName) {
     798        var AccountManager = Components.classes["@mozilla.org/messenger/account-manager;1"]
     799            .getService(Components.interfaces.nsIMsgAccountManager);
     800        for (let i = 0; i < AccountManager.accounts.Count(); i++) {
     801            var account = AccountManager.accounts.QueryElementAt(i, Components.interfaces.nsIMsgAccount);
     802            for (let j = 0; j < account.identities.Count(); j++) {
     803                var identity = account.identities.QueryElementAt(j, Components.interfaces.nsIMsgIdentity);
     804                if (name == identity.identityName || (fullName == identity.fullName && email == identity.email)) return identity.key;
     805            }
     806        }
     807        return null;
     808    },
     809   
     810    _getMatchingSMTP : function(label, hostname, username) {
     811        var servers = Components.classes["@mozilla.org/messengercompose/smtp;1"]
     812            .getService(Components.interfaces.nsISmtpService).smtpServers;
     813        if (typeof(servers.Count) == "undefined")       // TB 3.x
     814            while (servers && servers.hasMoreElements()) {
     815                var server = servers.getNext();
     816                if (server instanceof Components.interfaces.nsISmtpServer && !server.redirectorType)
     817                    if (label == (server.description?server.description:server.hostname) || (hostname == server.hostname && username == server.username))
     818                        return server.key;
     819            }
     820        else                            // TB 2.x
     821            for (var i=0 ; i<servers.Count(); i++)
     822                if (label == (server.description?server.description:server.hostname) || (hostname == server.hostname && username == server.username))
     823                        return server.key;
     824        return null;
     825    },
     826   
     827    import : function() {
     828        var filePicker = Components.classes["@mozilla.org/filepicker;1"]
     829            .createInstance(Components.interfaces.nsIFilePicker);
     830
     831        filePicker.init(window, "", Components.interfaces.nsIFilePicker.modeOpen);
     832        filePicker.appendFilter("RDF Files","*.rdf");
     833        filePicker.appendFilters(Components.interfaces.nsIFilePicker.filterText | Components.interfaces.nsIFilePicker.filterAll );
     834       
     835        if (filePicker.show() == Components.interfaces.nsIFilePicker.returnOK) {
     836            if (vI_notificationBar) vI_notificationBar.dump("## vI_rdfDatasourceImporter import: preparation:\n");
     837           
     838            var importRdfDataFile = Components.classes["@mozilla.org/file/local;1"]
     839                .createInstance(Components.interfaces.nsILocalFile);
     840            var file = Components.classes["@mozilla.org/file/directory_service;1"]
     841                .getService(Components.interfaces.nsIProperties).get("ProfD", Components.interfaces.nsIFile);
     842            var delimiter = (file.path.match(/\\/))?"\\":"/";
     843            importRdfDataFile.initWithPath(file.path + delimiter + this._rdfFileName + "_import");
     844//             importRdfDataFile.createUnique( Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 600); 
     845           
     846            var inp_fstream = Components.classes["@mozilla.org/network/file-input-stream;1"]
     847                .createInstance(Components.interfaces.nsIFileInputStream);
     848            var inp_cstream = Components.classes["@mozilla.org/intl/converter-input-stream;1"]
     849                .createInstance(Components.interfaces.nsIConverterInputStream);
     850            var out_fstream = Components.classes["@mozilla.org/network/file-output-stream;1"]
     851                .createInstance(Components.interfaces.nsIFileOutputStream);
     852            var out_cstream = Components.classes["@mozilla.org/intl/converter-output-stream;1"]
     853                .createInstance(Components.interfaces.nsIConverterOutputStream); 
     854
     855            inp_fstream.init(filePicker.file, -1, 0, 0);
     856            inp_cstream.init(inp_fstream, "UTF-8", 0, 0); // you can use another encoding here if you wish
     857            out_fstream.init(importRdfDataFile, 0x04 | 0x08 | 0x20, 0600, 0); // readwrite, create, truncate
     858            out_cstream.init(out_fstream, "UTF-8", 0, 0); 
     859           
     860            var regExpNamespace = new RegExp("http://virtual-id.absorb.it/","g");
     861            let (str = {}) { let read = 0;
     862                do {
     863                    read = inp_cstream.readString(0xffffffff, str); // read as much as we can and put it in str.value
     864                    var string = str.value.replace(regExpNamespace, "http://virtual-id-import.absorb.it/");
     865//                     out_fstream.write(string, string.length);
     866                    out_cstream.writeString(string);
     867                } while (read != 0);
     868            }
     869            inp_cstream.close();
     870            out_cstream.close();
     871
     872            if (vI_notificationBar) vI_notificationBar.dump("## vI_rdfDatasourceImporter import: copied file from " + filePicker.file.path + " to " + importRdfDataFile.path + "'\n");
     873            if (vI_notificationBar) vI_notificationBar.dump("## vI_rdfDatasourceImporter import: transferred NAMESPACES of import-file\n");
     874           
     875            // init Datasources
     876            this._rdfImportDataSource = new vI_rdfDatasource(importRdfDataFile.leafName, true, "http://virtual-id-import.absorb.it/");
     877           
     878            // search matching Identities for any used ones
     879            var relevantIDs = this._rdfImportDataSource.getRelevantIDs();
     880            for (var id in relevantIDs) {
     881                var resource = this._rdfImportDataSource._rdfService.GetResource(this._rdfImportDataSource._rdfNS + this._rdfImportDataSource._rdfNSIdentities + "/" + id);
     882                var rdfIdentityName = this._rdfImportDataSource._getRDFValue(resource, "identityName");
     883                var rdfEmail = this._rdfImportDataSource._getRDFValue(resource, "email");
     884                var rdfFullName = this._rdfImportDataSource._getRDFValue(resource, "fullName");
     885                var newId = this._getMatchingIdentity(rdfIdentityName, rdfEmail, rdfFullName);
     886                relevantIDs[id] = newId?newId:"import_" + id;
     887                if (vI_notificationBar) vI_notificationBar.dump("## vI_rdfDatasourceImporter import: translate relevant ID from " + id + " to " + relevantIDs[id] + "'\n");
     888            }
     889            // search matching SMTPs for any used ones
     890            var relevantSMTPs = this._rdfImportDataSource.getRelevantSMTPs();
     891            for (var smtp in relevantSMTPs) {
     892                var resource = this._rdfImportDataSource._rdfService.GetResource(this._rdfImportDataSource._rdfNS + this._rdfImportDataSource._rdfNSSMTPservers + "/" + smtp);
     893                var rdfSMTPlabel = this._rdfImportDataSource._getRDFValue(resource, "label");
     894                var rdfHostname = this._rdfImportDataSource._getRDFValue(resource, "hostname");
     895                var rdfUsername = this._rdfImportDataSource._getRDFValue(resource, "username")
     896                var newSMTP = this._getMatchingSMTP(rdfSMTPlabel, rdfHostname, rdfUsername);
     897                relevantSMTPs[smtp] = newSMTP?newSMTP:"import_" + smtp;
     898                if (vI_notificationBar) vI_notificationBar.dump("## vI_rdfDatasourceImporter import: translate relevant SMTP from " + smtp + " to " + relevantSMTPs[smtp] + "'\n");
     899            }
     900           
     901            if (vI_notificationBar) vI_notificationBar.dump("## vI_rdfDatasourceImporter import: preparation done.\n");
     902            if (vI_notificationBar) vI_notificationBar.dump("## vI_rdfDatasourceImporter import: starting import:");
     903
     904            for each (treeType in Array("email", "maillist", "newsgroup", "filter")) {
     905                var container = this._rdfImportDataSource.getContainer(treeType)
     906                if (vI_notificationBar) vI_notificationBar.dump("\n## vI_rdfDatasource importing " + treeType + " :" + container.GetCount()+ "datasets from " + this._rdfImportDataSource._rdfDataSource.URI + "\n");
     907                var enumerator = container.GetElements();
     908                this._rdfDataSource = new vI_rdfDatasource("virtualIdentity.rdf", true, "http://virtual-id.absorb.it/");
     909                var count = 0;
     910                while (enumerator.hasMoreElements()) {
     911                    var resource = enumerator.getNext(); count += 1;
     912                    resource.QueryInterface(Components.interfaces.nsIRDFResource);
     913                    if (vI_notificationBar) vI_notificationBar.dump("## " + count + ": vI_rdfDatasource (" + this._rdfImportDataSource._rdfNS + "): importing " + resource.ValueUTF8 + ".\n");
     914                    var name = this._rdfImportDataSource._getRDFValue(resource, "name")
     915                    var email = this._rdfImportDataSource._getRDFValue(resource, "email")
     916                    var fullName = this._rdfImportDataSource._getRDFValue(resource, "fullName")
     917                    var id = this._rdfImportDataSource._getRDFValue(resource, "id")
     918                    id = id?relevantIDs[id]:null
     919                    var smtp = this._rdfImportDataSource._getRDFValue(resource, "smtp")
     920                    smtp = (smtp && smtp != DEFAULT_SMTP_TAG)?relevantSMTPs[smtp]:smtp
     921                    if (!smtp) smtp = NO_SMTP_TAG;
     922                    var extras = new vI_storageExtras(this._rdfImportDataSource, resource);
     923                    var localIdentityData = new vI_identityData(email, fullName, id, smtp, extras)
     924                   
     925                    this._rdfDataSource.updateRDF(name, treeType, localIdentityData, true, true, null, null)
     926                    if (vI_notificationBar) vI_notificationBar.dump(".");
     927                }
     928                this._rdfDataSource = null;
     929            }
     930            if (vI_notificationBar) vI_notificationBar.dump("\n## vI_rdfDatasourceImporter import: import done.");
     931            this._rdfImportDataSource = null;
     932
     933            if (vI_notificationBar) vI_notificationBar.dump("## vI_rdfDatasourceImporter import: cleaning ID/SMTP storages:");
     934            this._rdfDataSource = new vI_rdfDatasource("virtualIdentity.rdf", true, "http://virtual-id.absorb.it/");
     935            this._rdfDataSource.searchIdentityMismatch();
     936            this._rdfDataSource.searchSmtpMismatch();
     937            this._rdfDataSource.clean();
     938            this._rdfDataSource = null;
     939            if (vI_notificationBar) vI_notificationBar.dump("## vI_rdfDatasourceImporter import: cleaning ID/SMTP storages done.");
     940        }
     941    }
     942}
Note: See TracChangeset for help on using the changeset viewer.