Return-Path: Mailing-List: contact struts-dev-help@jakarta.apache.org; run by ezmlm Delivered-To: mailing list struts-dev@jakarta.apache.org Received: (qmail 54129 invoked from network); 1 Mar 2001 17:47:07 -0000 Received: from unknown (HELO exchange.bdsinc.com) (12.33.112.231) by h31.sny.collab.net with SMTP; 1 Mar 2001 17:47:07 -0000 Received: by exchange.tallan.com with Internet Mail Service (5.5.2650.21) id ; Thu, 1 Mar 2001 12:43:29 -0500 Received: from bdshdeadman (pool-253-067.cmgisolutions.com [216.91.253.67]) by exchange.bdsinc.com with SMTP (Microsoft Exchange Internet Mail Service Version 5.5.2650.21) id F3WJRX4H; Thu, 1 Mar 2001 12:43:26 -0500 From: "Deadman, Hal" Reply-To: "Deadman, Hal" To: 'Struts Dev List' Subject: localizing direct template content with bean:message Date: Thu, 1 Mar 2001 12:46:17 -0500 Message-ID: <000a01c0a277$8564fd50$f347000a@bdshdeadman> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_000B_01C0A24D.9C8EF550" X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook CWS, Build 9.0.2416 (9.0.2911.0) X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 Importance: Normal X-Spam-Rating: h31.sny.collab.net 1.6.2 0/1000/N This is a multi-part message in MIME format. ------=_NextPart_000_000B_01C0A24D.9C8EF550 Content-Type: multipart/alternative; boundary="----=_NextPart_001_000C_01C0A24D.9C938930" ------=_NextPart_001_000C_01C0A24D.9C938930 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit I wanted to localize direct content when using templates such as the title of a page. I modified the bean:message tag so it would read its key from the tag body if it wasn't specified as an attribute. Is there a better way to internationalize direct content with templates? Are there any other reasons that someone would want to get the bean:message key from the body of the tag? Are there reasons why this doesn't make sense? Below are the diffs to the files I modified and I attached the MessageTag class. If these changes aren't worthwhile then I can wait until localization is built into the templates framework. Thanks, Hal src/doc/struts-bean.xml 407c407 < empty --- > JSP 473c473 < true --- > false src/share/org/apache/struts/taglib/bean/MessagesTag.java 71c71 < import javax.servlet.jsp.tagext.TagSupport; --- > import javax.servlet.jsp.tagext.BodyTagSupport; 88c88 < public class MessageTag extends TagSupport { --- > public class MessageTag extends BodyTagSupport { 210a211,214 > /** > * The body text which will be used as the key if key attribute not spec > */ > protected String text = null; 228a233,235 > // Do nothing until doEndTag() is called > return (EVAL_BODY_TAG); > } 229a237,253 > /** > * Process the body text of this tag (if any). > * > * @exception JspException if a JSP exception has occurred > */ > public int doAfterBody() throws JspException { > String text = bodyContent.getString(); > if (text != null) { > text = text.trim(); > if (text.length() > 0) > this.text = text; > } > return (SKIP_BODY); > } > > > public int doEndTag() throws JspException { 237a262,270 > if (key == null) > { > if (text == null ) > { > return (EVAL_PAGE); > } > key = text; > } > 251,253c284,285 < // Continue processing this page < return (SKIP_BODY); < --- > // Continue evaluating this page > return (EVAL_PAGE); 256d287 < 261d291 ------=_NextPart_001_000C_01C0A24D.9C938930 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
I = wanted to localize=20 direct content when using templates such as the title of a page. I = modified=20 the bean:message tag so it would read its key from the tag body if it = wasn't=20 specified as an attribute. Is there a better way to internationalize = direct=20 content with templates? Are there any other reasons that someone would = want to=20 get the bean:message key from the body of the tag? Are there reasons = why this=20 doesn't make sense?
 
<bean:message>
<template:get=20 name=3D"titlekey"=20 flush=3D"false"/>
</bean:message>
Below = are the diffs=20 to the files I modified and I attached the MessageTag class. If these = changes=20 aren't worthwhile then I can wait until localization is built into the = templates=20 framework.
 
Thanks,=20 Hal
 
src/doc/struts-bean.xml
 
407c407
<    =20 <bodycontent>empty</bodycontent>
---
>  &= nbsp; =20 <bodycontent>JSP</bodycontent>
473c473
<  = ;    =20 <required>true</required>
---
>   &n= bsp;  =20 <required>false</required>
 
