You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by Kazuhiro Kazama <ka...@ingrid.org> on 2001/12/13 09:52:35 UTC

[PROPOSAL] Multi-localization of a Tomcat 4 startup page

Dear Tomcat 4 committers,

I would like to propose multi-localization of a Tomcat 4 startup page
(CATALINA_HOME/webapps/ROOT/index.html). 

For example, Apache Web server has already provided a MultiView
function for this purpose and use it for multi-localized startup page.
And Tomcat 3.x has such function implemented by Arieh Markel.

But Tomcat 4 don't have such function. Therefore I propose the
following alternative approach using JSP 1.2's dynamic content type:

<%@ page import="java.io.*" %>
<%@ page import="java.util.Locale" %>
<%
	String language = "en";
	String encoding = "iso-8859-1";
        String file = "index.html";
	Locale locale = request.getLocale();
	if (locale != null) {
	    language = locale.getLanguage();
	}
	if (language.equalsIgnoreCase("ja")) {
	    encoding = "shift_jis";
	} else if (language.equalsIgnoreCase("en")) {
	    encoding = "iso-8859-1";
	}

	InputStream in;
	if ((in = config.getServletContext().getResourceAsStream(file + "." + language)) != null) {
	    response.setContentType("text/html; charset=" + encoding);
	} else {
	    in = config.getServletContext().getResourceAsStream(file);
	    encoding = "iso-8859-1";
	    response.setContentType("text/html");
	}
        BufferedReader reader = new BufferedReader(new InputStreamReader(in, encoding));
	String line;
	while ((line = reader.readLine()) != null) {
	    out.println(line);
 	}
%>

In short, this script has the following functions:

1, According to language specified by user's HTTP request, Tomcat
select a startup page. Its naming scheme is the same as Apache Web
Server, not Tomcat 3.x.

2, If there is no startup page written in the specified language,
Tomcat returns default page named "index.html".

Now there are some problems in this code. For example, the relation
between a language and a charset is hardcoded. In Tomcat 4,
org.apache.tomcat.util.http.LocaleToCharsetMap class provides the
mapping but it isn't in Servlet API. Such class is desirable in
Servlet API 2.4.

Anyway, I am ready to provide Japanese translations of startup pages
(webapps/ROOT/index.html and webapps/webdav/index.html) if this
proposal (or alternative proposal) will be accepted,

I am one of Japanese Tomcat volunteers which Craig has already
announced in this mailing-list (Thank you, Craig!). We are trying to
translate all Tomcat documents but it takes more time.

Kazuhiro Kazama (kazama@ingrid.org)	NTT Network Innovation Laboratories

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>