added:
[mir.git] / source / mircoders / global / Abuse.java
index dd54988..697d6e2 100755 (executable)
@@ -34,11 +34,11 @@ import mir.config.MirPropertiesConfiguration;
 import mir.entity.Entity;
 import mir.entity.adapter.EntityAdapterModel;
 import mir.log.LoggerWrapper;
+import mir.module.EntityNotFoundExc;
 import mir.session.Request;
 import mir.util.DateTimeRoutines;
 import mir.util.EntityUtility;
 import mir.util.GeneratorFormatAdapters;
-import mir.util.StringRoutines;
 import mircoders.abuse.FilterEngine;
 import mircoders.entity.EntityComment;
 import mircoders.entity.EntityContent;
@@ -51,7 +51,6 @@ import javax.servlet.http.Cookie;
 import javax.servlet.http.HttpServletResponse;
 import java.io.BufferedOutputStream;
 import java.io.File;
-import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.util.ArrayList;
 import java.util.Date;
@@ -78,7 +77,7 @@ public class Abuse {
   private boolean cookieOnBlock;
   private String articleBlockAction;
   private String commentBlockAction;
-  private List log;
+  private final List log = new ArrayList();
   private File configFile = MirGlobal.config().getFile("Abuse.Config");
   private FilterEngine filterEngine;
 
@@ -93,8 +92,6 @@ public class Abuse {
     filterEngine = new FilterEngine(aModel);
     model = aModel;
 
-    log = new ArrayList();
-
     try {
       configuration = MirPropertiesConfiguration.instance();
     }
@@ -289,40 +286,45 @@ public class Abuse {
     ModuleComment commentModule = new ModuleComment();
 
     synchronized (log) {
-      try {
-        List result = new ArrayList();
+      List result = new ArrayList();
 
-        Iterator i = log.iterator();
-        while (i.hasNext()) {
-          LogEntry logEntry = (LogEntry) i.next();
-          Map entry = new HashMap();
+      Iterator i = log.iterator();
+      while (i.hasNext()) {
+        LogEntry logEntry = (LogEntry) i.next();
+        Map entry = new HashMap();
 
-          entry.put("ip", logEntry.getIpNumber());
-          entry.put("id", logEntry.getId());
-          entry.put("timestamp", new GeneratorFormatAdapters.DateFormatAdapter(logEntry.getTimeStamp(), MirPropertiesConfiguration.instance().getString("Mir.DefaultTimezone")));
+        entry.put("ip", logEntry.getIpNumber());
+        entry.put("id", logEntry.getId());
+        entry.put("timestamp", new GeneratorFormatAdapters.DateFormatAdapter(logEntry.getTimeStamp(), MirPropertiesConfiguration.instance().getString("Mir.DefaultTimezone")));
 
-          if (logEntry.getIsArticle()) {
-            entry.put("type", "content");
+        if (logEntry.getIsArticle()) {
+          entry.put("type", "content");
+          try {
             entry.put("object",
                 model.makeEntityAdapter("content", contentModule.getById(logEntry.getId())));
           }
-          else {
-            entry.put("type", "comment");
+          catch (EntityNotFoundExc e) {
+            entry.put("object", null);
+          }
+        }
+        else {
+          entry.put("type", "comment");
+          try {
             entry.put("object",
                 model.makeEntityAdapter("comment", commentModule.getById(logEntry.getId())));
           }
-
-          entry.put("browser", logEntry.getBrowserString());
-          entry.put("filtertag", logEntry.getMatchingFilterTag());
-
-          result.add(entry);
+          catch (EntityNotFoundExc e) {
+            entry.put("object", null);
+          }
         }
 
-        return result;
-      }
-      catch (Throwable t) {
-        throw new RuntimeException(t.toString());
+        entry.put("browser", logEntry.getBrowserString());
+        entry.put("filtertag", logEntry.getMatchingFilterTag());
+
+        result.add(entry);
       }
+
+      return result;
     }
   }
 
@@ -360,13 +362,7 @@ public class Abuse {
 
   public synchronized void load() {
     try {
-      ExtendedProperties configuration = new ExtendedProperties();
-
-      try {
-        configuration = new ExtendedProperties(configFile.getAbsolutePath());
-      }
-      catch (FileNotFoundException e) {
-      }
+      ExtendedProperties configuration = new ExtendedProperties(configFile.getAbsolutePath());
 
       setOpenPostingDisabled(configuration.getString("abuse.openPostingDisabled", "0").equals("1"));
       setOpenPostingPassword(configuration.getString("abuse.openPostingPassword", "0").equals("1"));
@@ -406,8 +402,8 @@ public class Abuse {
 
       Iterator i = MirGlobal.localizer().adminInterface().simpleArticleOperations().iterator();
       while (i.hasNext()) {
-        MirAdminInterfaceLocalizer.MirSimpleEntityOperation operation =
-            (MirAdminInterfaceLocalizer.MirSimpleEntityOperation) i.next();
+        MirAdminInterfaceLocalizer.EntityOperation operation =
+            (MirAdminInterfaceLocalizer.EntityOperation) i.next();
 
         Map action = new HashMap();
         action.put("resource", operation.getName());
@@ -429,8 +425,8 @@ public class Abuse {
 
       Iterator i = MirGlobal.localizer().adminInterface().simpleCommentOperations().iterator();
       while (i.hasNext()) {
-        MirAdminInterfaceLocalizer.MirSimpleEntityOperation operation =
-            (MirAdminInterfaceLocalizer.MirSimpleEntityOperation) i.next();
+        MirAdminInterfaceLocalizer.EntityOperation operation =
+            (MirAdminInterfaceLocalizer.EntityOperation) i.next();
 
         Map action = new HashMap();
         action.put("resource", operation.getName());
@@ -446,25 +442,6 @@ public class Abuse {
     }
   }
 
-  private String escapeConfigListEntry(String aFilterPart) {
-    return StringRoutines.replaceStringCharacters(aFilterPart,
-        new char[] {'\\', ':'},
-        new String[] {"\\\\", "\\:"});
-  }
-
-  private String escapeFilterPart(String aFilterPart) {
-    return StringRoutines.replaceStringCharacters(aFilterPart,
-        new char[] {'\\', '\n', '\r', '\t', ' '},
-        new String[] {"\\\\", "\\n", "\\r", "\\t", "\\ "});
-  }
-
-  private String deescapeFilterPart(String aFilterPart) {
-    return StringRoutines.replaceEscapedStringCharacters(aFilterPart,
-        '\\',
-        new char[] {'\\', ':', 'n', 'r', 't', ' '},
-        new String[] {"\\", ":", "\n", "\r", "\t", " "});
-  }
-
   private static class LogEntry {
     private String ipNumber;
     private String browserString;