*/
package mircoders.servlet;
-import mir.log.LoggerWrapper;
-import mir.servlet.ServletModule;
+import mir.servlet.AdminServletModule;
import mir.servlet.ServletModuleExc;
import mir.util.StringRoutines;
import mircoders.entity.EntityComment;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.Vector;
-public class ServletModuleLocalizer extends ServletModule {
- private static ServletModuleLocalizer instance = new ServletModuleLocalizer();
- public static ServletModule getInstance() { return instance; }
+public class ServletModuleLocalizer extends AdminServletModule {
+ private final ModuleContent contentModule = new ModuleContent();
+ private final ModuleComment commentModule = new ModuleComment();
+ private final List administerOperations = new ArrayList();
- private ModuleContent contentModule;
- private ModuleComment commentModule;
- private List administerOperations;
-
- private ServletModuleLocalizer() {
+ public ServletModuleLocalizer() {
try {
- logger = new LoggerWrapper("ServletModule.Localizer");
-
- contentModule = new ModuleContent();
- commentModule = new ModuleComment();
-
- administerOperations = new Vector();
-
- String settings[] = configuration.getStringArray("Mir.Localizer.Admin.AdministerOperations");
+ String settings[] =
+ getConfiguration().getStringArray("Mir.Localizer.Admin.AdministerOperations");
if (settings!=null) {
for (int i = 0; i < settings.length; i++) {
if (setting.length() > 0) {
List parts = StringRoutines.splitString(setting, ":");
if (parts.size() != 2) {
- logger.error("config error: " + settings[i] + ", 2 parts expected");
+ getLogger().error("config error: " + settings[i] + ", 2 parts expected");
}
else {
Map entry = new HashMap();
}
}
catch (Exception e) {
- logger.error("ServletModuleLocalizer could not be initialized: " + e.getMessage());
+ getLogger().error("ServletModuleLocalizer could not be initialized" + e.getMessage(), e);
}
}
* @param anOperation The identifier of the operation to perform
*/
public void performCommentOperation(HttpServletRequest aRequest, String anId, String anOperation) {
- EntityComment entity;
-
try {
- entity = (EntityComment) commentModule.getById(anId);
+ EntityComment entity = (EntityComment) commentModule.getById(anId);
if (entity != null) {
MirGlobal.performCommentOperation(ServletHelper.getUser(aRequest), entity, anOperation);
- logger.info("Operation " + anOperation + " successfully performed on comment " + anId);
+ getLogger().debug("Operation " + anOperation + " successfully performed on comment " + anId);
logAdminUsage(aRequest, "comment."+anId, "operation " + anOperation + " performed");
}
else {
- logger.error("Error while performing " + anOperation + " on comment " + anId + ": comment is null");
+ getLogger().error("Error while performing " + anOperation + " on comment " + anId + ": comment is null");
}
}
catch (Throwable e) {
- logger.error("Error while performing " + anOperation + " on comment " + anId + ": " + e.getMessage());
+ getLogger().error("Error while performing " + anOperation + " on comment " + anId + ": " + e.getMessage(), e);
}
}
ServletHelper.redirect(aResponse, returnUrlString);
}
+ public void operation(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleExc {
+ String type = aRequest.getParameter("objecttype");
+ String id = aRequest.getParameter("id");
+ String operation = aRequest.getParameter("operation");
+ String returnUrl = aRequest.getParameter("returnurl");
+
+
+ if ("comment".equals(type)) {
+ performCommentOperation(aRequest, id, operation);
+ }
+ else {
+ performArticleOperation(aRequest, id, operation);
+ }
+
+ ServletHelper.redirect(aResponse, returnUrl);
+ }
+
public void commentoperationbatch(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleExc {
String returnUrlString = aRequest.getParameter("returnurl");
List parts = StringRoutines.splitString(operations[i], ";");
if (parts.size() != 2) {
- logger.error("commentoperationbatch: operation string invalid: " +
+ getLogger().error("commentoperationbatch: operation string invalid: " +
operations[i]);
}
else {
ServletHelper.redirect(aResponse, returnUrlString);
}
+ public void operationbatch(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleExc {
+ String returnUrlString = aRequest.getParameter("returnurl");
+
+ String[] operations = aRequest.getParameterValues("operation");
+
+ if (operations!=null) {
+ for (int i = 0; i < operations.length; i++) {
+ if (operations[i].length() > 0) {
+ List parts = StringRoutines.splitString(operations[i], ";");
+
+ if (parts.size() != 3) {
+ getLogger().error("commentoperationbatch: operation string invalid: " +
+ operations[i]);
+ }
+ else {
+ String type = (String) parts.get(0);
+ String id = (String) parts.get(1);
+ String operationString = (String) parts.get(2);
+
+ if ("comment".equals(type)) {
+ performCommentOperation(aRequest, id, operationString);
+ }
+ else {
+ performArticleOperation(aRequest, id, operationString);
+ }
+ }
+ }
+ }
+ }
+
+ ServletHelper.redirect(aResponse, returnUrlString);
+ }
public void performArticleOperation(HttpServletRequest aRequest, String anId, String anOperation) {
EntityContent entity;
if (entity != null) {
MirGlobal.performArticleOperation(ServletHelper.getUser(aRequest), entity, anOperation);
- logger.info("Operation " + anOperation + " successfully performed on article " + anId);
+ getLogger().info("Operation " + anOperation + " successfully performed on article " + anId);
logAdminUsage(aRequest, "article." + anId, "operation " + anOperation + " performed");
}
else {
- logger.error("Error while performing " + anOperation + " on article " + anId + ": article is null");
+ getLogger().error("Error while performing " + anOperation + " on article " + anId + ": article is null");
}
}
catch (Throwable e) {
- logger.error("Error while performing " + anOperation + " on article " + anId + ": " + e.getMessage());
+ getLogger().error("Error while performing " + anOperation + " on article " + anId + ": " + e.getMessage());
}
}
List parts = StringRoutines.splitString(operations[i], ";");
if (parts.size() != 2) {
- logger.error("articleoperationbatch: operation string invalid: " + operations[i]);
+ getLogger().error("articleoperationbatch: operation string invalid: " + operations[i]);
}
else {
String articleIdString = (String) parts.get(0);