src/share/org/apache/struts/taglib/bean/Messa= gesTag.java
71c71
< import=20 javax.servlet.jsp.tagext.TagSupport;
---
> import=20 javax.servlet.jsp.tagext.BodyTagSupport;
88c88
< public class=20 MessageTag extends TagSupport {
---
> public class MessageTag = extends=20 BodyTagSupport {
210a211,214
>    =20 /**
>      * The body text which will be = used as=20 the key if key attribute not spec
>      = */
>     protected String text =3D=20 null;
228a233,235
>       &n= bsp; //=20 Do nothing until doEndTag() is=20 called
>         return=20 (EVAL_BODY_TAG);
>    =20 }
229a237,253
>    =20 /**
>      * Process the body text of = this tag=20 (if any).
>     =20 *
>      * @exception JspException if a = JSP=20 exception has occurred
>     =20 */
>     public int doAfterBody() throws = JspException=20 {
>         String text = =3D=20 bodyContent.getString();
>      &nbs= p; =20 if (text !=3D null)=20 {
>          &nb= sp; =20 text =3D=20 text.trim();
>        &nbs= p;   =20 if (text.length() >=20 0)
>          &n= bsp;     =20 this.text =3D = text;
>        =20 }
>         return=20 (SKIP_BODY);
>     }
>
>=20
>     public int doEndTag() throws = JspException=20 {
237a262,270
>        = if (key=20 =3D=3D null)
>        =20 {
>          &nb= sp; =20 if (text =3D=3D null=20 )
>          &nb= sp; =20 {
>          &nb= sp;     =20 return=20 (EVAL_PAGE);
>        &nbs= p;   =20 }
>          &nb= sp; =20 key =3D text;
>         = }
>=20
251,253c284,285
<  // Continue processing this = page
<=20  return (SKIP_BODY);
<=20
---
>         // = Continue=20 evaluating this = page
>        =20 return (EVAL_PAGE);
256d287
<=20
261d291
------=_NextPart_001_000C_01C0A24D.9C938930-- ------=_NextPart_000_000B_01C0A24D.9C8EF550 Content-Type: application/octet-stream; name="MessageTag.java" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="MessageTag.java" /* * $Header: = /home/cvspublic/jakarta-struts/src/share/org/apache/struts/taglib/bean/M= essageTag.java,v 1.4 2001/02/20 01:48:45 craigmcc Exp $ * $Revision: 1.4 $ * $Date: 2001/02/20 01:48:45 $ * * = =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D * * The Apache Software License, Version 1.1 * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software = itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Struts", and "Apache Software * Foundation" must not be used to endorse or promote products = derived * from this software without prior written permission. For written * permission, please contact apache@apache.org. * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * = =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * . * */ package org.apache.struts.taglib.bean; import java.io.IOException; import java.util.Locale; import javax.servlet.jsp.JspException; import javax.servlet.jsp.JspWriter; import javax.servlet.jsp.PageContext; import javax.servlet.jsp.tagext.BodyTagSupport; import org.apache.struts.action.Action; import org.apache.struts.util.MessageResources; import org.apache.struts.util.RequestUtils; import org.apache.struts.util.ResponseUtils; /** * Custom tag that retrieves an internationalized messages string (with * optional parametric replacement) from the = ActionResources * object stored as a context attribute by our associated * ActionServlet implementation. * * @author Craig R. McClanahan * @version $Revision: 1.4 $ $Date: 2001/02/20 01:48:45 $ */ public class MessageTag extends BodyTagSupport { // ------------------------------------------------------------- = Properties /** * The first optional argument. */ protected String arg0 =3D null; public String getArg0() { return (this.arg0); } public void setArg0(String arg0) { this.arg0 =3D arg0; } /** * The second optional argument. */ protected String arg1 =3D null; public String getArg1() { return (this.arg1); } public void setArg1(String arg1) { this.arg1 =3D arg1; } /** * The third optional argument. */ protected String arg2 =3D null; public String getArg2() { return (this.arg2); } public void setArg2(String arg2) { this.arg2 =3D arg2; } /** * The fourth optional argument. */ protected String arg3 =3D null; public String getArg3() { return (this.arg3); } public void setArg3(String arg3) { this.arg3 =3D arg3; } /** * The fifth optional argument. */ protected String arg4 =3D null; public String getArg4() { return (this.arg4); } public void setArg4(String arg4) { this.arg4 =3D arg4; } /** * The servlet context attribute key for our resources. */ protected String bundle =3D Action.MESSAGES_KEY; public String getBundle() { return (this.bundle); } public void setBundle(String bundle) { this.bundle =3D bundle; } /** * The default Locale for our server. */ protected static final Locale defaultLocale =3D = Locale.getDefault(); /** * The message key of the message to be retrieved. */ protected String key =3D null; public String getKey() { return (this.key); } public void setKey(String key) { this.key =3D key; } /** * The session scope key under which our Locale is stored. */ protected String localeKey =3D Action.LOCALE_KEY; public String getLocale() { return (this.localeKey); } public void setLocale(String localeKey) { this.localeKey =3D localeKey; } /** * The body text which will be used as the key if key attribute not = specified */ protected String text =3D null; /** * The message resources for this package. */ protected static MessageResources messages =3D MessageResources.getMessageResources ("org.apache.struts.taglib.bean.LocalStrings"); // --------------------------------------------------------- Public = Methods /** * Process the start tag. * * @exception JspException if a JSP exception has occurred */ public int doStartTag() throws JspException { // Do nothing until doEndTag() is called return (EVAL_BODY_TAG); } /** * Process the body text of this tag (if any). * * @exception JspException if a JSP exception has occurred */ public int doAfterBody() throws JspException { String text =3D bodyContent.getString(); if (text !=3D null) { text =3D text.trim(); if (text.length() > 0) this.text =3D text; } return (SKIP_BODY); } public int doEndTag() throws JspException { // Construct the optional arguments array we will be using Object args[] =3D new Object[5]; args[0] =3D arg0; args[1] =3D arg1; args[2] =3D arg2; args[3] =3D arg3; args[4] =3D arg4; if (key =3D=3D null) { if (text =3D=3D null ) { return (EVAL_PAGE); } key =3D text; } // Retrieve the message string we are looking for String message =3D RequestUtils.message(pageContext, = this.bundle, this.localeKey, this.key, = args); if (message =3D=3D null) { JspException e =3D new JspException (messages.getMessage("message.message", key)); RequestUtils.saveException(pageContext, e); throw e; } // Print the retrieved message to our output writer ResponseUtils.write(pageContext, message); // Continue evaluating this page return (EVAL_PAGE); } /** * Release any acquired resources. */ public void release() { super.release(); arg0 =3D null; arg1 =3D null; arg2 =3D null; arg3 =3D null; arg4 =3D null; bundle =3D Action.MESSAGES_KEY; key =3D null; localeKey =3D Action.LOCALE_KEY; text =3D null; } } ------=_NextPart_000_000B_01C0A24D.9C8EF550--