KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > input > tags > AbstractMultiFieldTag


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.input.tags;
21
22 import javax.servlet.jsp.JspException JavaDoc;
23
24 import org.apache.struts.taglib.TagUtils;
25 import org.apache.struts.taglib.html.BaseFieldTag;
26 import org.apache.struts.util.MessageResources;
27
28 public class AbstractMultiFieldTag extends BaseFieldTag {
29     protected String JavaDoc targetTitleKey;
30     protected String JavaDoc addKey;
31     protected String JavaDoc removeKey;
32     protected String JavaDoc upKey;
33     protected String JavaDoc downKey;
34     protected String JavaDoc configureKey;
35     protected String JavaDoc configureOnClick;
36     protected boolean disabled;
37     protected boolean allowReordering;
38
39     /**
40      * The message resources for this package.
41      */

42     protected static MessageResources messages =
43         MessageResources.getMessageResources(
44             "org.apache.struts.taglib.bean.LocalStrings");
45     
46     public AbstractMultiFieldTag() {
47         super();
48         // TODO Auto-generated constructor stub
49
}
50
51     /**
52      * @return Returns the targetTitleKey.
53      */

54     public String JavaDoc getTargetTitleKey() {
55         return targetTitleKey;
56     }
57
58     /**
59      * @return Returns the addKey.
60      */

61     public String JavaDoc getAddKey() {
62         return addKey;
63     }
64
65     /**
66      * @return Returns the downKey.
67      */

68     public String JavaDoc getDownKey() {
69         return downKey;
70     }
71
72     /**
73      * @param downKey The downKey to set.
74      */

75     public void setDownKey(String JavaDoc downKey) {
76         this.downKey = downKey;
77     }
78
79     /**
80      * @return Returns the upKey.
81      */

82     public String JavaDoc getUpKey() {
83         return upKey;
84     }
85
86     /**
87      * @param upKey The upKey to set.
88      */

89     public void setUpKey(String JavaDoc upKey) {
90         this.upKey = upKey;
91     }
92
93     /**
94      * @param addKey The addKey to set.
95      */

96     public void setAddKey(String JavaDoc addKey) {
97         this.addKey = addKey;
98     }
99
100     /**
101      * @return Returns the removeKey.
102      */

103     public String JavaDoc getRemoveKey() {
104         return removeKey;
105     }
106
107     /**
108      * @param removeKey The removeKey to set.
109      */

110     public void setRemoveKey(String JavaDoc removeKey) {
111         this.removeKey = removeKey;
112     }
113
114     /**
115      * @param targetTitleKey The targetTitleKey to set.
116      */

117     public void setTargetTitleKey(String JavaDoc targetTitleKey) {
118         this.targetTitleKey = targetTitleKey;
119     }
120     
121     protected String JavaDoc prepareTargetTitle() throws JspException JavaDoc {
122
123         if(targetTitleKey != null) {
124             String JavaDoc targetTitle =
125                 TagUtils.getInstance().message(
126                 pageContext,
127                 getBundle(),
128                 getLocale(),
129                 targetTitleKey,
130                 new String JavaDoc[] { });
131             
132             if (targetTitle == null) {
133                 JspException JavaDoc e =
134                     new JspException JavaDoc(
135                         messages.getMessage("message.message", "\"" + targetTitleKey + "\""));
136                 TagUtils.getInstance().saveException(pageContext, e);
137                 throw e;
138             }
139             return targetTitle;
140         }
141         return null;
142     }
143     
144     protected String JavaDoc renderConfigureComponent() throws JspException JavaDoc {
145         StringBuffer JavaDoc results = new StringBuffer JavaDoc("<input class=\"configure\" onclick=\"");
146         results.append(configureOnClick);
147         results.append("\" type=\"button\" value=\"");
148         results.append(prepareConfigure());
149         results.append("\"");
150         results.append(prepareDisabled());
151         results.append("/>");
152         return results.toString();
153     }
154     
155     protected String JavaDoc renderUpComponent() throws JspException JavaDoc {
156         StringBuffer JavaDoc results = new StringBuffer JavaDoc("<input class=\"multiUp\"");
157         results.append(prepareDisabled());
158         results.append(" onclick=\"multiMoveUp(");
159         results.append("document.getElementById('");
160         if (indexed) {
161             this.prepareIndex(results, name);
162         }
163         results.append(property);
164         results.append("'), document.getElementById('");
165         results.append(prepareTargetId());
166         results.append("'));\" type=\"button\" value=\"");
167         results.append(prepareUp());
168         results.append("\"/>");
169         return results.toString();
170     }
171     
172     protected String JavaDoc renderDownComponent() throws JspException JavaDoc {
173         StringBuffer JavaDoc results = new StringBuffer JavaDoc("<input class=\"multiDown\"");
174         results.append(prepareDisabled());
175         results.append(" onclick=\"multiMoveDown(");
176         results.append("document.getElementById('");
177         if (indexed) {
178             this.prepareIndex(results, name);
179         }
180         results.append(property);
181         results.append("'), document.getElementById('");
182         results.append(prepareTargetId());
183         results.append("'));\" type=\"button\" value=\"");
184         results.append(prepareDown());
185         results.append("\"/>");
186         return results.toString();
187     }
188     
189     protected String JavaDoc prepareDisabled() {
190         if(isDisabled()) {
191             return " disabled=\"disabled\"";
192         }
193         else {
194             return "";
195         }
196     }
197     
198     protected String JavaDoc prepareConfigure() throws JspException JavaDoc {
199
200         if(addKey != null) {
201             String JavaDoc configure =
202                 TagUtils.getInstance().message(
203                 pageContext,
204                 getBundle(),
205                 getLocale(),
206                 configureKey,
207                 new String JavaDoc[] { });
208             
209             if (configureKey == null) {
210                 JspException JavaDoc e =
211                     new JspException JavaDoc(
212                         messages.getMessage("message.message", "\"" + addKey + "\""));
213                 TagUtils.getInstance().saveException(pageContext, e);
214                 throw e;
215             }
216             return configure;
217         }
218         return ">>";
219     }
220     
221     protected String JavaDoc prepareAdd() throws JspException JavaDoc {
222
223         if(addKey != null) {
224             String JavaDoc add =
225                 TagUtils.getInstance().message(
226                 pageContext,
227                 getBundle(),
228                 getLocale(),
229                 addKey,
230                 new String JavaDoc[] { });
231             
232             if (addKey == null) {
233                 JspException JavaDoc e =
234                     new JspException JavaDoc(
235                         messages.getMessage("message.message", "\"" + addKey + "\""));
236                 TagUtils.getInstance().saveException(pageContext, e);
237                 throw e;
238             }
239             return add;
240         }
241         return ">>";
242     }
243     
244     protected String JavaDoc prepareUp() throws JspException JavaDoc {
245
246         if(upKey != null) {
247             String JavaDoc up =
248                 TagUtils.getInstance().message(
249                 pageContext,
250                 getBundle(),
251                 getLocale(),
252                 upKey,
253                 new String JavaDoc[] { });
254             
255             if (upKey == null) {
256                 JspException JavaDoc e =
257                     new JspException JavaDoc(
258                         messages.getMessage("message.message", "\"" + upKey + "\""));
259                 TagUtils.getInstance().saveException(pageContext, e);
260                 throw e;
261             }
262             return up;
263         }
264         return "Up";
265     }
266     
267     protected String JavaDoc prepareDown() throws JspException JavaDoc {
268
269         if(downKey != null) {
270             String JavaDoc down =
271                 TagUtils.getInstance().message(
272                 pageContext,
273                 getBundle(),
274                 getLocale(),
275                 downKey,
276                 new String JavaDoc[] { });
277             
278             if (downKey == null) {
279                 JspException JavaDoc e =
280                     new JspException JavaDoc(
281                         messages.getMessage("message.message", "\"" + downKey + "\""));
282                 TagUtils.getInstance().saveException(pageContext, e);
283                 throw e;
284             }
285             return down;
286         }
287         return "Down";
288     }
289     
290     protected String JavaDoc prepareRemove() throws JspException JavaDoc {
291
292         if(removeKey != null) {
293             String JavaDoc remove =
294                 TagUtils.getInstance().message(
295                 pageContext,
296                 getBundle(),
297                 getLocale(),
298                 removeKey,
299                 new String JavaDoc[] { });
300             
301             if (remove == null) {
302                 JspException JavaDoc e =
303                     new JspException JavaDoc(
304                         messages.getMessage("message.message", "\"" + removeKey + "\""));
305                 TagUtils.getInstance().saveException(pageContext, e);
306                 throw e;
307             }
308             return remove;
309         }
310         return "<<";
311     }
312     
313     protected String JavaDoc prepareTargetId() throws JspException JavaDoc {
314         StringBuffer JavaDoc results = new StringBuffer JavaDoc("targetValues_");
315         if(indexed) {
316             prepareIndex(results, name);
317         }
318         results.append(property);
319         return results.toString();
320     }
321
322     /**
323      * @param configureKey The configureKey to set.
324      */

325     public void setConfigureKey(String JavaDoc configureKey) {
326         this.configureKey = configureKey;
327     }
328
329     /**
330      * @param configureOnClick The configureOnClick to set.
331      */

332     public void setConfigureOnClick(String JavaDoc configureOnClick) {
333         this.configureOnClick = configureOnClick;
334     }
335     
336     public void setDisabled(boolean disabled) {
337         this.disabled = disabled;
338     }
339     
340     public boolean isDisabled() {
341         return disabled;
342     }
343
344     public boolean isAllowReordering() {
345         return allowReordering;
346     }
347
348     public void setAllowReordering(boolean allowReordering) {
349         this.allowReordering = allowReordering;
350     }
351
352     /* (non-Javadoc)
353      * @see org.apache.struts.taglib.html.BaseFieldTag#release()
354      */

355     public void release() {
356         super.release();
357         targetTitleKey = null;
358         addKey = null;
359         removeKey = null;
360         upKey = null;
361         downKey = null;
362         configureKey = null;
363         configureOnClick = null;
364         disabled = false;
365         allowReordering = false;
366     }
367 }
368
Popular Tags