KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > taglibs > i18n > MessageArgumentTag


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 JavaDoc;
20
21 import javax.servlet.jsp.JspException JavaDoc;
22 import javax.servlet.jsp.JspTagException JavaDoc;
23 import javax.servlet.jsp.tagext.Tag JavaDoc;
24 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
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  * &lt;i18n:getMessage key="test"/&gt;
33  * &lt;i18n:msgArg value="&lt;%= test %&gt;"/&gt;
34  * &lt;i18n:msgArg value="&lt;%= test %&gt;"/&gt;
35  * &lt;/i18n:getMessage&gt;
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 JavaDoc
46 {
47   
48     /**
49      * locate the parent tag and add the argument to the Message's arg list
50      */

51     public void setValue(Object JavaDoc argumentValue) throws JspException JavaDoc
52     {
53         // Get the parent MessageTag
54
MessageTag messageTag = null;
55         try {
56             messageTag = (MessageTag)this.getParent();
57         } catch (ClassCastException JavaDoc e) {
58             ;
59         }
60
61         if ( messageTag == null ) {
62             throw new JspTagException JavaDoc(
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
Popular Tags