jakarta-taglibs-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jean-Christophe Brouze <...@core.auteurs-associes.com>
Subject System load question.
Date Sat, 02 Sep 2000 23:37:24 GMT


I propose the draft of tiny Tag which enables to write a same message in
different languages ;
it's runing well but I wonder if it's very efficient from the system
load (or speed) point of view ;

maybe you have an opinion about this ?

The point is: 
    is it more efficient to store the RessourceBundle
    as an attribute in the pageContext, cause this Tag is
    intended to be used many times in the JSP page ?
    (eg. using a kind of init Tag ...)


1. here is the tag:
<tools:imsg key="folder.youhave" rbfile="userpage" dlang="fr" />

2. here is the tag descriptor:
    Selects the message to insert into the JSP page, using the
    appropriate language.
    key      : the key of the message in the ressource file
    rbfile   : the ressource file name, without '.properties' suffix
    dlang    : the default language, eg. fr, en, ge

3. here is the java source file:
package tools;
import java.io.*;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
import java.util.ResourceBundle;
 * use this to select the appropriate message in a RessourceBundle ;
 * by Cybrarian
public class IntMessageTag extends TagSupport {
    private String key = null;
    private String rbfile = null;
    private String dlang = null;
    public static final String SESSION_LANG = "lang";

    public void setKey(String s)    { this.key = s; }
    public void setRbfile(String s) { this.rbfile = s; }
    public void setDlang(String s)  { this.dlang = s; }
    public int doStartTag() {
	/* Check the session 'lang' attribute first ;
	 * (use the 'default' attribute if needed)
	String lang = (String)
	if (lang == null) lang = dlang;
	ResourceBundle rb = ResourceBundle.getBundle(rbfile);
	try {
	    pageContext.getOut().print(rb.getString(lang + "." + key));
	} catch(IOException ioe) {System.out.println("Error: " + ioe);}
	return (SKIP_BODY);

4. here a piece of the text ressource file:
fr.title=Page utilisateur.
fr.folder.youhave=Vous avez un ou plusieurs dossiers.
fr.folder.havenot=Vous n'avez pas de dossier.

en.title=User page.
en.folder.youhave=You have one or more folders.
en.folder.havenot=You have no folder.

New Email address: jcb@core.auteurs-associes.com
Jean-Christophe BROUZE - Auteurs & AssociƩs
Phone: (33) - Fax: (33)
View raw message