Back to index

lightning-sunbird  0.9+nobinonly
nsI18nModule.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either of the GNU General Public License Version 2 or later (the "GPL"),
00026  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #include "nsIGenericFactory.h"
00039 #include "nsCOMPtr.h"
00040 #include "nsICategoryManager.h"
00041 #include "nsIServiceManager.h"
00042 
00043 // chardet
00044 #include "nsCharDetConstructors.h"
00045 
00046 // lwbrk
00047 #include "nsLWBrkConstructors.h"
00048 #include "nsSemanticUnitScanner.h"
00049 
00050 // unicharutil
00051 #include "nsUcharUtilConstructors.h"
00052 
00053 // string bundles (intl)
00054 #include "nsStrBundleConstructors.h"
00055 
00056 // locale
00057 #include "nsLocaleConstructors.h"
00058 
00059 
00060 NS_GENERIC_FACTORY_CONSTRUCTOR(nsSemanticUnitScanner)
00061 
00062 static NS_METHOD
00063 AddCategoryEntry(const char* category,
00064                  const char* key,
00065                  const char* value)
00066 {
00067   nsresult rv;
00068   nsCOMPtr<nsICategoryManager> 
00069     categoryManager(do_GetService("@mozilla.org/categorymanager;1", &rv));
00070   if (NS_FAILED(rv)) return rv;
00071   
00072   return categoryManager->AddCategoryEntry(category, key, value, 
00073                                            PR_TRUE, PR_TRUE,
00074                                            nsnull);
00075 }
00076 
00077 static NS_METHOD
00078 DeleteCategoryEntry(const char* category,
00079                     const char* key)
00080 {
00081   nsresult rv;
00082   nsCOMPtr<nsICategoryManager> 
00083     categoryManager(do_GetService("@mozilla.org/categorymanager;1", &rv));
00084   if (NS_FAILED(rv)) return rv;
00085   
00086   return categoryManager->DeleteCategoryEntry(category, key, PR_TRUE);
00087 }
00088 
00089 static NS_METHOD
00090 nsMetaCharsetObserverRegistrationProc(nsIComponentManager *aCompMgr,
00091                                       nsIFile *aPath,
00092                                       const char *registryLocation,
00093                                       const char *componentType,
00094                                       const nsModuleComponentInfo *info)
00095 {
00096   return AddCategoryEntry("parser-service-category", 
00097                           "Meta Charset Service",
00098                           NS_META_CHARSET_CONTRACTID);
00099 }
00100 
00101 static NS_METHOD
00102 nsMetaCharsetObserverUnegistrationProc(nsIComponentManager *aCompMgr,
00103                                        nsIFile *aPath,
00104                                        const char *registryLocation,
00105                                        const nsModuleComponentInfo *info)
00106 {
00107   return DeleteCategoryEntry("parser-service-category",
00108                              "Meta Charset Service");
00109 }
00110 
00111 static NS_METHOD
00112 nsDetectionAdaptorRegistrationProc(nsIComponentManager *aCompMgr,
00113                                    nsIFile *aPath,
00114                                    const char *registryLocation,
00115                                    const char *componentType,
00116                                    const nsModuleComponentInfo *info)
00117 {
00118   return AddCategoryEntry(NS_CHARSET_DETECTOR_CATEGORY, "off", "off");
00119 }
00120 
00121 static NS_METHOD
00122 nsJAPSMDetectorRegistrationProc(nsIComponentManager *aCompMgr,
00123                                 nsIFile *aPath,
00124                                 const char *registryLocation,
00125                                 const char *componentType,
00126                                 const nsModuleComponentInfo *info)
00127 {
00128   return AddCategoryEntry(NS_CHARSET_DETECTOR_CATEGORY,
00129                           "ja_parallel_state_machine",
00130                           info->mContractID);
00131 }
00132 
00133 static NS_METHOD
00134 nsKOPSMDetectorRegistrationProc(nsIComponentManager *aCompMgr,
00135                                 nsIFile *aPath,
00136                                 const char *registryLocation,
00137                                 const char *componentType,
00138                                 const nsModuleComponentInfo *info)
00139 {
00140   return AddCategoryEntry(NS_CHARSET_DETECTOR_CATEGORY,
00141                           "ko_parallel_state_machine",
00142                           info->mContractID);
00143 }
00144 
00145 static NS_METHOD
00146 nsZHTWPSMDetectorRegistrationProc(nsIComponentManager *aCompMgr,
00147                                   nsIFile *aPath,
00148                                   const char *registryLocation,
00149                                   const char *componentType,
00150                                   const nsModuleComponentInfo *info)
00151 {
00152   return AddCategoryEntry(NS_CHARSET_DETECTOR_CATEGORY,
00153                           "zhtw_parallel_state_machine",
00154                           info->mContractID);
00155 }
00156 
00157 static NS_METHOD
00158 nsZHCNPSMDetectorRegistrationProc(nsIComponentManager *aCompMgr,
00159                                   nsIFile *aPath,
00160                                   const char *registryLocation,
00161                                   const char *componentType,
00162                                   const nsModuleComponentInfo *info)
00163 {
00164   return AddCategoryEntry(NS_CHARSET_DETECTOR_CATEGORY,
00165                           "zhcn_parallel_state_machine",
00166                           info->mContractID);
00167 }
00168 
00169 static NS_METHOD
00170 nsZHPSMDetectorRegistrationProc(nsIComponentManager *aCompMgr,
00171                                 nsIFile *aPath,
00172                                 const char *registryLocation,
00173                                 const char *componentType,
00174                                 const nsModuleComponentInfo *info)
00175 {
00176   return AddCategoryEntry(NS_CHARSET_DETECTOR_CATEGORY,
00177                           "zh_parallel_state_machine",
00178                           info->mContractID);
00179 }
00180 
00181 static NS_METHOD
00182 nsCJKPSMDetectorRegistrationProc(nsIComponentManager *aCompMgr,
00183                                  nsIFile *aPath,
00184                                  const char *registryLocation,
00185                                  const char *componentType,
00186                                  const nsModuleComponentInfo *info)
00187 {
00188   return AddCategoryEntry(NS_CHARSET_DETECTOR_CATEGORY,
00189                           "cjk_parallel_state_machine",
00190                           info->mContractID);
00191 }
00192 
00193 static NS_METHOD
00194 nsRUProbDetectorRegistrationProc(nsIComponentManager *aCompMgr,
00195                                  nsIFile *aPath,
00196                                  const char *registryLocation,
00197                                  const char *componentType,
00198                                  const nsModuleComponentInfo *info)
00199 {
00200   return AddCategoryEntry(NS_CHARSET_DETECTOR_CATEGORY,
00201                           "ruprob",
00202                           info->mContractID);
00203 }
00204 
00205 static NS_METHOD
00206 nsUKProbDetectorRegistrationProc(nsIComponentManager *aCompMgr,
00207                                  nsIFile *aPath,
00208                                  const char *registryLocation,
00209                                  const char *componentType,
00210                                  const nsModuleComponentInfo *info)
00211 {
00212   return AddCategoryEntry(NS_CHARSET_DETECTOR_CATEGORY,
00213                           "ukprob",
00214                           info->mContractID);
00215 }
00216 
00217 
00218 static nsModuleComponentInfo components[] =
00219 {
00220     // chardet
00221  { "Meta Charset", NS_META_CHARSET_CID, 
00222     NS_META_CHARSET_CONTRACTID, nsMetaCharsetObserverConstructor, 
00223     nsMetaCharsetObserverRegistrationProc, nsMetaCharsetObserverUnegistrationProc,
00224     NULL},
00225  { "Document Charset Info", NS_DOCUMENTCHARSETINFO_CID, 
00226     NS_DOCUMENTCHARSETINFO_CONTRACTID, nsDocumentCharsetInfoConstructor, 
00227     NULL, NULL},
00228  { "XML Encoding", NS_XML_ENCODING_CID, 
00229     NS_XML_ENCODING_CONTRACTID, nsXMLEncodingObserverConstructor, 
00230     NULL, NULL},
00231  { "Charset Detection Adaptor", NS_CHARSET_DETECTION_ADAPTOR_CID, 
00232     NS_CHARSET_DETECTION_ADAPTOR_CONTRACTID, nsDetectionAdaptorConstructor, 
00233     nsDetectionAdaptorRegistrationProc, NULL},
00234  { "PSM based Japanese Charset Detector", NS_JA_PSMDETECTOR_CID, 
00235     NS_CHARSET_DETECTOR_CONTRACTID_BASE "ja_parallel_state_machine", nsJAPSMDetectorConstructor, 
00236     nsJAPSMDetectorRegistrationProc, NULL},
00237  { "PSM based Japanese String Charset Detector", NS_JA_STRING_PSMDETECTOR_CID, 
00238     NS_STRCDETECTOR_CONTRACTID_BASE "ja_parallel_state_machine", nsJAStringPSMDetectorConstructor, 
00239     NULL, NULL},
00240  { "PSM based Korean Charset Detector", NS_KO_PSMDETECTOR_CID, 
00241     NS_CHARSET_DETECTOR_CONTRACTID_BASE "ko_parallel_state_machine", nsKOPSMDetectorConstructor, 
00242     nsKOPSMDetectorRegistrationProc, NULL},
00243  { "PSM based Korean String Charset Detector", NS_KO_STRING_PSMDETECTOR_CID, 
00244     NS_STRCDETECTOR_CONTRACTID_BASE "ko_parallel_state_machine", nsKOStringPSMDetectorConstructor, 
00245     NULL, NULL},
00246  { "PSM based Traditional Chinese Charset Detector", NS_ZHTW_PSMDETECTOR_CID, 
00247     NS_CHARSET_DETECTOR_CONTRACTID_BASE "zhtw_parallel_state_machine", nsZHTWPSMDetectorConstructor, 
00248     nsZHTWPSMDetectorRegistrationProc, NULL},
00249  { "PSM based Traditional Chinese String Charset Detector", NS_ZHTW_STRING_PSMDETECTOR_CID, 
00250     NS_STRCDETECTOR_CONTRACTID_BASE "zhtw_parallel_state_machine", nsZHTWStringPSMDetectorConstructor, 
00251     NULL, NULL},
00252  { "PSM based Simplified Chinese Charset Detector", NS_ZHCN_PSMDETECTOR_CID, 
00253     NS_CHARSET_DETECTOR_CONTRACTID_BASE "zhcn_parallel_state_machine", nsZHCNPSMDetectorConstructor, 
00254     nsZHCNPSMDetectorRegistrationProc, NULL},
00255  { "PSM based Simplified Chinese String Charset Detector", NS_ZHCN_STRING_PSMDETECTOR_CID, 
00256     NS_STRCDETECTOR_CONTRACTID_BASE "zhcn_parallel_state_machine", nsZHCNStringPSMDetectorConstructor, 
00257     NULL, NULL},
00258  { "PSM based Chinese Charset Detector", NS_ZH_PSMDETECTOR_CID, 
00259     NS_CHARSET_DETECTOR_CONTRACTID_BASE "zh_parallel_state_machine", nsZHPSMDetectorConstructor, 
00260     nsZHPSMDetectorRegistrationProc, NULL},
00261  { "PSM based Chinese String Charset Detector", NS_ZH_STRING_PSMDETECTOR_CID, 
00262     NS_STRCDETECTOR_CONTRACTID_BASE "zh_parallel_state_machine", nsZHStringPSMDetectorConstructor, 
00263     NULL, NULL},
00264  { "PSM based CJK Charset Detector", NS_CJK_PSMDETECTOR_CID, 
00265     NS_CHARSET_DETECTOR_CONTRACTID_BASE "cjk_parallel_state_machine", nsCJKPSMDetectorConstructor, 
00266     nsCJKPSMDetectorRegistrationProc, NULL},
00267  { "PSM based CJK String Charset Detector", NS_CJK_STRING_PSMDETECTOR_CID, 
00268     NS_STRCDETECTOR_CONTRACTID_BASE "cjk_parallel_state_machine", nsCJKStringPSMDetectorConstructor, 
00269     NULL, NULL},
00270  { "Probability based Russian Charset Detector", NS_RU_PROBDETECTOR_CID, 
00271     NS_CHARSET_DETECTOR_CONTRACTID_BASE "ruprob", nsRUProbDetectorConstructor, 
00272     nsRUProbDetectorRegistrationProc, NULL},
00273  { "Probability based Ukrainian Charset Detector", NS_UK_PROBDETECTOR_CID, 
00274     NS_CHARSET_DETECTOR_CONTRACTID_BASE "ukprob", nsUKProbDetectorConstructor, 
00275     nsUKProbDetectorRegistrationProc, NULL},
00276  { "Probability based Russian String Charset Detector", NS_RU_STRING_PROBDETECTOR_CID, 
00277     NS_STRCDETECTOR_CONTRACTID_BASE "ruprob", nsRUStringProbDetectorConstructor, 
00278     NULL, NULL},
00279  { "Probability based Ukrainian String Charset Detector", NS_UK_STRING_PROBDETECTOR_CID, 
00280     NS_STRCDETECTOR_CONTRACTID_BASE "ukprob", nsUKStringProbDetectorConstructor, 
00281    NULL, NULL},
00282 #ifdef INCLUDE_DBGDETECTOR
00283  { "Debugging Detector 1st block", NS_1STBLKDBG_DETECTOR_CID, 
00284     NS_CHARSET_DETECTOR_CONTRACTID_BASE "1stblkdbg", ns1stBlkDbgDetectorConstructor, 
00285     NULL, NULL},
00286  { "Debugging Detector 2nd block", NS_2NDBLKDBG_DETECTOR_CID, 
00287     NS_CHARSET_DETECTOR_CONTRACTID_BASE "2ndblkdbg", ns2ndBlkDbgDetectorConstructor, 
00288     NULL, NULL},
00289  { "Debugging Detector Last block", NS_LASTBLKDBG_DETECTOR_CID, 
00290     NS_CHARSET_DETECTOR_CONTRACTID_BASE "lastblkdbg", nsLastBlkDbgDetectorConstructor, 
00291     NULL, NULL},
00292 #endif /* INCLUDE_DBGDETECTOR */
00293  // lwbrk
00294   { "Line and Word Breaker", NS_LWBRK_CID,
00295     NS_LWBRK_CONTRACTID, nsLWBreakerFImpConstructor},
00296   { "Semantic Unit Scanner", NS_SEMANTICUNITSCANNER_CID,
00297     NS_SEMANTICUNITSCANNER_CONTRACTID, nsSemanticUnitScannerConstructor},
00298 
00299  // unicharutil
00300   { "Unichar Utility", NS_UNICHARUTIL_CID, 
00301       NS_UNICHARUTIL_CONTRACTID, nsCaseConversionImp2Constructor},
00302   { "Unicode To Entity Converter", NS_ENTITYCONVERTER_CID, 
00303       NS_ENTITYCONVERTER_CONTRACTID, nsEntityConverterConstructor },
00304   { "Unicode To Charset Converter", NS_SAVEASCHARSET_CID, 
00305       NS_SAVEASCHARSET_CONTRACTID, nsSaveAsCharsetConstructor},
00306   { "Japanese Hankaku To Zenkaku", NS_HANKAKUTOZENKAKU_CID, 
00307       NS_HANKAKUTOZENKAKU_CONTRACTID, CreateNewHankakuToZenkaku},
00308   { "Unicode Normlization", NS_UNICODE_NORMALIZER_CID, 
00309       NS_UNICODE_NORMALIZER_CONTRACTID,  nsUnicodeNormalizerConstructor},
00310 
00311 
00312  // strres
00313   { "String Bundle", NS_STRINGBUNDLESERVICE_CID, NS_STRINGBUNDLE_CONTRACTID,
00314     nsStringBundleServiceConstructor},
00315   { "String Textfile Overrides", NS_STRINGBUNDLETEXTOVERRIDE_CID,
00316     NS_STRINGBUNDLETEXTOVERRIDE_CONTRACTID,
00317     nsStringBundleTextOverrideConstructor },
00318 
00319  // locale
00320   { "nsLocaleService component",
00321     NS_LOCALESERVICE_CID,
00322     NS_LOCALESERVICE_CONTRACTID,
00323     CreateLocaleService },
00324   { "Collation factory",
00325     NS_COLLATIONFACTORY_CID,
00326     NS_COLLATIONFACTORY_CONTRACTID,
00327     nsCollationFactoryConstructor },
00328   { "Scriptable Date Format",
00329     NS_SCRIPTABLEDATEFORMAT_CID,
00330     NS_SCRIPTABLEDATEFORMAT_CONTRACTID,
00331     NS_NewScriptableDateFormat },
00332   { "Language Atom Service",
00333     NS_LANGUAGEATOMSERVICE_CID,
00334     NS_LANGUAGEATOMSERVICE_CONTRACTID,
00335     nsLanguageAtomServiceConstructor },
00336   { "Font Package Service",
00337     NS_FONTPACKAGESERVICE_CID,
00338     NS_FONTPACKAGESERVICE_CONTRACTID,
00339     nsFontPackageServiceConstructor },
00340  
00341 #ifdef XP_WIN 
00342   { "Platform locale",
00343     NS_WIN32LOCALE_CID,
00344     NS_WIN32LOCALE_CONTRACTID,
00345     nsIWin32LocaleImplConstructor },
00346   { "Collation",
00347     NS_COLLATION_CID,
00348     NS_COLLATION_CONTRACTID,
00349     nsCollationWinConstructor },
00350   { "Date/Time formatter",
00351     NS_DATETIMEFORMAT_CID,
00352     NULL,
00353     nsDateTimeFormatWinConstructor },
00354 #endif
00355  
00356 #ifdef USE_UNIX_LOCALE
00357   { "Platform locale",
00358     NS_POSIXLOCALE_CID,
00359     NS_POSIXLOCALE_CONTRACTID,
00360     nsPosixLocaleConstructor },
00361 
00362   { "Collation",
00363     NS_COLLATION_CID,
00364     NS_COLLATION_CONTRACTID,
00365     nsCollationUnixConstructor },
00366 
00367   { "Date/Time formatter",
00368     NS_DATETIMEFORMAT_CID,
00369     NULL,
00370     nsDateTimeFormatUnixConstructor },
00371 #endif
00372 
00373 #ifdef USE_MAC_LOCALE
00374   { "Mac locale",
00375     NS_MACLOCALE_CID,
00376     NS_MACLOCALE_CONTRACTID,
00377     nsMacLocaleConstructor },
00378   { "Collation",
00379     NS_COLLATION_CID,
00380     NS_COLLATION_CONTRACTID,
00381 #ifdef USE_UCCOLLATIONKEY
00382     nsCollationMacUCConstructor },
00383 #else
00384     nsCollationMacConstructor },
00385 #endif
00386   { "Date/Time formatter",
00387     NS_DATETIMEFORMAT_CID,
00388     NULL,
00389     nsDateTimeFormatMacConstructor },
00390 #endif
00391 
00392 #ifdef XP_OS2
00393   { "OS/2 locale",
00394     NS_OS2LOCALE_CID,
00395     NS_OS2LOCALE_CONTRACTID,
00396     nsOS2LocaleConstructor },
00397   { "Collation",
00398     NS_COLLATION_CID,
00399     NS_COLLATION_CONTRACTID,
00400     nsCollationOS2Constructor },
00401   { "Date/Time formatter",
00402     NS_DATETIMEFORMAT_CID,
00403     NULL,
00404     nsDateTimeFormatOS2Constructor },
00405 #endif
00406       
00407 };
00408 
00409 
00410 NS_IMPL_NSGETMODULE(nsI18nModule, components)