Author: soh...@jb... Date: 2006-05-03 14:16:42 -0400 (Wed, 03 May 2006) New Revision: 4068 Added: labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/action/EditPost.java labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/action/PostAction.java labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/action/ReplyTopic.java labs/jbossforums/trunk/forums/src/resources/portal-forums-war/views/topics/posting_edit_body.xhtml labs/jbossforums/trunk/forums/src/resources/portal-forums-war/views/topics/posting_edit_preview.xhtml labs/jbossforums/trunk/forums/src/resources/portal-forums-war/views/topics/posting_new_body.xhtml labs/jbossforums/trunk/forums/src/resources/portal-forums-war/views/topics/posting_new_preview.xhtml labs/jbossforums/trunk/forums/src/resources/portal-forums-war/views/topics/posting_reply_body.xhtml labs/jbossforums/trunk/forums/src/resources/portal-forums-war/views/topics/posting_reply_preview.xhtml Removed: labs/jbossforums/trunk/forums/src/resources/portal-forums-war/views/topics/posting_body.xhtml labs/jbossforums/trunk/forums/src/resources/portal-forums-war/views/topics/posting_preview.xhtml Modified: labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/Constants.java labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/ForumsJSFPortlet.java labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/action/NewTopic.java labs/jbossforums/trunk/forums/src/resources/portal-forums-war/WEB-INF/forums-config.xml labs/jbossforums/trunk/forums/src/resources/portal-forums-war/views/topics/viewtopic_body.xhtml Log: http://jira.jboss.com/jira/browse/JBFORUMS-65 - Create a New Topic http://jira.jboss.com/jira/browse/JBFORUMS-66 - Post Reply http://jira.jboss.com/jira/browse/JBFORUMS-67 - Edit Post Modified: labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/Constants.java =================================================================== --- labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/Constants.java 2006-05-03 14:57:03 UTC (rev 4067) +++ labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/Constants.java 2006-05-03 18:16:42 UTC (rev 4068) @@ -32,10 +32,14 @@ public static final String START = "start"; public static final String CANCEL = "cancel"; public static final String SUCCESS = "success"; + public static final String START_REPLY = "startReply"; + public static final String START_NEW_TOPIC = "startNewTopic"; + public static final String START_EDIT_POST = "startEditPost"; //---------parameter constants-------------------------------------------------------------------------------------------------- public static final String p_categoryId = "c"; public static final String p_forumId = "f"; public static final String p_topicId = "t"; + public static final String p_postId = "p"; public static final String p_userId = "uid"; public static final String p_option = "o"; public static final String p_poll_title = "POLL_TITLE"; Modified: labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/ForumsJSFPortlet.java =================================================================== --- labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/ForumsJSFPortlet.java 2006-05-03 14:57:03 UTC (rev 4067) +++ labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/ForumsJSFPortlet.java 2006-05-03 18:16:42 UTC (rev 4068) @@ -61,6 +61,7 @@ String pollDelete = ForumUtil.getParameter(request,Constants.p_poll_delete); String attachment = ForumUtil.getParameter(request,Constants.p_attachment); String topicId = ForumUtil.getParameter(request,Constants.p_topicId); + String postId = ForumUtil.getParameter(request,Constants.p_postId); String userId = ForumUtil.getParameter(request,Constants.p_userId); if(categoryId!=null && categoryId.trim().length()>0) { @@ -94,5 +95,9 @@ { response.setRenderParameter(Constants.p_userId,userId); } + if(postId!=null && postId.trim().length()>0) + { + response.setRenderParameter(Constants.p_postId,postId); + } } } Added: labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/action/EditPost.java =================================================================== --- labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/action/EditPost.java 2006-05-03 14:57:03 UTC (rev 4067) +++ labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/action/EditPost.java 2006-05-03 18:16:42 UTC (rev 4068) @@ -0,0 +1,326 @@ +/* +* JBoss, Home of Professional Open Source +* Copyright 2005, JBoss Inc., and individual contributors as indicated +* by the @authors tag. See the copyright.txt in the distribution for a +* full listing of individual contributors. +* +* This is free software; you can redistribute it and/or modify it +* under the terms of the GNU Lesser General Public License as +* published by the Free Software Foundation; either version 2.1 of +* the License, or (at your option) any later version. +* +* This software is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this software; if not, write to the Free +* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA +* 02110-1301 USA, or see the FSF site: http://www.fsf.org. +*/ +package org.jboss.portlet.forums.ui.action; + +import java.util.ArrayList; +import java.util.Date; +import java.util.Iterator; +import java.util.List; +import java.util.Collection; + +import org.jboss.portlet.forums.ui.BaseController; +import org.jboss.portlet.forums.ui.Constants; +import org.jboss.portlet.forums.ui.ForumUtil; +import org.jboss.portlet.forums.ui.JSFUtil; +import org.jboss.portlet.forums.ui.PortalUtil; + +import org.jboss.portlet.forums.commands.ValidationException; +import org.jboss.portlet.forums.model.Forum; +import org.jboss.portlet.forums.model.Poll; +import org.jboss.portlet.forums.model.PollOption; +import org.jboss.portlet.forums.model.Poster; +import org.jboss.portlet.forums.model.Message; +import org.jboss.portlet.forums.model.Topic; +import org.jboss.portlet.forums.model.Post; +import org.jboss.portlet.forums.model.Attachment; + +/* + * Created on May 2, 2006 + * + * @author <a href="mailto:soh...@jb...">Sohil Shah</a> + */ +public class EditPost extends PostAction +{ + //constructor------------------------------------------------------------------------------------------------------------------ + /** + * + * + */ + public EditPost() + { + super(); + } + + //action processing methods----------------------------------------------------------------------------------------------------- + /** + * + * + */ + public String start() + { + String navState = null; + try + { + int postId = -1; + String p = ForumUtil.getParameter(Constants.p_postId); + if(p!=null && p.trim().length()>0) + { + postId = Integer.parseInt(p); + } + + //grab the post information + if(postId!=-1) + { + //re-initialize this controller to edit the specified post + this.cleanup(); + + //get the post from the module + Post post = BaseController.getForumsModule().findPostById(new Integer(postId)); + Topic topic = post.getTopic(); + + //set the selected post's topic id + this.topicId = topic.getId().intValue(); + this.postId = postId; + + //set the subject of the post + this.subject = post.getMessage().getSubject(); + + //set the message of the post + this.message = post.getMessage().getText(); + + //set the topicType + this.topicType = topic.getType(); + + //setup poll related information + this.setupPoll(topic.getPoll()); + + //setup the attachment related information + this.setupAttachments(post.getAttachments()); + } + + navState = Constants.START_EDIT_POST; + } + catch(Exception e) + { + JSFUtil.handleException(e); + } + return navState; + } + + /** + * + * + */ + public String execute() + { + String navState = null; + boolean success = false; + try + { + //setup the business objects to be updated + Post post = BaseController.getForumsModule().findPostById(new Integer(this.postId)); + Topic topic = post.getTopic(); + boolean isFirstPost = false; + if(topic.getFirstPost().getId().intValue()==post.getId().intValue()) + { + isFirstPost = true; + } + + //setup the message/subject related data + Message message = PortalUtil.createMessage(); + message.setText(this.message); + message.setSubject(this.subject); + + //update the message/subject/topicType data on the business objects + post.setMessage(message); + if(isFirstPost) + { + topic.setSubject(this.subject); + topic.setType(this.topicType); + } + + //miscellaneous post related update + post.setEditCount(post.getEditCount() + 1); + post.setEditDate(new Date()); + + + //TODO: cleanup this poll update process............move this as a private method + //setup poll information + List localPollOptions = new ArrayList(); + for(Iterator itr=this.options.iterator();itr.hasNext();) + { + String option = (String)itr.next(); + PollOption pollOption = PortalUtil.createPollOption(); + pollOption.setQuestion(option); + pollOption.setVotes(0); + localPollOptions.add(pollOption); + } + + //update poll information + if( topic.getPoll()==null || + topic.getPoll().getTitle() == null || + topic.getPoll().getTitle().trim().length() == 0 + ) + { + //no existing poll information found in the database + if(localPollOptions.size()>0 && this.question!=null && this.question.trim().length()>0) + { + //need to add a new poll to this topic + Poll poll = PortalUtil.createPoll(); + poll.setTitle(this.question); + poll.setLength(this.activeDuration); + poll.setOptions(localPollOptions); + BaseController.getForumsModule().addPollToTopic(topic,poll); + } + } + else + { + //existing poll information is available in the database + if(localPollOptions.size()>0) + { + //this is a diff update.............................. + + //setup the poll to be updated in the database + Poll poll = PortalUtil.createPoll(); + poll.setTitle(this.question); + poll.setLength(this.activeDuration); + poll.setVoted(topic.getPoll().getVoted()); + poll.setCreationDate(topic.getPoll().getCreationDate()); + + Iterator newOptions = localPollOptions.iterator(); + while (newOptions.hasNext()) + { + PollOption newPollOption = (PollOption)newOptions.next(); + Iterator stored = topic.getPoll().getOptions().iterator(); + while(stored.hasNext()) + { + PollOption oldPollOption = (PollOption)stored.next(); + if(oldPollOption!=null && oldPollOption.getQuestion().equals(newPollOption.getQuestion())) + { + newPollOption.setVotes(oldPollOption.getVotes()); + break; + } + } + } + poll.setOptions(localPollOptions); + + BaseController.getForumsModule().addPollToTopic(topic,poll); + } + else + { + //remove the poll from the database...poll was removed during this editPost process + topic.setPoll(null); + } + } + + + //TODO: cleanup this forums update process............move this as a private method + //setup attachment information + Collection attachments = this.produceAttachments(this.attachments); + Collection removeFilter = new ArrayList(); + Collection newAttachments = new ArrayList(); + + //filter out the newly added attachments + for(Iterator itr=attachments.iterator();itr.hasNext();) + { + Attachment cour = (Attachment)itr.next(); + if( + cour.getId()==null + ) + { + newAttachments.add(cour); //adds this new attachment to the database + removeFilter.add(cour); //remove this newly added attachments from the list + //to be compared against the list of stored attachments for update/remove + } + } + attachments.removeAll(removeFilter); + + //update/remove currently stored attachments on this post + Iterator storedAttachments = post.getAttachments().iterator(); + removeFilter = new ArrayList(); + while(storedAttachments.hasNext()) + { + Attachment storedAttachment = (Attachment)storedAttachments.next(); + + //not sure why a record like this is popping out from the hibernate layer + if(storedAttachment.getId()==null) + { + removeFilter.add(storedAttachment); //clean this record up + continue; + } + + //find this storedAttachment in the list of ui attachments. + //ones that are found are to be updated. once not found need to be removed + Iterator uiAttachments = attachments.iterator(); + if(uiAttachments==null || !uiAttachments.hasNext()) + { + //basically all attachments on the ui were deleted + removeFilter.add(storedAttachment); + break; + } + while(uiAttachments.hasNext()) + { + Attachment local = (Attachment)uiAttachments.next(); + if(local.getId().intValue()==storedAttachment.getId().intValue()) + { + //update this attachment + storedAttachment.setComment(local.getComment()); + break; + } + //check if this stored attachment should be removed + if(!uiAttachments.hasNext()) + { + //if i get here, no match was made with the list of ui attachments + //hence this particular stored attachment must be removed + removeFilter.add(storedAttachment); + } + } + } + post.getAttachments().removeAll(removeFilter); + + //add the newly added attachments + for(Iterator itr=newAttachments.iterator();itr.hasNext();) + { + post.addAttachment((Attachment)itr.next()); + } + + + //set the proper navigation state + navState = Constants.SUCCESS; + + success = true; + } + catch(Exception e) + { + if(e instanceof ValidationException) + { + //handle proper validation error with a proper message...not just a generic message.. + //just use generic error page for the proof of concept + //set the custom exception such that e.toString() results in the proper message + JSFUtil.handleException(e); + } + else + { + JSFUtil.handleException(e); + } + } + finally + { + //cleanup if necessary + if(success) + { + this.cleanup(); + } + } + return navState; + } +} Modified: labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/action/NewTopic.java =================================================================== --- labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/action/NewTopic.java 2006-05-03 14:57:03 UTC (rev 4067) +++ labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/action/NewTopic.java 2006-05-03 18:16:42 UTC (rev 4068) @@ -22,11 +22,9 @@ package org.jboss.portlet.forums.ui.action; import java.util.Date; -import java.util.Collection; import java.util.List; import java.util.ArrayList; import java.util.Iterator; -import java.text.SimpleDateFormat; import org.jboss.portlet.forums.ui.Constants; import org.jboss.portlet.forums.ui.BaseController; @@ -41,295 +39,16 @@ import org.jboss.portlet.forums.model.Post; import org.jboss.portlet.forums.commands.ValidationException; import org.jboss.portlet.forums.commands.post.PostTools; -import org.jboss.portlet.forums.helper.TempFileBinding; //myfaces -import org.apache.myfaces.custom.fileupload.UploadedFile; /** * @author <a href="mailto:soh...@jb...">Sohil Shah</a> * */ -public class NewTopic extends ActionController -{ - //post related view data - private String subject = null; - private String message = null; - private int topicType = 0; - - //poll related data view data - private String question = null; - private Collection options = new ArrayList(); - private int activeDuration = 0; - private boolean deletePoll = false; - private boolean deletePollActivated = false; - - //attachment related view data - private String attachmentComment = null; - private UploadedFile attachment = null; - private Collection attachments = new ArrayList(); - - - //navigation control related data - private boolean isPreview = false; - private int forumId = -1; - - //business state - - //---------------------------------------------------------------------------------------------------------------------------------------- - /** - * @return Returns the message. - */ - public String getMessage() - { - return message; - } - - /** - * @param message The message to set. - */ - public void setMessage(String message) - { - this.message = message; - } - - /** - * @return Returns the subject. - */ - public String getSubject() - { - return subject; - } - - /** - * @param subject The subject to set. - */ - public void setSubject(String subject) - { - this.subject = subject; - } - - /** - * @return Returns the topicType. - */ - public int getTopicType() - { - return topicType; - } - - /** - * @param topicType The topicType to set. - */ - public void setTopicType(int topicType) - { - this.topicType = topicType; - } - - /** - * - * @return - */ - public String getPostDate() - { - String dateStr = null; - - SimpleDateFormat dateFormat = PortalUtil.getSDF(); - - dateStr = dateFormat.format(new Date()); - - return dateStr; - } - - /** - * - * @return - */ - public String getQuestion() - { - return this.question; - } - - /** - * - * @param question - */ - public void setQuestion(String question) - { - this.question = question; - } - - /** - * @return Returns the activeDuration. - */ - public int getActiveDuration() - { - return activeDuration; - } - /** - * @param activeDuration The activeDuration to set. - */ - public void setActiveDuration(int activeDuration) - { - this.activeDuration = activeDuration; - } - - /** - * @return - */ - public String getOption() - { - return null; - } - - /** - * @param - */ - public void setOption(String option) - { - if(option!=null && option.trim().length()>0) - { - this.options.add(option); - } - } - - public Collection getOptions() - { - return this.options; - } - - /** - * - * @return - */ - public boolean getDeletePoll() - { - return this.deletePoll; - } - - /** - * - * @param deletePoll - */ - public void setDeletePoll(boolean deletePoll) - { - this.deletePoll = deletePoll; - } - - /** - * - * @return - */ - public boolean isDeletePollActivated() - { - return this.deletePollActivated; - } - - - /** - * @return Returns the attachmentComment. - */ - public String getAttachmentComment() - { - return this.attachmentComment; - } - - /** - * @param attachmentComment The attachmentComment to set. - */ - public void setAttachmentComment(String attachmentComment) - { - this.attachmentComment = attachmentComment; - } - - /** - * @return Returns the attachment. - */ - public UploadedFile getAttachment() - { - return attachment; - } - - /** - * @param attachment The attachment to set. - */ - public void setAttachment(UploadedFile attachment) - { - this.attachment = attachment; - } - - /** - * - * @return - */ - public Collection getAttachments() - { - return this.attachments; - } - - /** - * - * @return - */ - public int getNumberOfAttachments() - { - int numberOfAttachments = 0; - - if(this.attachments!=null) - { - numberOfAttachments = this.attachments.size(); - } - - return numberOfAttachments; - } - //-----navigation related data--------------------------------------------------------------------------------------------------------------- - /** - * - */ - public boolean isPreview() - { - return this.isPreview; - } - - /** - * - * - */ - public int getForumId() - { - return this.forumId; - } - - /** - * - * @author sshah - * since this controller is at session scope, must cleanup its state when not needed - * this will help optimize memory usage... - * puts the bean in an uninitialized state in that user's session - * - */ - private void cleanup() - { - //puts this controller in an cleaned up state for the next time it will be used in the session - this.subject = null; - this.message = null; - this.topicType = 0; - this.isPreview = false; - this.forumId = -1; - - //cleanup poll related data - this.question = null; - this.options = new ArrayList(); - this.activeDuration = 0; - this.deletePoll = false; - this.deletePollActivated = false; - - //cleanup attachment related data - this.attachment = null; - this.attachmentComment = null; - this.attachments = new ArrayList(); - } - +public class NewTopic extends PostAction +{ //---------------------------------------------------------------------------------------------------------------------------------------- /** * @@ -339,8 +58,7 @@ public NewTopic() { super(); - } - + } //---------------------------------------------------------------------------------------------------------------------------------------- /** * @@ -380,121 +98,14 @@ } } - navState = Constants.START; + navState = Constants.START_NEW_TOPIC; } catch(Exception e) { JSFUtil.handleException(e); } return navState; - } - //poll related operations-------------------------------------------------------------------------------------------------------------------- - /** - * - * @author sshah - */ - public String deleteOption() - { - String navState = null; - try - { - int optionIndex = Integer.parseInt(ForumUtil.getParameter(Constants.p_option)); - - //actually remove the option value - optionIndex--; - ((ArrayList)this.options).remove(optionIndex); - } - catch(Exception e) - { - JSFUtil.handleException(e); - } - return navState; - } - //-----------------attachment related------------------------------------------------------------------------------------------ - /** - * - */ - public String addAttachment() - { - String navState = null; - try - { - if(this.attachment!=null) - { - TempFileBinding file = new TempFileBinding( - this.attachment.getContentType(), - this.attachment.getBytes(), - this.attachment.getName(), - String.valueOf(System.currentTimeMillis()) + "_" + this.attachments.size() //unique fileId for this collection of files - ); - if(this.attachmentComment!=null) - { - file.setComment(this.attachmentComment); - } - this.attachments.add(file); - } - - //clear out the attachment related view data - this.setAttachment(null); - this.setAttachmentComment(null); - } - catch(Exception e) - { - JSFUtil.handleException(e); - } - return navState; - } - - /** - * - * @author sshah - */ - public String deleteAttachment() - { - String navState = null; - try - { - int attachmentIndex = Integer.parseInt(ForumUtil.getParameter(Constants.p_attachment)); - - attachmentIndex--; - ((ArrayList)this.attachments).remove(attachmentIndex); - } - catch(Exception e) - { - JSFUtil.handleException(e); - } - return navState; - } - //------------preview------------------------------------------------------------------------------------------------------- - /** - * - * @return - */ - public String preview() - { - String navState = null; - try - { - this.isPreview = true; - } - catch(Exception e) - { - JSFUtil.handleException(e); - } - return navState; - } - - //---------------------------cancel----------------------------------------------------------------------------------------- - /** - * - * @author sshah - * - */ - public String cancel() - { - return Constants.CANCEL; - } - + } //--------execute------------------------------------------------------------------------------------------------------------- /** * @@ -506,6 +117,7 @@ boolean success = false; try { + //setup the message Message message = PortalUtil.createMessage(); message.setText(this.message); message.setSubject(this.subject); @@ -544,7 +156,7 @@ new Date(), poster, poll, //poll - (List)this.attachments, //attachments + (List)this.produceAttachments(this.attachments), //attachments this.topicType ); BaseController.getForumsModule().createWatch(poster,post.getTopic()); @@ -578,5 +190,5 @@ } } return navState; - } + } } Added: labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/action/PostAction.java =================================================================== --- labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/action/PostAction.java 2006-05-03 14:57:03 UTC (rev 4067) +++ labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/action/PostAction.java 2006-05-03 18:16:42 UTC (rev 4068) @@ -0,0 +1,591 @@ +/* +* JBoss, Home of Professional Open Source +* Copyright 2005, JBoss Inc., and individual contributors as indicated +* by the @authors tag. See the copyright.txt in the distribution for a +* full listing of individual contributors. +* +* This is free software; you can redistribute it and/or modify it +* under the terms of the GNU Lesser General Public License as +* published by the Free Software Foundation; either version 2.1 of +* the License, or (at your option) any later version. +* +* This software is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this software; if not, write to the Free +* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA +* 02110-1301 USA, or see the FSF site: http://www.fsf.org. +*/ +package org.jboss.portlet.forums.ui.action; + +import java.util.Date; +import java.util.Collection; +import java.util.ArrayList; +import java.util.List; +import java.util.Iterator; +import java.text.SimpleDateFormat; + +import org.jboss.portlet.forums.ui.Constants; +import org.jboss.portlet.forums.ui.ForumUtil; +import org.jboss.portlet.forums.ui.JSFUtil; +import org.jboss.portlet.forums.ui.PortalUtil; +import org.jboss.portlet.forums.helper.TempFileBinding; + +import org.jboss.portlet.forums.model.Attachment; +import org.jboss.portlet.forums.impl.AttachmentImpl; +import org.jboss.portlet.forums.model.Poll; +import org.jboss.portlet.forums.model.PollOption; + +//myfaces +import org.apache.myfaces.custom.fileupload.UploadedFile; + + +/** + * @author <a href="mailto:soh...@jb...">Sohil Shah</a> + * + */ +public abstract class PostAction extends ActionController +{ + //post related view data + protected String subject = null; + protected String message = null; + protected int topicType = 0; + + //poll related data view data + protected String question = null; + protected Collection options = new ArrayList(); + protected int activeDuration = 0; + protected boolean deletePoll = false; + protected boolean deletePollActivated = false; + + //attachment related view data + protected String attachmentComment = null; + protected UploadedFile attachment = null; + protected Collection attachments = new ArrayList(); + + + //navigation control related data + protected boolean isPreview = false; + protected int forumId = -1; + protected int topicId = -1; + protected int postId = -1; + + //business state + + //ui related data accessors---------------------------------------------------------------------------------------------------------------------------------------- + /** + * @return Returns the message. + */ + public String getMessage() + { + return message; + } + + /** + * @param message The message to set. + */ + public void setMessage(String message) + { + this.message = message; + } + + /** + * @return Returns the subject. + */ + public String getSubject() + { + return subject; + } + + /** + * @param subject The subject to set. + */ + public void setSubject(String subject) + { + this.subject = subject; + } + + /** + * @return Returns the topicType. + */ + public int getTopicType() + { + return topicType; + } + + /** + * @param topicType The topicType to set. + */ + public void setTopicType(int topicType) + { + this.topicType = topicType; + } + + /** + * + * @return + */ + public String getPostDate() + { + String dateStr = null; + + SimpleDateFormat dateFormat = PortalUtil.getSDF(); + + dateStr = dateFormat.format(new Date()); + + return dateStr; + } + + /** + * + * @return + */ + public String getQuestion() + { + return this.question; + } + + /** + * + * @param question + */ + public void setQuestion(String question) + { + this.question = question; + } + + /** + * @return Returns the activeDuration. + */ + public int getActiveDuration() + { + return activeDuration; + } + /** + * @param activeDuration The activeDuration to set. + */ + public void setActiveDuration(int activeDuration) + { + this.activeDuration = activeDuration; + } + + /** + * @return + */ + public String getOption() + { + return null; + } + + /** + * @param + */ + public void setOption(String option) + { + if(option!=null && option.trim().length()>0) + { + this.options.add(option); + } + } + + public Collection getOptions() + { + return this.options; + } + + /** + * + * @return + */ + public boolean getDeletePoll() + { + return this.deletePoll; + } + + /** + * + * @param deletePoll + */ + public void setDeletePoll(boolean deletePoll) + { + this.deletePoll = deletePoll; + } + + /** + * + * @return + */ + public boolean isDeletePollActivated() + { + return this.deletePollActivated; + } + + + /** + * @return Returns the attachmentComment. + */ + public String getAttachmentComment() + { + return this.attachmentComment; + } + + /** + * @param attachmentComment The attachmentComment to set. + */ + public void setAttachmentComment(String attachmentComment) + { + this.attachmentComment = attachmentComment; + } + + /** + * @return Returns the attachment. + */ + public UploadedFile getAttachment() + { + return attachment; + } + + /** + * @param attachment The attachment to set. + */ + public void setAttachment(UploadedFile attachment) + { + this.attachment = attachment; + } + + /** + * + * @return + */ + public Collection getAttachments() + { + return this.attachments; + } + + /** + * + * @return + */ + public int getNumberOfAttachments() + { + int numberOfAttachments = 0; + + if(this.attachments!=null) + { + numberOfAttachments = this.attachments.size(); + } + + return numberOfAttachments; + } + //-----navigation related data--------------------------------------------------------------------------------------------------------------- + /** + * + */ + public boolean isPreview() + { + return this.isPreview; + } + + /** + * + * + */ + public boolean isPollPresent() + { + boolean isPollPresent = false; + + if(this.question!=null && this.question.trim().length()>0) + { + isPollPresent = true; + } + + return isPollPresent; + } + + /** + * + * + */ + public int getForumId() + { + return this.forumId; + } + + /** + * + * + */ + public int getTopicId() + { + return this.topicId; + } + + /** + * + * + */ + public int getPostId() + { + return this.postId; + } + + //------------------------------------------------------------------------------------------------------------------------------------------ + /** + * + * @author sshah + * since this controller is at session scope, must cleanup its state when not needed + * this will help optimize memory usage... + * puts the bean in an uninitialized state in that user's session + * + */ + protected void cleanup() + { + //puts this controller in an cleaned up state for the next time it will be used in the session + this.subject = null; + this.message = null; + this.topicType = 0; + this.isPreview = false; + this.forumId = -1; + this.topicId = -1; + this.postId = -1; + + //cleanup poll related data + this.question = null; + this.options = new ArrayList(); + this.activeDuration = 0; + this.deletePoll = false; + this.deletePollActivated = false; + + //cleanup attachment related data + this.attachment = null; + this.attachmentComment = null; + this.attachments = new ArrayList(); + } + + /** + * Takes a collection of tempFiles setup during data setup and produces attachments that are to be sent + * over to the module + * + * @param tempFiles + * @return + */ + protected Collection produceAttachments(Collection tempFiles) + { + Collection attachments = new ArrayList(); + if(tempFiles!=null) + { + for(Iterator itr=tempFiles.iterator();itr.hasNext();) + { + TempFileBinding cour = (TempFileBinding)itr.next(); + Attachment attachment = cour.produceAttachment(); + if(cour.getFileId()!=null && cour.getFileId().trim().length()>0) + { + try + { + //try to see if this fileId is the attachmentId in the database + int attachmentId = Integer.parseInt(cour.getFileId()); + if(attachmentId!=-1) + { + ((AttachmentImpl)attachment).setId(new Integer(attachmentId)); + } + else + { + ((AttachmentImpl)attachment).setId(null); + } + } + catch(Exception e){/*if an error occurs here...no problem..this is not the attachmentId anyways*/ + ((AttachmentImpl)attachment).setId(null);} + } + attachments.add(attachment); + } + } + return attachments; + } + + /** + * sets the poll information of a post for the ui from the business object + * + */ + protected void setupPoll(Poll poll) + { + if(poll!=null) + { + this.question = poll.getTitle(); + this.activeDuration = poll.getLength(); + List pollOptions = poll.getOptions(); + if(pollOptions!=null && pollOptions.size()>0) + { + this.options = new ArrayList(); + for(Iterator itr=pollOptions.iterator();itr.hasNext();) + { + PollOption cour = (PollOption)itr.next(); + this.options.add(cour.getQuestion()); + } + } + } + } + + /** + * sets up the attachment information of a post for the ui from the business object + * + */ + protected void setupAttachments(Collection attachments) throws Exception + { + if(attachments!=null) + { + this.attachments = new ArrayList(); + for(Iterator itr=attachments.iterator();itr.hasNext();) + { + Attachment cour = (Attachment)itr.next(); + TempFileBinding uiAttachment = new TempFileBinding( + cour.getFile().getContentType(), //contentType + "".getBytes(), //byte content....just use empty data...this object is for the ui and the actual + //content of the attachment is not needed here + cour.getFile().getName(), //file name + String.valueOf(System.currentTimeMillis()) + "_" + this.attachments.size() //unique fileId for this collection of files + ); + uiAttachment.setComment(cour.getComment()); + uiAttachment.setFileId(String.valueOf(cour.getId().intValue())); //this holds the information to actually identify the + //attachment stored in the database + this.attachments.add(uiAttachment); + } + } + } + + //---------------------------------------------------------------------------------------------------------------------------------------- + /** + * + * @author sshah + * + */ + public PostAction() + { + super(); + } + + //---------------------------------------------------------------------------------------------------------------------------------------- + /** + * + * @author sshah + * + */ + public abstract String start(); + + //poll related operations-------------------------------------------------------------------------------------------------------------------- + /** + * + * @author sshah + */ + public String deleteOption() + { + String navState = null; + try + { + int optionIndex = Integer.parseInt(ForumUtil.getParameter(Constants.p_option)); + + //actually remove the option value + optionIndex--; + ((ArrayList)this.options).remove(optionIndex); + } + catch(Exception e) + { + JSFUtil.handleException(e); + } + return navState; + } + //-----------------attachment related------------------------------------------------------------------------------------------ + /** + * + */ + public String addAttachment() + { + String navState = null; + try + { + if(this.attachment!=null) + { + TempFileBinding file = new TempFileBinding( + this.attachment.getContentType(), + this.attachment.getBytes(), + this.attachment.getName(), + String.valueOf(System.currentTimeMillis()) + "_" + this.attachments.size() //unique fileId for this collection of files + ); + if(this.attachmentComment!=null) + { + file.setComment(this.attachmentComment); + } + file.setFileId("-1"); //identifies attachments from ui that are not stored in the database yet + this.attachments.add(file); + } + + //clear out the attachment related view data + this.setAttachment(null); + this.setAttachmentComment(null); + } + catch(Exception e) + { + JSFUtil.handleException(e); + } + return navState; + } + + /** + * + * @author sshah + */ + public String deleteAttachment() + { + String navState = null; + try + { + int attachmentIndex = Integer.parseInt(ForumUtil.getParameter(Constants.p_attachment)); + + attachmentIndex--; + ((ArrayList)this.attachments).remove(attachmentIndex); + } + catch(Exception e) + { + JSFUtil.handleException(e); + } + return navState; + } + //------------preview------------------------------------------------------------------------------------------------------- + /** + * + * @return + */ + public String preview() + { + String navState = null; + try + { + this.isPreview = true; + } + catch(Exception e) + { + JSFUtil.handleException(e); + } + return navState; + } + + //---------------------------cancel----------------------------------------------------------------------------------------- + /** + * + * @author sshah + * + */ + public String cancel() + { + return Constants.CANCEL; + } + + //--------execute------------------------------------------------------------------------------------------------------------- + /** + * + * @return + */ + public abstract String execute(); +} Added: labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/action/ReplyTopic.java =================================================================== --- labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/action/ReplyTopic.java 2006-05-03 14:57:03 UTC (rev 4067) +++ labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/action/ReplyTopic.java 2006-05-03 18:16:42 UTC (rev 4068) @@ -0,0 +1,172 @@ +/* +* JBoss, Home of Professional Open Source +* Copyright 2005, JBoss Inc., and individual contributors as indicated +* by the @authors tag. See the copyright.txt in the distribution for a +* full listing of individual contributors. +* +* This is free software; you can redistribute it and/or modify it +* under the terms of the GNU Lesser General Public License as +* published by the Free Software Foundation; either version 2.1 of +* the License, or (at your option) any later version. +* +* This software is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this software; if not, write to the Free +* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA +* 02110-1301 USA, or see the FSF site: http://www.fsf.org. +*/ +package org.jboss.portlet.forums.ui.action; + +import java.util.Date; +import java.util.List; + + +import org.jboss.portlet.forums.ui.Constants; +import org.jboss.portlet.forums.ui.BaseController; +import org.jboss.portlet.forums.ui.ForumUtil; +import org.jboss.portlet.forums.ui.JSFUtil; +import org.jboss.portlet.forums.ui.PortalUtil; + +import org.jboss.portlet.forums.model.Forum; +import org.jboss.portlet.forums.model.Poster; +import org.jboss.portlet.forums.model.Topic; +import org.jboss.portlet.forums.model.Message; +import org.jboss.portlet.forums.model.Post; + +import org.jboss.portlet.forums.commands.ValidationException; +import org.jboss.portlet.forums.commands.post.PostTools; + +//myfaces + + +/** + * @author <a href="mailto:soh...@jb...">Sohil Shah</a> + * + */ +public class ReplyTopic extends PostAction +{ + //---------------------------------------------------------------------------------------------------------------------------------------- + /** + * + * @author sshah + * + */ + public ReplyTopic() + { + super(); + } + //---------------------------------------------------------------------------------------------------------------------------------------- + /** + * + * @author sshah + * + */ + public String start() + { + String navState = null; + try + { + int forumId = -1; + int topicId = -1; + String f = ForumUtil.getParameter(Constants.p_forumId); + String t = ForumUtil.getParameter(Constants.p_topicId); + if(f!=null && f.trim().length()>0) + { + forumId = Integer.parseInt(f); + } + if(t!=null && t.trim().length()>0) + { + topicId = Integer.parseInt(t); + } + + //grab the forum where this topic will be added + if(forumId!=-1) + { + //re-initialize this controller to add a reply post in a topic + //to the specified forum + this.cleanup(); + + //set the selected forum's id and topic's id + this.forumId = forumId; + this.topicId = topicId; + } + + navState = Constants.START_REPLY; + } + catch(Exception e) + { + JSFUtil.handleException(e); + } + return navState; + } + //--------execute------------------------------------------------------------------------------------------------------------- + /** + * + * @return + */ + public String execute() + { + String navState = null; + boolean success = false; + try + { + Message message = PortalUtil.createMessage(); + message.setText(this.message); + message.setSubject(this.subject); + + //perform domain level validation of information here....ui level validation should have already passed + //whether done using javascript or JSF validators + PostTools.validate(message); + + //setup the forum and the corresponding poster + Forum forum = BaseController.getForumsModule().findForumById(new Integer(this.forumId)); + Topic topic = BaseController.getForumsModule().findTopicById(new Integer(topicId)); + Poster poster = PortalUtil.getPoster(); + + + //actually post a reply to this topic in the forum + Post post = BaseController.getForumsModule().createPost(topic, + forum, + message, + new Date(), + poster, + (List)this.produceAttachments(this.attachments) //attachments + ); + poster.incrementPostCount(); + + + + //setup the navigation state + navState = Constants.SUCCESS; + + success = true; + } + catch(Exception e) + { + if(e instanceof ValidationException) + { + //handle proper validation error with a proper message...not just a generic message.. + //just use generic error page for the proof of concept + //set the custom exception such that e.toString() results in the proper message + JSFUtil.handleException(e); + } + else + { + JSFUtil.handleException(e); + } + } + finally + { + //cleanup if necessary + if(success) + { + this.cleanup(); + } + } + return navState; + } +} Modified: labs/jbossforums/trunk/forums/src/resources/portal-forums-war/WEB-INF/forums-config.xml =================================================================== --- labs/jbossforums/trunk/forums/src/resources/portal-forums-war/WEB-INF/forums-config.xml 2006-05-03 14:57:03 UTC (rev 4067) +++ labs/jbossforums/trunk/forums/src/resources/portal-forums-war/WEB-INF/forums-config.xml 2006-05-03 18:16:42 UTC (rev 4068) @@ -9,11 +9,11 @@ <!-- general application configuration --> <application> <!-- jbossportal-facelets integration --> - <!--property-resolver>org.jboss.portal.faces.el.DelegatingPropertyResolver</property-resolver> - <view-handler>com.sun.facelets.FaceletPortletViewHandler</view-handler--> + <property-resolver>org.jboss.portal.faces.el.DelegatingPropertyResolver</property-resolver> + <view-handler>com.sun.facelets.FaceletPortletViewHandler</view-handler> <!-- standalone facelets integration --> - <view-handler>com.sun.facelets.FaceletViewHandler</view-handler> + <!--view-handler>com.sun.facelets.FaceletViewHandler</view-handler--> <!-- internationalization --> <locale-config> @@ -58,7 +58,7 @@ </map-entry> <map-entry> <key>posting</key> - <value>/views/topics/posting_body.jsf</value> + <value>/views/topics/posting_new_body.jsf</value> </map-entry> <map-entry> <key>profile</key> @@ -108,7 +108,14 @@ <managed-bean-name>forum</managed-bean-name> <managed-bean-class>org.jboss.portlet.forums.ui.view.ViewForum</managed-bean-class> <managed-bean-scope>request</managed-bean-scope> - </managed-bean> + </managed-bean> + <navigation-rule> + <from-view-id>/views/forums/viewforum_body.xhtml</from-view-id> + <navigation-case> + <from-outcome>startNewTopic</from-outcome> + <to-view-id>/views/topics/posting_new_body.xhtml</to-view-id> + </navigation-case> + </navigation-rule> <!-- configuration for NewTopic --> <managed-bean> @@ -116,27 +123,21 @@ <managed-bean-class>org.jboss.portlet.forums.ui.action.NewTopic</managed-bean-class> <!-- this workflow is chatty and needs to be preserved on the session --> <managed-bean-scope>session</managed-bean-scope> - </managed-bean> - <navigation-rule> - <navigation-case> - <from-outcome>start</from-outcome> - <to-view-id>/views/topics/posting_body.xhtml</to-view-id> - </navigation-case> - </navigation-rule> + </managed-bean> <navigation-rule> - <from-view-id>/views/topics/posting_body.xhtml</from-view-id> + <from-view-id>/views/topics/posting_new_body.xhtml</from-view-id> <!-- straight jsf calls --> <navigation-case> <from-outcome>addOption</from-outcome> - <to-view-id>/views/topics/posting_body.xhtml</to-view-id> + <to-view-id>/views/topics/posting_new_body.xhtml</to-view-id> </navigation-case> <navigation-case> <from-outcome>updateOption</from-outcome> - <to-view-id>/views/topics/posting_body.xhtml</to-view-id> + <to-view-id>/views/topics/posting_new_body.xhtml</to-view-id> </navigation-case> <navigation-case> <from-outcome>updateAttachment</from-outcome> - <to-view-id>/views/topics/posting_body.xhtml</to-view-id> + <to-view-id>/views/topics/posting_new_body.xhtml</to-view-id> </navigation-case> <!-- jsf state by method call on managed bean first --> <navigation-case> @@ -149,12 +150,93 @@ </navigation-case> </navigation-rule> + <!-- configuration for replyTopic --> + <managed-bean> + <managed-bean-name>replyTopic</managed-bean-name> + <managed-bean-class>org.jboss.portlet.forums.ui.action.ReplyTopic</managed-bean-class> + <!-- this workflow is chatty and needs to be preserved on the session --> + <managed-bean-scope>session</managed-bean-scope> + </managed-bean> + <navigation-rule> + <from-view-id>/views/topics/posting_reply_body.xhtml</from-view-id> + <!-- straight jsf calls --> + <navigation-case> + <from-outcome>addOption</from-outcome> + <to-view-id>/views/topics/posting_reply_body.xhtml</to-view-id> + </navigation-case> + <navigation-case> + <from-outcome>updateOption</from-outcome> + <to-view-id>/views/topics/posting_reply_body.xhtml</to-view-id> + </navigation-case> + <navigation-case> + <from-outcome>updateAttachment</from-outcome> + <to-view-id>/views/topics/posting_reply_body.xhtml</to-view-id> + </navigation-case> + <!-- jsf state by method call on managed bean first --> + <navigation-case> + <from-outcome>cancel</from-outcome> + <to-view-id>/views/topics/viewtopic_body.xhtml</to-view-id> + </navigation-case> + <navigation-case> + <from-outcome>success</from-outcome> + <to-view-id>/views/topics/viewtopic_body.xhtml</to-view-id> + </navigation-case> + </navigation-rule> + + <!-- configuration for editPost --> + <managed-bean> + <managed-bean-name>editPost</managed-bean-name> + <managed-bean-class>org.jboss.portlet.forums.ui.action.EditPost</managed-bean-class> + <!-- this workflow is chatty and needs to be preserved on the session --> + <managed-bean-scope>session</managed-bean-scope> + </managed-bean> + <navigation-rule> + <from-view-id>/views/topics/posting_edit_body.xhtml</from-view-id> + <!-- straight jsf calls --> + <navigation-case> + <from-outcome>addOption</from-outcome> + <to-view-id>/views/topics/posting_edit_body.xhtml</to-view-id> + </navigation-case> + <navigation-case> + <from-outcome>updateOption</from-outcome> + <to-view-id>/views/topics/posting_edit_body.xhtml</to-view-id> + </navigation-case> + <navigation-case> + <from-outcome>updateAttachment</from-outcome> + <to-view-id>/views/topics/posting_edit_body.xhtml</to-view-id> + </navigation-case> + <!-- jsf state by method call on managed bean first --> + <navigation-case> + <from-outcome>cancel</from-outcome> + <to-view-id>/views/topics/viewtopic_body.xhtml</to-view-id> + </navigation-case> + <navigation-case> + <from-outcome>success</from-outcome> + <to-view-id>/views/topics/viewtopic_body.xhtml</to-view-id> + </navigation-case> + </navigation-rule> + <!-- managedBean for the viewTopic usecase --> <managed-bean> <managed-bean-name>topic</managed-bean-name> <managed-bean-class>org.jboss.portlet.forums.ui.view.ViewTopic</managed-bean-class> <managed-bean-scope>request</managed-bean-scope> </managed-bean> + <navigation-rule> + <from-view-id>/views/topics/viewtopic_body.xhtml</from-view-id> + <navigation-case> + <from-outcome>startNewTopic</from-outcome> + <to-view-id>/views/topics/posting_new_body.xhtml</to-view-id> + </navigation-case> + <navigation-case> + <from-outcome>startReply</from-outcome> + <to-view-id>/views/topics/posting_reply_body.xhtml</to-view-id> + </navigation-case> + <navigation-case> + <from-outcome>startEditPost</from-outcome> + <to-view-id>/views/topics/posting_edit_body.xhtml</to-view-id> + </navigation-case> + </navigation-rule> <!-- managedBean for the jumpbox usecase --> <managed-bean> Deleted: labs/jbossforums/trunk/forums/src/resources/portal-forums-war/views/topics/posting_body.xhtml =================================================================== --- labs/jbossforums/trunk/forums/src/resources/portal-forums-war/views/topics/posting_body.xhtml 2006-05-03 14:57:03 UTC (rev 4067) +++ labs/jbossforums/trunk/forums/src/resources/portal-forums-war/views/... [truncated message content] |