1 /* 2 * Copyright 1999,2004 The Apache Software Foundation. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package org.apache.taglibs.i18n; 18 19 import java.text.MessageFormat; 20 21 import javax.servlet.jsp.JspException; 22 import javax.servlet.jsp.JspTagException; 23 import javax.servlet.jsp.tagext.Tag; 24 import javax.servlet.jsp.tagext.TagSupport; 25 26 /** 27 * This class implements is used inside a MessageTag to create an ordered 28 * list of arguments to use with java.text.MessageFormat. 29 * <P> 30 * <H2>Examples</H2> 31 * <PRE> 32 * <i18n:getMessage key="test"/> 33 * <i18n:msgArg value="<%= test %>"/> 34 * <i18n:msgArg value="<%= test %>"/> 35 * </i18n:getMessage> 36 * etc... 37 * </PRE> 38 * <P> 39 * @see org.apache.taglibs.i18n.MessageTag 40 * @see java.text.MessageFormat 41 * 42 * @author <a HREF="mailto:tdawson@wamnet.com">Tim Dawson</a> 43 * 44 */ 45 public class MessageArgumentTag extends TagSupport 46 { 47 48 /** 49 * locate the parent tag and add the argument to the Message's arg list 50 */ 51 public void setValue(Object argumentValue) throws JspException 52 { 53 // Get the parent MessageTag 54 MessageTag messageTag = null; 55 try { 56 messageTag = (MessageTag)this.getParent(); 57 } catch (ClassCastException e) { 58 ; 59 } 60 61 if ( messageTag == null ) { 62 throw new JspTagException( 63 "i18n:msgArg tag must be nested inside a message tag."); 64 } 65 66 // now we know we're safe to add the argument 67 messageTag.addArg(argumentValue); 68 } 69 70 } 71