Index: lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/web/actions/ForumAction =================================================================== diff -u --- lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/web/actions/ForumAction (revision 0) +++ lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/web/actions/ForumAction (revision 128b2d94bbb6c4dd2c4c4ffb96857131f3dda6cf) @@ -0,0 +1,233 @@ +package org.lamsfoundation.lams.tool.forum.web.actions; + +import org.apache.log4j.Logger; +import org.apache.struts.action.*; +import org.lamsfoundation.lams.tool.forum.core.GenericObjectFactoryImpl; +import org.lamsfoundation.lams.tool.forum.core.PersistenceException; +import org.lamsfoundation.lams.tool.forum.persistence.Forum; +import org.lamsfoundation.lams.tool.forum.persistence.Message; +import org.lamsfoundation.lams.tool.forum.persistence.Attachment; +import org.lamsfoundation.lams.tool.forum.service.ForumManager; +import org.lamsfoundation.lams.tool.forum.web.ForumForm; +import org.lamsfoundation.lams.tool.forum.web.forms.MessageForm; +import org.lamsfoundation.lams.tool.forum.util.ContentHandler; +import org.lamsfoundation.lams.tool.forum.web.actions.*; +import org.lamsfoundation.lams.tool.forum.web.ForumForm; +import org.lamsfoundation.lams.tool.forum.web.forms.MessageForm; +import org.lamsfoundation.lams.contentrepository.CrNodeVersionProperty; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.io.File; +import java.util.*; + +/** + * Created by IntelliJ IDEA. + * User: conradb + * Date: 10/06/2005 + * Time: 12:18:57 + * To change this template use File | Settings | File Templates. + */ +public class ForumAction extends Action { + private static Logger log = Logger.getLogger(org.lamsfoundation.lams.tool.forum.web.actions.ForumAction.class.getName()); + private ForumManager forumManager; + + public void setForumManager(ForumManager forumManager) { + this.forumManager = forumManager; + } + + public ForumAction() { + this.forumManager = (ForumManager) GenericObjectFactoryImpl.getInstance().lookup("forumManager"); + //GenericObjectFactoryImpl.getInstance().configure(this); + } + public final ActionForward execute(ActionMapping mapping, ActionForm form, + HttpServletRequest request, HttpServletResponse response) throws Exception { + String param = mapping.getParameter(); + if (param.equals("createForum")) { + return createForum(mapping, form, request, response); + } + if (param.equals("editForum")) { + return editForum(mapping, form, request, response); + } + if (param.equals("getForum")) { + return getForum(mapping, form, request, response); + } + if (param.equals("deleteForum")) { + return deleteForum(mapping, form, request, response); + } + if (param.equals("createTopic")) { + return createTopic(mapping, form, request, response); + } + if (param.equals("instructions")) { + return saveInstructions(mapping, form, request, response); + } + if (param.equals("deleteAttachment")) { + return deleteAttachment(mapping, form, request, response); + } + if (param.equals("deleteTopic")) { + return deleteTopic(mapping, form, request, response); + } + if (param.equals("advanced")) { + return mapping.findForward("success"); + } + return mapping.findForward("error"); + } + + public ActionForward createForum(ActionMapping mapping, + ActionForm form, + HttpServletRequest request, + HttpServletResponse response) + throws IOException, ServletException, Exception { + ForumForm forumForm = (ForumForm) form; + Forum forum = forumForm.getForum(); + + Map topics = (Map) request.getSession().getAttribute("topics"); + forum = this.forumManager.createForum(forum, forumForm.getAttachments(), topics); + forumForm.setForum(forum); + + //populate topics with new topics + List topicList = this.forumManager.getTopics(forum.getId()); + topics = new HashMap(); + Iterator it = topicList.iterator(); + while (it.hasNext()) { + Message message = (Message) it.next(); + topics.put(message.getSubject(), message); + } + + request.getSession().setAttribute("topics", topics); + request.getSession().setAttribute("topicList", topicList); + return mapping.findForward("success"); + } + + public ActionForward editForum(ActionMapping mapping, + ActionForm form, + HttpServletRequest request, + HttpServletResponse response) + throws IOException, ServletException, Exception { + ForumForm forumForm = (ForumForm) form; + Forum forum = forumForm.getForum(); + Map topics = (Map) request.getSession().getAttribute("topics"); + this.forumManager.editForum(forum, forumForm.getAttachments(), topics); + return mapping.findForward("success"); + } + + public ActionForward getForum(ActionMapping mapping, + ActionForm form, + HttpServletRequest request, + HttpServletResponse response) + throws IOException, ServletException, Exception { + Long forumId = new Long((String) request.getParameter("forumId")); + Forum forum = forumManager.getForum(forumId); + List topicList = this.forumManager.getTopics(forum.getId()); + ForumForm forumForm = new ForumForm(); + + forumForm.setForum(forum); + request.getSession().setAttribute("forum", forumForm); + + Map topics = new HashMap(); + Iterator it = topicList.iterator(); + while (it.hasNext()) { + Message message = (Message) it.next(); + topics.put(message.getSubject(), message); + } + + request.getSession().setAttribute("topics", topics); + request.getSession().setAttribute("topicList", topicList); + + List attachmentList = new ArrayList(); + Collection entries = forum.getAttachments(); + it = entries.iterator(); + while (it.hasNext()) { + Attachment attachment = (Attachment) it.next(); + ContentHandler handler = new ContentHandler(); + Set properties = handler.getFileProperties(attachment.getUuid()); + Iterator propIt = properties.iterator(); + while (propIt.hasNext()) { + CrNodeVersionProperty property = (CrNodeVersionProperty) propIt.next(); + if ("FILENAME".equals(property.getName())) { + attachment.setName(property.getValue()); + } + if ("TYPE".equals(property.getName())) { + attachment.setType(property.getValue()); + } + if ("MIMETYPE".equals(property.getName())) { + attachment.setContentType(property.getValue()); + } + } + attachmentList.add(attachment); + } + request.getSession().setAttribute("attachmentList", attachmentList); + return mapping.findForward("success"); + } + + public ActionForward deleteForum(ActionMapping mapping, + ActionForm form, + HttpServletRequest request, + HttpServletResponse response) + throws IOException, ServletException, Exception { + Long forumId = new Long((String) request.getParameter("forumId")); + forumManager.deleteForum(forumId); + return (mapping.findForward("success")); + } + + public ActionForward createTopic(ActionMapping mapping, + ActionForm form, + HttpServletRequest request, + HttpServletResponse response) + throws IOException, ServletException, PersistenceException { + MessageForm messageForm = (MessageForm) form; + Message message = messageForm.getMessage(); + Map topics = (Map) request.getSession().getAttribute("topics"); + if (topics == null) { + topics = new HashMap(); + } + topics.put(message.getSubject(), message); + request.getSession().setAttribute("topics", topics); + request.getSession().setAttribute("topicList", new ArrayList(topics.values())); + return mapping.findForward("success"); + } + + public ActionForward saveInstructions(ActionMapping mapping, + ActionForm form, + HttpServletRequest request, + HttpServletResponse response) + throws IOException, ServletException, PersistenceException { + ForumForm forumForm = (ForumForm) form; + Collection entries = forumForm.getAttachments().values(); + List attachmentList = new ArrayList(entries); + request.getSession().setAttribute("attachmentList", attachmentList); + return mapping.findForward("success"); + } + + public ActionForward deleteAttachment(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { + ActionForward forward = new ActionForward(); + forward.setPath(mapping.getInput()); + String fileName = (String) request.getParameter("fileName"); + String type = (String) request.getParameter("type"); + ForumForm forumForm = (ForumForm) form; + Map attachments = forumForm.getAttachments(); + Attachment attachment = (Attachment) attachments.remove(fileName + "-" + type); + ContentHandler.deleteFile(attachment.getUuid()); + if (attachment.getId() != null) { + this.forumManager.deleteForumAttachment(attachment.getId()); + } + List attachmentList = new ArrayList(attachments.values()); + request.getSession().setAttribute("attachmentList", attachmentList); + return mapping.findForward("success"); + } + + public ActionForward deleteTopic(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws PersistenceException { + String topicName = (String) request.getParameter("topicName"); + Map topics = (Map) request.getSession().getAttribute("topics"); + Message topic = (Message) topics.remove(topicName); + if (topic.getId() != null) { + this.forumManager.deleteMessage(topic.getId()); + } + request.getSession().setAttribute("topics", topics); + request.getSession().setAttribute("topicList", new ArrayList(topics.values())); + return mapping.findForward("success"); + } + +} Index: lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/web/actions/LearningAction.java =================================================================== diff -u --- lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/web/actions/LearningAction.java (revision 0) +++ lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/web/actions/LearningAction.java (revision 128b2d94bbb6c4dd2c4c4ffb96857131f3dda6cf) @@ -0,0 +1,186 @@ +package org.lamsfoundation.lams.tool.forum.web.actions; + +/** + * Created by IntelliJ IDEA. + * User: conradb + * Date: 7/07/2005 + * Time: 16:44:50 + * To change this template use File | Settings | File Templates. + */ import org.apache.struts.action.Action; +import org.apache.struts.action.ActionForward; +import org.apache.struts.action.ActionMapping; +import org.apache.struts.action.ActionForm; +import org.apache.log4j.Logger; +import org.lamsfoundation.lams.tool.forum.service.ForumManager; +import org.lamsfoundation.lams.tool.forum.core.GenericObjectFactoryImpl; +import org.lamsfoundation.lams.tool.forum.core.PersistenceException; +import org.lamsfoundation.lams.tool.forum.persistence.Forum; +import org.lamsfoundation.lams.tool.forum.persistence.Message; +import org.lamsfoundation.lams.tool.forum.web.ForumForm; +import org.lamsfoundation.lams.tool.forum.web.forms.MessageForm; +import org.lamsfoundation.lams.tool.forum.permissions.Permission; +import org.lamsfoundation.lams.tool.forum.permissions.PermissionManagerImpl; +import org.lamsfoundation.lams.tool.forum.permissions.PermissionManager; +import org.lamsfoundation.lams.tool.forum.actions.*; +import org.lamsfoundation.lams.tool.forum.web.ForumForm; +import org.lamsfoundation.lams.tool.forum.web.forms.MessageForm; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.ServletException; +import java.io.IOException; +import java.util.List; + +/** + * Created by IntelliJ IDEA. + * User: conradb + * Date: 24/06/2005 + * Time: 10:54:09 + * To change this template use File | Settings | File Templates. + */ +public class LearningAction extends Action { + private static Logger log = Logger.getLogger(org.lamsfoundation.lams.tool.forum.web.actions.LearningAction.class.getName()); + private ForumManager forumManager; + private PermissionManager permissionManager; + + + public LearningAction() { + this.forumManager = (ForumManager) GenericObjectFactoryImpl.getInstance().lookup("forumManager"); + this.permissionManager = (PermissionManager) GenericObjectFactoryImpl.getInstance().lookup("permissionManager"); + } + + public final ActionForward execute(ActionMapping mapping, ActionForm form, + HttpServletRequest request, HttpServletResponse response) throws Exception { + String param = mapping.getParameter(); + if (param.equals("openForum")) { + return getForum(mapping, form, request, response); + } + if (param.equals("editMessage")) { + return editMessage(mapping, form, request, response); + } + if (param.equals("openTopic")) { + return getTopic(mapping, form, request, response); + } + if (param.equals("getMessage")) { + return getMessage(mapping, form, request, response); + } + if (param.equals("deleteMessage")) { + return deleteMessage(mapping, form, request, response); + } + if (param.equals("post")) { + return post(mapping, form, request, response); + } + if (param.equals("reply")) { + return replyToMessage(mapping, form, request, response); + } + return mapping.findForward("error"); + } + + public ActionForward post(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) + throws PersistenceException { + Long topicId = new Long((String) request.getParameter("topicId")); + Long parentId = new Long((String) request.getParameter("parentId")); + Message parent = forumManager.getMessage(parentId); + MessageForm messageForm = new MessageForm(); + Message reply = new Message(); + reply.setParent(parent); + reply.setSubject(parent.getSubject()); + messageForm.setTopicId(topicId); + messageForm.setParentId(parentId); + messageForm.setMessage(reply); + request.setAttribute("messageForm", messageForm); + return mapping.findForward("success"); + } + + public ActionForward getForum(ActionMapping mapping, + ActionForm form, + HttpServletRequest request, + HttpServletResponse response) + throws IOException, ServletException, Exception { + Long forumId = new Long((String) request.getParameter("forumId")); + Forum forum = forumManager.getForum(forumId); + List topicList = this.forumManager.getTopics(forum.getId()); + ForumForm forumForm = new ForumForm(); + forumForm.setForum(forum); + request.setAttribute("forum", forumForm); + request.setAttribute("forumTopics", topicList); + return mapping.findForward("success"); + } + + public ActionForward editMessage(ActionMapping mapping, + ActionForm form, + HttpServletRequest request, + HttpServletResponse response) + throws IOException, ServletException, PersistenceException { + MessageForm messageForm = (MessageForm) form; + Message message = messageForm.getMessage(); + message = this.forumManager.editMessage(message); + request.setAttribute("topicId", messageForm.getTopicId()); + return mapping.findForward("success"); + } + + public ActionForward replyToMessage(ActionMapping mapping, + ActionForm form, + HttpServletRequest request, + HttpServletResponse response) + throws IOException, ServletException, PersistenceException { + MessageForm messageForm = (MessageForm) form; + Message message = messageForm.getMessage(); + Long parentId = messageForm.getParentId(); + Message reply = this.forumManager.replyToMessage(parentId, message); + request.setAttribute("messageId", parentId); + request.setAttribute("topicId", messageForm.getTopicId()); + request.setAttribute("message", reply.getParent()); + return mapping.findForward("success"); + } + + public ActionForward deleteMessage(ActionMapping mapping, + ActionForm form, + HttpServletRequest request, + HttpServletResponse response) + throws IOException, ServletException, Exception { + Long messageId = new Long((String) request.getParameter("messageId")); + this.forumManager.deleteMessage(messageId); + return mapping.findForward("success"); + } + + public ActionForward getTopic(ActionMapping mapping, + ActionForm form, + HttpServletRequest request, + HttpServletResponse response) + throws IOException, ServletException, Exception { + Long topicId = new Long((String) request.getParameter("topicId")); + Message message = forumManager.getMessage(topicId); + request.setAttribute("message", message); + Long userId = null; + try { + userId = new Long((String) request.getParameter("userId")); + } catch (Exception e) { + //will always be null for now as we are handling tool independently from user for now later we have to get + //the current logged used from the session + } + boolean moderate = permissionManager.hasPermission(userId, Permission.MODERATE); + String permissionType = Permission.WRITE; + if (moderate) { + permissionType = Permission.MODERATE; + } + request.setAttribute("permission", permissionType); + return mapping.findForward("success"); + } + + public ActionForward getMessage(ActionMapping mapping, + ActionForm form, + HttpServletRequest request, + HttpServletResponse response) + throws IOException, ServletException, Exception { + Long topicId = new Long((String) request.getParameter("topicId")); + Long messageId = new Long((String) request.getParameter("messageId")); + Message message = forumManager.getMessage(messageId); + MessageForm messageForm = new MessageForm(); + messageForm.setMessage(message); + messageForm.setTopicId(topicId); + request.setAttribute("messageForm", messageForm); + return mapping.findForward("success"); + } + +} Index: lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/web/forms/ForumForm.java =================================================================== diff -u --- lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/web/forms/ForumForm.java (revision 0) +++ lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/web/forms/ForumForm.java (revision 128b2d94bbb6c4dd2c4c4ffb96857131f3dda6cf) @@ -0,0 +1,156 @@ +package org.lamsfoundation.lams.tool.forum.web.forms; + +import org.apache.struts.validator.ValidatorForm; +import org.apache.struts.upload.FormFile; +import org.apache.struts.action.ActionErrors; +import org.apache.struts.action.ActionMapping; +import org.apache.struts.action.ActionError; +import org.apache.log4j.Logger; +import org.lamsfoundation.lams.tool.forum.persistence.Forum; +import org.lamsfoundation.lams.tool.forum.persistence.Attachment; +import org.lamsfoundation.lams.tool.forum.util.ContentHandler; +import org.lamsfoundation.lams.tool.forum.util.ForumConstants; +import org.lamsfoundation.lams.contentrepository.NodeKey; + +import java.util.Map; +import java.util.HashMap; + +/** + * + * Message Form. + * @struts.form name="forumForm" + * + * Created by IntelliJ IDEA. + * User: conradb + * Date: 10/06/2005 + * Time: 15:44:36 + * To change this template use File | Settings | File Templates. + */ +public class ForumForm extends ValidatorForm { + protected Forum forum; + private FormFile offlineFile; + private FormFile onlineFile; + protected Map attachments; + protected boolean lockWhenFinished; + protected boolean forceOffline; + protected boolean allowAnnomity; + protected ContentHandler contentHander; + + private static Logger logger = Logger.getLogger(org.lamsfoundation.lams.tool.forum.web.ForumForm.class.getName()); + + public ForumForm() { + this.forum = new Forum(); + this.forum.setTitle("New Forum"); + this.attachments = new HashMap(); + } + + public void setForum(Forum forum) { + this.forum = forum; + } + + public Forum getForum() { + return forum; + } + + public void setOnlineFile(FormFile onlineFile) { + this.onlineFile = onlineFile; + } + + public FormFile getOnlineFile() { + return onlineFile; + } + + public void setOfflineFile(FormFile offlineFile) { + this.offlineFile = offlineFile; + } + + public FormFile getOfflineFile() { + return offlineFile; + } + + public boolean getAllowAnnomity() { + return allowAnnomity; + } + + public void setAllowAnnomity(boolean allowAnnomity) { + this.allowAnnomity = allowAnnomity; + } + + public boolean getLockWhenFinished() { + return lockWhenFinished; + } + + public void setLockWhenFinished(boolean lockWhenFinished) { + this.lockWhenFinished = lockWhenFinished; + } + + public boolean getForceOffline() { + return forceOffline; + } + + public void setForceOffline(boolean forceOffline) { + this.forceOffline = forceOffline; + } + + public void setAttachments(Map attachments) { + this.attachments = attachments; + } + + public Map getAttachments() { + return this.attachments; + } + + public ActionErrors validate(ActionMapping mapping, + javax.servlet.http.HttpServletRequest request) { + ActionErrors errors = super.validate(mapping, request); + ActionError ae; + try{ + if ("".equals(forum.getTitle())) { + ActionError error = new ActionError("error.valueReqd"); + errors.add("forum.title", error); + } + if (onlineFile != null && !(onlineFile.getFileName().trim().equals(""))) { + if (onlineFile.getFileSize() > ForumConstants.MAX_FILE_SIZE) { + ae = new ActionError("error.inputFileTooLarge"); + errors.add("onlineFile", ae); + } else { + String fileName = onlineFile.getFileName(); + if (!attachments.containsKey(fileName +"-" + Attachment.TYPE_ONLINE)) { + NodeKey node = ContentHandler.uploadFile(onlineFile.getInputStream(), fileName, onlineFile.getContentType()); + ContentHandler.setProperty(node.getUuid(), node.getVersion(), "TYPE", Attachment.TYPE_ONLINE); + Attachment attachment = new Attachment(); + attachment.setName(fileName); + attachment.setStream(onlineFile.getInputStream()); + attachment.setUuid(node.getUuid()); + attachment.setType(Attachment.TYPE_ONLINE); + attachments.put(fileName + "-" + Attachment.TYPE_ONLINE, attachment); + onlineFile = null; + } + } + } + if (offlineFile != null && !(offlineFile.getFileName().trim().equals(""))) { + if (offlineFile.getFileSize() > ForumConstants.MAX_FILE_SIZE) { + ae = new ActionError("error.inputFileTooLarge"); + errors.add("offlineFile", ae); + } else { + String fileName = offlineFile.getFileName(); + if (!attachments.containsKey(fileName +"-" + Attachment.TYPE_OFFLINE)) { + NodeKey node = ContentHandler.uploadFile(offlineFile.getInputStream(), fileName, offlineFile.getContentType()); + ContentHandler.setProperty(node.getUuid(), node.getVersion(), "TYPE", Attachment.TYPE_OFFLINE); + Attachment attachment = new Attachment(); + attachment.setName(fileName); + attachment.setStream(offlineFile.getInputStream()); + attachment.setUuid(node.getUuid()); + attachment.setType(Attachment.TYPE_OFFLINE); + attachments.put(fileName + "-" + Attachment.TYPE_OFFLINE, attachment); + offlineFile = null; + } + } + } + } catch (Exception e) { + logger.error("", e); + } + return errors; + } + +} Index: lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/web/forms/MessageForm.java =================================================================== diff -u --- lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/web/forms/MessageForm.java (revision 0) +++ lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/web/forms/MessageForm.java (revision 128b2d94bbb6c4dd2c4c4ffb96857131f3dda6cf) @@ -0,0 +1,83 @@ +package org.lamsfoundation.lams.tool.forum.web.forms; + +import org.apache.struts.validator.ValidatorForm; +import org.apache.struts.action.ActionErrors; +import org.apache.struts.action.ActionMapping; +import org.apache.struts.action.ActionError; +import org.apache.log4j.Logger; +import org.lamsfoundation.lams.tool.forum.persistence.Message; + +/** + * + * Message Form. + * @struts.form name="messageForm" + * + * Created by IntelliJ IDEA. + * User: conradb + * Date: 10/06/2005 + * Time: 15:44:47 + * To change this template use File | Settings | File Templates. + */ +public class MessageForm extends ValidatorForm { + protected Message message; + protected Long forumId; + protected Long parentId; + protected Long topicId; + private static Logger logger = Logger.getLogger(org.lamsfoundation.lams.tool.forum.web.ForumForm.class.getName()); + + public MessageForm() { + this.message = new Message(); + } + + public void setMessage(Message message) { + this.message = message; + } + + public Message getMessage() { + return message; + } + + public void setForumId(Long forumId) { + this.forumId = forumId; + } + + public Long getForumId() { + return this.forumId; + } + + public void setParentId(Long parentId) { + this.parentId = parentId; + } + + public Long getParentId() { + return this.parentId; + } + + public void setTopicId(Long topicId) { + this.topicId = topicId; + } + + public Long getTopicId() { + return this.topicId; + } + + public ActionErrors validate(ActionMapping mapping, + javax.servlet.http.HttpServletRequest request) { + ActionErrors errors = super.validate(mapping, request); + ActionError ae; + try{ + if ("".equals(message.getSubject())) { + ActionError error = new ActionError("error.valueReqd"); + errors.add("message.subject", error); + } + if ("".equals(message.getBody())) { + ActionError error = new ActionError("error.valueReqd"); + errors.add("message.body", error); + } + } catch (Exception e) { + logger.error("", e); + } + return errors; + } + +} Index: lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/web/util/MessageMapTag.java =================================================================== diff -u --- lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/web/util/MessageMapTag.java (revision 0) +++ lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/web/util/MessageMapTag.java (revision 128b2d94bbb6c4dd2c4c4ffb96857131f3dda6cf) @@ -0,0 +1,166 @@ +package org.lamsfoundation.lams.tool.forum.web.util; + +import org.lamsfoundation.lams.tool.forum.persistence.Message; +import org.lamsfoundation.lams.tool.forum.permissions.Permission; + +import javax.servlet.jsp.tagext.TagSupport; +import javax.servlet.jsp.JspException; +import javax.servlet.jsp.JspWriter; +import java.util.logging.Logger; +import java.util.Set; +import java.util.Iterator; +import java.text.SimpleDateFormat; + +/** + * Created by IntelliJ IDEA. + * User: conradb + * Date: 24/06/2005 + * Time: 15:33:51 + * To change this template use File | Settings | File Templates. + */ +public class MessageMapTag extends TagSupport { + + private Logger log = Logger.getLogger(MessageMapTag.class.getName()); + private Set replies = null; + private String path=""; + private String mode; + private String topicId; + + private SimpleDateFormat formatter = new SimpleDateFormat("dd:MM:yy hh:mm a"); + + public MessageMapTag() { + + } + + public void setPath(String path) { + this.path = path; + } + + public void setTopicId(String topicId) { + this.topicId = topicId; + } + + public void setReplies(Set replies) { + this.replies = replies; + } + + public void setMode(String mode) { + this.mode = mode; + } + + /** + * Defer our checking until the end of this tag is encountered. + * + * @exception javax.servlet.jsp.JspException if a JSP exception has occurred + */ + public int doStartTag() throws JspException { + return (SKIP_BODY); + } + + /** + * + * @exception JspException if a JSP exception has occurred + */ + public int doEndTag() throws JspException { + try { + + if (replies != null) { + String output = ""; + Iterator it = replies.iterator(); + + while (it.hasNext()) { + String indentPrefix = "\n"; + String indentPostfix = "
\n

\n"; + int level = 0; + output = output + this.getIndentedView(level, indentPrefix, indentPostfix, (Message) it.next()); + } + JspWriter writer = pageContext.getOut(); + writer.print(output); + } + return EVAL_PAGE; + } catch (Exception e) { + throw new JspException(e.getMessage()); + } + } + + /** + * Release any acquired resources. + */ + public void release() { + super.release(); + replies = null; + } + + private StringBuffer getIndentedView(int level, String indentPrefix, String indentPostfix, Message reply) throws Exception { + StringBuffer buffer = new StringBuffer(); + buffer.append(indentPrefix); + buffer.append("\n"); + + //Creadted By Link + buffer.append("\n"); + if (reply.getCreatedBy() == null) { + buffer.append("Anonymous\n"); + } else { + buffer.append("" + reply.getCreatedBy() + "\n"); + } + buffer.append("\n"); + + //Created Date + buffer.append("\n"); + buffer.append("" + formatter.format(reply.getCreated()) + "\n"); + buffer.append("\n"); + + //Edit Link + if (Permission.MODERATE.equals(mode)) { + buffer.append("\n"); + //buffer.append(""); + buffer.append("Edit"); + buffer.append("\n"); + buffer.append("\n"); + } + + //Reply To Link + if (Permission.MODERATE.equals(mode) || Permission.WRITE.equals(mode)) { + buffer.append("\n"); + buffer.append(""); + buffer.append("Reply"); + buffer.append("\n"); + buffer.append("\n"); + } + + //Body of Message + buffer.append("\n"); + buffer.append("\n"); + buffer.append(reply.getBody()); + buffer.append("\n"); + buffer.append("\n"); + + //Intented Replies of the Messages + buffer.append(indentPostfix); + Iterator it = reply.getReplies().iterator(); + level = level + 2; + while (it.hasNext()) { + StringBuffer preFix = new StringBuffer(); + preFix.append("\n"); + preFix.append("\n"); + preFix.append("\n"); + preFix.append("\n"); + postFix.append("
\n"); + preFix.append(""); + preFix.append("\n"); + StringBuffer postFix = new StringBuffer(); + postFix.append("
\n"); + postFix.append("
\n"); + postFix.append("

\n"); + buffer.append(this.getIndentedView(level, preFix.toString(), postFix.toString(), (Message) it.next())); + } + return buffer; + } +} Index: lams_tool_forum/web/WEB-INF/forum.tld =================================================================== diff -u -r751f9c3d1b91aba9a9c322394fd70778cd7aa64a -r128b2d94bbb6c4dd2c4c4ffb96857131f3dda6cf --- lams_tool_forum/web/WEB-INF/forum.tld (.../forum.tld) (revision 751f9c3d1b91aba9a9c322394fd70778cd7aa64a) +++ lams_tool_forum/web/WEB-INF/forum.tld (.../forum.tld) (revision 128b2d94bbb6c4dd2c4c4ffb96857131f3dda6cf) @@ -23,7 +23,7 @@ messagemap - org.lamsfoundation.lams.tool.forum.util.MessageMapTag + org.lamsfoundation.lams.tool.forum.web.util.MessageMapTag empty Generate a messagemap