KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > core > BundleActionMessage


1 /*
2  * SSL-Explorer
3  *
4  * Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */

19             
20 package com.sslexplorer.core;
21
22 import org.apache.struts.action.ActionMessage;
23
24 /**
25  * An extension of the standard struts
26  * {@link org.apache.struts.action.ActionMessage} that allows a resource bundle
27  * ID to be supplied at the point of creating the message instead of inside the
28  * JSP page.
29  * <p>
30  * In the JSP you <i>must</i> use the tag <b>sslexplorer:messages</b>, using
31  * the standard struts tag will result in an attemp to get the resources from
32  * the bundle specified in the tag (which may or may not work).
33  * <p>
34  * This is useful for generic message that may occur on any page at any time.
35  *
36  * @author Brett Smith <a HREF="mailto: brett@3sp.com">&lt;brett@3sp.com&gt;</a>
37  * @see com.sslexplorer.core.tags.BundleMessagesTag
38  */

39 public class BundleActionMessage extends ActionMessage {
40
41     private static final long serialVersionUID = -3827880344627981596L;
42
43     // Private instance variables
44

45     private String JavaDoc bundle;
46
47     /**
48      * Constructor
49      *
50      * @param bundle message bundle id
51      * @param key message key
52      */

53     public BundleActionMessage(String JavaDoc bundle, String JavaDoc key) {
54         super(key);
55         init(bundle);
56     }
57
58     /**
59      * Constructor
60      *
61      * @param bundle message bundle id
62      * @param key message key
63      * @param value0 first argument value
64      */

65     public BundleActionMessage(String JavaDoc bundle, String JavaDoc key, Object JavaDoc value0) {
66         super(key, value0);
67         init(bundle);
68     }
69
70     /**
71      * Constructor
72      *
73      * @param bundle message bundle id
74      * @param key message key
75      * @param value0 first argument value
76      * @param value1 argument 0 value
77      */

78     public BundleActionMessage(String JavaDoc bundle, String JavaDoc key, Object JavaDoc value0, Object JavaDoc value1) {
79         super(key, value0, value1);
80         init(bundle);
81     }
82
83     /**
84      * Constructor
85      *
86      * @param bundle message bundle id
87      * @param key message key
88      * @param value0 first argument value
89      * @param value1 argument 0 value
90      * @param value2 argument 0 value
91      */

92     public BundleActionMessage(String JavaDoc bundle, String JavaDoc key, Object JavaDoc value0, Object JavaDoc value1, Object JavaDoc value2) {
93         super(key, value0, value1, value2);
94         init(bundle);
95     }
96
97     /**
98      * Constructor
99      *
100      * @param bundle message bundle id
101      * @param key message key
102      * @param value0 argument 0 value
103      * @param value1 argument 0 value
104      * @param value2 argument 0 value
105      * @param value3 argument 0 value
106      */

107     public BundleActionMessage(String JavaDoc bundle, String JavaDoc key, Object JavaDoc value0, Object JavaDoc value1, Object JavaDoc value2, Object JavaDoc value3) {
108         super(key, value0, value1, value2, value3);
109         init(bundle);
110     }
111
112     /**
113      * Constructor
114      *
115      * @param bundle message bundle id
116      * @param key message key
117      * @param values all argument value
118      */

119     public BundleActionMessage(String JavaDoc bundle, String JavaDoc key, Object JavaDoc[] values) {
120         super(key, values);
121         init(bundle);
122     }
123
124     protected void init(String JavaDoc bundle) {
125         this.bundle = bundle;
126     }
127
128     /**
129      * Get the value of argument 0
130      *
131      * @return value of argument 0
132      */

133     public String JavaDoc getArg0() {
134         return values != null && values.length > 0 ? String.valueOf(values[0]) : null;
135     }
136
137     /**
138      * Get the value of argument 1
139      *
140      * @return value of argument 1
141      */

142     public String JavaDoc getArg1() {
143         return values != null && values.length > 1 ? String.valueOf(values[1]) : null;
144     }
145
146     /**
147      * Get the value of argument 2
148      *
149      * @return value of argument 2
150      */

151     public String JavaDoc getArg2() {
152         return values != null && values.length > 2 ? String.valueOf(values[2]) : null;
153     }
154
155     /**
156      * Get the value of argument 3
157      *
158      * @return value of argument 3
159      */

160     public String JavaDoc getArg3() {
161         return values != null && values.length > 3 ? String.valueOf(values[3]) : null;
162     }
163
164     /**
165      * Get the message bundle id where this message is displayed.
166      *
167      * @return message bundle id
168      */

169     public String JavaDoc getBundle() {
170         return bundle;
171     }
172
173     /**
174      * Set the message bundle id where this message is displayed.
175      *
176      * @param bundle message bundle id
177      */

178     public void setBundle(String JavaDoc bundle) {
179         this.bundle = bundle;
180     }
181
182     /**
183      * Set arguent 0.
184      *
185      * @param arg0 argument 0
186      */

187     public void setArg0(Object JavaDoc arg0) {
188         if (values == null || values.length == 0) {
189             values = new Object JavaDoc[1];
190         }
191         values[0] = arg0;
192     }
193
194     /**
195      * Set arguent 1.
196      *
197      * @param arg1 argument 1
198      */

199     public void setArg1(Object JavaDoc arg1) {
200         if (values == null || values.length < 2) {
201             values = new Object JavaDoc[] { values == null ? null : values[0], arg1 };
202         } else {
203             values[1] = arg1;
204         }
205     }
206
207     /**
208      * Set arguent 2.
209      *
210      * @param arg2 argument 2
211      */

212     public void setArg2(Object JavaDoc arg2) {
213         if (values == null || values.length < 3) {
214             values = new Object JavaDoc[] { values == null ? null : values[0], values == null ? null : values[1], arg2 };
215         } else {
216             values[2] = arg2;
217         }
218     }
219
220     /**
221      * Set arguent 3.
222      *
223      * @param arg3 argument 3
224      */

225     public void setArg3(Object JavaDoc arg3) {
226         if (values == null || values.length < 4) {
227             values = new Object JavaDoc[] { values == null ? null : values[0],
228                 values == null ? null : values[1],
229                 values == null ? null : values[2],
230                 arg3 };
231         } else {
232             values[3] = arg3;
233         }
234     }
235 }
236
Popular Tags