KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > j2biz > blogunity > web > taglibs > I18NTag


1 /*
2  * $Id: I18NTag.java,v 1.3 2005/01/17 11:21:24 keyboardsamurai Exp $
3  *
4  * Copyright (c) 2004 j2biz Group, http://www.j2biz.com Koeln / Duesseldorf ,
5  * Germany
6  *
7  * @author Max Kalina
8  *
9  *
10  * This program is free software; you can redistribute it and/or modify it under
11  * the terms of the GNU General Public License as published by the Free Software
12  * Foundation; either version 2 of the License, or (at your option) any later
13  * version.
14  *
15  * This program is distributed in the hope that it will be useful, but WITHOUT
16  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License along with
21  * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
22  * Place, Suite 330, Boston, MA 02111-1307 USA
23  *
24  */

25
26 package com.j2biz.blogunity.web.taglibs;
27
28 import java.io.IOException JavaDoc;
29 import java.util.Locale JavaDoc;
30
31 import javax.servlet.http.HttpServletRequest JavaDoc;
32 import javax.servlet.jsp.JspException JavaDoc;
33 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
34
35 import org.apache.commons.lang.StringUtils;
36
37 import com.j2biz.blogunity.IConstants;
38 import com.j2biz.blogunity.exception.BlogunityRuntimeException;
39 import com.j2biz.blogunity.i18n.I18N;
40 import com.j2biz.blogunity.i18n.I18NMessageManager;
41 import com.j2biz.blogunity.i18n.I18NStatusFactory;
42
43 public class I18NTag extends TagSupport JavaDoc {
44
45     /**
46      * Comment for <code>serialVersionUID</code>
47      */

48     private static final long serialVersionUID = 3257001073016387897L;
49
50     private String JavaDoc key;
51
52     private String JavaDoc params;
53
54     /*
55      * (non-Javadoc)
56      *
57      * @see javax.servlet.jsp.tagext.TagSupport#doStartTag()
58      */

59     public int doStartTag() throws JspException JavaDoc {
60
61         HttpServletRequest JavaDoc request = (HttpServletRequest JavaDoc) pageContext.getRequest();
62         Locale JavaDoc currentLocale = (Locale JavaDoc) request.getAttribute(IConstants.Request.LOCALE);
63
64         String JavaDoc[] _params = new String JavaDoc[]{};
65         if (StringUtils.isNotEmpty(params)) {
66             _params = (String JavaDoc[]) request.getAttribute(params);
67         }
68
69         String JavaDoc msg = I18NMessageManager.getInstance().getMessage(getKey(), _params, currentLocale);
70
71         try {
72             pageContext.getOut().print(msg);
73         } catch (IOException JavaDoc e) {
74             throw new BlogunityRuntimeException(I18NStatusFactory.create(
75                     I18N.ERRORS.TAGLIB_RENDERING, e));
76         }
77
78         return SKIP_BODY;
79     }
80
81     /*
82      * (non-Javadoc)
83      *
84      * @see javax.servlet.jsp.tagext.TagSupport#doEndTag()
85      */

86     public int doEndTag() throws JspException JavaDoc {
87         return EVAL_PAGE;
88     }
89
90     public String JavaDoc getKey() {
91         return key;
92     }
93
94     public void setKey(String JavaDoc key) {
95         this.key = key;
96     }
97
98     public String JavaDoc getParams() {
99         return params;
100     }
101
102     public void setParams(String JavaDoc params) {
103         this.params = params;
104     }
105 }
Popular Tags