Changeset 603625


Ignore:
Timestamp:
Jan 13, 2009, 1:01:54 AM (13 years ago)
Author:
rene <rene@…>
Branches:
lite_0.1, multiEdit, ng_0.6, ng_0.6_help, ng_0.8, ng_0.9
Children:
44a21d
Parents:
133338
Message:

create Containers for new rdf 0.0.3 (not completely implemented)

Location:
chrome/content/v_identity
Files:
3 edited

Legend:

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

    r133338 r603625  
    3030    rdfFileName : "virtualIdentity.rdf",
    3131    rdfNS : "http://virtual-id.absorb.it/",
    32     rdfNSEmail : "vIStorage/email/",
    33     rdfNSMaillist : "vIStorage/maillist/",
    34     rdfNSNewsgroup : "vIStorage/newsgroup/",
    35     rdfNSFilter : "vIStorage/filter/",
     32    rdfNSStorage : "vIStorage",
     33    rdfNSEmail : "vIStorage/email",
     34    rdfNSMaillist : "vIStorage/maillist",
     35    rdfNSNewsgroup : "vIStorage/newsgroup",
     36    rdfNSFilter : "vIStorage/filter",
    3637   
    3738    // seamonkey doesn't have a extensionmanager, so read version of extension from hidden version-label
     
    3940    //      .getService(Components.interfaces.nsIExtensionManager),
    4041   
    41     rdfVersion : "0.0.2",   // version of current implemented RDF-schema, internal only to trigger updates
     42    rdfVersion : "0.0.3",   // version of current implemented RDF-schema, internal only to trigger updates
    4243   
    4344    virtualIdentityID : "{dddd428e-5ac8-4a81-9f78-276c734f75b8}",
     
    4647        .createInstance(Components.interfaces.nsIScriptableUnicodeConverter),
    4748   
     49    emailContainer : Components.classes["@mozilla.org/rdf/container;1"]
     50            .createInstance(Components.interfaces.nsIRDFContainer),
     51
     52    maillistContainer : Components.classes["@mozilla.org/rdf/container;1"]
     53            .createInstance(Components.interfaces.nsIRDFContainer),
     54
     55    newsgroupContainer : Components.classes["@mozilla.org/rdf/container;1"]
     56            .createInstance(Components.interfaces.nsIRDFContainer),
     57
     58    filterContainer : Components.classes["@mozilla.org/rdf/container;1"]
     59            .createInstance(Components.interfaces.nsIRDFContainer),
     60
    4861    init: function() {
    4962        if (vI_rdfDatasource.rdfDataSource) return;     
     
    6578        vI_rdfDatasource.rdfDataSource =
    6679            vI_rdfDatasource.rdfService.GetDataSourceBlocking(fileURI.spec);
    67     },
    68    
     80        vI_rdfDatasource.__initContainers();
     81    },
     82   
     83    __initContainers: function() {
     84        try {   // will possibly fail before upgrade
     85            var storageRes = vI_rdfDatasource.rdfService
     86                .GetResource(vI_rdfDatasource.rdfNS + vI_rdfDatasource.rdfNSEmail);
     87            vI_rdfDatasource.emailContainer.Init(vI_rdfDatasource.rdfDataSource, storageRes);
     88            storageRes = vI_rdfDatasource.rdfService
     89                .GetResource(vI_rdfDatasource.rdfNS + vI_rdfDatasource.rdfNSMaillist);
     90            vI_rdfDatasource.maillistContainer.Init(vI_rdfDatasource.rdfDataSource, storageRes);
     91            storageRes = vI_rdfDatasource.rdfService
     92                .GetResource(vI_rdfDatasource.rdfNS + vI_rdfDatasource.rdfNSNewsgroup);
     93            vI_rdfDatasource.newsgroupContainer.Init(vI_rdfDatasource.rdfDataSource, storageRes);
     94            storageRes = vI_rdfDatasource.rdfService
     95                .GetResource(vI_rdfDatasource.rdfNS + vI_rdfDatasource.rdfNSFilter);
     96            vI_rdfDatasource.filterContainer.Init(vI_rdfDatasource.rdfDataSource, storageRes);
     97        } catch (e) { };
     98    },
     99
    69100    rdfUpgradeRequired: function() {
    70101        oldRdfVersion = vI_rdfDatasource.getCurrentRDFFileVersion();
     
    127158            case "maillist" : rdfNSRecType = vI_rdfDatasource.rdfNSMaillist; break;
    128159        }
    129         return vI_rdfDatasource.rdfService.GetResource(vI_rdfDatasource.rdfNS + rdfNSRecType + recDescription);
     160        return vI_rdfDatasource.rdfService.GetResource(vI_rdfDatasource.rdfNS + rdfNSRecType + "/" + recDescription);
     161    },
     162   
     163    removeBagForResource: function (resource, recType) {
     164        var rdfContainerUtils = Components.classes["@mozilla.org/rdf/container-utils;1"].
     165            getService(Components.interfaces.nsIRDFContainerUtils);
     166        var rdfNSRecType = null;
     167        switch (recType) {
     168            case "email": rdfNSRecType = vI_rdfDatasource.rdfNSEmail; break;
     169            case "newsgroup" : rdfNSRecType = vI_rdfDatasource.rdfNSNewsgroup; break;
     170            case "maillist" : rdfNSRecType = vI_rdfDatasource.rdfNSMaillist; break;
     171            case "filter" : rdfNSRecType = vI_rdfDatasource.rdfNSFilter; break;
     172        }
     173        var storageRes = vI_rdfDatasource.rdfService
     174            .GetResource(vI_rdfDatasource.rdfNS + rdfNSRecType);
     175        var container = Components.classes["@mozilla.org/rdf/container;1"]
     176            .createInstance(Components.interfaces.nsIRDFContainer);
     177        container.Init(vI_rdfDatasource.rdfDataSource, storageRes);
     178
     179        if (container.IndexOf(emailRes) != -1) container.RemoveElement(resource);
    130180    },
    131181   
     
    136186        vI_rdfDatasource.__unsetRDFValue(resource, "id", vI_rdfDatasource.__getRDFValue(resource, "id"))
    137187        vI_rdfDatasource.__unsetRDFValue(resource, "smtp", vI_rdfDatasource.__getRDFValue(resource, "smtp"))
     188        vI_rdfDatasource.__unsetRDFValue(resource, "name", vI_rdfDatasource.__getRDFValue(resource, "name"))
    138189       
    139190        var extras = new vI_storageExtras(vI_rdfDatasource.__getRDFValue, resource);
     
    150201   
    151202    // this will be used from rdfDataTree to get all RDF values, callFunction is vI_rdfDataTree.__addNewDatum
    152     readAllVIdentitiesFromRDF : function (callFunction) {
    153         vI_notificationBar.dump("## vI_rdfDatasource: readAllVIdentitiesFromRDF.\n");
     203    readAllEntriesFromRDF : function (container, rdfDataTree) {
     204        vI_notificationBar.dump("## vI_rdfDatasource: readAllEntriesFromRDF.\n");
     205        var enumerator = container.GetElements();
     206        while (enumerator && enumerator.hasMoreElements()) {
     207            var resource = enumerator.getNext();
     208            resource.QueryInterface(Components.interfaces.nsIRDFResource);
     209            var name = vI_rdfDatasource.__getRDFValue(resource, "name")
     210            var email = vI_rdfDatasource.__getRDFValue(resource, "email")
     211            var fullName = vI_rdfDatasource.__getRDFValue(resource, "fullName")
     212            var id = vI_rdfDatasource.__getRDFValue(resource, "id")
     213            var smtp = vI_rdfDatasource.__getRDFValue(resource, "smtp")
     214            if (!smtp) smtp = ""; // to indicate default SMTP (different than null like with SmartReply)
     215           
     216            var extras = new vI_storageExtras(vI_rdfDatasource.__getRDFValue, resource);
     217           
     218            var localIdentityData = new identityData(email, fullName, id, smtp, extras)
     219            rdfDataTree.addNewDatum (resource, name, localIdentityData, rdfDataTree.idData)
     220        }
     221    },
     222   
     223    readAllResourcesFromRDF : function (rdfDataTree) {
     224        vI_notificationBar.dump("## vI_rdfDatasource: readAllResourcesFromRDF.\n");
    154225        var enumerator = vI_rdfDatasource.rdfDataSource.GetAllResources();
    155226        while (enumerator && enumerator.hasMoreElements()) {
     
    166237            else continue;
    167238           
    168             var email = vI_rdfDatasource.__getRDFValue(resource, "email")
    169             var fullName = vI_rdfDatasource.__getRDFValue(resource, "fullName")
    170             var id = vI_rdfDatasource.__getRDFValue(resource, "id")
    171             var smtp = vI_rdfDatasource.__getRDFValue(resource, "smtp")
    172             if (!smtp) smtp = ""; // to indicate default SMTP (different than null like with SmartReply)
    173            
    174             var extras = new vI_storageExtras(vI_rdfDatasource.__getRDFValue, resource);
    175            
    176             var localIdentityData = new identityData(email, fullName, id, smtp, extras)
    177             callFunction (resource, type, name, localIdentityData)     
    178         }
    179     },
    180    
     239            rdfDataTree.addNewDatum(resource, type, name, rdfDataTree.idData)
     240        }
     241    },
     242
     243    __findMatchingFilter : function (recDescription) {
     244        vI_notificationBar.dump("## vI_rdfDatasource: __findMatchingFilter.\n");
     245        var enumerator = vI_rdfDatasource.filterContainer.GetElements();
     246        while (enumerator && enumerator.hasMoreElements()) {
     247            var resource = enumerator.getNext();
     248            resource.QueryInterface(Components.interfaces.nsIRDFResource);
     249            var filter = vI_rdfDatasource.__getRDFValue(resource, "filter");
     250            vI_notificationBar.dump("## vI_rdfDatasource: __findMatchingFilter trying '" + filter + "'.\n");
     251            if (filter && recDescription.match(new RegExp(filter,"i"))) return resource;
     252        }
     253        return null;
     254    },
     255
    181256    readVIdentityFromRDF : function (recDescription, recType) {
    182257        var resource = vI_rdfDatasource.__getRDFResourceForVIdentity(recDescription, recType);
    183258        if (!resource) return null;
    184        
     259
    185260        var email = vI_rdfDatasource.rdfService.GetResource(vI_rdfDatasource.rdfNS + "rdf#email");
     261        if (!vI_rdfDatasource.rdfDataSource.hasArcOut(resource, email))
     262            resource = vI_rdfDatasource.__findMatchingFilter(recDescription);
    186263        if (!vI_rdfDatasource.rdfDataSource.hasArcOut(resource, email)) {
    187264            vI_notificationBar.dump("## vI_rdfDatasource: readVIdentityFromRDF no data found.\n");
  • chrome/content/v_identity/vI_upgrade.js

    r133338 r603625  
    9898        vI_notificationBar.dump("checking for previous version of rdf, found " +
    9999            vI_rdfDatasource.getCurrentRDFFileVersion() + "\nrdf-upgrade required.\n")
    100         switch (vI_rdfDatasource.getCurrentRDFFileVersion()) {
    101             case "0.0.1":
    102                 vI_upgrade.__removeQuotesFromResourceName(); break;
    103         }
     100        vI_upgrade.__createRDFContainers();
    104101        vI_rdfDatasource.storeRDFVersion();
    105102        vI_notificationBar.dump("rdf-upgrade to " + vI_rdfDatasource.getCurrentRDFFileVersion() + " done.\n\n");
    106103    },
    107104   
    108     __removeQuotesFromResourceName : function() {
    109         vI_notificationBar.quiet = true;
    110         vI_rdfDatasource.readAllVIdentitiesFromRDF(vI_upgrade.__removeQuotesFromResourceNameCallback)
    111         vI_notificationBar.quiet = null;
    112         vI_notificationBar.dump("done.\n");
    113     },
    114    
    115     __removeQuotesFromResourceNameCallback : function(resource, type, name, localIdentityData) {
    116         vI_rdfDatasource.updateRDF(name, type, localIdentityData, true);
    117         vI_notificationBar.quiet = null;
    118         vI_notificationBar.dump(".");
    119         vI_notificationBar.quiet = true;
     105    __createContainersUpgradeElems: function(resource, type, name) {
     106        var container;
     107       
     108        switch (type) {
     109            case "email": container = vI_rdfDatasource.emailContainer; break;
     110            case "newsgroup" : container = vI_rdfDatasource.newsgroupContainer; break;
     111            case "maillist" : container = vI_rdfDatasource.maillistContainer; break;
     112        }
     113        vI_rdfDatasource.__setRDFValue(resource, "name", name);
     114        if (container.IndexOf(resource) == -1) container.AppendElement(resource);
     115    },
     116
     117    __createRDFContainers: function() {
     118        var rdfContainerUtils = Components.classes["@mozilla.org/rdf/container-utils;1"].
     119            getService(Components.interfaces.nsIRDFContainerUtils);
     120
     121        var storageRes = vI_rdfDatasource.rdfService
     122            .GetResource(vI_rdfDatasource.rdfNS + vI_rdfDatasource.rdfNSStorage);
     123        var emailRes = vI_rdfDatasource.rdfService
     124            .GetResource(vI_rdfDatasource.rdfNS + vI_rdfDatasource.rdfNSEmail);
     125        var maillistRes = vI_rdfDatasource.rdfService
     126            .GetResource(vI_rdfDatasource.rdfNS + vI_rdfDatasource.rdfNSMaillist);
     127        var newsgroupRes = vI_rdfDatasource.rdfService
     128            .GetResource(vI_rdfDatasource.rdfNS + vI_rdfDatasource.rdfNSNewsgroup);
     129        var filterRes = vI_rdfDatasource.rdfService
     130            .GetResource(vI_rdfDatasource.rdfNS + vI_rdfDatasource.rdfNSFilter);
     131        vI_rdfDatasource.__setRDFValue(emailRes, "name", "E-Mail");
     132        vI_rdfDatasource.__setRDFValue(maillistRes, "name", "Mailing-List");
     133        vI_rdfDatasource.__setRDFValue(newsgroupRes, "name", "Newsgroup");
     134        vI_rdfDatasource.__setRDFValue(filterRes, "name", "Filter");
     135
     136        rdfContainerUtils.MakeBag(vI_rdfDatasource.rdfDataSource, storageRes);
     137        rdfContainerUtils.MakeBag(vI_rdfDatasource.rdfDataSource, emailRes);
     138        rdfContainerUtils.MakeBag(vI_rdfDatasource.rdfDataSource, maillistRes);
     139        rdfContainerUtils.MakeBag(vI_rdfDatasource.rdfDataSource, newsgroupRes);
     140        // use a sequence for the filters, order does matter
     141        rdfContainerUtils.MakeSeq(vI_rdfDatasource.rdfDataSource, filterRes);
     142       
     143        container = Components.classes["@mozilla.org/rdf/container;1"].
     144            createInstance(Components.interfaces.nsIRDFContainer);
     145
     146        container.Init(vI_rdfDatasource.rdfDataSource, storageRes);
     147        if (container.IndexOf(emailRes) == -1) container.AppendElement(emailRes);
     148        if (container.IndexOf(maillistRes) == -1) container.AppendElement(maillistRes);
     149        if (container.IndexOf(newsgroupRes) == -1) container.AppendElement(newsgroupRes);
     150        if (container.IndexOf(filterRes) == -1) container.AppendElement(filterRes);
     151       
     152        vI_rdfDatasource.__initContainers();
     153        vI_rdfDatasource.readAllResourcesFromRDF(vI_upgrade.__createContainersUpgradeElems)
    120154    },
    121155   
  • chrome/content/v_identity/vI_upgrade.xul

    r133338 r603625  
    5050
    5151<stringbundle id="vITextBoxBundle" src="chrome://v_identity/locale/vI_upgrade.properties" />
     52<stringbundle id="bundle_messenger" src="chrome://messenger/locale/messenger.properties" />
    5253   
    5354    <wizardpage id="introPage"
Note: See TracChangeset for help on using the changeset viewer.