KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > portlet > forums > commands > post > PostTools


1 /*****************************************
2  * *
3  * JBoss Portal: The OpenSource Portal *
4  * *
5  * Forums JBoss Portlet *
6  * *
7  * Distributable under GPL license. *
8  * See terms of license at gnu.org. *
9  * *
10  *****************************************/

11 package org.jboss.portlet.forums.commands.post;
12
13 import java.util.Iterator JavaDoc;
14
15 import org.jboss.portlet.forums.commands.CommandConstants;
16 import org.jboss.portlet.forums.commands.ValidationException;
17 import org.jboss.portlet.forums.helper.ForumsTools;
18 import org.jboss.portlet.forums.model.Message;
19 import org.jboss.portlet.forums.model.Poll;
20
21 /**
22  * @author <a HREF="mailto:julien@jboss.org">Julien Viet</a>
23  * @version $Revision: 1.2 $
24  */

25 public class PostTools
26 {
27    /**
28     * DOCUMENT_ME
29     *
30     * @param message DOCUMENT_ME
31     *
32     * @throws ValidationException DOCUMENT_ME
33     */

34    public static void validate(Message message)
35    throws ValidationException
36    {
37       if (ForumsTools.isNullOrBlank(message.getSubject()))
38       {
39          throw new ValidationException(CommandConstants.TYPE_INVALID_POST_SUBJECT);
40       }
41
42       if (ForumsTools.isNullOrBlank(message.getText()))
43       {
44          throw new ValidationException(CommandConstants.TYPE_INVALID_POST_MESSAGE);
45       }
46
47       // if (BBTools.isNullOrBlank(message.userName))
48
// {
49
// message.userName = "";
50
// }
51
}
52
53    /**
54     * DOCUMENT_ME
55     *
56     * @param poll DOCUMENT_ME
57     *
58     * @throws ValidationException DOCUMENT_ME
59     */

60    public static void validate(Poll poll)
61    throws ValidationException
62    {
63       // if (isNullOrBlank(poll.title))
64
// {
65
// throw new ValidationException(CommandConstants.TYPE_INVALID_POLL_TITLE);
66
// }
67
// if (poll.options.size() < 2)
68
// {
69
// throw new ValidationException(CommandConstants.TYPE_TOO_FEW_POLL_OPTION);
70
// }
71
if (poll.getOptions().size() > 10) // $board_config['max_poll_options']
72
{
73          throw new ValidationException(CommandConstants.TYPE_TOO_MANY_POLL_OPTION);
74       }
75
76       for (Iterator JavaDoc i = poll.getOptions().iterator(); i.hasNext();)
77       {
78          String JavaDoc txt = (String JavaDoc) i.next();
79          if (ForumsTools.isNullOrBlank(txt))
80          {
81             throw new ValidationException(CommandConstants.TYPE_INVALID_POLL_OPTION);
82          }
83       }
84    }
85 }
Popular Tags