Bug 452579 Start dropping some direct RDF usages in address book. r/sr=bienvenu
authorMark Banner <bugzilla@standard8.plus.com>
Thu, 28 Aug 2008 17:47:42 +0100
changeset 210 d80415828244cfe2676ec30770a52c82f16f4e9d
parent 209 771f940f90f5be2a72283184b8303ebc79818d06
child 211 8e89694ee82fe4ee8550b80b8abc93e6b77fd97b
push idunknown
push userunknown
push dateunknown
bugs452579
Bug 452579 Start dropping some direct RDF usages in address book. r/sr=bienvenu
mailnews/addrbook/src/nsAbLDAPDirFactory.cpp
mailnews/addrbook/src/nsAbLDAPDirectory.cpp
mailnews/addrbook/src/nsAbOSXDirFactory.cpp
mailnews/addrbook/src/nsAbView.cpp
mailnews/addrbook/src/nsAddbookProtocolHandler.cpp
--- a/mailnews/addrbook/src/nsAbLDAPDirFactory.cpp
+++ b/mailnews/addrbook/src/nsAbLDAPDirFactory.cpp
@@ -36,19 +36,17 @@
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "nsAbLDAPDirFactory.h"
 #include "nsAbUtils.h"
 
 #include "nsServiceManagerUtils.h"
-#include "nsIRDFService.h"
-#include "nsIRDFResource.h"
-
+#include "nsIAbManager.h"
 #include "nsIAbDirectory.h"
 #include "nsAbLDAPDirectory.h"
 
 #include "nsEnumeratorUtils.h"
 #include "nsAbBaseCID.h"
 
 NS_IMPL_ISUPPORTS1(nsAbLDAPDirFactory, nsIAbDirFactory)
 
