1 43 package net.jforum.view.forum.common; 44 45 import java.util.Date ; 46 47 import net.jforum.ActionServletRequest; 48 import net.jforum.JForumExecutionContext; 49 import net.jforum.entities.Poll; 50 import net.jforum.entities.PollOption; 51 52 56 public class PollCommon 57 { 58 private PollCommon() {} 59 60 public static Poll fillPollFromRequest() throws Exception 61 { 62 ActionServletRequest request = JForumExecutionContext.getRequest(); 63 String label = request.getParameter("poll_label"); 64 65 if (label == null || label.length() == 0) { 66 return null; 67 } 68 69 Poll poll = new Poll(); 70 poll.setStartTime(new Date ()); 71 poll.setLabel(label); 72 73 int count = request.getIntParameter("poll_option_count"); 74 75 for (int i = 0; i <= count; i++) { 76 String option = request.getParameter("poll_option_" + i); 77 78 if (option == null) { 79 continue; 80 } 81 82 option = option.trim(); 83 84 if (option.length() > 0) { 85 PollOption po = new PollOption(); 86 po.setId(i); 87 po.setText(option); 88 poll.addOption(po); 89 } 90 } 91 92 String pollLength = request.getParameter("poll_length"); 93 94 if (pollLength != null && pollLength.length() > 0) { 95 poll.setLength(Integer.parseInt(pollLength)); 96 } 97 98 return poll; 99 } 100 } 101 | Popular Tags |