- major bugfix: many many threads were being created until a "can't create native...
authorzapata <zapata>
Thu, 1 May 2003 01:42:11 +0000 (01:42 +0000)
committerzapata <zapata>
Thu, 1 May 2003 01:42:11 +0000 (01:42 +0000)
source/Mir.java
source/OpenMir.java
source/default.properties
source/mircoders/localizer/MirCachingLocalizerDecorator.java
source/mircoders/localizer/basic/MirBasicAdminInterfaceLocalizer.java
source/mircoders/localizer/basic/MirBasicArticlePostingHandler.java
source/mircoders/localizer/basic/MirBasicChildArticlePostingHandler.java [new file with mode: 0755]
source/mircoders/localizer/basic/MirBasicCommentPostingHandler.java
source/mircoders/localizer/basic/MirBasicGeneratorLocalizer.java
source/mircoders/localizer/basic/MirBasicPostingSessionHandler.java

index 820c41b..c67ecfc 100755 (executable)
@@ -80,7 +80,7 @@ import mircoders.storage.DatabaseUsers;
  * Mir.java - main servlet, that dispatches to servletmodules
  *
  * @author $Author: zapata $
- * @version $Id: Mir.java,v 1.47 2003/04/28 01:57:14 zapata Exp $
+ * @version $Id: Mir.java,v 1.48 2003/05/01 01:42:11 zapata Exp $
  *
  */
 public class Mir extends AbstractServlet {
@@ -179,33 +179,23 @@ public class Mir extends AbstractServlet {
 
     if (aRequest.getServerPort() == 443) {
       http = "https";
-    } else {
+    }
+    else {
       http = "http";
     }
 
-    //make sure client browsers don't cache anything
     setNoCaching(aResponse);
 
-    //FIXME: this seems kind of hackish and only here because we can have
-    // default other than the one that the browser is set to.
     Locale locale = new Locale(getDefaultLanguage(aRequest), "");
-    String htmlcharset = "UTF-8";
-    try {
-      htmlcharset = MirPropertiesConfiguration.instance().getString("Mir.DefaultHTMLCharset");
-    }
-    catch (Throwable t) {
-    }
 
-    aResponse.setContentType("text/html; charset=" + htmlcharset);
+    aResponse.setContentType("text/html; charset=" +
+        configuration.getString("Mir.DefaultHTMLCharset", "UTF-8"));
 
     String moduleName = aRequest.getParameter("module");
     checkLanguage(session, aRequest);
 
-
-
     // Authentication
-    if (((moduleName != null) && moduleName.equals("login")) ||
-        (userEntity == null)) {
+    if (((moduleName != null) && moduleName.equals("login")) || (userEntity == null)) {
       String user = aRequest.getParameter("login");
       String passwd = aRequest.getParameter("password");
       logger.debug("--login: evaluating for user: " + user);
@@ -269,8 +259,6 @@ public class Mir extends AbstractServlet {
       logger.info("--logout");
       session.invalidate();
 
-      //session = aRequest.getSession(true);
-      //checkLanguage(session, aRequest);
       _sendLoginPage(aResponse, aRequest, aResponse.getWriter());
 
       return;
@@ -282,9 +270,8 @@ public class Mir extends AbstractServlet {
       String redirectString = aRequest.getRequestURI();
       String queryString = aRequest.getQueryString();
 
-      if ((queryString != null) && !queryString.equals("")) {
+      if ((queryString != null) && queryString.length()!=0) {
         redirectString += ("?" + aRequest.getQueryString());
-        logger.debug("STORING: " + redirectString);
         session.setAttribute("login.target", redirectString);
       }
 
@@ -295,14 +282,12 @@ public class Mir extends AbstractServlet {
 
     // If no module is specified goto standard startpage
     if ((moduleName == null) || moduleName.equals("")) {
-      logger.debug("no module: redirect to standardpage");
+//      logger.debug("no module: redirect to standardpage");
       _sendStartPage(aResponse, aRequest, aResponse.getWriter(), userEntity);
 
       return;
     }
 
-    // end of auth
-    // From now on regular dispatching...
     try {
       // get servletmodule by parameter and continue with dispacher
       ServletModule smod = getServletModuleForName(moduleName);
@@ -386,8 +371,8 @@ public class Mir extends AbstractServlet {
           fallbackLocale);
       out.close();
     }
-    catch (Exception e) {
-      logger.error("Error in UserErrorTemplate");
+    catch (Throwable e) {
+      logger.error("Error handling user error" + e.toString());
     }
 
   }
@@ -405,8 +390,8 @@ public class Mir extends AbstractServlet {
           modelRoot,null,out, getLocale(aRequest), getFallbackLocale());
       out.close();
     }
-    catch (Exception e) {
-      logger.error("Error in ErrorTemplate");
+    catch (Throwable e) {
+      logger.error("Error handling error: " + e.toString());
     }
   }
 
@@ -473,7 +458,7 @@ public class Mir extends AbstractServlet {
       mergeData.put("searchorder", null);
       mergeData.put("selectarticleurl", null);
 
-      ServletHelper.generateResponse(aResponse.getWriter(), mergeData, startTemplate);
+      ServletHelper.generateResponse(out, mergeData, startTemplate);
     }
     catch (Exception e) {
       e.printStackTrace(logger.asPrintWriter(LoggerWrapper.DEBUG_MESSAGE));
index 8c57e54..2a5b7cc 100755 (executable)
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  *
  * In addition, as a special exception, The Mir-coders gives permission to link
- * the code of this program with  any library licensed under the Apache Software License, 
- * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library 
- * (or with modified versions of the above that use the same license as the above), 
- * and distribute linked combinations including the two.  You must obey the 
- * GNU General Public License in all respects for all of the code used other than 
- * the above mentioned libraries.  If you modify this file, you may extend this 
- * exception to your version of the file, but you are not obligated to do so.  
+ * the code of this program with  any library licensed under the Apache Software License,
+ * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library
+ * (or with modified versions of the above that use the same license as the above),
+ * and distribute linked combinations including the two.  You must obey the
+ * GNU General Public License in all respects for all of the code used other than
+ * the above mentioned libraries.  If you modify this file, you may extend this
+ * exception to your version of the file, but you are not obligated to do so.
  * If you do not wish to do so, delete this exception statement from your version.
  */
 
@@ -47,7 +47,7 @@ import mircoders.servlet.ServletModuleOpenIndy;
  *  OpenMir.java - main servlet for open posting and comment feature to articles
  *
  *  @author RK 1999-2001, the mir-coders group
- *  @version $Id: OpenMir.java,v 1.34 2003/04/21 12:42:46 idfx Exp $
+ *  @version $Id: OpenMir.java,v 1.35 2003/05/01 01:42:11 zapata Exp $
  *
  */
 
@@ -113,7 +113,7 @@ public class OpenMir extends AbstractServlet {
     String requestLanguage = aRequest.getParameter("language");
     String sessionLanguage = (String) aSession.getAttribute("language");
     String acceptLanguage = aRequest.getLocale().getLanguage();
-    String defaultLanguage = MirGlobal.config().getString("Mir.Login.DefaultLanguage", "en");
+    String defaultLanguage = configuration.getString("Mir.Login.DefaultLanguage", "en");
 
     String language = requestLanguage;
 
index 913e348..6d40fac 100755 (executable)
@@ -162,7 +162,7 @@ Producer.StorageRoot=/pub/Dokumente/Indymedia/de-tech/Mir/produced
 #      <name>:<path>:<file filter>:<0|1 (recursion off or on)> [, ....]
 
 ServletModule.FileEdit.Configuration= \
-  includes:/pub/Dokumente/Indymedia/de-tech/Mir/produced:.*\\.inc:1
+  includes:/pub/Dokumente/Indymedia/de-tech/Mir/produced/inc:.*\\.inc:1
 
 #
 #
index e6d5561..340d2bd 100755 (executable)
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  *
  * In addition, as a special exception, The Mir-coders gives permission to link
- * the code of this program with  any library licensed under the Apache Software License, 
- * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library 
- * (or with modified versions of the above that use the same license as the above), 
- * and distribute linked combinations including the two.  You must obey the 
- * GNU General Public License in all respects for all of the code used other than 
- * the above mentioned libraries.  If you modify this file, you may extend this 
- * exception to your version of the file, but you are not obligated to do so.  
+ * the code of this program with  any library licensed under the Apache Software License,
+ * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library
+ * (or with modified versions of the above that use the same license as the above),
+ * and distribute linked combinations including the two.  You must obey the
+ * GNU General Public License in all respects for all of the code used other than
+ * the above mentioned libraries.  If you modify this file, you may extend this
+ * exception to your version of the file, but you are not obligated to do so.
  * If you do not wish to do so, delete this exception statement from your version.
  */
 
 package mircoders.localizer;
 
+import mir.generator.Generator;
+import mir.generator.WriterEngine;
+
+
 public class MirCachingLocalizerDecorator implements MirLocalizer {
   private MirLocalizer localizer;
   private MirProducerLocalizer producerLocalizer;
@@ -53,7 +57,7 @@ public class MirCachingLocalizerDecorator implements MirLocalizer {
 
   public MirGeneratorLocalizer generators() throws MirLocalizerFailure, MirLocalizerExc {
     if (generatorLocalizer==null) {
-      generatorLocalizer = localizer.generators();
+      generatorLocalizer = new MirCachingGeneratorLocalizer(localizer.generators());
     }
 
     return generatorLocalizer;
@@ -91,5 +95,48 @@ public class MirCachingLocalizerDecorator implements MirLocalizer {
     return adminInterfaceLocalizer;
   };
 
+  private static class MirCachingGeneratorLocalizer implements MirGeneratorLocalizer {
+    private MirGeneratorLocalizer master;
+    private WriterEngine writerEngine;
+    private Generator.GeneratorLibrary producerGeneratorLibrary;
+    private Generator.GeneratorLibrary adminGeneratorLibrary;
+    private Generator.GeneratorLibrary openPostingGeneratorLibrary;
+
+    public MirCachingGeneratorLocalizer(MirGeneratorLocalizer aMaster) {
+      master = aMaster;
+    }
+
+    public WriterEngine makeWriterEngine() throws MirLocalizerExc, MirLocalizerFailure {
+      if (writerEngine==null) {
+        writerEngine = master.makeWriterEngine();
+      }
+
+      return writerEngine;
+    };
+
+    public Generator.GeneratorLibrary makeProducerGeneratorLibrary() throws MirLocalizerExc, MirLocalizerFailure {
+      if (producerGeneratorLibrary==null) {
+        producerGeneratorLibrary = master.makeProducerGeneratorLibrary();
+      }
+
+      return producerGeneratorLibrary;
+    };
+
+    public Generator.GeneratorLibrary makeAdminGeneratorLibrary() throws MirLocalizerExc, MirLocalizerFailure {
+      if (adminGeneratorLibrary==null) {
+        adminGeneratorLibrary = master.makeAdminGeneratorLibrary();
+      }
+
+      return adminGeneratorLibrary;
+    };
+
+    public Generator.GeneratorLibrary makeOpenPostingGeneratorLibrary() throws MirLocalizerExc, MirLocalizerFailure {
+      if (openPostingGeneratorLibrary==null) {
+        openPostingGeneratorLibrary = master.makeOpenPostingGeneratorLibrary();
+      }
+
+      return openPostingGeneratorLibrary;
+    };
+  }
 
 }
\ No newline at end of file
index 313b9c7..97a3f28 100755 (executable)
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  *
  * In addition, as a special exception, The Mir-coders gives permission to link
- * the code of this program with  any library licensed under the Apache Software License, 
- * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library 
- * (or with modified versions of the above that use the same license as the above), 
- * and distribute linked combinations including the two.  You must obey the 
- * GNU General Public License in all respects for all of the code used other than 
- * the above mentioned libraries.  If you modify this file, you may extend this 
- * exception to your version of the file, but you are not obligated to do so.  
+ * the code of this program with  any library licensed under the Apache Software License,
+ * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library
+ * (or with modified versions of the above that use the same license as the above),
+ * and distribute linked combinations including the two.  You must obey the
+ * GNU General Public License in all respects for all of the code used other than
+ * the above mentioned libraries.  If you modify this file, you may extend this
+ * exception to your version of the file, but you are not obligated to do so.
  * If you do not wish to do so, delete this exception statement from your version.
  */
+
 package mircoders.localizer.basic;
 
 import java.text.SimpleDateFormat;
index fe50c13..3923bcb 100755 (executable)
@@ -27,6 +27,7 @@
  * exception to your version of the file, but you are not obligated to do so.
  * If you do not wish to do so, delete this exception statement from your version.
  */
+
 package mircoders.localizer.basic;
 
 import java.util.GregorianCalendar;
@@ -68,6 +69,16 @@ public class MirBasicArticlePostingHandler extends MirBasicPostingSessionHandler
   protected DatabaseContentToMedia contentToMedia = DatabaseContentToMedia.getInstance();
   protected DatabaseContent contentDatabase = DatabaseContent.getInstance();
 
+  public MirBasicArticlePostingHandler() {
+    super();
+
+    setResponseGenerators(
+      configuration.getString("Localizer.OpenSession.article.EditTemplate"),
+      configuration.getString("Localizer.OpenSession.article.DupeTemplate"),
+      configuration.getString("Localizer.OpenSession.article.UnsupportedMediaTemplate"),
+      configuration.getString("Localizer.OpenSession.article.DoneTemplate"));
+  }
+
   protected void initializeResponseData(Request aRequest, Session aSession, Response aResponse) throws SessionExc, SessionFailure {
     super.initializeResponseData(aRequest, aSession, aResponse);
 
@@ -86,14 +97,14 @@ public class MirBasicArticlePostingHandler extends MirBasicPostingSessionHandler
     testFieldEntered(aRequest, "content_data", "validationerror.missing", aResults);
   }
 
-  public void finalizeArticle(Request aRequest, Session aSession, EntityContent aContent) throws SessionExc, SessionFailure {
-    aContent.setValueForProperty("is_published", "1");
-    aContent.setValueForProperty("is_produced", "0");
-    aContent.setValueForProperty("date", StringUtil.date2webdbDate(new GregorianCalendar()));
-    aContent.setValueForProperty("is_html","0");
-    aContent.setValueForProperty("publish_path", StringUtil.webdbDate2path(aContent.getValue("date")));
-    aContent.setValueForProperty("to_article_type", "1");
-    aContent.setValueForProperty("to_publisher", "1");
+  public void finalizeArticle(Request aRequest, Session aSession, EntityContent anArticle) throws SessionExc, SessionFailure {
+    anArticle.setValueForProperty("is_published", "1");
+    anArticle.setValueForProperty("is_produced", "0");
+    anArticle.setValueForProperty("date", StringUtil.date2webdbDate(new GregorianCalendar()));
+    anArticle.setValueForProperty("is_html","0");
+    anArticle.setValueForProperty("publish_path", StringUtil.webdbDate2path(anArticle.getValue("date")));
+    anArticle.setValueForProperty("to_article_type", "1");
+    anArticle.setValueForProperty("to_publisher", "1");
   }
 
   public void setArticleTopics(Request aRequest, Session aSession, EntityContent aContent) throws SessionExc, SessionFailure {
@@ -122,7 +133,7 @@ public class MirBasicArticlePostingHandler extends MirBasicPostingSessionHandler
       id = article.insert();
       if (id == null) {
         logger.info("Duplicate article rejected");
-        throw new DuplicateArticleExc("Duplicate article rejected");
+        throw new DuplicatePostingExc("Duplicate article rejected");
       }
       aSession.setAttribute("content", article);
 
@@ -165,36 +176,4 @@ public class MirBasicArticlePostingHandler extends MirBasicPostingSessionHandler
     logger.info("article posted");
   };
 
-  protected void makeInitialResponse(Request aRequest, Session aSession, Response aResponse) throws SessionExc, SessionFailure {
-    aResponse.setResponseGenerator(configuration.getString("Localizer.OpenSession.article.EditTemplate"));
-  };
-
-  protected void makeResponse(Request aRequest, Session aSession, Response aResponse, List anErrors) throws SessionExc, SessionFailure {
-    aResponse.setResponseValue("errors", anErrors);
-    aResponse.setResponseGenerator(configuration.getString("Localizer.OpenSession.article.EditTemplate"));
-  };
-
-  protected void makeFinalResponse(Request aRequest, Session aSession, Response aResponse) throws SessionExc, SessionFailure {
-    aResponse.setResponseGenerator(configuration.getString("Localizer.OpenSession.article.DoneTemplate"));
-  };
-
-  protected void makeErrorResponse(Request aRequest, Session aSession, Response aResponse, Throwable anError) throws SessionExc, SessionFailure {
-    anError.printStackTrace();
-    Throwable rootCause = ExceptionFunctions.traceCauseException(anError);
-
-    if (rootCause instanceof DuplicateArticleExc)
-      aResponse.setResponseGenerator(configuration.getString("Localizer.OpenSession.article.DupeTemplate"));
-    if (rootCause instanceof ModuleMediaType.UnsupportedMimeTypeExc) {
-      aResponse.setResponseValue("mimetype", ((ModuleMediaType.UnsupportedMimeTypeExc) rootCause).getMimeType());
-      aResponse.setResponseGenerator(configuration.getString("Localizer.OpenSession.article.UnsupportedMediaTemplate"));
-    }
-    else
-      super.makeErrorResponse(aRequest, aSession, aResponse, anError);
-  };
-
-  protected static class DuplicateArticleExc extends SessionExc {
-    public DuplicateArticleExc(String aMessage) {
-      super(aMessage);
-    }
-  }
-}
+}
\ No newline at end of file
diff --git a/source/mircoders/localizer/basic/MirBasicChildArticlePostingHandler.java b/source/mircoders/localizer/basic/MirBasicChildArticlePostingHandler.java
new file mode 100755 (executable)
index 0000000..492d47c
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2001, 2002 The Mir-coders group
+ *
+ * This file is part of Mir.
+ *
+ * Mir is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Mir is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Mir; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * In addition, as a special exception, The Mir-coders gives permission to link
+ * the code of this program with  any library licensed under the Apache Software License,
+ * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library
+ * (or with modified versions of the above that use the same license as the above),
+ * and distribute linked combinations including the two.  You must obey the
+ * GNU General Public License in all respects for all of the code used other than
+ * the above mentioned libraries.  If you modify this file, you may extend this
+ * exception to your version of the file, but you are not obligated to do so.
+ * If you do not wish to do so, delete this exception statement from your version.
+ */
+
+package mircoders.localizer.basic;
+
+import mir.session.*;
+import mircoders.entity.*;
+
+
+public class MirBasicChildArticlePostingHandler extends MirBasicArticlePostingHandler {
+  public MirBasicChildArticlePostingHandler() {
+    super();
+
+    setNormalResponseGenerator(configuration.getString("Localizer.OpenSession.article.EditTemplate"));
+  }
+
+  public void finalizeArticle(Request aRequest, Session aSession, EntityContent anArticle) throws SessionExc, SessionFailure {
+    super.finalizeArticle(aRequest, aSession, anArticle);
+
+    anArticle.setValueForProperty("to_media", (String) aSession.getAttribute("to_media"));
+  }
+
+  protected void initializeSession(Request aRequest, Session aSession) throws SessionExc, SessionFailure {
+    super.initializeSession(aRequest, aSession);
+
+    String parentId = aRequest.getParameter("to_media");
+    if (parentId==null)
+      throw new SessionExc("initializeSession: parent id not set!");
+
+    aSession.setAttribute("to_media", parentId);
+  };
+
+
+
+}
\ No newline at end of file
index 6571dd3..61edd55 100755 (executable)
@@ -65,6 +65,17 @@ public class MirBasicCommentPostingHandler extends MirBasicPostingSessionHandler
   protected ModuleComment commentModule = new ModuleComment(DatabaseComment.getInstance());
   protected DatabaseCommentToMedia commentToMedia = DatabaseCommentToMedia.getInstance();
 
+
+  public MirBasicCommentPostingHandler() {
+    super();
+
+    setResponseGenerators(
+      configuration.getString("Localizer.OpenSession.comment.EditTemplate"),
+      configuration.getString("Localizer.OpenSession.comment.DupeTemplate"),
+      configuration.getString("Localizer.OpenSession.comment.DoneTemplate"),
+      configuration.getString("Localizer.OpenSession.comment.UnsupportedMediaTemplate"));
+  }
+
   protected void initializeResponseData(Request aRequest, Session aSession, Response aResponse) throws SessionExc, SessionFailure {
     super.initializeResponseData(aRequest, aSession, aResponse);
 
@@ -86,7 +97,7 @@ public class MirBasicCommentPostingHandler extends MirBasicPostingSessionHandler
 
     String articleId = aRequest.getParameter("to_media");
     if (articleId==null)
-      throw new SessionExc("initializeCommentPosting: article id not set!");
+      throw new SessionExc("initializeSession: article id not set!");
 
     aSession.setAttribute("to_media", articleId);
   };
@@ -95,6 +106,7 @@ public class MirBasicCommentPostingHandler extends MirBasicPostingSessionHandler
     aComment.setValueForProperty("is_published", "1");
     aComment.setValueForProperty("to_comment_status", "1");
     aComment.setValueForProperty("is_html","0");
+    aComment.setValueForProperty("to_media", (String) aSession.getAttribute("to_media"));
   }
 
   public void preProcessRequest(Request aRequest, Session aSession) throws SessionExc, SessionFailure {
@@ -104,7 +116,6 @@ public class MirBasicCommentPostingHandler extends MirBasicPostingSessionHandler
 
       EntityComment comment = (EntityComment) commentModule.createNew();
       comment.setValues(values);
-      comment.setValueForProperty("to_media", (String) aSession.getAttribute("to_media"));
       finalizeComment(aRequest, aSession, comment);
       id = comment.insert();
       if (id == null) {
@@ -148,33 +159,6 @@ public class MirBasicCommentPostingHandler extends MirBasicPostingSessionHandler
     logger.info("Comment posted");
   };
 
-  protected void makeInitialResponse(Request aRequest, Session aSession, Response aResponse) throws SessionExc, SessionFailure {
-    aResponse.setResponseGenerator(configuration.getString("Localizer.OpenSession.comment.EditTemplate"));
-  };
-
-  protected void makeResponse(Request aRequest, Session aSession, Response aResponse, List anErrors) throws SessionExc, SessionFailure {
-    aResponse.setResponseValue("errors", anErrors);
-    aResponse.setResponseGenerator(configuration.getString("Localizer.OpenSession.comment.EditTemplate"));
-  };
-
-  protected void makeFinalResponse(Request aRequest, Session aSession, Response aResponse) throws SessionExc, SessionFailure {
-    aResponse.setResponseGenerator(configuration.getString("Localizer.OpenSession.comment.DoneTemplate"));
-  };
-
-  protected void makeErrorResponse(Request aRequest, Session aSession, Response aResponse, Throwable anError) throws SessionExc, SessionFailure {
-    anError.printStackTrace();
-    Throwable rootCause = ExceptionFunctions.traceCauseException(anError);
-
-    if (rootCause instanceof DuplicateCommentExc)
-      aResponse.setResponseGenerator(configuration.getString("Localizer.OpenSession.comment.DupeTemplate"));
-    if (rootCause instanceof ModuleMediaType.UnsupportedMimeTypeExc) {
-      aResponse.setResponseValue("mimetype", ((ModuleMediaType.UnsupportedMimeTypeExc) rootCause).getMimeType());
-      aResponse.setResponseGenerator(configuration.getString("Localizer.OpenSession.comment.UnsupportedMediaTemplate"));
-    }
-    else
-      super.makeErrorResponse(aRequest, aSession, aResponse, anError);
-  };
-
   protected static class DuplicateCommentExc extends SessionExc {
     public DuplicateCommentExc(String aMessage) {
       super(aMessage);
index c6e4cbb..f3b205d 100755 (executable)
@@ -47,7 +47,6 @@ public class MirBasicGeneratorLocalizer implements MirGeneratorLocalizer {
     repository = new GeneratorLibraryRepository();
     logger = new LoggerWrapper("Localizer.Basic.Generator");
 
-
     buildRepository(repository);
   }
 
index 0152cab..e89d119 100755 (executable)
@@ -56,6 +56,7 @@ import mircoders.module.ModuleComment;
 import mircoders.storage.DatabaseComment;
 import mircoders.storage.DatabaseCommentToMedia;
 import mircoders.storage.DatabaseContent;
+import mircoders.module.*;
 
 /**
  *
@@ -71,6 +72,12 @@ public abstract class MirBasicPostingSessionHandler implements SessionHandler {
   protected LoggerWrapper logger;
   protected MirPropertiesConfiguration configuration;
 
+  private String normalResponseGenerator;
+  private String dupeResponseGenerator;
+  private String unsupportedMediaTypeResponseGenerator;
+  private String finalResponseGenerator;
+
+
   public MirBasicPostingSessionHandler() {
     logger = new LoggerWrapper("Localizer.OpenPosting");
     try {
@@ -83,6 +90,18 @@ public abstract class MirBasicPostingSessionHandler implements SessionHandler {
     }
   }
 
+  protected void setNormalResponseGenerator(String aGenerator) {
+    normalResponseGenerator = aGenerator;
+  }
+
+  protected void setResponseGenerators(String aNormalResponseGenerator, String aDupeResponseGenerator,
+        String anUnsupportedMediaTypeResponseGenerator, String aFinalResponseGenerator) {
+    setNormalResponseGenerator(aNormalResponseGenerator);
+    dupeResponseGenerator = aDupeResponseGenerator;
+    unsupportedMediaTypeResponseGenerator = anUnsupportedMediaTypeResponseGenerator;
+    finalResponseGenerator = aFinalResponseGenerator;
+  }
+
   public void processRequest(Request aRequest, Session aSession, Response aResponse) throws SessionExc, SessionFailure {
     if (aSession.getAttribute("initialRequest")==null) {
       initialRequest(aRequest, aSession, aResponse);
@@ -170,9 +189,34 @@ public abstract class MirBasicPostingSessionHandler implements SessionHandler {
     aResponse.setResponseValue("errors", null);
   }
 
-  protected abstract void makeInitialResponse(Request aRequest, Session aSession, Response aResponse) throws SessionExc, SessionFailure;
-  protected abstract void makeResponse(Request aRequest, Session aSession, Response aResponse, List anErrors) throws SessionExc, SessionFailure;
-  protected abstract void makeFinalResponse(Request aRequest, Session aSession, Response aResponse) throws SessionExc, SessionFailure;
+  protected void makeInitialResponse(Request aRequest, Session aSession, Response aResponse) throws SessionExc, SessionFailure {
+    aResponse.setResponseGenerator(normalResponseGenerator);
+  };
+
+  protected void makeResponse(Request aRequest, Session aSession, Response aResponse, List anErrors) throws SessionExc, SessionFailure {
+    aResponse.setResponseValue("errors", anErrors);
+    aResponse.setResponseGenerator(normalResponseGenerator);
+  };
+
+  protected void makeFinalResponse(Request aRequest, Session aSession, Response aResponse) throws SessionExc, SessionFailure {
+    aResponse.setResponseGenerator(finalResponseGenerator);
+  };
+
+  protected void makeErrorResponse(Request aRequest, Session aSession, Response aResponse, Throwable anError) throws SessionExc, SessionFailure {
+    anError.printStackTrace();
+    Throwable rootCause = ExceptionFunctions.traceCauseException(anError);
+
+    if (rootCause instanceof DuplicatePostingExc)
+      aResponse.setResponseGenerator(dupeResponseGenerator);
+    if (rootCause instanceof ModuleMediaType.UnsupportedMimeTypeExc) {
+      aResponse.setResponseValue("mimetype", ((ModuleMediaType.UnsupportedMimeTypeExc) rootCause).getMimeType());
+      aResponse.setResponseGenerator(unsupportedMediaTypeResponseGenerator);
+    }
+    else {
+      aResponse.setResponseValue("errorstring", anError.getMessage());
+      aResponse.setResponseGenerator(configuration.getString("Localizer.OpenSession.ErrorTemplate"));
+    }
+  };
 
   protected void preProcessRequest(Request aRequest, Session aSession) throws SessionExc, SessionFailure {
   };
@@ -202,11 +246,6 @@ public abstract class MirBasicPostingSessionHandler implements SessionHandler {
   protected void validate(List aResults, Request aRequest, Session aSession) throws SessionExc, SessionFailure {
   }
 
-  protected void makeErrorResponse(Request aRequest, Session aSession, Response aResponse, Throwable anError) throws SessionExc, SessionFailure {
-    aResponse.setResponseValue("errorstring", anError.getMessage());
-    aResponse.setResponseGenerator(configuration.getString("Localizer.OpenSession.ErrorTemplate"));
-  };
-
   /**
    * Class that represents a validation error
    *
@@ -364,4 +403,10 @@ public abstract class MirBasicPostingSessionHandler implements SessionHandler {
     return result;
   }
 
+  protected static class DuplicatePostingExc extends SessionExc {
+    public DuplicatePostingExc(String aMessage) {
+      super(aMessage);
+    }
+  }
+
 }