1 25 26 package net.killingar.forum.actions; 27 28 import net.killingar.Utils; 29 import net.killingar.forum.internal.Poll; 30 import net.killingar.forum.internal.PollAlternative; 31 import net.killingar.forum.internal.PollAnswer; 32 import net.killingar.forum.internal.Quote; 33 import net.killingar.forum.internal.managers.OptionsManager; 34 import net.killingar.forum.internal.managers.PollManager; 35 import net.killingar.forum.internal.managers.QuoteManager; 36 37 import java.util.ArrayList ; 38 import java.util.List ; 39 40 public class ViewWelcome 41 extends ActionForumSupport 42 { 43 Quote quote; 45 Poll poll; 46 List pollAlternatives; 47 long totalNumberOfAnswers; 48 boolean vote; 49 long selectedID; 50 List invites; 51 52 static class PollAlternativeData 54 { 55 PollAlternative alternative; 56 int width; 57 String barURL; 58 boolean selected; 59 double percent; 60 61 public PollAlternativeData(PollAlternative alternative, double percent, int width, String barURL, boolean selected) 62 { 63 this.alternative = alternative; 64 this.percent = percent; 65 this.width = width; 66 this.barURL = barURL; 67 this.selected = selected; 68 } 69 70 public PollAlternative getAlternative() { return alternative; } 71 public int getWidth() { return width; } 72 public String getBarURL() { return barURL; } 73 public boolean getSelected() { return selected; } 74 public double getPercent() { return percent; } 75 } 76 77 79 public Quote getQuote() { return quote; } 81 public Poll getPoll() { return poll; } 82 public List getPollAlternatives() { return pollAlternatives; } 83 public long getTotalNumberOfAnswers() { return totalNumberOfAnswers; } 84 public long getSelectedID() { return selectedID; } 85 public boolean getVote() { return vote; } 86 public List getInvites() { return invites; } 87 protected String doExecute() 89 { 90 try 91 { 92 OptionsManager options = (OptionsManager)manager.getManager(OptionsManager.class.getName()); 94 String barImageURL = options.get("bar image"); 95 96 quote = ((QuoteManager)manager.getManager(QuoteManager.class.getName())).getRandomQuote(); 98 99 invites = manager.getInvites(); 101 102 if (!"true".equals(Utils.getProperties().get(getClass().getName()+".hidePoll"))) 104 { 105 PollManager pollmgr = (PollManager)manager.getManager(PollManager.class.getName()); 106 poll = pollmgr.getRandomUnAnsweredPoll(); 107 if (poll == null) { 109 vote = false; 110 111 poll = pollmgr.getRandomPoll(); 112 } 113 else vote = true; 115 116 if (poll != null) 117 { 118 PollAlternative pollAlternativesData[] = pollmgr.getPollAlternatives(poll.getId()); 119 selectedID = 0; 120 { 121 PollAnswer foo = pollmgr.getMyAnswer(poll.ID); 122 if (foo != null) 123 selectedID = foo.pollAlternativeID; 124 } 125 126 pollAlternatives = new ArrayList (); 127 128 totalNumberOfAnswers = 0; 129 for (int i = 0; i < pollAlternativesData.length; i++) 130 totalNumberOfAnswers += pollAlternativesData[i].numberOfAnswers; 131 132 for (int i = 0; i < pollAlternativesData.length; i++) 133 { 134 double percent = (totalNumberOfAnswers == 0)?0:(double)((int)((double)pollAlternativesData[i].numberOfAnswers/totalNumberOfAnswers*1000))/10; 135 int width = (int)(percent*2)+1; 136 String barURL = pollAlternativesData[i].color.equals("722899")?barImageURL:"servlet/Pixel?"+pollAlternativesData[i].color; 137 138 pollAlternatives.add(new PollAlternativeData( 139 pollAlternativesData[i], 140 percent, 141 width, 142 barURL, 143 selectedID == pollAlternativesData[i].ID 144 )); 145 } 146 } 147 } 148 149 return SUCCESS; 150 } 151 catch (Exception e) 152 { 153 addErrorMessage("displaying welcome page failed, exception thrown ("+e.toString()+")"); 154 e.printStackTrace(); 155 return ERROR; 156 } 157 } 158 } | Popular Tags |