1 11 package org.jboss.portlet.forums.commands.post; 12 13 import java.util.Iterator ; 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 25 public class PostTools 26 { 27 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 } 52 53 60 public static void validate(Poll poll) 61 throws ValidationException 62 { 63 if (poll.getOptions().size() > 10) { 73 throw new ValidationException(CommandConstants.TYPE_TOO_MANY_POLL_OPTION); 74 } 75 76 for (Iterator i = poll.getOptions().iterator(); i.hasNext();) 77 { 78 String txt = (String ) i.next(); 79 if (ForumsTools.isNullOrBlank(txt)) 80 { 81 throw new ValidationException(CommandConstants.TYPE_INVALID_POLL_OPTION); 82 } 83 } 84 } 85 } | Popular Tags |