001: /*
002: * Copyright (c) JForum Team
003: * All rights reserved.
004: *
005: * Redistribution and use in source and binary forms,
006: * with or without modification, are permitted provided
007: * that the following conditions are met:
008: *
009: * 1) Redistributions of source code must retain the above
010: * copyright notice, this list of conditions and the
011: * following disclaimer.
012: * 2) Redistributions in binary form must reproduce the
013: * above copyright notice, this list of conditions and
014: * the following disclaimer in the documentation and/or
015: * other materials provided with the distribution.
016: * 3) Neither the name of "Rafael Steil" nor
017: * the names of its contributors may be used to endorse
018: * or promote products derived from this software without
019: * specific prior written permission.
020: *
021: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
022: * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
023: * EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
024: * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
025: * MERCHANTABILITY AND FITNESS FOR A PARTICULAR
026: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
027: * THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
028: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
029: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES
030: * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
031: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
032: * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
033: * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
034: * IN CONTRACT, STRICT LIABILITY, OR TORT
035: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
036: * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
037: * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
038: *
039: * This file creation date: 04/03/2004 - 20:32:13
040: * The JForum Project
041: * http://www.jforum.net
042: */
043: package net.jforum.util.mail;
044:
045: import java.text.MessageFormat;
046: import java.util.List;
047:
048: import net.jforum.entities.Forum;
049: import net.jforum.entities.Post;
050: import net.jforum.entities.Topic;
051: import net.jforum.util.preferences.ConfigKeys;
052: import net.jforum.util.preferences.SystemGlobals;
053: import net.jforum.view.forum.common.PostCommon;
054: import net.jforum.view.forum.common.ViewCommon;
055: import freemarker.template.SimpleHash;
056:
057: /**
058: * @author Rafael Steil
059: * @version $Id: ForumNewTopicSpammer.java,v 1.4 2006/10/09 00:54:09 rafaelsteil Exp $
060: */
061: public class ForumNewTopicSpammer extends Spammer {
062: public ForumNewTopicSpammer(Forum forum, Topic topic, Post post,
063: List users) {
064: String forumLink = ViewCommon.getForumLink();
065: String path = this .postLink(topic, forumLink);
066: String unwatch = this .unwatchLink(forum, forumLink);
067:
068: SimpleHash params = new SimpleHash();
069: params.put("topic", topic);
070: params.put("path", path);
071: params.put("forumLink", forumLink);
072: params.put("unwatch", unwatch);
073:
074: this .setUsers(users);
075:
076: if (post != null) {
077: post = PostCommon.preparePostForDisplay(post);
078: params.put("message", post.getText());
079: }
080:
081: this .setTemplateParams(params);
082:
083: String subject = SystemGlobals
084: .getValue(ConfigKeys.MAIL_NEW_TOPIC_SUBJECT);
085:
086: super .prepareMessage(MessageFormat.format(subject,
087: new Object[] { topic.getTitle() }), SystemGlobals
088: .getValue(ConfigKeys.MAIL_NEW_TOPIC_MESSAGE_FILE));
089: }
090:
091: /**
092: * @param forum
093: * @param forumLink
094: * @return
095: */
096: private String unwatchLink(Forum forum, String forumLink) {
097: String unwatch = new StringBuffer(128)
098: .append(forumLink)
099: .append("forums/unwatchForum/")
100: .append(forum.getId())
101: .append(
102: SystemGlobals
103: .getValue(ConfigKeys.SERVLET_EXTENSION))
104: .toString();
105: return unwatch;
106: }
107:
108: /**
109: * @param topic
110: * @param forumLink
111: * @return
112: */
113: private String postLink(Topic topic, String forumLink) {
114: String path = new StringBuffer(128).append(forumLink).append(
115: "posts/list/").append(topic.getId()).append(
116: SystemGlobals.getValue(ConfigKeys.SERVLET_EXTENSION))
117: .append('#').append(topic.getLastPostId()).toString();
118: return path;
119: }
120: }
|