import mir.session.Session;
import mir.session.SessionExc;
import mir.session.SessionFailure;
-import mir.session.UploadedFile;
import mir.session.ValidationHelper;
+import mir.util.EntityUtility;
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>
+ * Session handler for comment postings
+ *
* @author Zapata
- * @version 1.0
*/
public class MirBasicCommentPostingHandler extends MirBasicPostingSessionHandler {
- protected ModuleComment commentModule = new ModuleComment(DatabaseComment.getInstance());
+ protected DatabaseComment commentDatabase = DatabaseComment.getInstance();
protected DatabaseCommentToMedia commentToMedia = DatabaseCommentToMedia.getInstance();
public MirBasicCommentPostingHandler() {
- super();
+ this(false);
+ }
+
+
+ public MirBasicCommentPostingHandler(boolean aPersistentUploadedFiles) {
+ super(aPersistentUploadedFiles);
setResponseGenerators(
configuration.getString("Localizer.OpenSession.comment.EditTemplate"),
protected void initializeResponseData(Request aRequest, Session aSession, Response aResponse) throws SessionExc, SessionFailure {
super.initializeResponseData(aRequest, aSession, aResponse);
- Iterator i = DatabaseComment.getInstance().getFields().iterator();
+ Iterator i = DatabaseComment.getInstance().getFieldNames().iterator();
while (i.hasNext()) {
String field = (String) i.next();
aResponse.setResponseValue(field, aRequest.getParameter(field));
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.setFieldValue("is_published", "1");
- ModuleCommentStatus module = new ModuleCommentStatus(DatabaseCommentStatus.getInstance());
+ ModuleCommentStatus module = new ModuleCommentStatus();
aComment.setFieldValue("to_comment_status", module.commentStatusIdForName(configuration.getString("Localizer.OpenSession.comment.DefaultCommentStatus")));
aComment.setFieldValue("is_html", "0");
aComment.setFieldValue("to_media", (String) aSession.getAttribute("to_media"));
String id;
Map values = getIntersectingValues(aRequest, DatabaseComment.getInstance());
- EntityComment comment = (EntityComment) commentModule.createNew();
- comment.setValues(values);
+ EntityComment comment = (EntityComment) commentDatabase.createNewEntity();
+ comment.setFieldValues(values);
finalizeComment(aRequest, aSession, comment);
id = comment.insert();
if (id == null) {
}
}
- public void processUploadedFile(Request aRequest, Session aSession, UploadedFile aFile) throws SessionExc, SessionFailure {
+ public void processAttachment(Request aRequest, Session aSession, Attachment aFile) throws SessionExc, SessionFailure {
try {
Map values = new HashMap();
- values.put("title", aRequest.getParameter(aFile.getFieldName()+"_title"));
values.put("creator", aRequest.getParameter("creator"));
+ values.putAll(aFile.getAllAttributes());
values.put("to_publisher", "0");
values.put("is_published", "1");
- ModuleMediafolder module = new ModuleMediafolder(DatabaseMediafolder.getInstance());
+ ModuleMediafolder module = new ModuleMediafolder();
values.put("to_media_folder", module.mediaFolderIdForName(configuration.getString("Localizer.OpenSession.comment.DefaultMediaFolder")));
Entity mediaItem = MediaUploadProcessor.processMediaUpload(aFile, values);
}
}
+ public void processAttachmentError(Request aRequest, Session aSession, Attachment aFile, Throwable anError) {
+ EntityUtility.appendLineToField( ((EntityComment) aSession.getAttribute("comment")), "comment",
+ "error with attachment: " + anError.toString());
+
+ ((EntityComment) aSession.getAttribute("comment")).update();
+ }
+
public void postProcessRequest(Request aRequest, Session aSession) throws SessionExc, SessionFailure {
EntityComment comment = (EntityComment) aSession.getAttribute("comment");
}
DatabaseContent.getInstance().setUnproduced("id=" + comment.getFieldValue("to_media"));
logger.info("Comment posted");
- };
+ }
protected static class DuplicateCommentExc extends SessionExc {
public DuplicateCommentExc(String aMessage) {