KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > dbforms > taglib > MessageTag


1 /*
2  * $Header: /cvsroot/jdbforms/dbforms/src/org/dbforms/taglib/MessageTag.java,v 1.13 2004/08/18 12:26:08 hkollmann Exp $
3  * $Revision: 1.13 $
4  * $Date: 2004/08/18 12:26:08 $
5  *
6  * DbForms - a Rapid Application Development Framework
7  * Copyright (C) 2001 Joachim Peer <joepeer@excite.com>
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22  */

23
24 package org.dbforms.taglib;
25
26 import org.dbforms.util.MessageResources;
27
28 import java.util.Locale JavaDoc;
29 import java.util.StringTokenizer JavaDoc;
30
31 import javax.servlet.http.HttpServletRequest JavaDoc;
32 import javax.servlet.jsp.JspException JavaDoc;
33
34
35
36 /**
37  * 2002-09-23 HKK: Extented to support parameters
38  */

39 public class MessageTag extends TagSupportWithScriptHandler
40    implements javax.servlet.jsp.tagext.TryCatchFinally JavaDoc {
41    private String JavaDoc key = null;
42    private String JavaDoc param = null;
43
44    /**
45     * DOCUMENT ME!
46     *
47     * @param newKey DOCUMENT ME!
48     */

49    public void setKey(String JavaDoc newKey) {
50       key = newKey;
51    }
52
53
54    /**
55     * DOCUMENT ME!
56     *
57     * @return DOCUMENT ME!
58     */

59    public String JavaDoc getKey() {
60       return key;
61    }
62
63
64    /**
65     * DOCUMENT ME!
66     *
67     * @param newParam DOCUMENT ME!
68     */

69    public void setParam(String JavaDoc newParam) {
70       param = newParam;
71    }
72
73
74    /**
75     * DOCUMENT ME!
76     *
77     * @return DOCUMENT ME!
78     */

79    public String JavaDoc getParam() {
80       return param;
81    }
82
83
84    /**
85     * DOCUMENT ME!
86     *
87     * @param t DOCUMENT ME!
88     *
89     * @throws Throwable DOCUMENT ME!
90     */

91    public void doCatch(Throwable JavaDoc t) throws Throwable JavaDoc {
92       throw t;
93    }
94
95
96    /**
97     * DOCUMENT ME!
98     *
99     * @return DOCUMENT ME!
100     *
101     * @throws JspException DOCUMENT ME!
102     */

103    public int doEndTag() throws JspException JavaDoc {
104       if (getKey() != null) {
105          Locale JavaDoc locale = MessageResources.getLocale((HttpServletRequest JavaDoc) pageContext
106                                                     .getRequest());
107          String JavaDoc message;
108
109          if ((param == null) || (param.length() == 0)) {
110             message = MessageResources.getMessage(getKey(), locale);
111          } else {
112             message = MessageResources.getMessage(getKey(), locale,
113                                                   splitString(param, ","));
114          }
115
116          try {
117             if (message != null) {
118                pageContext.getOut()
119                           .write(message);
120             } else {
121                pageContext.getOut()
122                           .write(getKey());
123
124                if (param != null) {
125                   pageContext.getOut()
126                              .write("&nbsp;");
127                   pageContext.getOut()
128                              .write(param);
129                }
130             }
131          } catch (java.io.IOException JavaDoc ioe) {
132             throw new JspException JavaDoc("IO Error: " + ioe.getMessage());
133          }
134       }
135
136       return EVAL_PAGE;
137    }
138
139
140    /**
141     * DOCUMENT ME!
142     */

143    public void doFinally() {
144       key = null;
145       param = null;
146    }
147
148
149    /**
150     * DOCUMENT ME!
151     *
152     * @return DOCUMENT ME!
153     *
154     * @throws javax.servlet.jsp.JspException DOCUMENT ME!
155     */

156    public int doStartTag() throws javax.servlet.jsp.JspException JavaDoc {
157       return SKIP_BODY;
158    }
159
160
161    private String JavaDoc[] splitString(String JavaDoc str,
162                                 String JavaDoc delimeter) {
163       StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(str, delimeter);
164       int i = 0;
165       String JavaDoc[] result = new String JavaDoc[st.countTokens()];
166
167       while (st.hasMoreTokens()) {
168          result[i] = st.nextToken();
169          i++;
170       }
171
172       return result;
173    }
174 }
175
Popular Tags