import mir.entity.adapter.EntityAdapterEngine;
import mir.entity.adapter.EntityAdapterModel;
-import mir.log.LoggerWrapper;
-import mir.servlet.ServletModule;
+import mir.servlet.AdminServletModule;
import mir.servlet.ServletModuleExc;
import mir.servlet.ServletModuleFailure;
import mir.servlet.ServletModuleUserExc;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-import java.util.*;
-
-/*
- * ServletModuleComment - controls navigation for Comments
- *
- *
- * @author the mir-coders
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+
+/**
+ * ServletModule for managing Comments
*/
-public class ServletModuleComment extends ServletModule
-{
- private static ServletModuleComment instance = new ServletModuleComment();
- public static ServletModule getInstance() { return instance; }
-
- private ServletModuleComment() {
- logger = new LoggerWrapper("ServletModule.Comment");
- try {
- mainModule = new ModuleComment();
- definition = "comment";
- }
- catch (Exception e) {
- logger.error("servletmodule comment could not be initialized:" + e.getMessage());
- }
+public class ServletModuleComment extends AdminServletModule {
+ public ServletModuleComment() {
+ mainModule = new ModuleComment();
+ definition = "comment";
}
public void delete(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleExc, ServletModuleUserExc, ServletModuleFailure {
}
}
- public void edit(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleExc
- {
+ public void edit(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleExc {
String idParam = aRequest.getParameter("id");
- if (idParam == null)
+ if (idParam == null) {
throw new ServletModuleExc("Invalid call: id not supplied ");
+ }
- editObject(aRequest, aResponse, idParam);
+ editObject(aRequest, aResponse, idParam, null);
}
- public void editObject(HttpServletRequest aRequest, HttpServletResponse aResponse, String anId) throws ServletModuleExc {
+ public void editObject(HttpServletRequest aRequest, HttpServletResponse aResponse, String anId, String aTemplate) throws ServletModuleExc {
try {
HTTPRequestParser requestParser = new HTTPRequestParser(aRequest);
Map responseData = ServletHelper.makeGenerationData(aRequest, aResponse, new Locale[] {getLocale(aRequest), getFallbackLocale(aRequest)});
EntityAdapterModel model = MirGlobal.localizer().dataModel().adapterModel();
- Map comment;
+ Object comment;
URLBuilder urlBuilder = new URLBuilder();
urlBuilder.setValue("module", "Comment");
else {
List fields = DatabaseComment.getInstance().getFieldNames();
responseData.put("new", Boolean.TRUE);
- comment = new HashMap();
+ Map emptyComment = new HashMap();
Iterator i = fields.iterator();
while (i.hasNext()) {
- comment.put(i.next(), null);
+ emptyComment.put(i.next(), null);
}
+
+ comment = emptyComment;
}
responseData.put("comment", comment);
}
}
- public void attach(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleExc
- {
+ public void attach(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleExc {
String mediaIdParam = aRequest.getParameter("mid");
String commentId = aRequest.getParameter("commentid");
- if (commentId == null || mediaIdParam==null) throw new ServletModuleExc("smod comment :: attach :: commentid/mid missing");
+ if (commentId == null || mediaIdParam==null) {
+ throw new ServletModuleExc("smod comment :: attach :: commentid/mid missing");
+ }
try {
EntityComment comment = (EntityComment) mainModule.getById(commentId);
logAdminUsage(aRequest, commentId, "media " + mediaIdParam + " attached");
- editObject(aRequest, aResponse, commentId);
+ editObject(aRequest, aResponse, commentId, null);
}
- public void dettach(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleExc
- {
+ public void dettach(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleExc {
String commentId = aRequest.getParameter("commentid");
String midParam = aRequest.getParameter("mid");
- if (commentId == null)
+ if (commentId == null) {
throw new ServletModuleExc("smod comment :: dettach :: commentid missing");
- if (midParam == null)
+ }
+ if (midParam == null) {
throw new ServletModuleExc("smod comment :: dettach :: mid missing");
+ }
try {
EntityComment comment = (EntityComment)mainModule.getById(commentId);
logAdminUsage(aRequest, commentId, "media " + midParam + " deattached");
- editObject(aRequest, aResponse, commentId);
+ editObject(aRequest, aResponse, commentId, null);
}
String searchStatus = requestParser.getParameter("searchstatus");
String searchOrder = requestParser.getParameter("searchorder");
- if (searchIsPublished.equals("0")) {
+ if ("0".equals(searchIsPublished)) {
queryBuilder.appendAndCondition("is_published='f'");
}
- else if (searchIsPublished.equals("1")) {
+ else if ("1".equals(searchIsPublished)) {
queryBuilder.appendAndCondition("is_published='t'");
}
}
if (searchOrder.length()>0) {
- if (searchOrder.equals("datedesc"))
+ if ("datedesc".equals(searchOrder)) {
queryBuilder.appendDescendingOrder("webdb_create");
- else if (searchOrder.equals("dateasc"))
+ }
+ else if ("dateasc".equals(searchOrder)) {
queryBuilder.appendAscendingOrder("webdb_create");
- else if (searchOrder.equals("articletitle"))
+ }
+ else if ("articletitle".equals(searchOrder)) {
queryBuilder.appendAscendingOrder("(select content.title from content where content.id = comment.to_media)");
- else if (searchOrder.equals("creator"))
+ }
+ else if ("creator".equals(searchOrder)) {
queryBuilder.appendDescendingOrder("creator");
+ }
}
returnList(aRequest, aResponse, queryBuilder.getWhereClause(), queryBuilder.getOrderByClause(), 0);
}
- public void articlecomments(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleExc
- {
+ public void articlecomments(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleExc {
String articleIdString = aRequest.getParameter("articleid");
- int articleId;
-
try {
- articleId = Integer.parseInt(articleIdString);
+ int articleId = Integer.parseInt(articleIdString);
returnList( aRequest, aResponse, "to_media="+articleId, "webdb_create desc", 0);
}
Map responseData = ServletHelper.makeGenerationData(aRequest, aResponse, new Locale[] { getLocale(aRequest), getFallbackLocale(aRequest)});
List commentList =
- EntityAdapterEngine.retrieveAdapterList(model, definition, aWhereClause, anOrderByClause, nrEntitiesPerListPage, anOffset);
+ EntityAdapterEngine.retrieveAdapterList(getModel(), definition, aWhereClause,
+ anOrderByClause, nrEntitiesPerListPage, anOffset);
responseData.put("nexturl", null);
responseData.put("prevurl", null);
responseData.put("searchorder", requestParser.getParameter("searchorder"));
urlBuilder.setValue("offset", anOffset);
- responseData.put("offset" , new Integer(anOffset).toString());
+ responseData.put("offset" , Integer.toString(anOffset));
responseData.put("thisurl" , urlBuilder.getQuery());
if (commentList.size()>=nrEntitiesPerListPage) {
String returnUrl = requestParser.getParameter("returnurl");
String idParam = aRequest.getParameter("id");
- if (idParam == null)
+ if (idParam == null) {
throw new ServletModuleExc("Wrong call: (id) is missing");
+ }
Map withValues = getIntersectingValues(aRequest, DatabaseComment.getInstance());
- if (!withValues.containsKey("is_published"))
+ if (!withValues.containsKey("is_published")) {
withValues.put("is_published","0");
- if (!withValues.containsKey("is_html"))
+ }
+ if (!withValues.containsKey("is_html")) {
withValues.put("is_html","0");
+ }
String webdbCreate = (String) withValues.get("webdb_create");
- if (webdbCreate==null || webdbCreate.trim().length()==0)
+ if (webdbCreate==null || webdbCreate.trim().length()==0) {
withValues.remove("webdb_create");
+ }
String id = mainModule.set(withValues);
if (returnUrl!=null){
ServletHelper.redirect(aResponse, returnUrl);
}
- else
- editObject(aRequest, aResponse, idParam);
+ else {
+ editObject(aRequest, aResponse, idParam, null);
+ }
}
catch (Throwable e) {
throw new ServletModuleFailure(e);