-/*\r
- * Copyright (C) 2001, 2002 The Mir-coders group\r
- *\r
- * This file is part of Mir.\r
- *\r
- * Mir is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU General Public License as published by\r
- * the Free Software Foundation; either version 2 of the License, or\r
- * (at your option) any later version.\r
- *\r
- * Mir is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with Mir; if not, write to the Free Software\r
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
- *\r
- * In addition, as a special exception, The Mir-coders gives permission to link\r
- * the code of this program with any library licensed under the Apache Software License,\r
- * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library\r
- * (or with modified versions of the above that use the same license as the above),\r
- * and distribute linked combinations including the two. You must obey the\r
- * GNU General Public License in all respects for all of the code used other than\r
- * the above mentioned libraries. If you modify this file, you may extend this\r
- * exception to your version of the file, but you are not obligated to do so.\r
- * If you do not wish to do so, delete this exception statement from your version.\r
- */\r
-package mircoders.localizer.basic;\r
-\r
-import java.util.HashMap;\r
-import java.util.Iterator;\r
-import java.util.List;\r
-import java.util.Map;\r
-\r
-import mir.entity.Entity;\r
-import mir.session.Request;\r
-import mir.session.Response;\r
-import mir.session.Session;\r
-import mir.session.SessionExc;\r
-import mir.session.SessionFailure;\r
-import mir.session.UploadedFile;\r
-import mir.session.ValidationHelper;\r
-import mircoders.entity.EntityComment;\r
-import mircoders.global.MirGlobal;\r
-import mircoders.media.MediaUploadProcessor;\r
-import mircoders.module.ModuleComment;\r
-import mircoders.module.ModuleCommentStatus;\r
-import mircoders.module.ModuleMediafolder;\r
-import mircoders.storage.DatabaseComment;\r
-import mircoders.storage.DatabaseCommentStatus;\r
-import mircoders.storage.DatabaseCommentToMedia;\r
-import mircoders.storage.DatabaseContent;\r
-import mircoders.storage.DatabaseMediafolder;\r
-\r
-/**\r
- *\r
- * <p>Title: Experimental session handler for comment postings </p>\r
- * <p>Description: </p>\r
- * <p>Copyright: Copyright (c) 2003</p>\r
- * <p>Company: </p>\r
- * @author Zapata\r
- * @version 1.0\r
- */\r
-\r
-public class MirBasicCommentPostingHandler extends MirBasicPostingSessionHandler {\r
- protected ModuleComment commentModule = new ModuleComment(DatabaseComment.getInstance());\r
- protected DatabaseCommentToMedia commentToMedia = DatabaseCommentToMedia.getInstance();\r
-\r
-\r
- public MirBasicCommentPostingHandler() {\r
- super();\r
-\r
- setResponseGenerators(\r
- configuration.getString("Localizer.OpenSession.comment.EditTemplate"),\r
- configuration.getString("Localizer.OpenSession.comment.DupeTemplate"),\r
- configuration.getString("Localizer.OpenSession.comment.UnsupportedMediaTemplate"),\r
- configuration.getString("Localizer.OpenSession.comment.DoneTemplate"));\r
- }\r
-\r
- protected void initializeResponseData(Request aRequest, Session aSession, Response aResponse) throws SessionExc, SessionFailure {\r
- super.initializeResponseData(aRequest, aSession, aResponse);\r
-\r
- Iterator i = DatabaseComment.getInstance().getFields().iterator();\r
- while (i.hasNext()) {\r
- String field = (String) i.next();\r
- aResponse.setResponseValue(field, aRequest.getParameter(field));\r
- }\r
- }\r
-\r
- public void validate(List aResults, Request aRequest, Session aSession) throws SessionExc, SessionFailure {\r
- super.validate(aResults, aRequest, aSession);\r
-\r
- ValidationHelper.testFieldEntered(aRequest, "title", "validationerror.missing", aResults);\r
- ValidationHelper.testFieldEntered(aRequest, "description", "validationerror.missing", aResults);\r
- ValidationHelper.testFieldEntered(aRequest, "creator", "validationerror.missing", aResults);\r
- }\r
-\r
- protected void initializeSession(Request aRequest, Session aSession) throws SessionExc, SessionFailure {\r
- super.initializeSession(aRequest, aSession);\r
-\r
- String articleId = aRequest.getParameter("to_media");\r
- if (articleId==null)\r
- throw new SessionExc("initializeSession: article id not set!");\r
-\r
- aSession.setAttribute("to_media", articleId);\r
- };\r
-\r
- public void finalizeComment(Request aRequest, Session aSession, EntityComment aComment) throws SessionExc, SessionFailure {\r
- try {\r
- aComment.setValueForProperty("is_published", "1");\r
- ModuleCommentStatus module = new ModuleCommentStatus(DatabaseCommentStatus.getInstance());\r
- aComment.setValueForProperty("to_comment_status", module.commentStatusIdForName(configuration.getString("Localizer.OpenSession.comment.DefaultCommentStatus")));\r
- aComment.setValueForProperty("is_html", "0");\r
- aComment.setValueForProperty("to_media", (String) aSession.getAttribute("to_media"));\r
- }\r
- catch (Throwable t) {\r
- throw new SessionFailure(t);\r
- }\r
- }\r
-\r
- public void preProcessRequest(Request aRequest, Session aSession) throws SessionExc, SessionFailure {\r
- try {\r
- String id;\r
- Map values = getIntersectingValues(aRequest, DatabaseComment.getInstance());\r
-\r
- EntityComment comment = (EntityComment) commentModule.createNew();\r
- comment.setValues(values);\r
- finalizeComment(aRequest, aSession, comment);\r
- id = comment.insert();\r
- if (id == null) {\r
- logger.info("Duplicate comment rejected");\r
- throw new DuplicateCommentExc("Duplicate comment rejected");\r
- }\r
- aSession.setAttribute("comment", comment);\r
- }\r
- catch (Throwable t) {\r
- throw new SessionFailure(t);\r
- }\r
- }\r
-\r
- public void processUploadedFile(Request aRequest, Session aSession, UploadedFile aFile) throws SessionExc, SessionFailure {\r
- try {\r
- Map values = new HashMap();\r
- values.put("title", aRequest.getParameter(aFile.getFieldName()+"_title"));\r
- values.put("creator", aRequest.getParameter("creator"));\r
- values.put("to_publisher", "0");\r
- values.put("is_published", "1");\r
- ModuleMediafolder module = new ModuleMediafolder(DatabaseMediafolder.getInstance());\r
- values.put("to_media_folder", module.mediaFolderIdForName(configuration.getString("Localizer.OpenSession.comment.DefaultMediaFolder")));\r
-\r
- Entity mediaItem = MediaUploadProcessor.processMediaUpload(aFile, values);\r
- mediaItem.update();\r
- commentToMedia.addMedia(((EntityComment) aSession.getAttribute("comment")).getId(), mediaItem.getId());\r
- }\r
- catch (Throwable t) {\r
- throw new SessionFailure(t);\r
- }\r
- }\r
-\r
- public void postProcessRequest(Request aRequest, Session aSession) throws SessionExc, SessionFailure {\r
- EntityComment comment = (EntityComment) aSession.getAttribute("comment");\r
-\r
- MirGlobal.abuse().checkComment(comment, aRequest, null);\r
- try {\r
- MirGlobal.localizer().openPostings().afterCommentPosting(comment);\r
- }\r
- catch (Throwable t) {\r
- throw new SessionFailure(t);\r
- }\r
- DatabaseContent.getInstance().setUnproduced("id=" + comment.getValue("to_media"));\r
- logger.info("Comment posted");\r
- };\r
-\r
- protected static class DuplicateCommentExc extends SessionExc {\r
- public DuplicateCommentExc(String aMessage) {\r
- super(aMessage);\r
- }\r
- }\r
-}\r
+/*
+ * 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 java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import mir.entity.Entity;
+import mir.session.Request;
+import mir.session.Response;
+import mir.session.Session;
+import mir.session.SessionExc;
+import mir.session.SessionFailure;
+import mir.session.UploadedFile;
+import mir.session.ValidationHelper;
+import mircoders.entity.EntityComment;
+import mircoders.global.MirGlobal;
+import mircoders.media.MediaUploadProcessor;
+import mircoders.module.ModuleComment;
+import mircoders.module.ModuleCommentStatus;
+import mircoders.module.ModuleMediafolder;
+import mircoders.storage.DatabaseComment;
+import mircoders.storage.DatabaseCommentStatus;
+import mircoders.storage.DatabaseCommentToMedia;
+import mircoders.storage.DatabaseContent;
+import mircoders.storage.DatabaseMediafolder;
+
+/**
+ *
+ * <p>Title: Experimental session handler for comment postings </p>
+ * <p>Description: </p>
+ * <p>Copyright: Copyright (c) 2003</p>
+ * <p>Company: </p>
+ * @author Zapata
+ * @version 1.0
+ */
+
+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.UnsupportedMediaTemplate"),
+ configuration.getString("Localizer.OpenSession.comment.DoneTemplate"));
+ }
+
+ protected void initializeResponseData(Request aRequest, Session aSession, Response aResponse) throws SessionExc, SessionFailure {
+ super.initializeResponseData(aRequest, aSession, aResponse);
+
+ Iterator i = DatabaseComment.getInstance().getFields().iterator();
+ while (i.hasNext()) {
+ String field = (String) i.next();
+ aResponse.setResponseValue(field, aRequest.getParameter(field));
+ }
+ }
+
+ public void validate(List aResults, Request aRequest, Session aSession) throws SessionExc, SessionFailure {
+ super.validate(aResults, aRequest, aSession);
+
+ ValidationHelper.testFieldEntered(aRequest, "title", "validationerror.missing", aResults);
+ ValidationHelper.testFieldEntered(aRequest, "description", "validationerror.missing", aResults);
+ ValidationHelper.testFieldEntered(aRequest, "creator", "validationerror.missing", aResults);
+ }
+
+ protected void initializeSession(Request aRequest, Session aSession) throws SessionExc, SessionFailure {
+ super.initializeSession(aRequest, aSession);
+
+ String articleId = aRequest.getParameter("to_media");
+ if (articleId==null)
+ throw new SessionExc("initializeSession: article id not set!");
+
+ aSession.setAttribute("to_media", articleId);
+ };
+
+ public void finalizeComment(Request aRequest, Session aSession, EntityComment aComment) throws SessionExc, SessionFailure {
+ try {
+ aComment.setValueForProperty("is_published", "1");
+ ModuleCommentStatus module = new ModuleCommentStatus(DatabaseCommentStatus.getInstance());
+ aComment.setValueForProperty("to_comment_status", module.commentStatusIdForName(configuration.getString("Localizer.OpenSession.comment.DefaultCommentStatus")));
+ aComment.setValueForProperty("is_html", "0");
+ aComment.setValueForProperty("to_media", (String) aSession.getAttribute("to_media"));
+ }
+ catch (Throwable t) {
+ throw new SessionFailure(t);
+ }
+ }
+
+ public void preProcessRequest(Request aRequest, Session aSession) throws SessionExc, SessionFailure {
+ try {
+ String id;
+ Map values = getIntersectingValues(aRequest, DatabaseComment.getInstance());
+
+ EntityComment comment = (EntityComment) commentModule.createNew();
+ comment.setValues(values);
+ finalizeComment(aRequest, aSession, comment);
+ id = comment.insert();
+ if (id == null) {
+ logger.info("Duplicate comment rejected");
+ throw new DuplicateCommentExc("Duplicate comment rejected");
+ }
+ aSession.setAttribute("comment", comment);
+ }
+ catch (Throwable t) {
+ throw new SessionFailure(t);
+ }
+ }
+
+ public void processUploadedFile(Request aRequest, Session aSession, UploadedFile aFile) throws SessionExc, SessionFailure {
+ try {
+ Map values = new HashMap();
+ values.put("title", aRequest.getParameter(aFile.getFieldName()+"_title"));
+ values.put("creator", aRequest.getParameter("creator"));
+ values.put("to_publisher", "0");
+ values.put("is_published", "1");
+ ModuleMediafolder module = new ModuleMediafolder(DatabaseMediafolder.getInstance());
+ values.put("to_media_folder", module.mediaFolderIdForName(configuration.getString("Localizer.OpenSession.comment.DefaultMediaFolder")));
+
+ Entity mediaItem = MediaUploadProcessor.processMediaUpload(aFile, values);
+ mediaItem.update();
+ commentToMedia.addMedia(((EntityComment) aSession.getAttribute("comment")).getId(), mediaItem.getId());
+ }
+ catch (Throwable t) {
+ throw new SessionFailure(t);
+ }
+ }
+
+ public void postProcessRequest(Request aRequest, Session aSession) throws SessionExc, SessionFailure {
+ EntityComment comment = (EntityComment) aSession.getAttribute("comment");
+
+ MirGlobal.abuse().checkComment(comment, aRequest, null);
+ try {
+ MirGlobal.localizer().openPostings().afterCommentPosting(comment);
+ }
+ catch (Throwable t) {
+ throw new SessionFailure(t);
+ }
+ DatabaseContent.getInstance().setUnproduced("id=" + comment.getValue("to_media"));
+ logger.info("Comment posted");
+ };
+
+ protected static class DuplicateCommentExc extends SessionExc {
+ public DuplicateCommentExc(String aMessage) {
+ super(aMessage);
+ }
+ }
+}