Initial revision
[mir.git] / source / mircoders / servlet / ServletModuleMessage.java
diff --git a/source/mircoders/servlet/ServletModuleMessage.java b/source/mircoders/servlet/ServletModuleMessage.java
new file mode 100755 (executable)
index 0000000..b065a91
--- /dev/null
@@ -0,0 +1,80 @@
+package mircoders.servlet;
+
+import java.io.*;
+import java.net.*;
+import javax.servlet.http.*;
+import javax.servlet.*;
+import freemarker.template.*;
+import webdb.servlet.*;
+import webdb.misc.*;
+import webdb.entity.*;
+import webdb.storage.*;
+import webdb.module.*;
+import mir.module.*;
+import mir.storage.*;
+
+/**
+ * Title:    ServletModuleMessage
+ * Description:
+ * Copyright:    Copyright (c) 2001
+ * Company:      Indymedia
+ * @author
+ * @version 1.0
+ */
+
+
+public class ServletModuleMessage extends ServletModule
+{
+
+       // Singelton / Kontruktor
+
+       private static ServletModuleMessage instance = new ServletModuleMessage();
+       public static ServletModule getInstance() { return instance; }
+
+       private ServletModuleMessage() {
+               theLog = Logfile.getInstance(Configuration.getProperty("Home") + Configuration.getProperty("ServletModule.Messages.Logfile"));
+               templateListString = Configuration.getProperty("ServletModule.Messages.ListTemplate");
+               templateObjektString = Configuration.getProperty("ServletModule.Messages.ObjektTemplate");
+               templateConfirmString = Configuration.getProperty("ServletModule.Messages.ConfirmTemplate");
+               try {
+                       mainModule = new ModuleMessage(DatabaseMessages.getInstance());
+               }
+               catch (StorageObjectException e) {
+                       theLog.printDebugInfo("ServletModuleMessage konnte nicht initialisiert werden");
+               }
+       }
+
+       public void list(HttpServletRequest req, HttpServletResponse res)
+               throws ServletModuleException
+       {
+               // fetch and deliver
+               try {
+                       SimpleHash mergeData = new SimpleHash();
+                       String offset = req.getParameter("offset");
+                       if (offset==null || offset.equals("")) offset="0";
+                       mergeData.put("offset",offset);
+                       EntityList theList = mainModule.getByWhereClause(null, "webdb_create desc", (new Integer(offset)).intValue());
+                       mergeData.put("contentlist",HTMLTemplateProcessor.makeSimpleList(theList));
+                       if(theList.getOrder()!=null) {
+                               mergeData.put("order", theList.getOrder());
+                               mergeData.put("order_encoded", URLEncoder.encode(theList.getOrder()));
+                       }
+                       mergeData.put("count", (new Integer(theList.getCount())).toString());
+                       mergeData.put("from", (new Integer(theList.getFrom())).toString());
+                       mergeData.put("to", (new Integer(theList.getTo())).toString());
+                       if (theList.hasNextBatch())
+                               mergeData.put("next", (new Integer(theList.getNextBatch())).toString());
+                       if (theList.hasPrevBatch())
+                               mergeData.put("prev", (new Integer(theList.getPrevBatch())).toString());
+
+                       // raus damit
+                       HTMLTemplateProcessor.process(getLanguage(req)+"/"+templateListString, mergeData, res.getWriter());
+
+               }
+               catch (ModuleException e) {throw new ServletModuleException(e.toString());}
+               catch (IOException e) {throw new ServletModuleException(e.toString());}
+               catch (Exception e) {throw new ServletModuleException(e.toString());}
+       }
+
+
+}