@@ -64,20 +62,20 @@ NS_IMETHODIMP
 nsAbLDAPDirFactory::GetDirectories(const nsAString &aDirName,
                                    const nsACString &aURI,
                                    const nsACString &aPrefName,
                                    nsISimpleEnumerator **aDirectories)
 {
   NS_ENSURE_ARG_POINTER(aDirectories);
 
   nsresult rv;
-  nsCOMPtr<nsIRDFService> rdf = do_GetService (NS_RDF_CONTRACTID "/rdf-service;1", &rv);
+  nsCOMPtr<nsIAbManager> abManager(do_GetService(NS_ABMANAGER_CONTRACTID, &rv));
   NS_ENSURE_SUCCESS(rv, rv);
 
-  nsCOMPtr<nsIRDFResource> resource;
+  nsCOMPtr<nsIAbDirectory> directory;
   if (Substring(aURI, 0, 5).EqualsLiteral("ldap:") ||
       Substring(aURI, 0, 6).EqualsLiteral("ldaps:")) {
     /*
      * if the URI starts with ldap: or ldaps:
      * then this directory is an LDAP directory.
      *
      * we don't want to use the ldap:// or ldaps:// URI 
      * as the RDF resource URI because the ldap:// or ldaps:// URI 
@@ -89,26 +87,23 @@ nsAbLDAPDirFactory::GetDirectories(const
      * (the bridge URI) will be moz-abldapdirectory://<prefName>
      * and when we need the hostname, basedn, port, etc,
      * we'll use the <prefName> to get the necessary prefs.
      * note, <prefName> does not change.
      */
     nsCAutoString bridgeURI;
     bridgeURI = NS_LITERAL_CSTRING(kLDAPDirectoryRoot);
     bridgeURI += aPrefName;
-    rv = rdf->GetResource(bridgeURI, getter_AddRefs(resource));
+    rv = abManager->GetDirectory(bridgeURI, getter_AddRefs(directory));
   }
   else {
-    rv = rdf->GetResource(aURI, getter_AddRefs(resource));
+    rv = abManager->GetDirectory(aURI, getter_AddRefs(directory));
   }
   NS_ENSURE_SUCCESS(rv, rv);
 
-  nsCOMPtr<nsIAbDirectory> directory(do_QueryInterface(resource, &rv));
-  NS_ENSURE_SUCCESS(rv, rv);
-
   return NS_NewSingletonEnumerator(aDirectories, directory);
 }
 
 /* void deleteDirectory (in nsIAbDirectory directory); */
 NS_IMETHODIMP nsAbLDAPDirFactory::DeleteDirectory(nsIAbDirectory *directory)
 {
     // No actual deletion - as the LDAP Address Book is not physically
     // created in the corresponding CreateDirectory() unlike the Personal
--- a/mailnews/addrbook/src/nsAbLDAPDirectory.cpp
+++ b/mailnews/addrbook/src/nsAbLDAPDirectory.cpp
@@ -41,17 +41,16 @@
  * ***** END LICENSE BLOCK ***** */
 
 #include "nsAbLDAPDirectory.h"
 
 #include "nsAbQueryStringToExpression.h"
 
 #include "nsAbBaseCID.h"
 #include "nsIAbManager.h"
-#include "nsIRDFService.h"
 #include "nsServiceManagerUtils.h"
 #include "nsComponentManagerUtils.h"
 #include "nsAutoLock.h"
 #include "nsNetCID.h"
 #include "nsIIOService.h"
 #include "nsCOMArray.h"
 #include "nsArrayEnumerator.h"
 #include "nsEnumeratorUtils.h"
@@ -179,41 +178,40 @@ NS_IMETHODIMP nsAbLDAPDirectory::GetChil
     // when offline, we need to get the child cards for the local, replicated mdb directory 
     PRBool offline;
     nsCOMPtr <nsIIOService> ioService = do_GetService(NS_IOSERVICE_CONTRACTID, &rv);
     NS_ENSURE_SUCCESS(rv,rv);
     rv = ioService->GetOffline(&offline);
     NS_ENSURE_SUCCESS(rv,rv);
     
     if (offline) {
-      nsCOMPtr <nsIRDFService> rdfService = do_GetService("@mozilla.org/rdf/rdf-service;1",&rv);
-      NS_ENSURE_SUCCESS(rv, rv);
-
       nsCString fileName;
       rv = GetReplicationFileName(fileName);
       NS_ENSURE_SUCCESS(rv,rv);
       
       // if there is no fileName, bail out now.
       if (fileName.IsEmpty())
         return NS_OK;
 
       // perform the same query, but on the local directory
       nsCAutoString localDirectoryURI(NS_LITERAL_CSTRING(kMDBDirectoryRoot));
       localDirectoryURI.Append(fileName);
       if (mIsQueryURI) 
       {
         localDirectoryURI.AppendLiteral("?");
         localDirectoryURI.Append(mQueryString);
       }
-      
-      nsCOMPtr <nsIRDFResource> resource;
-      rv = rdfService->GetResource(localDirectoryURI, getter_AddRefs(resource));
+
+      nsCOMPtr<nsIAbManager> abManager(do_GetService(NS_ABMANAGER_CONTRACTID,
+                                                     &rv));
       NS_ENSURE_SUCCESS(rv, rv);
-      
-      nsCOMPtr <nsIAbDirectory> directory = do_QueryInterface(resource, &rv);
+
+      nsCOMPtr <nsIAbDirectory> directory;
+      rv = abManager->GetDirectory(localDirectoryURI,
+                                   getter_AddRefs(directory));
       NS_ENSURE_SUCCESS(rv, rv);
 
       rv = directory->GetChildCards(result);
     }
     else {
       // Start the search
       rv = StartSearch();
       NS_ENSURE_SUCCESS(rv, rv);
--- a/mailnews/addrbook/src/nsAbOSXDirFactory.cpp
+++ b/mailnews/addrbook/src/nsAbOSXDirFactory.cpp
@@ -36,18 +36,17 @@
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "nsAbOSXDirFactory.h"
 #include "nsAbBaseCID.h"
 #include "nsEnumeratorUtils.h"
 #include "nsIAbDirectory.h"
-#include "nsIRDFService.h"
-#include "rdf.h"
+#include "nsIAbManager.h"
 #include "nsStringGlue.h"
 #include "nsServiceManagerUtils.h"
 #include "nsAbOSXDirectory.h"
 
 NS_IMPL_ISUPPORTS1(nsAbOSXDirFactory, nsIAbDirFactory)
 
 NS_IMETHODIMP
 nsAbOSXDirFactory::GetDirectories(const nsAString &aDirName,
@@ -55,30 +54,27 @@ nsAbOSXDirFactory::GetDirectories(const 
                                   const nsACString &aPrefName,
                                   nsISimpleEnumerator **aDirectories)
 {
   NS_ENSURE_ARG_POINTER(aDirectories);
   
   *aDirectories = nsnull;
 
   nsresult rv;
-  nsCOMPtr<nsIRDFService> rdf =
-    do_GetService(NS_RDF_CONTRACTID "/rdf-service;1", &rv);
+  nsCOMPtr<nsIAbManager> abManager(do_GetService(NS_ABMANAGER_CONTRACTID, &rv));
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  nsCOMPtr<nsIAbDirectory> directory;
+  rv = abManager->GetDirectory(NS_LITERAL_CSTRING(NS_ABOSXDIRECTORY_URI_PREFIX "/"),
+                               getter_AddRefs(directory));
   NS_ENSURE_SUCCESS(rv, rv);
   
-  // We hardcode the root to "moz-abosxdirectory:///".
-  nsCOMPtr<nsIRDFResource> resource;
-  rv = rdf->GetResource(NS_LITERAL_CSTRING(NS_ABOSXDIRECTORY_URI_PREFIX "/"),
-                        getter_AddRefs(resource));
+  nsCOMPtr<nsIAbOSXDirectory> osxDirectory(do_QueryInterface(directory, &rv));
   NS_ENSURE_SUCCESS(rv, rv);
-  
-  nsCOMPtr<nsIAbOSXDirectory> osxDirectory =
-    do_QueryInterface(resource, &rv);
-  NS_ENSURE_SUCCESS(rv, rv);
-  
+
   rv = osxDirectory->AssertChildNodes();
   NS_ENSURE_SUCCESS(rv, rv);
   
   return NS_NewSingletonEnumerator(aDirectories, osxDirectory);
 }
 
 // No actual deletion, since you cannot create the address books from Mozilla.
 NS_IMETHODIMP
--- a/mailnews/addrbook/src/nsAbView.cpp
+++ b/mailnews/addrbook/src/nsAbView.cpp
@@ -34,17 +34,16 @@
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "nsAbView.h"
 #include "nsISupports.h"
-#include "nsIRDFService.h"
 #include "nsCOMPtr.h"
 #include "nsIServiceManager.h"
 #include "nsIAbCard.h"
 #include "nsILocale.h"
 #include "nsILocaleService.h"
 #include "prmem.h"
 #include "nsCollationCID.h"
 #include "nsIAbManager.h"
@@ -55,17 +54,16 @@
 #include "nsCRTGlue.h"
 #include "nsIMutableArray.h"
 #include "nsIPrefService.h"
 #include "nsIPrefBranch2.h"
 #include "nsIStringBundle.h"
 #include "nsIPrefLocalizedString.h"
 #include "nsArrayUtils.h"
 #include "nsIAddrDatabase.h" // for kPriEmailColumn
-#include "rdf.h"
 
 #define CARD_NOT_FOUND -1
 #define ALL_ROWS -1
 
 #define PREF_MAIL_ADDR_BOOK_LASTNAMEFIRST "mail.addr_book.lastnamefirst"
 #define PREF_MAIL_ADDR_BOOK_DISPLAYNAME_AUTOGENERATION "mail.addr_book.displayName.autoGeneration"
 #define PREF_MAIL_ADDR_BOOK_DISPLAYNAME_LASTNAMEFIRST "mail.addr_book.displayName.lastnamefirst"
 
@@ -1278,26 +1276,27 @@ NS_IMETHODIMP nsAbView::GetSelectedAddre
   for (PRUint32 i = 0; i < count; i++) {
     nsCOMPtr<nsIAbCard> card(do_QueryElementAt(selectedCards, i, &rv));
     NS_ENSURE_SUCCESS(rv, rv);
 
     PRBool isMailList;
     card->GetIsMailList(&isMailList);
     nsAutoString primaryEmail;
     if (isMailList) {
-      nsCOMPtr<nsIRDFService> rdfService = do_GetService(NS_RDF_CONTRACTID "/rdf-service;1", &rv);
+      nsCOMPtr<nsIAbManager> abManager(do_GetService(NS_ABMANAGER_CONTRACTID,
+                                                     &rv));
       NS_ENSURE_SUCCESS(rv, rv);
+
       nsCString mailListURI;
-      card->GetMailListURI(getter_Copies(mailListURI));
-      nsCOMPtr<nsIRDFResource> resource;
-      rv = rdfService->GetResource(mailListURI, getter_AddRefs(resource));
-      NS_ENSURE_SUCCESS(rv,rv);
+      rv = card->GetMailListURI(getter_Copies(mailListURI));
+      NS_ENSURE_SUCCESS(rv, rv);
 
-      nsCOMPtr<nsIAbDirectory> mailList = do_QueryInterface(resource, &rv);
-      NS_ENSURE_SUCCESS(rv,rv);
+      nsCOMPtr<nsIAbDirectory> mailList;
+      rv = abManager->GetDirectory(mailListURI, getter_AddRefs(mailList));
+      NS_ENSURE_SUCCESS(rv, rv);
 
       nsCOMPtr<nsIMutableArray> mailListAddresses;
       rv = mailList->GetAddressLists(getter_AddRefs(mailListAddresses));
       NS_ENSURE_SUCCESS(rv,rv);
 
       PRUint32 mailListCount = 0;
       mailListAddresses->GetLength(&mailListCount);	
 
--- a/mailnews/addrbook/src/nsAddbookProtocolHandler.cpp
+++ b/mailnews/addrbook/src/nsAddbookProtocolHandler.cpp
@@ -45,19 +45,17 @@
 
 #include "nsAddbookUrl.h"
 #include "nsAddbookProtocolHandler.h"
 #include "nsCOMPtr.h"
 #include "nsAbBaseCID.h"
 #include "nsNetUtil.h"
 #include "nsStringStream.h"
 #include "nsIAbDirectory.h"
-#include "nsIRDFResource.h"
-#include "nsIRDFService.h"
-#include "nsRDFCID.h"
+#include "nsIAbManager.h"
 #include "prmem.h"
 #include "nsIAbView.h"
 #include "nsITreeView.h"
 #include "nsIStringBundle.h"
 #include "nsIServiceManager.h"
 
 nsAddbookProtocolHandler::nsAddbookProtocolHandler()
 {
@@ -198,19 +196,16 @@ nsAddbookProtocolHandler::GeneratePrintO
                                               nsString &aOutput)
 {
   NS_ENSURE_ARG_POINTER(addbookUrl);
 
   nsCAutoString uri;
   nsresult rv = addbookUrl->GetPath(uri);
   NS_ENSURE_SUCCESS(rv,rv);
 
-  nsCOMPtr<nsIRDFService> rdfService = do_GetService("@mozilla.org/rdf/rdf-service;1", &rv);
-  NS_ENSURE_SUCCESS(rv,rv);
-
   /* turn
    "//moz-abmdbdirectory/abook.mab?action=print"
    into "moz-abmdbdirectory://abook.mab"
   */
 
   /* step 1:  
    turn "//moz-abmdbdirectory/abook.mab?action=print"
    into "moz-abmdbdirectory/abook.mab?action=print"
@@ -236,25 +231,25 @@ nsAddbookProtocolHandler::GeneratePrintO
    */
   pos = uri.Find("/");
   if (pos == -1)
     return NS_ERROR_UNEXPECTED;
 
   uri.Insert('/', pos);
   uri.Insert(':', pos);
 
-  nsCOMPtr <nsIRDFResource> resource;
-  rv = rdfService->GetResource(uri, getter_AddRefs(resource));
-  NS_ENSURE_SUCCESS(rv,rv);
-  
-  nsCOMPtr <nsIAbDirectory> directory = do_QueryInterface(resource, &rv);
-  NS_ENSURE_SUCCESS(rv,rv);
+  nsCOMPtr<nsIAbManager> abManager(do_GetService(NS_ABMANAGER_CONTRACTID, &rv));
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  nsCOMPtr<nsIAbDirectory> directory;
+  rv = abManager->GetDirectory(uri, getter_AddRefs(directory));
+  NS_ENSURE_SUCCESS(rv, rv);
 
   rv = BuildDirectoryXML(directory, aOutput);
-  NS_ENSURE_SUCCESS(rv,rv);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   return NS_OK;
 }
 
 nsresult
 nsAddbookProtocolHandler::BuildDirectoryXML(nsIAbDirectory *aDirectory, 
                                        nsString &aOutput)
 {