You are viewing a plain text version of this content. The canonical link for it is here.
Posted to taglibs-dev@jakarta.apache.org by Jean-Christophe Brouze <jc...@core.auteurs-associes.com> on 2000/09/03 01:37:24 UTC

System load question.

Hello,

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 ...)

regards.

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

2. here is the tag descriptor:
------------------------------
  <tag>
    <name>imsg</name>
    <tagclass>tools.IntMessageTag</tagclass>
    <bodycontent>empty</bodycontent>
    <info>
    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
    </info>
    <attribute>
      <name>key</name>
      <required>true</required>
      <rtexprvalue>true</rtexprvalue>
    </attribute>
    <attribute>
      <name>rbfile</name>
      <required>true</required>
      <rtexprvalue>true</rtexprvalue>
    </attribute>
    <attribute>
      <name>dlang</name>
      <required>true</required>
      <rtexprvalue>false</rtexprvalue>
    </attribute>
  </tag>

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)
pageContext.getSession().getAttribute(SESSION_LANG);
	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.welcome=Bienvenue
fr.folder.youhave=Vous avez un ou plusieurs dossiers.
fr.folder.havenot=Vous n'avez pas de dossier.

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

[END OF MESSAGE]
-- 
New Email address: jcb@core.auteurs-associes.com
--
Jean-Christophe BROUZE - Auteurs & AssociƩs
http://core.auteurs-associes.com:7778/~Jean-Christ/
http://auteurs-associes.com
Phone: (33) 04.50.75.26.01 - Fax: (33) 04.50.75.27.62