From 268131e95e819508c2b4a03caa2cbca8890b68b6 Mon Sep 17 00:00:00 2001 From: "bbaetz%cs.mcgill.ca" Date: Fri, 19 Oct 2001 03:03:30 +0000 Subject: [PATCH] Bug 82439 - html direcotry listings not localisable. r=sfraser, sr=darin --- .../resources/locale/en-US/necko.properties | 3 ++ netwerk/streamconv/converters/Makefile.in | 1 + netwerk/streamconv/converters/makefile.win | 1 + .../streamconv/converters/nsIndexedToHTML.cpp | 44 ++++++++++++++++--- .../streamconv/converters/nsIndexedToHTML.h | 2 + 5 files changed, 45 insertions(+), 6 deletions(-) diff --git a/netwerk/resources/locale/en-US/necko.properties b/netwerk/resources/locale/en-US/necko.properties index b9ec93b83d5..27295d101ce 100644 --- a/netwerk/resources/locale/en-US/necko.properties +++ b/netwerk/resources/locale/en-US/necko.properties @@ -47,3 +47,6 @@ EnterUserPasswordForProxy=Enter username and password for proxy at %1$S EnterUserPasswordFor=Enter username and password for %1$S EnterPasswordFor=Enter password for %1$S on %2$S DeniedPortAccess=Access to the port number given has been disabled for security reasons. + +# Directory listing strings +DirTitle=Index of %1$S diff --git a/netwerk/streamconv/converters/Makefile.in b/netwerk/streamconv/converters/Makefile.in index 197e3d34187..379fddb12a3 100644 --- a/netwerk/streamconv/converters/Makefile.in +++ b/netwerk/streamconv/converters/Makefile.in @@ -32,6 +32,7 @@ REQUIRES = xpcom \ string \ mimetype \ locale \ + intl \ unicharutil \ util \ pref \ diff --git a/netwerk/streamconv/converters/makefile.win b/netwerk/streamconv/converters/makefile.win index f52bf27b9af..ee6993f6ac5 100644 --- a/netwerk/streamconv/converters/makefile.win +++ b/netwerk/streamconv/converters/makefile.win @@ -28,6 +28,7 @@ REQUIRES = xpcom \ pref \ exthandler \ uconv \ + intl \ unicharutil \ zlib \ $(NULL) diff --git a/netwerk/streamconv/converters/nsIndexedToHTML.cpp b/netwerk/streamconv/converters/nsIndexedToHTML.cpp index 1761de9b157..5a704f190db 100644 --- a/netwerk/streamconv/converters/nsIndexedToHTML.cpp +++ b/netwerk/streamconv/converters/nsIndexedToHTML.cpp @@ -62,6 +62,12 @@ nsIndexedToHTML::Init(nsIStreamListener* aListener) { mDateTime = do_CreateInstance(kDateTimeFormatCID, &rv); + nsCOMPtr sbs = + do_GetService(NS_STRINGBUNDLE_CONTRACTID, &rv); + if (NS_FAILED(rv)) return rv; + rv = sbs->CreateBundle("chrome://necko/locale/necko.properties", + getter_AddRefs(mBundle)); + return rv; } @@ -137,8 +143,21 @@ nsIndexedToHTML::OnStartRequest(nsIRequest* request, nsISupports *aContext) { char* spec = nsCRT::strdup(tmp.get()); nsUnescape(spec); - buffer.Append(NS_LITERAL_STRING("\nIndex of ")); //FIX i18n. - buffer.AppendWithConversion(spec); + buffer.Append(NS_LITERAL_STRING("<html>\n<head><title>")); + + nsXPIDLString title; + nsAutoString uniSpec; uniSpec.AssignWithConversion(spec); + + const PRUnichar* formatTitle[] = { + uniSpec.get() + }; + + rv = mBundle->FormatStringFromName(NS_LITERAL_STRING("DirTitle").get(), + formatTitle, sizeof(formatTitle), + getter_Copies(title)); + if (NS_FAILED(rv)) return rv; + buffer.Append(title); + buffer.Append(NS_LITERAL_STRING("\n")); @@ -153,14 +172,25 @@ nsIndexedToHTML::OnStartRequest(nsIRequest* request, nsISupports *aContext) { buffer.Append(NS_LITERAL_STRING("\n
\n"));
 
-    buffer.Append(NS_LITERAL_STRING("

Index of ")); //FIX i18n. + buffer.Append(NS_LITERAL_STRING("

")); + char* escaped = nsEscapeHTML(spec); - buffer.AppendWithConversion(escaped); + nsAutoString escapedSpec; escapedSpec.AssignWithConversion(escaped); nsMemory::Free(escaped); + const PRUnichar* formatHeading[] = { + escapedSpec.get() + }; + + rv = mBundle->FormatStringFromName(NS_LITERAL_STRING("DirTitle").get(), + formatHeading, sizeof(formatHeading), + getter_Copies(title)); + if (NS_FAILED(rv)) return rv; + + buffer.Append(title); buffer.Append(NS_LITERAL_STRING("

\n")); buffer.Append(NS_LITERAL_STRING("
\n")); -// buffer.AppendWithConversion("\n"); //FIX i18n. + //buffer.Append(NS_LITERAL_STRING("\n")); // Push buffer to the listener now, so the initial HTML will not // be parsed in OnDataAvailable(). @@ -262,7 +292,9 @@ nsIndexedToHTML::OnIndexAvailable(nsIRequest *aRequest, PRUint32 size; aIndex->GetSize(&size); - if (size != PRUint32(-1)) { + if (size != PRUint32(-1) && + type != nsIDirIndex::TYPE_DIRECTORY && + type != nsIDirIndex::TYPE_SYMLINK) { pushBuffer.AppendInt(size); } else { pushBuffer.Append(NS_LITERAL_STRING(" ")); diff --git a/netwerk/streamconv/converters/nsIndexedToHTML.h b/netwerk/streamconv/converters/nsIndexedToHTML.h index a053f232292..06c9ecfbe8f 100644 --- a/netwerk/streamconv/converters/nsIndexedToHTML.h +++ b/netwerk/streamconv/converters/nsIndexedToHTML.h @@ -47,6 +47,7 @@ #include "nsIDirIndexListener.h" #include "nsILocaleService.h" #include "nsIDateTimeFormat.h" +#include "nsIStringBundle.h" #define NS_NSINDEXEDTOHTMLCONVERTER_CID \ { 0xcf0f71fd, 0xfafd, 0x4e2b, {0x9f, 0xdc, 0x13, 0x4d, 0x97, 0x2e, 0x16, 0xe2} } @@ -87,6 +88,7 @@ protected: nsCOMPtr mLocale; nsCOMPtr mDateTime; + nsCOMPtr mBundle; }; #endif
NameSizeLast modifiedDescription
NameSizeLast modified