From: <jbo...@li...> - 2005-11-20 19:18:17
|
Author: unibrew Date: 2005-11-20 14:18:12 -0500 (Sun, 20 Nov 2005) New Revision: 1610 Modified: trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/PollTools.java Log: [JBLAB-407] Adding few needed tool features. Modified: trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/PollTools.java =================================================================== --- trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/PollTools.java 2005-11-20 19:17:16 UTC (rev 1609) +++ trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/PollTools.java 2005-11-20 19:18:12 UTC (rev 1610) @@ -24,7 +24,17 @@ package org.jboss.forge.common.projects; import java.io.File; +import java.util.List; +import java.util.Map; +import javax.portlet.PortletURL; + +import org.jboss.forge.common.ForgeHelper; +import org.jboss.portal.common.context.Context; +import org.jboss.portal.common.context.DelegateContext; +import org.jboss.portlet.JBossRenderResponse; +import org.jboss.shotoku.ContentManager; + public class PollTools { /** @@ -33,11 +43,24 @@ public static final String POLLS_DIR="polls"; /** - * Name of JSP view file. + * Name of JSP view file prepared for displaying voting results. */ - public static final String POLLS_JSP="normal.jsp"; + public static final String POLLS_INFO_JSP="polls_info.jsp"; /** + * Name of JSP view file prepared for voting. + */ + public static final String POLLS_VOTING_JSP="polls_voting.jsp"; + + /** + * Private constructor made in order to prevent from creating + * PollTools object. + */ + private PollTools () { + + } + + /** * Method constructs path to polls descriptor. * * @param portalName @@ -60,14 +83,86 @@ File.separator+ProjectsHelper.POLL_DESC; } + public static PollsDescriptor getDesc(final String portalName,ContentManager contentManager) { + PollsDescriptor desc = (PollsDescriptor) ForgeHelper + .getForgeManagement().getFromCache(portalName, + PollsDescriptor.class.getName()); + if (desc==null) { + desc = (PollsDescriptor) ForgeHelper.getForgeManagement() + .addNodeWatcher(portalName, + PollsDescriptor.class.getName(), + new PollsWatcher(contentManager)); + } + return desc; + } + /** - * Method constructs path to the PollPortlet JSP view file. + * Method constructs path to the PollPortlet JSP view file containing + * information about voting results. * * @param portalName - * @return Path to the PollPortlet's JSP view file. + * @return Path to the PollPortlet's JSP voting info view file. */ - public static String getJspCmPath() { - return POLLS_DIR + File.separator + POLLS_JSP; + public static String getInfoJsp() { + return POLLS_DIR + File.separator + POLLS_INFO_JSP; } + /** + * Method constructs path to the PollPortlet JSP view file containing + * voting question. + * + * @param portalName + * @return Path to the PollPortlet's JSP voting view file. + */ + public static String getVotingJsp() { + return POLLS_DIR + File.separator + POLLS_VOTING_JSP; + } + + public static Context getInfoContext (String portalName,String projectId, + ContentManager cm,JBossRenderResponse response) { + + return new DelegateContext(); + } + + public static Context getVotingContext (String portalName, String projectId, + ContentManager cm,JBossRenderResponse response) { +// If the projectId is null method returns empty DelegateContext object. + if (projectId==null) { + return new DelegateContext(); + } + + // Creating new empty context. + DelegateContext ctx = new DelegateContext(); + + // Getting the PollsDescriptor object containing counters. + PollsDescriptor desc = getDesc(portalName,cm); + + // If there isn't a descriptor in cache, return empty context. + if (desc==null) { + return ctx; + } + + // If there is no tracked link for projectId return empty context. + if (!desc.checkForProjectPolls(projectId)) { + return ctx; + } + + // Getting the polls for given projectId. + List<Poll> values = desc.getPollsMap().get(projectId); + + // Filling the context for portlet. + DelegateContext polls = ctx.next("polls"); + for (Poll pollElem:values) { + + DelegateContext poll = polls.next("poll"); + + // Resolving the question + String question = pollElem.getQuestion(); + + poll.put("question",question); + poll.put("actionurl",response.createActionURL().toString()); + } + return ctx; + } + } |