1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package org.dbforms.taglib;
25
26 import org.dbforms.util.MessageResources;
27
28 import java.util.Locale;
29 import java.util.StringTokenizer;
30
31 import javax.servlet.http.HttpServletRequest;
32 import javax.servlet.jsp.JspException;
33
34
35
36 /***
37 * 2002-09-23 HKK: Extented to support parameters
38 */
39 public class MessageTag extends AbstractScriptHandlerTag
40 implements javax.servlet.jsp.tagext.TryCatchFinally {
41 private String key = null;
42 private String param = null;
43
44 /***
45 * DOCUMENT ME!
46 *
47 * @param newKey DOCUMENT ME!
48 */
49 public void setKey(String newKey) {
50 key = newKey;
51 }
52
53
54 /***
55 * DOCUMENT ME!
56 *
57 * @return DOCUMENT ME!
58 */
59 public String getKey() {
60 return key;
61 }
62
63
64 /***
65 * DOCUMENT ME!
66 *
67 * @param newParam DOCUMENT ME!
68 */
69 public void setParam(String newParam) {
70 param = newParam;
71 }
72
73
74 /***
75 * DOCUMENT ME!
76 *
77 * @return DOCUMENT ME!
78 */
79 public String getParam() {
80 return param;
81 }
82
83
84 /***
85 * DOCUMENT ME!
86 *
87 * @return DOCUMENT ME!
88 *
89 * @throws JspException DOCUMENT ME!
90 */
91 public int doEndTag() throws JspException {
92 if (getKey() != null) {
93 Locale locale = MessageResources.getLocale((HttpServletRequest) pageContext
94 .getRequest());
95 String message;
96
97 if ((param == null) || (param.length() == 0)) {
98 message = MessageResources.getMessage(getKey(), locale);
99 } else {
100 message = MessageResources.getMessage(getKey(), locale,
101 splitString(param, ","));
102 }
103
104 try {
105 if (message != null) {
106 pageContext.getOut()
107 .write(message);
108 } else {
109 pageContext.getOut()
110 .write(getKey());
111
112 if (param != null) {
113 pageContext.getOut()
114 .write(" ");
115 pageContext.getOut()
116 .write(param);
117 }
118 }
119 } catch (java.io.IOException ioe) {
120 throw new JspException("IO Error: " + ioe.getMessage());
121 }
122 }
123
124 return EVAL_PAGE;
125 }
126
127
128 /***
129 * DOCUMENT ME!
130 */
131 public void doFinally() {
132 key = null;
133 param = null;
134 }
135
136
137 /***
138 * DOCUMENT ME!
139 *
140 * @return DOCUMENT ME!
141 *
142 * @throws javax.servlet.jsp.JspException DOCUMENT ME!
143 */
144 public int doStartTag() throws javax.servlet.jsp.JspException {
145 return SKIP_BODY;
146 }
147
148
149 private String[] splitString(String str,
150 String delimeter) {
151 StringTokenizer st = new StringTokenizer(str, delimeter);
152 int i = 0;
153 String[] result = new String[st.countTokens()];
154
155 while (st.hasMoreTokens()) {
156 result[i] = st.nextToken();
157 i++;
158 }
159
160 return result;
161 }
162 }