KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > quikj > application > communicator > applications > webtalk > controller > GroupWizardCannedMessageForm


1 /*
2  * GroupWizardCannedMessageInfoForm.java
3  *
4  * Created on March 28, 2004, 10:28 PM
5  */

6
7 package com.quikj.application.communicator.applications.webtalk.controller;
8
9 import javax.servlet.http.HttpServletRequest JavaDoc;
10 import org.apache.struts.action.*;
11 import org.apache.struts.util.*;
12 import java.util.*;
13 import java.sql.*;
14 import java.net.*;
15 import com.quikj.server.framework.*;
16 import com.quikj.application.communicator.applications.webtalk.model.*;
17
18 /**
19  *
20  * @author bhm
21  */

22 public class GroupWizardCannedMessageForm extends ActionForm
23 {
24
25     /** Holds value of property counter. */
26     private int counter = 0;
27
28     /** Holds value of property messageType. */
29     private String JavaDoc messageType = "text";
30
31     /** Holds value of property content. */
32     private String JavaDoc content;
33
34     /** Holds value of property description. */
35     private String JavaDoc description;
36
37     /** Holds value of property group. */
38     private String JavaDoc group;
39
40     /** Holds value of property submit. */
41     private String JavaDoc submit;
42
43     /** Holds value of property userGroups. */
44     private ArrayList userGroups = new ArrayList();
45
46     /** Holds value of property domain. */
47     private String JavaDoc domain;
48
49     /** Creates a new instance of GroupWizardCannedMessageInfoForm */
50     public GroupWizardCannedMessageForm()
51     {
52     }
53
54     public ActionErrors validate(ActionMapping mapping,
55             HttpServletRequest JavaDoc request)
56     {
57         if ((submit.startsWith("Finished") == true)
58                 || (submit.startsWith("Cancel") == true))
59         {
60             return null;
61         }
62
63         // Check for mandatory data
64
ActionErrors errors = new ActionErrors();
65         try
66         {
67             if ((group == null) || (group.length() == 0))
68             {
69                 errors.add("group", new ActionError(
70                         "error.cannedmessage.no.group"));
71             }
72
73             if ((description == null) || (description.length() == 0))
74             {
75                 errors.add("description", new ActionError(
76                         "error.cannedmessage.no.description"));
77             }
78
79             if ((content == null) || (content.length() == 0))
80             {
81                 errors.add("content", new ActionError(
82                         "error.cannedmessage.no.content"));
83             }
84
85             try
86             {
87                 URL url = new URL(content);
88             }
89             catch (MalformedURLException ex)
90             {
91                 try
92                 {
93                     // assume that it is HTTP
94
URL url = new URL("http://" + content);
95                 }
96                 catch (MalformedURLException ex1)
97                 {
98                     errors.add("content", new ActionError(
99                             "error.cannedmessage.invalid.url"));
100                 }
101             }
102
103             if (errors.isEmpty() == false)
104             {
105                 GroupTable groups = new GroupTable();
106                 Connection c = (Connection) request.getSession().getAttribute(
107                         "connection");
108
109                 groups.setConnection(c);
110                 ArrayList group_list = groups.list(domain);
111
112                 if (group_list != null)
113                 {
114                     ArrayList list = new ArrayList();
115                     Iterator iter = group_list.iterator();
116
117                     while (iter.hasNext() == true)
118                     {
119                         String JavaDoc group = (String JavaDoc) iter.next();
120
121                         if (group.equals(domain) == false)
122                         {
123                             list.add(new LabelValueBean(group, URLEncoder
124                                     .encode(group, "UTF-8")));
125                         }
126                         else
127                         {
128                             list.add(0, new LabelValueBean(
129                                     "All of this customer's groups", URLEncoder
130                                             .encode(group, "UTF-8")));
131                         }
132                     }
133
134                     setUserGroups(list);
135                 }
136             }
137         }
138         catch (Exception JavaDoc e)
139         {
140             errors.add("content", new ActionError("error.internal.error"));
141         }
142         return errors;
143     }
144
145     /**
146      * Getter for property counter.
147      *
148      * @return Value of property counter.
149      *
150      */

151     public int getCounter()
152     {
153         return this.counter;
154     }
155
156     /**
157      * Setter for property counter.
158      *
159      * @param counter
160      * New value of property counter.
161      *
162      */

163     public void setCounter(int counter)
164     {
165         this.counter = counter;
166     }
167
168     /**
169      * Getter for property messageType.
170      *
171      * @return Value of property messageType.
172      *
173      */

174     public String JavaDoc getMessageType()
175     {
176         return this.messageType;
177     }
178
179     /**
180      * Setter for property messageType.
181      *
182      * @param messageType
183      * New value of property messageType.
184      *
185      */

186     public void setMessageType(String JavaDoc messageType)
187     {
188         this.messageType = messageType.trim();
189     }
190
191     /**
192      * Getter for property content.
193      *
194      * @return Value of property content.
195      *
196      */

197     public String JavaDoc getContent()
198     {
199         return this.content;
200     }
201
202     /**
203      * Setter for property content.
204      *
205      * @param content
206      * New value of property content.
207      *
208      */

209     public void setContent(String JavaDoc content)
210     {
211         this.content = content.trim();
212     }
213
214     public String JavaDoc getFormattedContent()
215     {
216         if (messageType.equals("text") == true)
217         {
218             return ("<text>" + AceXMLHelper.encodeXMLString(content) + "</text>");
219         }
220         else if (messageType.equals("url") == true)
221         {
222             String JavaDoc loc = content;
223             try
224             {
225                 URL url = new URL(content);
226             }
227             catch (MalformedURLException ex)
228             {
229                 // assume that it is HTTP
230
loc = "http://" + content;
231             }
232
233             return ("<href>" + loc + "</href>");
234         }
235
236         return "";
237     }
238
239     /**
240      * Getter for property description.
241      *
242      * @return Value of property description.
243      *
244      */

245     public String JavaDoc getDescription()
246     {
247         return this.description;
248     }
249
250     /**
251      * Setter for property description.
252      *
253      * @param description
254      * New value of property description.
255      *
256      */

257     public void setDescription(String JavaDoc description)
258     {
259         this.description = description.trim();
260     }
261
262     /**
263      * Getter for property group.
264      *
265      * @return Value of property group.
266      *
267      */

268     public String JavaDoc getGroup()
269     {
270         return this.group;
271     }
272
273     /**
274      * Setter for property group.
275      *
276      * @param group
277      * New value of property group.
278      *
279      */

280     public void setGroup(String JavaDoc group)
281     {
282         this.group = group.trim();
283     }
284
285     /**
286      * Getter for property submit.
287      *
288      * @return Value of property submit.
289      *
290      */

291     public String JavaDoc getSubmit()
292     {
293         return this.submit;
294     }
295
296     /**
297      * Setter for property submit.
298      *
299      * @param submit
300      * New value of property submit.
301      *
302      */

303     public void setSubmit(String JavaDoc submit)
304     {
305         this.submit = submit.trim();
306     }
307
308     /**
309      * Getter for property usrGroups.
310      *
311      * @return Value of property usrGroups.
312      *
313      */

314     public ArrayList getUserGroups()
315     {
316         return this.userGroups;
317     }
318
319     /**
320      * Setter for property usrGroups.
321      *
322      * @param usrGroups
323      * New value of property usrGroups.
324      *
325      */

326     public void setUserGroups(ArrayList userGroups)
327     {
328         this.userGroups = userGroups;
329     }
330
331     /**
332      * Getter for property domain.
333      *
334      * @return Value of property domain.
335      *
336      */

337     public String JavaDoc getDomain()
338     {
339         return this.domain;
340     }
341
342     /**
343      * Setter for property domain.
344      *
345      * @param domain
346      * New value of property domain.
347      *
348      */

349     public void setDomain(String JavaDoc domain)
350     {
351         this.domain = domain.trim();
352     }
353
354 }
Popular Tags