1 11 package org.jboss.portlet.forums.interceptors; 12 13 import java.util.Date ; 14 15 import org.jboss.portal.common.command.Command; 16 import org.jboss.portal.common.command.CommandException; 17 import org.jboss.portal.common.command.filter.AbstractCommandFilter; 18 import org.jboss.portal.common.command.result.Result; 19 import org.jboss.portal.core.model.User; 20 import org.jboss.portal.core.modules.ModuleException; 21 import org.jboss.portlet.forums.commands.CommandConstants; 22 import org.jboss.portlet.forums.commands.post.ForumCommand; 23 24 31 public class FloodControlInterceptor 32 extends AbstractCommandFilter 33 { 34 private long floodInterval; 35 36 47 public Result filter(Command cmd) throws CommandException 48 { 49 if (cmd instanceof ForumCommand) 50 { 51 ForumCommand command = (ForumCommand) cmd; 52 53 if (command.poster.getID() != null) 54 { 55 User user = command.poster.getUser(); 56 57 long lastPostTime = 0; 58 59 try 60 { 61 Date lastPost = command.forumsModule 62 .findLastPostDateForUser(user); 63 if (lastPost != null) 64 { 65 lastPostTime = lastPost.getTime(); 66 } 67 } 68 catch (ModuleException e) 69 { 70 e.printStackTrace(); 71 } 72 if (lastPostTime > 0) 73 { 74 long now = new Date ().getTime(); 75 long interval = (now - lastPostTime) / 1000; 76 77 System.out.println("INTERVAL:" + interval); 78 79 if (interval < floodInterval) 80 { 81 return CommandConstants.TYPE_FLOODING_CANNOT_CREATE; 82 } 83 } 84 } 85 } 86 87 return getNext().filter(cmd); 88 } 89 90 95 public long getFloodInterval() 96 { 97 return floodInterval; 98 } 99 100 106 public void setFloodInterval(long floodInterval) 107 { 108 this.floodInterval = floodInterval; 109 } 110 } | Popular Tags |