зеркало из https://github.com/mozilla/gecko-dev.git
fix for bug 148180 - untangle intl dependencies by removing redundant code to load .properties files
instead, go through the string bundle service. all intl libraries except the string bundle service are now free of necko dependencies r=ftang, sr=jag
This commit is contained in:
Родитель
9c2fbebce4
Коммит
7bf8b60881
|
@ -33,7 +33,7 @@ REQUIRES = xpcom \
|
|||
string \
|
||||
uconv \
|
||||
unicharutil \
|
||||
necko \
|
||||
intl \
|
||||
$(NULL)
|
||||
|
||||
ifeq ($(MOZ_WIDGET_TOOLKIT),os2)
|
||||
|
|
|
@ -32,7 +32,7 @@ REQUIRES = xpcom \
|
|||
string \
|
||||
uconv \
|
||||
unicharutil \
|
||||
necko \
|
||||
intl \
|
||||
$(NULL)
|
||||
LIBRARY_NAME = nslocale_s
|
||||
|
||||
|
|
|
@ -38,12 +38,11 @@
|
|||
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsLanguageAtomService.h"
|
||||
#include "nsIURI.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsICharsetConverterManager.h"
|
||||
#include "nsILocaleService.h"
|
||||
#include "nsXPIDLString.h"
|
||||
#include "nsUnicharUtils.h"
|
||||
#include "nsIServiceManager.h"
|
||||
|
||||
class nsLanguageAtom : public nsILanguageAtom
|
||||
{
|
||||
|
@ -137,21 +136,17 @@ nsLanguageAtomService::InitLangTable()
|
|||
NS_IMETHODIMP
|
||||
nsLanguageAtomService::InitLangGroupTable()
|
||||
{
|
||||
if (!mLangGroups.get()) {
|
||||
nsAutoString uriStr;
|
||||
uriStr.Assign(NS_LITERAL_STRING("resource:/res/langGroups.properties"));
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
NS_ENSURE_SUCCESS(NS_NewURI(getter_AddRefs(uri), uriStr), NS_ERROR_FAILURE);
|
||||
nsCOMPtr<nsIInputStream> in;
|
||||
NS_ENSURE_SUCCESS(NS_OpenURI(getter_AddRefs(in), uri), NS_ERROR_FAILURE);
|
||||
NS_ENSURE_SUCCESS(nsComponentManager::CreateInstance(
|
||||
NS_PERSISTENTPROPERTIES_CONTRACTID, nsnull,
|
||||
NS_GET_IID(nsIPersistentProperties), getter_AddRefs(mLangGroups)),
|
||||
NS_ERROR_FAILURE);
|
||||
NS_ENSURE_SUCCESS(mLangGroups->Load(in), NS_ERROR_FAILURE);
|
||||
}
|
||||
if (mLangGroups) return NS_OK;
|
||||
nsresult rv;
|
||||
|
||||
nsCOMPtr<nsIStringBundleService> bundleService =
|
||||
do_GetService(NS_STRINGBUNDLE_CONTRACTID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return NS_OK;
|
||||
|
||||
rv = bundleService->CreateBundle("resource:/res/langGroups.properties",
|
||||
getter_AddRefs(mLangGroups));
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
@ -189,7 +184,7 @@ nsLanguageAtomService::LookupLanguage(const PRUnichar* aLanguage,
|
|||
if (!lang) {
|
||||
nsLanguageAtom* language = new nsLanguageAtom();
|
||||
NS_ENSURE_TRUE(language, NS_ERROR_OUT_OF_MEMORY);
|
||||
nsAutoString langGroupStr;
|
||||
nsXPIDLString langGroupStr;
|
||||
|
||||
if (lowered.Equals(NS_LITERAL_STRING("en-us"))) {
|
||||
langGroupStr.Assign(NS_LITERAL_STRING("x-western"));
|
||||
|
@ -201,13 +196,13 @@ nsLanguageAtomService::LookupLanguage(const PRUnichar* aLanguage,
|
|||
if (!mLangGroups) {
|
||||
NS_ENSURE_SUCCESS(InitLangGroupTable(), NS_ERROR_FAILURE);
|
||||
}
|
||||
res = mLangGroups->GetStringProperty(lowered, langGroupStr);
|
||||
res = mLangGroups->GetStringFromName(lowered.get(), getter_Copies(langGroupStr));
|
||||
if (NS_FAILED(res)) {
|
||||
PRInt32 hyphen = lowered.FindChar('-');
|
||||
if (hyphen >= 0) {
|
||||
nsAutoString truncated(lowered);
|
||||
truncated.Truncate(hyphen);
|
||||
res = mLangGroups->GetStringProperty(truncated, langGroupStr);
|
||||
res = mLangGroups->GetStringFromName(truncated.get(), getter_Copies(langGroupStr));
|
||||
if (NS_FAILED(res)) {
|
||||
langGroupStr.Assign(NS_LITERAL_STRING("x-western"));
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@
|
|||
#include "nsCOMPtr.h"
|
||||
#include "nsICharsetConverterManager2.h"
|
||||
#include "nsILanguageAtomService.h"
|
||||
#include "nsIPersistentProperties2.h"
|
||||
#include "nsIStringBundle.h"
|
||||
#include "nsISupportsArray.h"
|
||||
#include "nsCRT.h"
|
||||
|
||||
|
@ -60,7 +60,7 @@ public:
|
|||
protected:
|
||||
nsCOMPtr<nsICharsetConverterManager2> mCharSets;
|
||||
nsCOMPtr<nsISupportsArray> mLangs;
|
||||
nsCOMPtr<nsIPersistentProperties> mLangGroups;
|
||||
nsCOMPtr<nsIStringBundle> mLangGroups;
|
||||
nsCOMPtr<nsIAtom> mLocaleLangGroup;
|
||||
nsCOMPtr<nsIAtom> mUnicode;
|
||||
};
|
||||
|
|
|
@ -33,6 +33,7 @@ REQUIRES = xpcom \
|
|||
unicharutil \
|
||||
pref \
|
||||
uconv \
|
||||
intl \
|
||||
$(NULL)
|
||||
|
||||
SHARED_LIBRARY_LIBS = ../$(LIB_PREFIX)nslocale_s.$(LIB_SUFFIX)
|
||||
|
|
|
@ -36,6 +36,7 @@ REQUIRES = xpcom \
|
|||
unicharutil \
|
||||
pref \
|
||||
uconv \
|
||||
intl \
|
||||
$(NULL)
|
||||
|
||||
SHARED_LIBRARY_LIBS = ../libnslocale_s.a
|
||||
|
|
|
@ -35,6 +35,7 @@ REQUIRES = xpcom \
|
|||
string \
|
||||
unicharutil \
|
||||
uconv \
|
||||
intl \
|
||||
$(NULL)
|
||||
|
||||
SHARED_LIBRARY_LIBS = ../$(LIB_PREFIX)nslocale_s.$(LIB_SUFFIX)
|
||||
|
|
|
@ -25,6 +25,7 @@ REQUIRES = xpcom \
|
|||
string \
|
||||
unicharutil \
|
||||
uconv \
|
||||
intl \
|
||||
$(NULL)
|
||||
include <$(DEPTH)/config/config.mak>
|
||||
|
||||
|
|
|
@ -41,7 +41,6 @@ REQUIRES = xpcom \
|
|||
intl \
|
||||
locale \
|
||||
unicharutil \
|
||||
necko \
|
||||
$(NULL)
|
||||
|
||||
CSRCS = \
|
||||
|
|
|
@ -26,7 +26,6 @@ REQUIRES = xpcom \
|
|||
intl \
|
||||
locale \
|
||||
unicharutil \
|
||||
necko \
|
||||
$(NULL)
|
||||
include <$(DEPTH)/config/config.mak>
|
||||
|
||||
|
|
|
@ -96,7 +96,7 @@ NS_IMETHODIMP nsCharsetAlias2::GetPreferred(const nsAString& aAlias, nsAString&
|
|||
//load charsetalias.properties string bundle with all remaining aliases
|
||||
// we may need to protect the following section with a lock so we won't call the
|
||||
// 'new nsURLProperties' from two different threads
|
||||
mDelegate = new nsURLProperties( NS_LITERAL_STRING("resource:/res/charsetalias.properties") );
|
||||
mDelegate = new nsURLProperties( NS_LITERAL_CSTRING("resource:/res/charsetalias.properties") );
|
||||
NS_ASSERTION(mDelegate, "cannot create nsURLProperties");
|
||||
if(nsnull == mDelegate)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
|
|
@ -72,7 +72,7 @@ nsresult nsPlatformCharset::InitInfo()
|
|||
{
|
||||
// load the .property file if necessary
|
||||
if (gInfo == nsnull) {
|
||||
nsURLProperties *info = new nsURLProperties( NS_LITERAL_STRING("resource:/res/maccharset.properties") );
|
||||
nsURLProperties *info = new nsURLProperties( NS_LITERAL_CSTRING("resource:/res/maccharset.properties") );
|
||||
NS_ASSERTION(info , "cannot open properties file");
|
||||
NS_ENSURE_TRUE(info, NS_ERROR_FAILURE);
|
||||
gInfo = info;
|
||||
|
|
|
@ -47,7 +47,7 @@ nsPlatformCharset::nsPlatformCharset()
|
|||
// XXX We should make the following block critical section
|
||||
if(nsnull == gInfo)
|
||||
{
|
||||
nsURLProperties *info = new nsURLProperties(NS_LITERAL_STRING("resource:/res/os2charset.properties"));
|
||||
nsURLProperties *info = new nsURLProperties(NS_LITERAL_CSTRING("resource:/res/os2charset.properties"));
|
||||
NS_ASSERTION( info , " cannot create nsURLProperties");
|
||||
gInfo = info;
|
||||
}
|
||||
|
|
|
@ -59,7 +59,7 @@ private:
|
|||
|
||||
nsresult InitInfo();
|
||||
nsresult MapToCharset(short script, short region, nsAString& outCharset);
|
||||
nsresult MapToCharset(nsString& inANSICodePage, nsAString& outCharset);
|
||||
nsresult MapToCharset(nsAString& inANSICodePage, nsAString& outCharset);
|
||||
nsresult InitGetCharset(nsAString& oString);
|
||||
nsresult ConvertLocaleToCharsetUsingDeprecatedConfig(nsAutoString& locale, nsAString& oResult);
|
||||
nsresult VerifyCharset(nsString &aCharset);
|
||||
|
|
|
@ -97,7 +97,7 @@ nsPlatformCharset::ConvertLocaleToCharsetUsingDeprecatedConfig(nsAutoString& loc
|
|||
{
|
||||
nsAutoLock guard(gLock);
|
||||
if (!gInfo_deprecated) {
|
||||
nsURLProperties *info = new nsURLProperties(NS_LITERAL_STRING("resource:/res/unixcharset.properties"));
|
||||
nsURLProperties *info = new nsURLProperties(NS_LITERAL_CSTRING("resource:/res/unixcharset.properties"));
|
||||
NS_ASSERTION( info, "cannot create nsURLProperties");
|
||||
gInfo_deprecated = info;
|
||||
}
|
||||
|
|
|
@ -39,77 +39,54 @@
|
|||
#include "nsURLProperties.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsIURL.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsAString.h"
|
||||
#include "nsPromiseFlatString.h"
|
||||
#include "nsXPIDLString.h"
|
||||
|
||||
static NS_DEFINE_IID(kIPersistentPropertiesIID, NS_IPERSISTENTPROPERTIES_IID);
|
||||
static NS_DEFINE_IID(kIOServiceCID, NS_IOSERVICE_CID);
|
||||
|
||||
nsIIOService* nsURLProperties::gIOService = nsnull;
|
||||
nsIStringBundleService* nsURLProperties::gStringBundleService = nsnull;
|
||||
nsrefcnt nsURLProperties::gRefCnt = 0;
|
||||
|
||||
nsURLProperties::nsURLProperties(const nsAFlatString& aUrl)
|
||||
nsURLProperties::nsURLProperties(const nsACString& aUrl)
|
||||
{
|
||||
mDelegate = nsnull;
|
||||
nsresult res = NS_OK;
|
||||
nsIURI* url = nsnull;
|
||||
nsIInputStream* in = nsnull;
|
||||
|
||||
if (gRefCnt == 0) {
|
||||
res = nsServiceManager::GetService(kIOServiceCID,
|
||||
NS_GET_IID(nsIIOService),
|
||||
(nsISupports**)&gIOService);
|
||||
res = CallGetService(NS_STRINGBUNDLE_CONTRACTID, &gStringBundleService);
|
||||
if (NS_FAILED(res)) return;
|
||||
gRefCnt++;
|
||||
}
|
||||
|
||||
res = gIOService->NewURI(NS_ConvertUCS2toUTF8(aUrl), nsnull, nsnull, &url);
|
||||
if (NS_FAILED(res)) return;
|
||||
|
||||
res = NS_OpenURI(&in, url);
|
||||
NS_RELEASE(url);
|
||||
if (NS_FAILED(res)) return;
|
||||
|
||||
if(NS_SUCCEEDED(res))
|
||||
res = nsComponentManager::CreateInstance(kPersistentPropertiesCID, NULL,
|
||||
kIPersistentPropertiesIID,
|
||||
(void**)&mDelegate);
|
||||
|
||||
if(NS_SUCCEEDED(res)) {
|
||||
if(in) {
|
||||
res = mDelegate->Load(in);
|
||||
}
|
||||
else {
|
||||
res = NS_ERROR_FAILURE;
|
||||
}
|
||||
if (NS_SUCCEEDED(res)) {
|
||||
gStringBundleService->CreateBundle(PromiseFlatCString(aUrl).get(), getter_AddRefs(mBundle));
|
||||
}
|
||||
|
||||
if(NS_FAILED(res)) {
|
||||
NS_IF_RELEASE(mDelegate);
|
||||
mDelegate=nsnull;
|
||||
}
|
||||
NS_IF_RELEASE(in);
|
||||
}
|
||||
|
||||
nsURLProperties::~nsURLProperties()
|
||||
{
|
||||
NS_IF_RELEASE(mDelegate);
|
||||
if (--gRefCnt == 0) {
|
||||
nsServiceManager::ReleaseService(kIOServiceCID, gIOService);
|
||||
gIOService = nsnull;
|
||||
NS_RELEASE(gStringBundleService);
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsURLProperties::Get(const nsAString& aKey, nsAString& oValue)
|
||||
NS_IMETHODIMP nsURLProperties::Get(const nsAString& aKey,
|
||||
nsAString& oValue)
|
||||
{
|
||||
if(mDelegate)
|
||||
return mDelegate->GetStringProperty(aKey, oValue);
|
||||
if(mBundle) {
|
||||
nsXPIDLString value;
|
||||
nsresult rv;
|
||||
|
||||
rv = mBundle->GetStringFromName(PromiseFlatString(aKey).get(),
|
||||
getter_Copies(value));
|
||||
if (NS_SUCCEEDED(rv))
|
||||
oValue = value;
|
||||
return rv;
|
||||
}
|
||||
else
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsURLProperties::DidLoad(PRBool &oDidLoad)
|
||||
{
|
||||
oDidLoad = (mDelegate!=nsnull);
|
||||
oDidLoad = (mBundle!=nsnull);
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
|
@ -39,23 +39,23 @@
|
|||
#ifndef nsURLProperties_h__
|
||||
#define nsURLProperties_h__
|
||||
|
||||
#include "nsIPersistentProperties2.h"
|
||||
#include "nsString.h"
|
||||
#include "nsIIOService.h"
|
||||
#include "nsIStringBundle.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsAString.h"
|
||||
|
||||
class nsURLProperties {
|
||||
public:
|
||||
nsURLProperties(const nsAFlatString& aUrl);
|
||||
nsURLProperties(const nsACString& aUrl);
|
||||
virtual ~nsURLProperties();
|
||||
|
||||
NS_IMETHOD DidLoad(PRBool&);
|
||||
NS_IMETHOD Get( const nsAString& aKey, nsAString& value);
|
||||
|
||||
private:
|
||||
static nsIIOService* gIOService; // to speed up creating URLs
|
||||
static nsIStringBundleService* gStringBundleService; // to speed up getting bundles
|
||||
static nsrefcnt gRefCnt;
|
||||
|
||||
nsIPersistentProperties *mDelegate;
|
||||
nsCOMPtr<nsIStringBundle> mBundle;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -83,7 +83,7 @@ nsPlatformCharset::InitInfo()
|
|||
PR_AtomicIncrement(&gCnt); // count for gInfo
|
||||
|
||||
if (gInfo == nsnull) {
|
||||
nsURLProperties *info = new nsURLProperties(NS_LITERAL_STRING("resource:/res/wincharset.properties"));
|
||||
nsURLProperties *info = new nsURLProperties(NS_LITERAL_CSTRING("resource:/res/wincharset.properties"));
|
||||
|
||||
NS_ASSERTION(info , "cannot open properties file");
|
||||
NS_ENSURE_TRUE(info, NS_ERROR_FAILURE);
|
||||
|
@ -93,7 +93,7 @@ nsPlatformCharset::InitInfo()
|
|||
}
|
||||
|
||||
nsresult
|
||||
nsPlatformCharset::MapToCharset(nsString& inANSICodePage, nsAString& outCharset)
|
||||
nsPlatformCharset::MapToCharset(nsAString& inANSICodePage, nsAString& outCharset)
|
||||
{
|
||||
//delay loading wincharset.properties bundle if possible
|
||||
if (inANSICodePage.Equals(NS_LITERAL_STRING("acp.1252"))) {
|
||||
|
|
|
@ -35,7 +35,7 @@ MODULE_NAME = UcharUtil
|
|||
REQUIRES = xpcom \
|
||||
string \
|
||||
uconv \
|
||||
necko \
|
||||
intl \
|
||||
$(NULL)
|
||||
|
||||
CPPSRCS = \
|
||||
|
|
|
@ -31,7 +31,7 @@ MODULE_NAME=UcharUtil
|
|||
REQUIRES = xpcom \
|
||||
string \
|
||||
uconv \
|
||||
necko \
|
||||
intl \
|
||||
$(NULL)
|
||||
include <$(DEPTH)\config\config.mak>
|
||||
|
||||
|
|
|
@ -41,15 +41,10 @@
|
|||
#include "nsIServiceManager.h"
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsReadableUtils.h"
|
||||
#include "nsIURL.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsCRT.h"
|
||||
|
||||
//
|
||||
// guids
|
||||
//
|
||||
NS_DEFINE_IID(kIFactoryIID,NS_IFACTORY_IID);
|
||||
NS_DEFINE_IID(kIPersistentPropertiesIID,NS_IPERSISTENTPROPERTIES_IID);
|
||||
#include "nsLiteralString.h"
|
||||
#include "nsXPIDLString.h"
|
||||
#include "nsString.h"
|
||||
|
||||
//
|
||||
// implementation methods
|
||||
|
@ -69,93 +64,72 @@ nsEntityConverter::~nsEntityConverter()
|
|||
NS_IMETHODIMP
|
||||
nsEntityConverter::LoadVersionPropertyFile()
|
||||
{
|
||||
NS_NAMED_LITERAL_STRING(aUrl, "resource:/res/entityTables/htmlEntityVersions.properties");
|
||||
nsIPersistentProperties* entityProperties = NULL;
|
||||
nsIURI* url = NULL;
|
||||
nsIInputStream* in = NULL;
|
||||
NS_NAMED_LITERAL_CSTRING(url, "resource:/res/entityTables/htmlEntityVersions.properties");
|
||||
nsresult rv;
|
||||
|
||||
rv = NS_NewURI(&url,aUrl);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
nsCOMPtr<nsIStringBundleService> bundleService =
|
||||
do_CreateInstance(NS_STRINGBUNDLE_CONTRACTID, &rv);
|
||||
|
||||
rv = NS_OpenURI(&in,url);
|
||||
NS_RELEASE(url);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIStringBundle> entities;
|
||||
rv = bundleService->CreateBundle(url.get(), getter_AddRefs(entities));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
PRInt32 result;
|
||||
|
||||
rv = nsComponentManager::CreateInstance(NS_PERSISTENTPROPERTIES_CONTRACTID,NULL,
|
||||
kIPersistentPropertiesIID,
|
||||
(void**)&entityProperties);
|
||||
if(NS_SUCCEEDED(rv) && in) {
|
||||
rv = entityProperties->Load(in);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
nsAutoString key, value; key.Assign(NS_LITERAL_STRING("length"));
|
||||
PRInt32 result;
|
||||
nsAutoString key;
|
||||
nsXPIDLString value;
|
||||
rv = entities->GetStringFromName(NS_LITERAL_STRING("length").get(),
|
||||
getter_Copies(value));
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv),"nsEntityConverter: malformed entity table\n");
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
mVersionListLength = nsAutoString(value).ToInteger(&result);
|
||||
NS_ASSERTION(32 >= mVersionListLength,"nsEntityConverter: malformed entity table\n");
|
||||
if (32 < mVersionListLength) return NS_ERROR_FAILURE;
|
||||
|
||||
mVersionList = new nsEntityVersionList[mVersionListLength];
|
||||
if (!mVersionList) return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
rv = entityProperties->GetStringProperty(key,value);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv),"nsEntityConverter: malformed entity table\n");
|
||||
if (NS_FAILED(rv)) goto done;
|
||||
mVersionListLength = value.ToInteger(&result);
|
||||
NS_ASSERTION(32 >= mVersionListLength,"nsEntityConverter: malformed entity table\n");
|
||||
if (32 < mVersionListLength) goto done;
|
||||
mVersionList = new nsEntityVersionList[mVersionListLength];
|
||||
if (NULL == mVersionList) {rv = NS_ERROR_OUT_OF_MEMORY; goto done;}
|
||||
|
||||
for (PRUint32 i = 0; i < mVersionListLength && NS_SUCCEEDED(rv); i++) {
|
||||
for (PRUint32 i = 0; i < mVersionListLength && NS_SUCCEEDED(rv); i++) {
|
||||
key.SetLength(0);
|
||||
key.AppendInt(i+1, 10);
|
||||
rv = entityProperties->GetStringProperty(key, value);
|
||||
rv = entities->GetStringFromName(key.get(), getter_Copies(value));
|
||||
PRUint32 len = value.Length();
|
||||
if (kVERSION_STRING_LEN < len) {rv = NS_ERROR_OUT_OF_MEMORY; goto done;}
|
||||
if (kVERSION_STRING_LEN < len) return NS_ERROR_UNEXPECTED;
|
||||
|
||||
memcpy(mVersionList[i].mEntityListName, value.get(), len*sizeof(PRUnichar));
|
||||
mVersionList[i].mEntityListName[len] = 0;
|
||||
mVersionList[i].mVersion = (1 << i);
|
||||
mVersionList[i].mEntityProperties = NULL;
|
||||
}
|
||||
}
|
||||
done:
|
||||
NS_IF_RELEASE(in);
|
||||
NS_IF_RELEASE(entityProperties);
|
||||
}
|
||||
return rv;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsIPersistentProperties*
|
||||
nsEntityConverter::LoadEntityPropertyFile(PRInt32 version)
|
||||
already_AddRefed<nsIStringBundle>
|
||||
nsEntityConverter::LoadEntityBundle(PRUint32 version)
|
||||
{
|
||||
nsString aUrl(NS_LITERAL_STRING("resource:/res/entityTables/"));
|
||||
nsIPersistentProperties* entityProperties = NULL;
|
||||
nsIURI* url = NULL;
|
||||
nsIInputStream* in = NULL;
|
||||
nsCAutoString url(NS_LITERAL_CSTRING("resource:/res/entityTables/"));
|
||||
const PRUnichar *versionName = NULL;
|
||||
nsresult rv;
|
||||
nsresult rv;
|
||||
|
||||
nsCOMPtr<nsIStringBundleService> bundleService =
|
||||
do_GetService(NS_STRINGBUNDLE_CONTRACTID, &rv);
|
||||
if (NS_FAILED(rv)) return NULL;
|
||||
|
||||
versionName = GetVersionName(version);
|
||||
if (NULL == versionName) return NULL;
|
||||
|
||||
aUrl.Append(versionName);
|
||||
aUrl.Append(NS_LITERAL_STRING(".properties"));
|
||||
// all property file names are ASCII, like "html40Latin1" so this is safe
|
||||
url.Append(NS_LossyConvertUCS2toASCII(versionName) +
|
||||
NS_LITERAL_CSTRING(".properties"));
|
||||
|
||||
rv = NS_NewURI(&url,aUrl);
|
||||
if (NS_FAILED(rv)) return NULL;
|
||||
|
||||
rv = NS_OpenURI(&in,url);
|
||||
NS_RELEASE(url);
|
||||
if (NS_FAILED(rv)) return NULL;
|
||||
|
||||
rv = nsComponentManager::CreateInstance(NS_PERSISTENTPROPERTIES_CONTRACTID,NULL,
|
||||
kIPersistentPropertiesIID,
|
||||
(void**)&entityProperties);
|
||||
if(NS_SUCCEEDED(rv) && in) {
|
||||
rv = entityProperties->Load(in);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
NS_IF_RELEASE(in);
|
||||
return entityProperties;
|
||||
}
|
||||
}
|
||||
NS_IF_RELEASE(in);
|
||||
NS_IF_RELEASE(entityProperties);
|
||||
|
||||
return NULL;
|
||||
nsIStringBundle* bundle;
|
||||
rv = bundleService->CreateBundle(url.get(), &bundle);
|
||||
if (NS_FAILED(rv)) return NULL;
|
||||
|
||||
// does this addref right?
|
||||
return bundle;
|
||||
}
|
||||
|
||||
const PRUnichar*
|
||||
|
@ -169,8 +143,8 @@ nsEntityConverter:: GetVersionName(PRUint32 versionNumber)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
nsIPersistentProperties*
|
||||
nsEntityConverter:: GetVersionPropertyInst(PRUint32 versionNumber)
|
||||
nsIStringBundle*
|
||||
nsEntityConverter:: GetVersionBundleInstance(PRUint32 versionNumber)
|
||||
{
|
||||
if (NULL == mVersionList) {
|
||||
// load the property file which contains available version names
|
||||
|
@ -182,13 +156,13 @@ nsEntityConverter:: GetVersionPropertyInst(PRUint32 versionNumber)
|
|||
PRUint32 i;
|
||||
for (i = 0; i < mVersionListLength; i++) {
|
||||
if (versionNumber == mVersionList[i].mVersion) {
|
||||
if (NULL == mVersionList[i].mEntityProperties)
|
||||
if (NULL == mVersionList[i].mEntities)
|
||||
{ // not loaded
|
||||
// load the property file
|
||||
mVersionList[i].mEntityProperties = LoadEntityPropertyFile(versionNumber);
|
||||
NS_ASSERTION(mVersionList[i].mEntityProperties, "LoadEntityPropertyFile failed");
|
||||
mVersionList[i].mEntities = LoadEntityBundle(versionNumber);
|
||||
NS_ASSERTION(mVersionList[i].mEntities, "LoadEntityBundle failed");
|
||||
}
|
||||
return mVersionList[i].mEntityProperties;
|
||||
return mVersionList[i].mEntities.get();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -216,15 +190,17 @@ nsEntityConverter::ConvertToEntity(PRUnichar character, PRUint32 entityVersion,
|
|||
for (PRUint32 mask = 1, mask2 = 0xFFFFFFFFL; (0!=(entityVersion & mask2)); mask<<=1, mask2<<=1) {
|
||||
if (0 == (entityVersion & mask))
|
||||
continue;
|
||||
nsIPersistentProperties* entityProperties = GetVersionPropertyInst(entityVersion & mask);
|
||||
NS_ASSERTION(entityProperties, "Cannot get the property file");
|
||||
nsIStringBundle* entities = GetVersionBundleInstance(entityVersion & mask);
|
||||
NS_ASSERTION(entities, "Cannot get the property file");
|
||||
|
||||
if (NULL == entityProperties)
|
||||
if (NULL == entities)
|
||||
continue;
|
||||
|
||||
nsAutoString key, value; key.Assign(NS_LITERAL_STRING("entity."));
|
||||
key.AppendInt(character,10);
|
||||
nsresult rv = entityProperties->GetStringProperty(key, value);
|
||||
nsAutoString key(NS_LITERAL_STRING("entity."));
|
||||
key.AppendInt(character,10);
|
||||
|
||||
nsXPIDLString value;
|
||||
nsresult rv = entities->GetStringFromName(key.get(), getter_Copies(value));
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
*_retval = ToNewCString(value);
|
||||
if(nsnull == *_retval)
|
||||
|
@ -251,19 +227,23 @@ nsEntityConverter::ConvertToEntities(const PRUnichar *inString, PRUint32 entityV
|
|||
// per character look for the entity
|
||||
PRUint32 len = nsCRT::strlen(inString);
|
||||
for (PRUint32 i = 0; i < len; i++) {
|
||||
nsAutoString value, key; key.Assign(NS_LITERAL_STRING("entity."));
|
||||
key.AppendInt(inString[i],10);
|
||||
nsAutoString key(NS_LITERAL_STRING("entity."));
|
||||
key.AppendInt(inString[i],10);
|
||||
|
||||
nsXPIDLString value;
|
||||
|
||||
entity = NULL;
|
||||
for (PRUint32 mask = 1, mask2 = 0xFFFFFFFFL; (0!=(entityVersion & mask2)); mask<<=1, mask2<<=1) {
|
||||
if (0 == (entityVersion & mask))
|
||||
continue;
|
||||
nsIPersistentProperties* entityProperties = GetVersionPropertyInst(entityVersion & mask);
|
||||
NS_ASSERTION(entityProperties, "Cannot get the property file");
|
||||
nsIStringBundle* entities = GetVersionBundleInstance(entityVersion & mask);
|
||||
NS_ASSERTION(entities, "Cannot get the property file");
|
||||
|
||||
if (NULL == entityProperties)
|
||||
if (NULL == entities)
|
||||
continue;
|
||||
|
||||
nsresult rv = entityProperties->GetStringProperty(key, value);
|
||||
nsresult rv = entities->GetStringFromName(key.get(),
|
||||
getter_Copies(value));
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
entity = value.get();
|
||||
break;
|
||||
|
|
|
@ -38,8 +38,8 @@
|
|||
|
||||
#include "nsIEntityConverter.h"
|
||||
#include "nsIFactory.h"
|
||||
#include "nsIPersistentProperties2.h"
|
||||
|
||||
#include "nsIStringBundle.h"
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
nsresult NS_NewEntityConverter(nsISupports** oResult);
|
||||
|
||||
|
@ -48,11 +48,11 @@ nsresult NS_NewEntityConverter(nsISupports** oResult);
|
|||
class nsEntityVersionList
|
||||
{
|
||||
public:
|
||||
nsEntityVersionList() : mEntityProperties(NULL) {}
|
||||
~nsEntityVersionList() {NS_IF_RELEASE(mEntityProperties);}
|
||||
PRUint32 mVersion;
|
||||
PRUnichar mEntityListName[kVERSION_STRING_LEN+1];
|
||||
nsIPersistentProperties *mEntityProperties;
|
||||
nsEntityVersionList() : mEntities(NULL) {}
|
||||
|
||||
PRUint32 mVersion;
|
||||
PRUnichar mEntityListName[kVERSION_STRING_LEN+1];
|
||||
nsCOMPtr<nsIStringBundle> mEntities;
|
||||
};
|
||||
|
||||
class nsEntityConverter: public nsIEntityConverter
|
||||
|
@ -85,11 +85,11 @@ protected:
|
|||
// map version number to version string
|
||||
const PRUnichar* GetVersionName(PRUint32 versionNumber);
|
||||
|
||||
// map version number to nsIPersistentProperties
|
||||
nsIPersistentProperties* GetVersionPropertyInst(PRUint32 versionNumber);
|
||||
// map version number to a string bundle
|
||||
nsIStringBundle* GetVersionBundleInstance(PRUint32 versionNumber);
|
||||
|
||||
// load a properies file
|
||||
nsIPersistentProperties* LoadEntityPropertyFile(PRInt32 version);
|
||||
// load a string bundle file
|
||||
already_AddRefed<nsIStringBundle> LoadEntityBundle(PRUint32 version);
|
||||
|
||||
|
||||
nsEntityVersionList *mVersionList; // array of version number/name pairs
|
||||
|
|
Загрузка…
Ссылка в новой задаче