X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=source%2Fmircoders%2Flocalizer%2Fbasic%2FMirBasicAdminInterfaceLocalizer.java;h=224d980a34a889c05e6215be136e7c1c52eddee3;hb=8b91e8d8bf4a31a88440a404e83238dcf32f8f4a;hp=74e1b3efd1f38bb5fc029cf46179f2fd860ba4ee;hpb=55d545036aa5c04676f2d20f0e98316a4679ec27;p=mir.git diff --git a/source/mircoders/localizer/basic/MirBasicAdminInterfaceLocalizer.java b/source/mircoders/localizer/basic/MirBasicAdminInterfaceLocalizer.java index 74e1b3ef..224d980a 100755 --- a/source/mircoders/localizer/basic/MirBasicAdminInterfaceLocalizer.java +++ b/source/mircoders/localizer/basic/MirBasicAdminInterfaceLocalizer.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2001, 2002 The Mir-coders group + * Copyright (C) 2001, 2002 The Mir-coders group * * This file is part of Mir. * @@ -18,33 +18,38 @@ * 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 the com.oreilly.servlet library, 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. + * 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; +import java.util.Arrays; import java.util.GregorianCalendar; import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.Vector; import mir.entity.Entity; import mir.entity.adapter.EntityAdapter; +import mir.log.LoggerWrapper; import mir.misc.StringUtil; import mir.storage.StorageObjectFailure; -import mir.util.StringRoutines; +import mir.util.DateTimeFunctions; +import mir.util.EntityUtility; import mircoders.entity.EntityComment; import mircoders.entity.EntityContent; +import mircoders.global.MirGlobal; import mircoders.localizer.MirAdminInterfaceLocalizer; import mircoders.localizer.MirLocalizerExc; import mircoders.localizer.MirLocalizerFailure; @@ -56,9 +61,10 @@ public class MirBasicAdminInterfaceLocalizer implements MirAdminInterfaceLocaliz private Vector simpleArticleOperations; private Map simpleCommentOperationsMap; private Map simpleArticleOperationsMap; - private static SimpleDateFormat dateFormatter = new SimpleDateFormat("dd.MM.yyyy HH:mm"); + protected static LoggerWrapper logger = new LoggerWrapper("Localizer.AdminInterface");; public MirBasicAdminInterfaceLocalizer() throws MirLocalizerFailure, MirLocalizerExc { + simpleCommentOperations = new Vector(); simpleArticleOperations = new Vector(); simpleCommentOperationsMap = new HashMap(); @@ -72,6 +78,10 @@ public class MirBasicAdminInterfaceLocalizer implements MirAdminInterfaceLocaliz addSimpleCommentOperation(new ModifyCommentFieldOperation("hide", "is_published", "0")); } + public String getAdminPageGenerator(String aPage, Map aTemplateData, EntityAdapter aUser, String aDefault) { + return aDefault; + } + public String makePasswordDigest(String aPassword) { return aPassword; } @@ -121,9 +131,11 @@ public class MirBasicAdminInterfaceLocalizer implements MirAdminInterfaceLocaliz protected abstract static class EntityModifyingOperation implements MirSimpleEntityOperation { private String name; + private boolean logOperation; - protected EntityModifyingOperation(String aName) { + protected EntityModifyingOperation(String aName, boolean aLogOperation) { name = aName; + logOperation = aLogOperation; } public String getName() { @@ -140,23 +152,52 @@ public class MirBasicAdminInterfaceLocalizer implements MirAdminInterfaceLocaliz } }; - public void perform(EntityAdapter aUser, EntityAdapter anEntity) { + public void perform(EntityAdapter aUser, EntityAdapter anEntity) throws MirLocalizerExc, MirLocalizerFailure { Entity entity = anEntity.getEntity(); try { performModification(aUser, entity); + + if (logOperation) { + try { + StringBuffer line = new StringBuffer(); + + line.append(DateTimeFunctions.advancedDateFormat( + MirGlobal.config().getString("Mir.DefaultDateTimeFormat"), + (new GregorianCalendar()).getTime(), + MirGlobal.config().getString("Mir.DefaultTimezone"))); + line.append(" "); + if (aUser != null) + line.append(aUser.get("login")); + else + line.append("unknown"); + + line.append(" "); + line.append(getName()); + EntityUtility.appendLineToField(entity, "comment", line.toString()); + } + catch (Throwable t) { + logger.error("Error while trying to log an article operation: " + t.toString()); + } + } + entity.update(); } catch (Throwable t) { + throw new MirLocalizerFailure(t); } }; protected abstract boolean isAvailable(Entity anEntity) throws StorageObjectFailure ; - protected abstract void performModification(EntityAdapter aUser, Entity anEntity) throws StorageObjectFailure ; + protected abstract void performModification(EntityAdapter aUser, Entity anEntity) throws MirLocalizerExc, MirLocalizerFailure ; } public static abstract class CommentModifyingOperation extends EntityModifyingOperation { + public CommentModifyingOperation(String aName, boolean aLogOperation) { + super(aName, aLogOperation); + } + public CommentModifyingOperation(String aName) { - super(aName); + this(aName, true); } protected boolean isAvailable(Entity anEntity) throws StorageObjectFailure { @@ -165,7 +206,7 @@ public class MirBasicAdminInterfaceLocalizer implements MirAdminInterfaceLocaliz protected void performModification(EntityAdapter aUser, Entity anEntity) throws StorageObjectFailure { performModification(aUser, (EntityComment) anEntity); - DatabaseContent.getInstance().setUnproduced("id="+anEntity.getValue("to_media")); + DatabaseContent.getInstance().setUnproduced("id="+anEntity.getFieldValue("to_media")); }; protected abstract boolean isAvailable(EntityComment aComment) throws StorageObjectFailure ; @@ -173,12 +214,8 @@ public class MirBasicAdminInterfaceLocalizer implements MirAdminInterfaceLocaliz } public static abstract class ArticleModifyingOperation extends EntityModifyingOperation { - private boolean logOperation; - public ArticleModifyingOperation(String aName, boolean aLogOperation) { - super(aName); - - logOperation = aLogOperation; + super(aName, aLogOperation); } protected boolean isAvailable(Entity anEntity) throws StorageObjectFailure { @@ -187,29 +224,7 @@ public class MirBasicAdminInterfaceLocalizer implements MirAdminInterfaceLocaliz protected void performModification(EntityAdapter aUser, Entity anEntity) throws StorageObjectFailure { performModification(aUser, (EntityContent) anEntity); - anEntity.setValueForProperty("is_produced", "0"); - - if (logOperation) { - StringBuffer comment = new StringBuffer(); - try { - comment.append(StringRoutines.interpretAsString(anEntity.getValue("comment"))); - } - catch (Throwable t) { - } - if (comment.length()>0 && comment.charAt(comment.length()-1)!='\n') { - comment.append('\n'); - } - comment.append(dateFormatter.format((new GregorianCalendar()).getTime())); - comment.append(" "); - try { - comment.append(StringRoutines.interpretAsString(aUser.get("login"))); - } - catch (Throwable t) { - } - comment.append(" "); - comment.append(getName()); - anEntity.setValueForProperty("comment", comment.toString()); - } + anEntity.setFieldValue("is_produced", "0"); }; protected abstract boolean isAvailable(EntityContent anArticle) throws StorageObjectFailure ; @@ -232,10 +247,37 @@ public class MirBasicAdminInterfaceLocalizer implements MirAdminInterfaceLocaliz } protected void performModification(EntityAdapter aUser, EntityComment aComment) throws StorageObjectFailure { - aComment.setValueForProperty(field, value); + aComment.setFieldValue(field, value); + } + } + + protected static class SetCommentFieldsOperation extends CommentModifyingOperation { + private Map values; + + public SetCommentFieldsOperation(String aName, String aFields[], String aValues[]) throws MirLocalizerExc { + super(aName); + + values = new HashMap(); + + for (int i=0; i