Index: lams_tool_forum/web/WEB-INF/classes/org/lamsfoundation/lams/tool/forum/util/MessageMapTag.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_forum/web/WEB-INF/classes/org/lamsfoundation/lams/tool/forum/util/Attic/MessageMapTag.java,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lams_tool_forum/web/WEB-INF/classes/org/lamsfoundation/lams/tool/forum/util/MessageMapTag.java 29 Jun 2005 06:37:27 -0000 1.1 @@ -0,0 +1,184 @@ +package org.lamsfoundation.lams.tool.forum.util; + +import org.lamsfoundation.lams.tool.forum.persistence.Message; + +import javax.servlet.jsp.tagext.TagSupport; +import javax.servlet.jsp.JspException; +import javax.servlet.jsp.JspWriter; +import java.util.logging.Logger; +import java.util.List; +import java.util.Set; +import java.util.Iterator; +import java.util.Map; +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 ordered = "ul"; + private String path; + 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 setOrdered(String ordered) { + if (ordered.equals("true")) { + this.ordered = "ol"; + } + } + + /** + * 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()) { + output = output + "<" + ordered + ">" + getThreadView((Message) it.next()) + + "\n"; + } + output = output + "

"; + //output = output + " "; + 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; + ordered = "ul"; + } + + private StringBuffer getThreadView(Message reply) throws Exception { + StringBuffer buffer = new StringBuffer(); + + buffer.append("\n
  • "); + buffer.append(reply.getBody()); + buffer.append(""); + buffer.append(" - "); + buffer.append(formatter.format(reply.getCreated())); + Set subReplies = reply.getReplies(); + + if (subReplies != null) { + buffer.append("\n<"); + buffer.append(ordered); + buffer.append(">"); + Iterator it = subReplies.iterator(); + while (it.hasNext()) { + buffer.append(getThreadView((Message) it.next())); + } + buffer.append("\n"); + } + buffer.append("
  • "); + return buffer; + } + + private StringBuffer getIndentedView(int level, String indentPrefix, String indentPostfix, Message reply) throws Exception { + StringBuffer buffer = new StringBuffer(); + buffer.append(indentPrefix); + buffer.append("\n"); + buffer.append("\n"); + if (reply.getCreatedBy() == null) { + buffer.append("Anonymous\n"); + } else { + buffer.append("" + reply.getCreatedBy() + "\n"); + } + buffer.append("\n"); + buffer.append("\n"); + buffer.append("" + formatter.format(reply.getCreated()) + "\n"); + buffer.append("\n"); + buffer.append("\n"); + buffer.append(""); + buffer.append("Reply"); + buffer.append("\n"); + buffer.append("\n"); + buffer.append("\n"); + buffer.append("\n"); + buffer.append(reply.getBody()); + buffer.append("\n"); + buffer.append("\n"); + 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; + } +}